###################################
# Defend Caliphate Ending
###################################
#
## Make it a Pious playthrough that encourage the Caliph to get support from the Muslim world
#### Struggle Persia Ending Assertion Decision ###
#struggle_persia_ending_assertion_decision = {
#	decision_group_type = major
#	title = struggle_persia_ending_assertion
#	picture = {
#		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_supremacy.dds"
#	}
#	extra_picture = "gfx/interface/illustrations/struggle_decision_buttons/fp3_decision_strength.dds"
#	desc = struggle_persia_ending_assertion_decision_desc
#	selection_tooltip = struggle_persia_ending_assertion_tooltip
#	confirm_click_sound = "event:/DLC/FP2/SFX/UI/fp2_struggle_ending_decision_confirm"
#	is_invisible = yes
#	sort_order = 80
#
#	is_valid = {
#		custom_tooltip = {
#			text = struggle_persia_ending_tension_decision_correct_phase_tt
#			any_character_struggle = {
#				involvement = involved
#				is_struggle_type = persian_struggle
#				is_struggle_phase = struggle_persia_phase_stabilisation
#			}
#		}
#		has_trait = fp3_struggle_supporter
#
#		custom_tooltip = {
#			text = struggle_persia_ending_decision_caliphate_exists_tt
#			exists = title:e_arabia.holder
#			title:d_sunni.holder ?= title:e_arabia.holder
#		}
#
#		# > 50% of involved rulers are supporters of the Caliph
#		custom_tooltip = {
#			text = struggle_persia_ending_assertion.l
#			fp3_persia_supporter_rulers_count_value > fp3_persia_supporter_rulers_half_value
#		}
#		
#		custom_tooltip = {
#			text = struggle_persia_ending_assertion.2
#			struggle:persian_struggle = {
#				NOT = {
#					any_involved_ruler = {
#						top_liege = this
#						is_landed = yes
#						highest_held_title_tier >= tier_duchy
#						has_trait = fp3_struggle_detractor
#					}
#				}
#			}
#		}
#		
#		custom_tooltip = {
#			text = struggle_persia_ending_assertion.3
#			struggle:persian_struggle = {
#				NOT = {
#					any_involved_ruler = {
#						top_liege = this
#						is_landed = yes
#						highest_held_title_tier >= tier_duchy
#						faith = {
#							NOT = {
#								has_doctrine = muhammad_succession_sunni_doctrine
#							}
#						}
#					}
#				}
#			}
#		}
#		
#
#		# They need to be super pious
#		piety_level >= very_high_piety_level
#
#		# Specific to the caliph themselves
#		trigger_if = {
#			limit = { fp3_struggle_is_the_caliph = yes }
#			# They need to fully control the abbasids empire
#			completely_controls = title:e_arabia
#		}
#		trigger_else = {
#			custom_tooltip = {
#				text = struggle_persia_strengthen_decision_right_hof_tt
#				faith.religious_head = title:d_sunni.holder
#			}
#			custom_tooltip = {
#				text = struggle_persia_strengthen_decision_alliance_tt
#				any_ally = {
#					this = title:e_arabia.holder
#				}
#			}
#		}
#	}
#
#	is_valid_showing_failures_only = {
#		is_available_adult = yes
#	}
#
#	effect = {
#		if = {
#			limit = { has_dlc_feature = legends }
#			legend_seed_struggle_ending_effect = {
#				ENDER = root
#				STRUGGLE = persian_struggle
#			}
#		}
#		if = {
#			limit = { has_ach_dlc_trigger = yes }
#			add_character_flag = ach_ended_struggle
#		}
#		show_as_tooltip = {
#			fp3_ending_effects_assertion = yes
#		}
#		trigger_event = fp3_struggle.0071
#		
#		if = { # If you can adopt admin government, show a tooltip to explain it - Actual effect is executed in the event
#			limit = {
#				has_dlc_feature = roads_to_power
#				fp3_struggle_is_the_caliph = yes
#				NOT = { government_has_flag = government_is_administrative }
#			}
#			custom_tooltip = adopt_admin_government_tt
#		}
#
#		title:d_sunni = { remove_variable = struggle_block_dissolution_faction }
#		title:e_arabia = { remove_variable = struggle_block_dissolution_faction }
#
#		# Silk Road bonus towards prosperity if and when Persia's turmoil comes to an end
#		tgp_silk_road_iranian_intermezzo_ending_effect = yes
#	}
#	
#	ai_check_interval_by_tier = {
#		barony = 0
#		county = 0
#		duchy = 36
#		kingdom = 36
#		empire = 36
#		hegemony = 36
#	}
#	ai_potential = { always = yes }
#	ai_will_do = { base = 100 }
#}
#
#
####################################
## Humiliate Caliphate Ending
####################################
#
#### Struggle Persia Ending Foundation Decision ###
#struggle_persia_ending_foundation_decision = {
#	decision_group_type = major
#	title = struggle_persia_ending_foundation
#	picture = {
#		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_sunder.dds"
#	}
#	extra_picture = "gfx/interface/illustrations/struggle_decision_buttons/fp3_decision_temper.dds"
#	desc = struggle_persia_ending_foundation_decision_desc
#	selection_tooltip = struggle_persia_ending_foundation_tooltip
#	confirm_click_sound = "event:/DLC/FP2/SFX/UI/fp2_struggle_ending_decision_confirm"
#	is_invisible = yes
#	sort_order = 80
#	
#	is_valid_showing_failures_only = {
#		is_available_adult = yes
#		# Independent
#		top_liege = this
#		# Muslim
#		custom_tooltip = {
#			text = struggle_persia_ending_decision_caliphate_muslim_tt
#			religion = religion:islam_religion
#		}
#		trigger_if = {
#			limit = { exists = title:d_sunni.holder }
#			NOT = { title:d_sunni.holder = root }
#		}
#		trigger_else = {
#			custom_tooltip = {
#				text = struggle_persia_strengthen_decision_right_hof_tt
#				faith.religious_head = title:d_sunni.holder
#			}
#		}
#		
#		# HERE GOES THE SPECIFIC TRIGGERS FOR EACH OPTION - It goes here to make the buttons selectable (UI issue workaround)
#		trigger_if = { # CHALLENGER
#			limit = {  scope:struggle_persia_ending_foundation_decision_option_shia = yes }
#			# Only valid if faith permits HoF
#			custom_tooltip = {
#				text = struggle_persia_ending_foundation_decision_option_hof_tt
#				NOT = {
#					faith = { has_doctrine = doctrine_no_head }
#				}
#			}
#		}
#	}
#
#	is_valid = { # We can skip some of the more elementary checks due to this being struggle-only
#		# Involved & Unrest phase
#		custom_tooltip = {
#			text = struggle_persia_ending_anarchy_decision_correct_phase_tt
#			any_character_struggle = {
#				involvement = involved
#				is_struggle_type = persian_struggle
#				is_struggle_phase = struggle_persia_phase_unrest
#			}
#		}
#		# Detractor
#		has_trait = fp3_struggle_detractor
#		trigger_if = { # CHALLENGER
#			limit = {  scope:struggle_persia_ending_foundation_decision_option_shia = yes }
#			# Only valid if not Ashari
#			custom_tooltip = {
#				text = struggle_persia_ending_foundation_decision_option_succession_tt
#				NOT = {
#					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
#				}
#			}
#		}
#		# King or above
#		highest_held_title_tier >= tier_kingdom
#		# Realm must be bigger than the Caliphate
#		trigger_if = {
#			limit = {
#				exists = title:d_sunni.holder
#			}
#			custom_tooltip = {
#				text = larger_realm_than_caliph
#				sub_realm_size >= title:d_sunni.holder.realm_size
#			}
#		}
#		# At least 2 king tier allies
#		OR = {
#			custom_tooltip = {
#				text = struggle_persia_ending_foundation_decision_nb_ally_tt
#				any_ally = {
#					count >= 2
#					highest_held_title_tier >= tier_kingdom
#				}
#			}
#			sub_realm_size >= 50
#		}
#
#		# HERE GOES THE SPECIFIC TRIGGERS FOR EACH OPTION - It goes here to make the buttons selectable (UI issue workaround)
#		trigger_if = {
#			# CHALLENGER - if you change this, also change the `ai_chance = {}` of the specific widget option below!
#			limit = {  scope:struggle_persia_ending_foundation_decision_option_shia = yes }
#			OR = {
#				any_realm_province = {
#					OR = {
#						custom_tooltip = {
#							text = holy_site_of_root_faith_tt
#							barony = {
#								is_holy_site_of = root.faith
#							}
#						}
#						has_building_or_higher = the_friday_mosque_01
#						has_building_or_higher = house_of_wisdom_01
#						has_building_or_higher = holy_site_great_mosque_of_samarra_01
#						trigger_if = {
#							limit = {
#								root.faith = {
#									has_doctrine = muhammad_succession_shia_doctrine
#								}
#							}
#							has_building_or_higher = holy_site_imam_ali_mosque_01
#						}
#						trigger_if = {
#							limit = {
#								root.faith = {
#									has_doctrine = muhammad_succession_shia_doctrine
#								}
#							}
#							has_building_or_higher = imam_reza_shrine_01
#						}
#					}
#				}
#			}
#			# Muhakkima
#			trigger_if = {
#				limit = {
#					faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
#				}
#				fp3_valid_muhakkima_head = yes
#			}
#			# Shia/Zandaqa
#			trigger_else = { fp3_valid_shia_head = yes }
#			# HoF does not already exist, or isn't of your faith
#			OR = {
#				custom_tooltip = {
#					text = hof_must_not_exist_tt
#					NOT = { exists = faith.religious_head }
#				}
#				custom_tooltip = {
#					text = hof_must_not_be_your_faith_tt
#					faith.religious_head.faith != root.faith
#				}
#				faith.religious_head = root
#			}
#		}
#		trigger_if = { # VASSALIZE - if you change this, also change the `ai_chance = {}` of the specific widget option below!
#			limit = { scope:struggle_persia_ending_foundation_decision_option_vassalize = yes }
#			# Sunni Caliph still holds Arabia
#			custom_tooltip = {
#				text = struggle_persia_ending_decision_caliphate_exists_tt
#				exists = title:d_sunni.holder
#				exists = title:e_arabia.holder
#				title:d_sunni.holder = title:e_arabia.holder
#			}
#			# Piety
#			prestige_level >= high_piety_level
#			# Control historic capital of Caliph
#			completely_controls = title:d_samarra
#			custom_tooltip = {
#				text = fp3_struggle_ending_vassalize_caliph_control_samarra_tt
#				title:c_samarra = {
#					title_held_years >= 5
#					holder = root
#				}
#			}
#			OR = {
#				custom_tooltip = {
#					text = fp3_struggle_ending_vassalize_caliph_control_baghdad_tt
#					title:c_baghdad.holder = root
#				}
#				title:d_sunni.holder = { is_imprisoned_by = root }
#				has_strong_hook = title:d_sunni.holder
#			}
#		}
#	}
#
#	widget = {
#		gui = "decision_view_widget_fp3_foundation_ending"
#		controller = decision_option_list_controller
#		decision_to_second_step_button = "struggle_persia_ending_foundation_button_text"
#		show_from_start = yes
#
#		item = { # SHIA CALIPHATE
#			value = struggle_persia_ending_foundation_decision_option_shia
#
#			current_description = struggle_persia_ending_foundation_decision_option_shia_desc
#			localization = struggle_persia_ending_foundation_decision_option_shia
#			icon = "gfx/interface/icons/faith/shia.dds"
#
#			# ADD THE OPTION-SPECIFIC REQUIREMENTS FOR THE OPTION - This makes the AI actually be select the 'second' option if it is available
#            # ALSO - This also fixes alerts for Players, since their default option will be the one with the highest score
#			ai_chance = {
#				value = ai_zeal
#
#				if = { # CHALLENGER - if you change this, also change the `is_valid = {}` of the decision!
#	                limit = {
#	                    OR = {
#	                        any_realm_province = {
#	                            OR = {
#	                                custom_tooltip = {
#	                                    text = holy_site_of_root_faith_tt
#	                                    barony = {
#	                                        is_holy_site_of = root.faith
#	                                    }
#	                                }
#	                                has_building_or_higher = the_friday_mosque_01
#	                                has_building_or_higher = house_of_wisdom_01
#	                                has_building_or_higher = holy_site_great_mosque_of_samarra_01
#	                                trigger_if = {
#	                                    limit = {
#	                                        root.faith = {
#	                                            has_doctrine = muhammad_succession_shia_doctrine
#	                                        }
#	                                    }
#	                                    has_building_or_higher = holy_site_imam_ali_mosque_01
#	                                }
#	                                trigger_if = {
#	                                    limit = {
#	                                        root.faith = {
#	                                            has_doctrine = muhammad_succession_shia_doctrine
#	                                        }
#	                                    }
#	                                    has_building_or_higher = imam_reza_shrine_01
#	                                }
#	                            }
#	                        }
#	                    }
#	                    # Muhakkima
#	                    trigger_if = {
#	                        limit = {
#	                            faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
#	                        }
#	                        fp3_valid_muhakkima_head = yes
#	                    }
#	                    # Shia/Zandaqa
#	                    trigger_else = { fp3_valid_shia_head = yes }
#	                    # HoF does not already exist, or isn't of your faith
#	                    OR = {
#	                        custom_tooltip = {
#	                            text = hof_must_not_exist_tt
#	                            NOT = { exists = faith.religious_head }
#	                        }
#	                        custom_tooltip = {
#	                            text = hof_must_not_be_your_faith_tt
#	                            faith.religious_head.faith != root.faith
#	                        }
#	                        faith.religious_head = root
#	                    }
#	                }
#	                add = 100
#	            }
#			}
# 		}
#
#		item = { # VASSALIZE THE CALIPH
#			value = struggle_persia_ending_foundation_decision_option_vassalize
#
#			current_description = struggle_persia_ending_foundation_decision_option_vassalize_desc
#			localization = struggle_persia_ending_foundation_decision_option_vassalize
#			icon = "gfx/interface/icons/faith/sunni.dds"
#
#			# ADD THE OPTION-SPECIFIC REQUIREMENTS FOR THE OPTION - This makes the AI actually be select the 'second' option if it is available
#       		# ALSO - This also fixes alerts for Players, since their default option will be the one with the highest score
#			ai_chance = {
#				value = ai_zeal
#
#	            if = { # VASSALIZE - if you change this, also change the `is_valid = {}` of the decision!
#                    limit = {
#                        # Sunni Caliph still holds Arabia
#                        custom_tooltip = {
#                            text = struggle_persia_ending_decision_caliphate_exists_tt
#                            exists = title:d_sunni.holder
#                            exists = title:e_arabia.holder
#                            title:d_sunni.holder = title:e_arabia.holder
#                        }
#                        # Piety
#                        prestige_level >= high_piety_level
#                        # Control historic capital of Caliph
#                        completely_controls = title:d_samarra
#                        custom_tooltip = {
#                            text = fp3_struggle_ending_vassalize_caliph_control_samarra_tt
#                            title:c_samarra = {
#                                title_held_years >= 5
#                                holder = root
#                            }
#                        }
#                        OR = {
#                            custom_tooltip = {
#                                text = fp3_struggle_ending_vassalize_caliph_control_baghdad_tt
#                                title:c_baghdad.holder = root
#                            }
#                            title:d_sunni.holder = { is_imprisoned_by = root }
#                            has_strong_hook = title:d_sunni.holder
#                        }
#                    }
#                    add = 100
#                }
#			}
#		}
#	}
#
#	effect = {
#		if = {
#			limit = { has_dlc_feature = legends }
#			legend_seed_struggle_ending_effect = {
#				ENDER = root
#				STRUGGLE = persian_struggle
#			}
#		}
#		if = {
#			limit = { has_ach_dlc_trigger = yes }
#			add_character_flag = ach_ended_struggle
#		}
#		if = { # Shia Caliphate
#			limit = { scope:struggle_persia_ending_foundation_decision_option_shia = yes }
#			custom_tooltip = struggle_persia_ending_foundation_decision_option.t.shia
#
#			trigger_event = fp3_struggle.0095
#
#			show_as_tooltip = {
#				fp3_struggle_ending_shia_caliphate_effects = yes
#				struggle:persian_struggle = { end_struggle = yes }
#			}
#		}
#		else_if = { # Vassalize Caliphate
#			limit = { scope:struggle_persia_ending_foundation_decision_option_vassalize = yes }
#			custom_tooltip = struggle_persia_ending_foundation_decision_option.t.vassalize
#
#			trigger_event = fp3_struggle.0100
#
#			show_as_tooltip = {
#				fp3_struggle_ending_vassalize_caliph_effects = yes
#				struggle:persian_struggle = { end_struggle = yes }
#			}
#		}
#		else = {
#			custom_tooltip = struggle_persia_ending_foundation_decision_option.t_selected_foundation.none # QoL addition
#			assert_if = { # Just in case
#				limit = { always = yes }
#				text = "Persian Struggle ended with foundation ending but had an invalid or missing widget item value!"
#			}
#		}
#
#		title:d_sunni = { remove_variable = struggle_block_dissolution_faction }
#		title:e_arabia = { remove_variable = struggle_block_dissolution_faction }
#		
#		# Silk Road bonus towards prosperity if and when Persia's turmoil comes to an end
#		tgp_silk_road_iranian_intermezzo_ending_effect = yes
#	}
#	
#	# Kingdom+ only
#	ai_check_interval_by_tier = {
#		barony = 0
#		county = 0
#		duchy = 0
#		kingdom = 36
#		empire = 36
#		hegemony = 36
#	}
#	ai_potential = { always = yes }
#	ai_will_do = { base = 100 }
#}
#
####################################
## Resurgent Persia Ending
####################################
#
#### Struggle Persia Ending Rekindle Iran Decision ###
#struggle_persia_ending_rekindle_iran_decision = {
#	decision_group_type = major
#	title = struggle_persia_ending_rekindle_iran
#	picture = {
#		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_foundation.dds"
#	}
#	extra_picture = "gfx/interface/illustrations/struggle_decision_buttons/fp3_decision_foundation.dds"
#	desc = struggle_persia_ending_rekindle_iran_decision_desc
#	selection_tooltip = struggle_persia_ending_rekindle_iran_tooltip
#	confirm_click_sound = "event:/DLC/FP2/SFX/UI/fp2_struggle_ending_decision_confirm"
#	is_invisible = yes
#	sort_order = 80
#
#	is_valid_showing_failures_only = {
#		is_available_adult = yes
#		# Independent
#		top_liege = this
#	}
#
#	is_valid = { # We can skip some of the more elementary checks due to this being struggle-only
#		# Involved
#		custom_tooltip = {
#			text = struggle_ending_decision_correct_involvement_tt
#			any_character_struggle = {
#				involvement = involved
#				is_struggle_type = persian_struggle
#			}
#		}
#		# Iranian
#		custom_tooltip = {
#			text = struggle_persia_ending_rekindle_iran_decision_heritage_tt
#			culture = { has_cultural_pillar = heritage_iranian }
#		}
#		# At least a king
#		highest_held_title_tier >= tier_kingdom
#		# Famed
#		prestige_level >= very_high_prestige_level
#		# Control enough of Persia
#		custom_tooltip = {
#			text = struggle_persia_ending_rekindle_iran_decision_region_control_tt
#			any_county_in_region = {
#				region = world_persian_empire
#				percent >= fp3_persia_owned_for_rekindle_persia_decimal_value
#				holder.top_liege = root
#			}
#		}
#		OR = {
#			# Iranian allies
#			custom_tooltip = {
#				text = struggle_persia_ending_rekindle_iran_decision_nb_ally_tt
#				any_ally = {
#					count >= 2
#					top_liege = this
#					primary_title = { is_mercenary_company = no }
#					primary_title = { is_holy_order = no }
#					highest_held_title_tier = tier_kingdom
#					culture = { has_cultural_pillar = heritage_iranian }
#				}
#			}
#			custom_tooltip = {
#				text = struggle_persia_ending_rekindle_iran_decision_iranian_sub_realm_counties_tt
#				any_sub_realm_county = {
#					count >= 40
#					culture = { has_cultural_pillar = heritage_iranian }
#				}
#			}
#		}
#		# Iranian rulers
#		custom_tooltip = {
#			text = struggle_persia_ending_rekindle_iran_decision_iranian_rulers_tt
#			fp3_persia_iranian_rulers_count_value >= fp3_persia_all_rulers_requirement_value
#		}
#
#		trigger_if = {
#			limit = { scope:struggle_persia_ending_rekindle_iran_decision_option_secret_faith = yes }
#			custom_tooltip = {
#				text = struggle_persia_ending_rekindle_iran_decision_secret_tt
#				any_secret = { type = secret_crypto_religionist }
#			}
#		}
#	}
#
#	widget = {
#		gui = "decision_view_widget_fp3_foundation_ending"
#		controller = decision_option_list_controller
#		decision_to_second_step_button = "struggle_persia_ending_rekindle_iran_button_text"
#
#		item = { # PUBLIC FAITH
#			value = struggle_persia_ending_rekindle_iran_decision_option_public_faith
#
#			current_description = struggle_persia_ending_rekindle_iran_decision_option_public_faith_desc
#			localization = struggle_persia_ending_rekindle_iran_decision_option_public_faith
#			icon = "gfx/interface/icons/character_interactions/religious.dds"
#			ai_chance = { value = ai_zeal }
# 		}
#
#		item = { # SECRET FAITH
#			value = struggle_persia_ending_rekindle_iran_decision_option_secret_faith
#			is_valid = {
#				exists = secret_faith
#			}
#			current_description = struggle_persia_ending_rekindle_iran_decision_option_secret_faith_desc
#			localization = struggle_persia_ending_rekindle_iran_decision_option_secret_faith
#			icon = "gfx/interface/icons/character_interactions/icon_scheme_crypto_religion.dds"
#			ai_chance = { value = ai_zeal }
#		}
#	}
#
#	effect = {
#		if = {
#			limit = { has_dlc_feature = legends }
#			legend_seed_struggle_ending_effect = {
#				ENDER = root
#				STRUGGLE = persian_struggle
#			}
#		}
#		if = {
#			limit = { has_ach_dlc_trigger = yes }
#			add_character_flag = ach_ended_struggle
#		}
#		if = {
#			limit = { scope:struggle_persia_ending_rekindle_iran_decision_option_secret_faith = yes }
#			if = {
#				limit = { exists = secret_faith }
#				secret_faith = { save_scope_as = propagated_faith }
#			}
#			else = {
#				faith =  { save_scope_as = propagated_faith }
#			}
#		}
#		else = {
#			faith =  { save_scope_as = propagated_faith }
#		}
#		trigger_event = fp3_struggle.0091
#		show_as_tooltip = { # Fake effects, custom-made to be readable (and also a summary of what happens across several events for OOP/UX reasons)
#			struggle:persian_struggle = { end_struggle = yes }
#
#			fp3_struggle_rekindle_iran_effects = yes
#		}
#
#		title:d_sunni = { remove_variable = struggle_block_dissolution_faction }
#		title:e_arabia = { remove_variable = struggle_block_dissolution_faction }
#		
#		# Silk Road bonus towards prosperity if and when Persia's turmoil comes to an end
#		tgp_silk_road_iranian_intermezzo_ending_effect = yes
#	}
#
#	# Kingdom+ only
#	ai_check_interval_by_tier = {
#		barony = 0
#		county = 0
#		duchy = 0
#		kingdom = 36
#		empire = 36
#		hegemony = 36
#	}
#	ai_potential = { always = yes }
#	ai_will_do = { base = 100 }
#}
#
###################################
# Favour Skilled Outsiders
# By Ewan Cowhig Croft
###################################

# Bring in skilled characters that like you at the cost of offending your other vassals.
### Favor Skilled Outsiders ###
favour_skilled_outsiders_decision = {
	desc = favour_skilled_outsiders_decision_desc
	confirm_text = favour_skilled_outsiders_decision_confirm
	selection_tooltip = favour_skilled_outsiders_decision_tooltip
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
	}
	sort_order = 90
	decision_group_type = courtier
	
	is_shown = {
		has_fp3_dlc_trigger = yes
		is_landed = yes
		favour_skilled_outsiders_decision_valid_character_to_take_trigger = yes
	}

	is_valid = {
		any_sub_realm_county = { favour_skilled_outsiders_decision_valid_county_to_generate_trigger = yes }
		favour_skilled_outsiders_decision_valid_character_to_take_trigger = yes
		realm_size >= medium_realm_size
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war = no
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "favour_skilled_outsiders_decision.second_step"

		# Diplomacy-Martial: Eloquent Captains
		item = {
			value = outsider_diplomacy_martial
			current_description = favour_skilled_outsiders_decision.tt.diplomacy_martial
			localization = favour_skilled_outsiders_decision.tt.diplomacy_martial
			icon = "gfx/interface/icons/message_feed/a_catch_all_councillor_icon.dds"
			is_valid = {
				custom_tooltip = {
					text = COUNCILLOR_MISSING_CHANCELLOR
					exists = cp:councillor_chancellor
				}
				trigger_if = {
					limit = { exists = cp:councillor_chancellor }
					cp:councillor_chancellor = { diplomacy < favour_skilled_outsiders_decision_skill_threshold_value }
					# And an extra tooltip for narrative clarity.
					custom_tooltip = {
						text = favour_skilled_outsiders_decision.tt.skilled_councillor_keeps_clean_house
						cp:councillor_chancellor = { diplomacy < favour_skilled_outsiders_decision_skill_threshold_value }
					}
				}
			}
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = diplomacy
				subtract = martial
			}
		}
		# Martial-Prowess: Career Soldiers
		item = {
			value = outsider_martial_prowess
			current_description = favour_skilled_outsiders_decision.tt.martial_prowess
			localization = favour_skilled_outsiders_decision.tt.martial_prowess
			icon = "gfx/interface/icons/message_feed/mercenary.dds"
			is_valid = {
				custom_tooltip = {
					text = COUNCILLOR_MISSING_MARSHAL
					exists = cp:councillor_marshal
				}
				trigger_if = {
					limit = { exists = cp:councillor_marshal }
					cp:councillor_marshal = { martial < favour_skilled_outsiders_decision_skill_threshold_value }
					# And an extra tooltip for narrative clarity.
					custom_tooltip = {
						text = favour_skilled_outsiders_decision.tt.skilled_councillor_keeps_clean_house
						cp:councillor_marshal = { martial < favour_skilled_outsiders_decision_skill_threshold_value }
					}
				}
			}
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = martial
				subtract = prowess
			}
		}
		# Prowess-Learning: Fringe Nobility
		item = {
			value = outsider_prowess_learning
			current_description = favour_skilled_outsiders_decision.tt.prowess_learning
			localization = favour_skilled_outsiders_decision.tt.prowess_learning
			icon = "gfx/interface/icons/message_feed/tier_down.dds"
			# Always valid.
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = prowess
				subtract = learning
			}
		}
		# Learning-Intrigue: Dedicated Functionaries
		item = {
			value = outsider_learning_intrigue
			current_description = favour_skilled_outsiders_decision.tt.learning_intrigue
			localization = favour_skilled_outsiders_decision.tt.learning_intrigue
			icon = "gfx/interface/icons/message_feed/secret.dds"
			is_valid = {
				custom_tooltip = {
					text = COUNCILLOR_MISSING_COURT_CHAPLAIN
					exists = cp:councillor_court_chaplain
				}
				trigger_if = {
					limit = { exists = cp:councillor_court_chaplain }
					cp:councillor_court_chaplain = { learning < favour_skilled_outsiders_decision_skill_threshold_value }
					# And an extra tooltip for narrative clarity.
					custom_tooltip = {
						text = favour_skilled_outsiders_decision.tt.skilled_councillor_keeps_clean_house
						cp:councillor_court_chaplain = { learning < favour_skilled_outsiders_decision_skill_threshold_value }
					}
				}
			}
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = learning
				subtract = intrigue
			}
		}
		# Intrigue-Stewardship: Cunning Officials
		item = {
			value = outsider_intrigue_stewardship
			current_description = favour_skilled_outsiders_decision.tt.intrigue_stewardship
			localization = favour_skilled_outsiders_decision.tt.intrigue_stewardship
			icon = "gfx/interface/icons/message_feed/spy_master.dds"
			is_valid = {
				custom_tooltip = {
					text = COUNCILLOR_MISSING_SPYMASTER
					exists = cp:councillor_spymaster
				}
				trigger_if = {
					limit = { exists = cp:councillor_spymaster }
					cp:councillor_spymaster = { intrigue < favour_skilled_outsiders_decision_skill_threshold_value }
					# And an extra tooltip for narrative clarity.
					custom_tooltip = {
						text = favour_skilled_outsiders_decision.tt.skilled_councillor_keeps_clean_house
						cp:councillor_spymaster = { intrigue < favour_skilled_outsiders_decision_skill_threshold_value }
					}
				}
			}
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = intrigue
				subtract = stewardship
			}
		}
		# Stewardship-Diplomacy: Skilled Administrators
		item = {
			value = outsider_stewardship_diplomacy
			current_description = favour_skilled_outsiders_decision.tt.stewardship_diplomacy
			localization = favour_skilled_outsiders_decision.tt.stewardship_diplomacy
			icon = "gfx/interface/icons/message_feed/money.dds"
			is_valid = {
				custom_tooltip = {
					text = COUNCILLOR_MISSING_STEWARD
					exists = cp:councillor_steward
				}
				trigger_if = {
					limit = { exists = cp:councillor_steward }
					cp:councillor_steward = { stewardship < favour_skilled_outsiders_decision_skill_threshold_value }
					# And an extra tooltip for narrative clarity.
					custom_tooltip = {
						text = favour_skilled_outsiders_decision.tt.skilled_councillor_keeps_clean_house
						cp:councillor_steward = { stewardship < favour_skilled_outsiders_decision_skill_threshold_value }
					}
				}
			}
			ai_chance = {
				# The AI wants to recruit characters that compensate for their skills.
				## So we set a high base.
				value = 100
				## Then we subtract root's relevant skills.
				subtract = stewardship
				subtract = diplomacy
			}
		}
	}

	effect = {
		# So here's what'll happen.
		custom_tooltip = favour_skilled_outsiders_decision.tt.promote_minorities_from_within_realm
		custom_tooltip = favour_skilled_outsiders_decision.tt.two_batches_to_choose_from
		# And how people will react.
		show_as_tooltip = { favour_skilled_outsiders_decision_apply_opinions_effect = yes }
		# Save how much prestige we paid in case we back out.
		save_scope_value_as = {
			name = prestige_cost
			value = favour_skilled_outsiders_decision_prestige_cost_value
		}
		# Now fire the actual event.
		trigger_event = fp3_misc_decisions.0032
	}

	cooldown = { years = 25 }
	
	cost = { prestige = favour_skilled_outsiders_decision_prestige_cost_value }

	ai_check_interval = 0

	ai_potential = {
		# Check this stuff early, else we'll go through a bunch of county checks unnecessarily.
		favour_skilled_outsiders_decision_valid_character_to_take_trigger = yes
		# Plus simple validity checks.
		is_adult = yes
		is_at_war = no
	}

	ai_will_do = {
		# We don't want to use this too much - the AI is gonna have trouble utilising such characters correctly.
		base = -50

		# Missing councillors.
		## Chancellor
		modifier = {
			add = 50
			NOT = { exists = cp:councillor_chancellor }
		}
		## Steward
		modifier = {
			add = 50
			NOT = { exists = cp:councillor_steward }
		}
		## Marshal
		modifier = {
			add = 50
			NOT = { exists = cp:councillor_marshal }
		}
		## Spymaster
		modifier = {
			add = 50
			NOT = { exists = cp:councillor_spymaster }
		}
		## Court_chaplain
		modifier = {
			add = 50
			NOT = { exists = cp:councillor_court_chaplain }
		}
		modifier = {
			add = 50
			has_any_kurultai_trigger = no
		}
		# Government.
		## Teensy upweight for clans, as the model for the decision.
		modifier = {
			add = 20
			government_has_flag = government_is_clan
		}
		# Traits.
		## Calm
		modifier = {
			add = 15
			has_trait = calm
		}
		## Humble
		modifier = {
			add = 15
			has_trait = humble
		}
		## Ambitious
		modifier = {
			add = 15
			has_trait = ambitious
		}
	}
}

####################################
## Sunder Caliphate Ending
####################################
#### Destroy the Caliphate ###
#fp3_sunder_the_caliphate_decision = {
#	decision_group_type = major
#	title = fp3_sunder_the_caliphate_decision
#	picture = {
#		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_strength.dds"
#	}
#	extra_picture = "gfx/interface/illustrations/struggle_decision_buttons/fp3_decision_assertion.dds" # Does this need to be updated?
#	desc = fp3_sunder_the_caliphate_decision_desc
#	selection_tooltip = fp3_sunder_the_caliphate_decision_tooltip
#	sort_order = 80
#
#	is_shown = {
#		is_landless_adventurer = no
#		exists = title:d_sunni.holder
#		NOR = {
#			this = title:d_sunni.holder
#			house = title:d_sunni.holder.house
#		}
#		any_character_struggle = {
#			involvement = involved
#			is_struggle_type = persian_struggle
#		}
#	}
#
#	is_valid = {
#		highest_held_title_tier >= tier_kingdom
#		custom_tooltip = {
#			text = struggle_persia_ending_foundation_decision_option_succession_tt
#			NOT = {
#				faith = { has_doctrine = muhammad_succession_sunni_doctrine }
#			}
#		}
#		custom_tooltip = {
#			text = fp3_caliph_is_imprisoned_by_you
#			any_prisoner = {
#				any_held_title = {
#					this = title:d_sunni
#				}
#			}
#		}
#		custom_tooltip = {
#			text = fp3_caliph_faith_is_hostile_or_higher
#			faith = {
#			faith_hostility_level = {
#					target = title:d_sunni.holder.faith
#					value >= religious_cb_enabled_hostility_level
#				}
#			}
#		}
#
#
#		piety_level >= high_piety_level
#
#		completely_controls = title:d_samarra
#	}
#
#	is_valid_showing_failures_only = {
#		is_available_adult = yes
#	}
#
#	effect = {
#		if = {
#			limit = { has_dlc_feature = legends }
#			legend_seed_struggle_ending_effect = {
#				ENDER = root
#				STRUGGLE = persian_struggle
#			}
#			
#		}
#		if = {
#			limit = { has_ach_dlc_trigger = yes }
#			add_character_flag = ach_ended_struggle
#		}
#		
#		title:d_sunni.holder = {
#			save_scope_as = the_caliph
#		}
#		show_as_tooltip = {
#			fp3_sundered_caliphate_effects = yes
#		}
#		trigger_event = fp3_struggle.0191
#
#		title:d_sunni = { remove_variable = struggle_block_dissolution_faction }
#		title:e_arabia = { remove_variable = struggle_block_dissolution_faction }
#	}
#
#	cost = {
#		piety = massive_piety_value
#	}
#
#	ai_check_interval_by_tier = {
#		barony = 0
#		county = 0
#		duchy = 0
#		kingdom = 120
#		empire = 120
#		hegemony = 120
#	}
#	ai_potential = { always = yes }
#	ai_will_do = { base = 100 }
#}
#
###################################
# Become a Clan Government
###################################
### Adopt Clan Ways through House ###
fp3_become_clan_government_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/friendly.dds"
	}
	desc = fp3_become_clan_government_decision_desc
	selection_tooltip = fp3_become_clan_government_decision_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 64
		duchy = 64
		kingdom = 64
		empire = 64
		hegemony = 64
	}

	cost = { prestige = major_prestige_value }

	is_shown = {
		has_fp3_dlc_trigger = yes
		# You are Feudal
		government_has_flag = government_is_feudal
		# Has a House and is not House Head
		exists = house
		house.house_head != root
		# Religion is Islam (Clan)
		religion = religion:islam_religion
		# House head is Clan
		house.house_head = { government_has_flag = government_is_clan }
	}

	is_valid = {
		# You are Feudal
		custom_tooltip = {
			text = government_is_feudal_tt
			government_has_flag = government_is_feudal
		}
		# Religion is Islam (Clan)
		religion = religion:islam_religion
		# House head is Clan
		custom_tooltip = {
			text = fp3_become_clan_government_decision_house_head_tt
			house.house_head = { government_has_flag = government_is_clan }
		}
	}

	effect = {
#		legend_seed_struggle_ending_effect = {
#			ENDER = root
#			STRUGGLE = persian_struggle
#		}
		if = {
			limit = { has_ach_dlc_trigger = yes }
			add_character_flag = ach_ended_struggle
		}
		show_as_tooltip ={
			change_government = clan_government
			# Increase unity, uses this effect since both chars are not clan when script is evaluated
			house.house_head = {
				apply_clan_unity_interaction_effect = {
					CHARACTER = root
					TARGET = root.house.house_head
					DESC = clan_unity_adopt_clan.desc
					VALUE = medium_unity_gain
					VALUE_REVERSED = no
				}
			}
		}
		trigger_event = fp3_misc_decisions.0051
	}

	ai_will_do = {
		base = -25
		# More likely if Clan preferred culture
		modifier = {
			add = 10
			culture = {
				OR = {
					has_cultural_pillar = heritage_arabic
					has_cultural_pillar = heritage_iranian
					has_cultural_pillar = heritage_turkic
				}
			}
		}
		# More likely if a fan of House Head
		opinion_modifier = {
			opinion_target = house.house_head
			multiplier = 0.5
		}
	}
}
