establish_muslim_tributary_vassal = {
	category = influence

	alert_index = 6
	alert_tooltip = establish_muslim_tributary_vassal_alert_tooltip

	require_acceptance = yes

	is_visible = {
		can_create_subject_type = {
			subject = FROM
			subject_type = muslim_tributary_vassal
		}
	}

	is_allowed = {
		can_create_subject_type = {
			subject = FROM
			subject_type = muslim_tributary_vassal
		}
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		NOT = { truce_with = FROM }
		FROM = {
			NOT = { num_of_cities = ROOT }
		}
		army_size = 20
	}

	on_accept = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = muslim_tributary_vassal
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				NOT = { truce_with = FROM }
				FROM = {
					NOT = { num_of_cities = ROOT }
				}
				army_size = 20
			}
			create_subject = {
				subject = FROM
				subject_type = muslim_tributary_vassal
				keep_liberty_desire = yes
			}
			add_piety = 0.05
			FROM = {
				country_event = { id = subjects_expanded_muslim_tributary_vassal_events.1 }
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = muslim_tributary_vassal
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				NOT = { truce_with = FROM }
				FROM = {
					NOT = { num_of_cities = ROOT }
				}
				army_size = 20
			}
			FROM = {
				clr_country_flag = declined_establish_muslim_tributary_vassal_@ROOT
				set_country_flag = declined_establish_muslim_tributary_vassal_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_establish_muslim_tributary_vassal_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = FROM_IS_VASSAL_OF_ROOT
			limit = {
				overlord_of = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
		}
		add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				overlord_of = FROM
				FROM = {
					liberty_desire = 50
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_threatened }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 4 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 2 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_DEVELOPMENT
			export_to_variable = {
				which = ai_value
				value = trigger_value:total_development
				who = FROM
			}
			#subtract_variable = { which = ai_value value = 1 }
			divide_variable = { which = ai_value value = -2 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					NOT = { check_variable = { which = military_power value = -39 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = -39 }
					NOT = { check_variable = { which = military_power value = 30 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 0
			}
			export_to_variable = {
				which = our_mil_tech
				value = trigger_value:mil_tech
			}
			export_to_variable = {
				which = their_mil_tech
				value = trigger_value:mil_tech
				who = FROM
			}
			export_to_variable = {
				which = our_army_size
				value = trigger_value:army_size
			}
			export_to_variable = {
				which = their_army_size
				value = trigger_value:army_size
				who = FROM
			}
			divide_variable = { which = our_army_size value = 10 }
			divide_variable = { which = their_army_size value = -10 }
			change_variable = { which = our_army_size which = their_army_size }
			multiply_variable = { which = their_mil_tech value = -1 }
			change_variable = { which = our_mil_tech which = their_mil_tech }
			multiply_variable = { which = our_mil_tech value = 3 }
			change_variable = { which = ai_value which = our_army_size }
			change_variable = { which = ai_value which = our_mil_tech }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = 30 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
		}
		add_entry = {
			name = FROM_IS_HRE_MEMBER
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_SUBJECTS
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					num_of_subjects = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_PAPAL_STATE
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					tag = PAP
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_ALLIED_TO_PAPAL_STATE
			limit = {
				FROM = {
					religion = catholic
					OR = {
						alliance_with = PAP
						guaranteed_by = PAP
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_DEFENDER_OF_FAITH
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					is_defender_of_faith = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_ALLIED_TO_DEFENDER_OF_FAITH
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					any_ally = {
						religion = PREV
						is_defender_of_faith = yes
						NOT = { army_size = ROOT }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_ALLIED_TO_DEFENDER_OF_FAITH
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					any_ally = {
						religion = PREV
						is_defender_of_faith = yes
						army_size = ROOT
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				any_owned_province = {
					is_core = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_A_REPUBLIC
			limit = {
				FROM = {
					government = republic
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_A_THEOCRACY
			limit = {
				FROM = {
					government = theocracy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_EMPEROR
			limit = {
				FROM = {
					is_emperor = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_ALLIED_TO_EMPEROR
			limit = {
				FROM = {
					OR = {
						any_ally = {
							is_emperor = yes
						}
						guaranteed_by = emperor
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_ALLIES
			limit = {
				FROM = {
					any_ally = {
						NOT = { tag = ROOT }
						army_size = 20
					}
					NOT = {
						calc_true_if = {
							all_ally = {
								NOT = { tag = ROOT }
								army_size = 20
							}
							amount = 2
						}
					}
					NOT = {
						any_ally = {
							NOT = { tag = ROOT }
							OR = {
								army_size = 100
								military_strength = { who = ROOT value = 2 }
							}
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_ALLIES
			limit = {
				FROM = {
					calc_true_if = {
						all_ally = {
							NOT = { tag = ROOT }
							army_size = 20
						}
						amount = 2
					}
					NOT = {
						any_ally = {
							NOT = { tag = ROOT }
							OR = {
								army_size = 100
								military_strength = { who = ROOT value = 2 }
							}
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_ALLIES
			limit = {
				FROM = {
					any_ally = {
						NOT = { tag = ROOT }
						OR = {
							army_size = 100
							military_strength = { who = ROOT value = 2 }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_GUARANTEES
			limit = {
				any_country = {
					NOT = { tag = ROOT }
					FROM = {
						guaranteed_by = PREV
					}
					army_size = 20
				}
				NOT = {
					calc_true_if = {
						all_country = {
							NOT = { tag = ROOT }
							FROM = {
								guaranteed_by = PREV
							}
							army_size = 20
						}
						amount = 2
					}
				}
				NOT = {
					any_country = {
						NOT = { tag = ROOT }
						FROM = {
							guaranteed_by = PREV
						}
						OR = {
							army_size = 100
							military_strength = { who = ROOT value = 2 }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_GUARANTEES
			limit = {
				calc_true_if = {
					all_country = {
						NOT = { tag = ROOT }
						FROM = {
							guaranteed_by = PREV
						}
						army_size = 20
					}
					amount = 2
				}
				NOT = {
					any_country = {
						NOT = { tag = ROOT }
						FROM = {
							guaranteed_by = PREV
						}
						OR = {
							army_size = 100
							military_strength = { who = ROOT value = 2 }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_STRONG_GUARANTEES
			limit = {
				any_country = {
					NOT = { tag = ROOT }
					FROM = {
						guaranteed_by = PREV
					}
					OR = {
						army_size = 100
						military_strength = { who = ROOT value = 2 }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_SOME_MUSLIM_PROVINCES
			limit = {
				FROM = {
					OR = {
						num_of_religion = { religion = sunni value = 0.1 }
						num_of_religion = { religion = shiite value = 0.1 }
						num_of_religion = { religion = ibadi value = 0.1 }
					}
					NOT = { dominant_religion = sunni }
					NOT = { dominant_religion = shiite }
					NOT = { dominant_religion = ibadi }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_MUSLIM_DOMINANT_FAITH
			limit = {
				FROM = {
					OR = {
						dominant_religion = sunni
						dominant_religion = shiite
						dominant_religion = ibadi
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_ARE_ALLIED
			limit = {
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_FRIENDS
			limit = {
				FROM = {
					historical_friend_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_RIVALS
			limit = {
				FROM = {
					historical_rival_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_ROOT_RIVALS
			limit = {
				any_country = {
					OR = {
						alliance_with = FROM
						FROM = {
							guaranteed_by = PREV
						}
					}
					OR = {
						is_enemy = ROOT
						is_rival = ROOT
					}
				}
				NOT = {
					calc_true_if = {
						all_country = {
							OR = {
								alliance_with = FROM
								FROM = {
									guaranteed_by = PREV
								}
							}
							OR = {
								is_enemy = ROOT
								is_rival = ROOT
							}
						}
						amount = 2
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_ROOT_RIVALS
			limit = {
				calc_true_if = {
					all_country = {
						OR = {
							alliance_with = FROM
							FROM = {
								guaranteed_by = PREV
							}
						}
						OR = {
							is_enemy = ROOT
							is_rival = ROOT
						}
					}
					amount = 2
				}
				NOT = {
					calc_true_if = {
						all_country = {
							OR = {
								alliance_with = FROM
								FROM = {
									guaranteed_by = PREV
								}
							}
							OR = {
								is_enemy = ROOT
								is_rival = ROOT
							}
						}
						amount = 3
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_ROOT_RIVALS
			limit = {
				calc_true_if = {
					all_country = {
						OR = {
							alliance_with = FROM
							FROM = {
								guaranteed_by = PREV
							}
						}
						OR = {
							is_enemy = ROOT
							is_rival = ROOT
						}
					}
					amount = 3
				}
				NOT = {
					calc_true_if = {
						all_country = {
							OR = {
								alliance_with = FROM
								FROM = {
									guaranteed_by = PREV
								}
							}
							OR = {
								is_enemy = ROOT
								is_rival = ROOT
							}
						}
						amount = 4
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -75
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_ROOT_RIVALS
			limit = {
				calc_true_if = {
					all_country = {
						OR = {
							alliance_with = FROM
							FROM = {
								guaranteed_by = PREV
							}
						}
						OR = {
							is_enemy = ROOT
							is_rival = ROOT
						}
					}
					amount = 4
				}
				NOT = {
					calc_true_if = {
						all_country = {
							OR = {
								alliance_with = FROM
								FROM = {
									guaranteed_by = PREV
								}
							}
							OR = {
								is_enemy = ROOT
								is_rival = ROOT
							}
						}
						amount = 5
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_ROOT_RIVALS
			limit = {
				calc_true_if = {
					all_country = {
						OR = {
							alliance_with = FROM
							FROM = {
								guaranteed_by = PREV
							}
						}
						OR = {
							is_enemy = ROOT
							is_rival = ROOT
						}
					}
					amount = 5
				}
			}
			export_to_variable = {
				which = ai_value
				value = -1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		religion = sunni
		num_of_free_diplomatic_relations = 1
		FROM = {
			OR = {
				NOT = { has_country_flag = declined_establish_muslim_tributary_vassal_@ROOT }
				had_country_flag = { flag = declined_establish_muslim_tributary_vassal_@ROOT days = 1825 }
			}
			NOT = { is_subject_of = ROOT }
			capital_scope = {
				continent = europe
			}
			NOT = { total_development = 150 }
			NOT = {
				num_of_owned_provinces_with = {
					value = 5
					OR = {
						is_claim = ROOT
						is_core = ROOT
					}
				}
			}
		}
	}
}

ask_for_muslim_tributary_vassal = {
	category = influence

	alert_index = 6
	alert_tooltip = establish_muslim_tributary_vassal_alert_tooltip

	require_acceptance = yes

	is_visible = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = muslim_tributary_vassal
			}
		}
	}

	is_allowed = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = muslim_tributary_vassal
			}
		}
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		NOT = { truce_with = FROM }
		NOT = { num_of_cities = FROM }
		FROM = {
			army_size = 20
		}
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = muslim_tributary_vassal
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				NOT = { truce_with = FROM }
				NOT = { num_of_cities = FROM }
				FROM = {
					army_size = 20
				}
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = muslim_tributary_vassal
					keep_liberty_desire = yes
				}
				add_piety = 0.05
			}
			country_event = { id = subjects_expanded_muslim_tributary_vassal_events.1 }
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = muslim_tributary_vassal
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				NOT = { truce_with = FROM }
				NOT = { num_of_cities = FROM }
				FROM = {
					army_size = 20
				}
			}
			clr_country_flag = declined_establish_muslim_tributary_vassal_@FROM
			set_country_flag = declined_establish_muslim_tributary_vassal_@FROM
			add_opinion = {
				who = FROM
				modifier = declined_ask_for_muslim_tributary_vassal_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = ROOT_IS_VASSAL_OF_FROM
			limit = {
				is_subject_of = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_ATTITUDE_TOWARDS_FROM
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_threatened }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
						ai_attitude = { who = ROOT attitude = attitude_threatened }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 4 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 2 }
		}
		add_entry = {
			name = ROOT_DEVELOPMENT
			export_to_variable = {
				which = ai_value
				value = trigger_value:total_development
			}
			#subtract_variable = { which = ai_value value = 1 }
			divide_variable = { which = ai_value value = -4 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					NOT = { check_variable = { which = military_power value = -39 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = -39 }
					NOT = { check_variable = { which = military_power value = 30 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 0
			}
			export_to_variable = {
				which = our_mil_tech
				value = trigger_value:mil_tech
				who = FROM
			}
			export_to_variable = {
				which = their_mil_tech
				value = trigger_value:mil_tech
			}
			export_to_variable = {
				which = our_army_size
				value = trigger_value:army_size
				who = FROM
			}
			export_to_variable = {
				which = their_army_size
				value = trigger_value:army_size
			}
			divide_variable = { which = our_army_size value = 10 }
			divide_variable = { which = their_army_size value = -10 }
			change_variable = { which = our_army_size which = their_army_size }
			multiply_variable = { which = their_mil_tech value = -1 }
			change_variable = { which = our_mil_tech which = their_mil_tech }
			multiply_variable = { which = our_mil_tech value = 3 }
			change_variable = { which = ai_value which = our_army_size }
			change_variable = { which = ai_value which = our_mil_tech }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = 30 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
		}
		add_entry = {
			name = STRATEGIC_VALUE
			limit = {
				NOT = {
					AND = {
						FROM = {
							religion = sunni
							num_of_free_diplomatic_relations = 1
						}
						OR = {
							NOT = { has_country_flag = declined_establish_muslim_tributary_vassal_@FROM }
							had_country_flag = { flag = declined_establish_muslim_tributary_vassal_@FROM days = 1825 }
						}
						NOT = { is_subject_of = FROM }
						capital_scope = {
							continent = europe
						}
						NOT = { total_development = 150 }
						NOT = {
							num_of_owned_provinces_with = {
								value = 5
								OR = {
									is_claim = FROM
									is_core = FROM
								}
							}
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_ARE_ALLIED
			limit = {
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_FRIENDS
			limit = {
				FROM = {
					historical_friend_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_RIVALS
			limit = {
				FROM = {
					historical_rival_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		NOT = { tag = PAP }
		is_papal_controller = no
		government = monarchy
		is_emperor = no
		is_defender_of_faith = no
		religion_group = christian
		is_part_of_hre = no
		NOT = { num_of_cities = 10 }
		capital_scope = {
			continent = europe
		}
		NOT = { historical_rival_with = FROM }
		NOT = { alliance_with = FROM }
		OR = {
			NOT = { religion = catholic }
			NOT = { alliance_with = PAP }
		}
		OR = {
			AND = {
				NOT = { religion = catholic }
				NOT = { religion = protestant }
				NOT = { religion = reformed }
			}
			NOT = { alliance_with = emperor }
		}
		NOT = {
			calc_true_if = {
				all_ally = {
					NOT = { tag = FROM }
					army_size = 20
				}
				amount = 2
			}
		}
		NOT = {
			any_ally = {
				NOT = { tag = FROM }
				OR = {
					army_size = 100
					military_strength = { who = FROM value = 2 }
					is_defender_of_faith = yes
				}
			}
		}
		NOT = {
			calc_true_if = {
				all_country = {
					NOT = { tag = FROM }
					ROOT = {
						guaranteed_by = PREV
					}
					army_size = 20
				}
				amount = 2
			}
		}
		NOT = {
			any_country = {
				NOT = { tag = FROM }
				ROOT = {
					guaranteed_by = PREV
				}
				OR = {
					army_size = 100
					military_strength = { who = FROM value = 2 }
				}
			}
		}
		NOT = {
			calc_true_if = {
				all_country = {
					OR = {
						alliance_with = FROM
						FROM = {
							guaranteed_by = PREV
						}
					}
					OR = {
						is_enemy = ROOT
						is_rival = ROOT
					}
				}
				amount = 2
			}
		}
		OR = {
			NOT = { has_country_flag = declined_establish_muslim_tributary_vassal_@FROM }
			had_country_flag = { flag = declined_establish_muslim_tributary_vassal_@FROM days = 1825 }
		}
		NOT = { num_of_religion = { religion = sunni value = 0.1 } }
		NOT = { num_of_religion = { religion = shiite value = 0.1 } }
		NOT = { num_of_religion = { religion = ibadi value = 0.1 } }
		NOT = { dominant_religion = sunni }
		NOT = { dominant_religion = shiite }
		NOT = { dominant_religion = ibadi }
		NOT = { is_subject_of = FROM }
		NOT = { army_size = FROM }
		NOT = { core_claim = FROM }
		NOT = { num_of_subjects = 1 }
		NOT = { ai_attitude = { who = FROM attitude = attitude_hostile } }
		NOT = { ai_attitude = { who = FROM attitude = attitude_outraged } }
		NOT = { ai_attitude = { who = FROM attitude = attitude_rivalry } }
		NOT = { coalition_target = FROM }
		FROM = {
			num_of_free_diplomatic_relations = 1
			OR = {
				tag = TUR
				AND = {
					OR = {
						ai = no
						NOT = { exists = TUR }
					}
					is_defender_of_faith = yes
					government_rank = 3
				}
			}
			OR = {
				religion = sunni
				AND = {
					ai = no
					religion_group = muslim
				}
			}
			NOT = { truce_with = ROOT }
			has_casus_belli_against = ROOT
			NOT = { coalition_target = ROOT }
		}
	}
}

cancel_muslim_tributary_vassal = {
	category = influence

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = muslim_tributary_vassal
		}
	}

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = muslim_tributary_vassal
			}
		}
		NOT = { truce_with = FROM }
		prestige = 0
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = muslim_tributary_vassal
				}
				NOT = { truce_with = FROM }
				prestige = 0
			}
			FROM = {
				if = {
					limit = {
						NOT = { liberty_desire = 50 }
					}
					add_opinion = {
						who = ROOT
						modifier = vassal_abandoned
					}
				}
				grant_independence = yes
				add_truce_with = ROOT
			}
			add_truce_with = FROM
			add_prestige = -25
		}
	}

	ai_will_do = {
		FROM = {
			liberty_desire = 100
			years_in_vassalage_under = {
				who = ROOT
				years = 25
				all_subject_country = yes
			}
		}
	}
}