establish_papal_sanctuary_subject = {
	category = influence

	alert_index = 6
	alert_tooltip = establish_papal_sanctuary_subject_alert_tooltip

	require_acceptance = yes

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

	is_allowed = {
		can_create_subject_type = {
			subject = FROM
			subject_type = papal_sanctuary_subject
		}
		NOT = { truce_with = FROM }
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		FROM = {
			has_opinion = {
				who = ROOT
				value = 100
			}
		}
		FROM = {
			religious_unity = 0.9
		}
	}

	on_accept = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = papal_sanctuary_subject
				}
				NOT = { truce_with = FROM }
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				FROM = {
					has_opinion = {
						who = ROOT
						value = 100
					}
				}
				FROM = {
					religious_unity = 0.9
				}
			}
			create_subject = {
				subject = FROM
				subject_type = papal_sanctuary_subject
				keep_liberty_desire = yes
			}
			add_truce_with = FROM
		}
	}

	on_decline = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = papal_sanctuary_subject
				}
				NOT = { truce_with = FROM }
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				FROM = {
					has_opinion = {
						who = ROOT
						value = 100
					}
				}
				FROM = {
					religious_unity = 0.9
				}
			}
			FROM = {
				clr_country_flag = declined_establish_papal_sanctuary_subject_@ROOT
				set_country_flag = declined_establish_papal_sanctuary_subject_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_establish_papal_sanctuary_subject_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_allied }
						ai_attitude = { who = ROOT attitude = attitude_friendly }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_threatened }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			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 }

					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 = {
				is_part_of_hre = no
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_HRE_MEMBER
			limit = {
				is_part_of_hre = yes
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_HRE_ELECTOR
			limit = {
				NOT = { hre_reform_passed = erbkaisertum }
				NOT = { hre_reform_passed = emperor_erbkaisertum }
				FROM = {
					is_elector = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			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_HAS_SUBJECTS
			limit = {
				FROM = {
					num_of_subjects = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_CURIA_CONTROLLER
			limit = {
				is_papal_controller = yes
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
		}
		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 = -3 }
		}
		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 = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = -2 }
		}
		add_entry = {
			name = ROOT_FROM_ARE_ALLIED
			limit = {
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_ROOT_ARE_RIVALS
			limit = {
				OR = {
					is_rival = FROM
					is_enemy = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			divide_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_IMPERIAL_CITY
			limit = {
				FROM = {
					has_reform = free_city
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_MONARCHY
			limit = {
				FROM = {
					government = monarchy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			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 = 10
			}
		}
		add_entry = {
			name = FROM_AMOUNT_OF_INVESTED_PAPAL_INFLUENCE
			limit = {
				FROM = {
					invested_papal_influence = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:invested_papal_influence
				who = FROM
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				OR = {
					ruler_has_personality = zealot_personality
					ruler_has_personality = pious_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				ruler_has_personality = sinner_personality
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					OR = {
						ruler_has_personality = zealot_personality
						ruler_has_personality = pious_personality
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					ruler_has_personality = sinner_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_SUBJECT
			limit = {
				is_subject = yes
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_DEFENDER_OF_FAITH
			limit = {
				is_defender_of_faith = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_HAS_ESTABLISHED_THE_KINGDOM_OF_GOD
			limit = {
				has_country_flag = is_kingdom_of_god_flag
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_HAS_STRONG_NEIGHBOR_WITH_DIFFERENT_RELIGION
			limit = {
				FROM = {
					any_neighbor_country = {
						NOT = { religion = PREV }
						variable_arithmetic_trigger = {
							export_to_variable = {
								which = this_army_size
								value = trigger_value:army_size
							}
							export_to_variable = {
								which = our_army_size
								value = trigger_value:army_size
								who = ROOT
							}
							export_to_variable = {
								which = their_army_size
								value = trigger_value:army_size
								who = FROM
							}
							divide_variable = { which = this_army_size value = 2 }
							divide_variable = { which = our_army_size value = 3 }
							check_variable = { which = this_army_size which = their_army_size }
							check_variable = { which = our_army_size which = this_army_size }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
		}
		add_entry = {
			name = FROM_HAS_STRONG_NEIGHBOR_WITH_DIFFERENT_RELIGION
			limit = {
				FROM = {
					any_neighbor_country = {
						NOT = { religion = PREV }
						variable_arithmetic_trigger = {
							export_to_variable = {
								which = this_army_size
								value = trigger_value:army_size
							}
							export_to_variable = {
								which = our_army_size
								value = trigger_value:army_size
								who = ROOT
							}
							export_to_variable = {
								which = their_army_size
								value = trigger_value:army_size
								who = FROM
							}
							divide_variable = { which = this_army_size value = 2 }
							divide_variable = { which = our_army_size value = 3 }
							check_variable = { which = this_army_size which = their_army_size }
							NOT = { check_variable = { which = our_army_size which = this_army_size } }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
		}
	}

	ai_will_do = {
		OR = {
			is_defender_of_faith = yes
			is_papal_controller = yes
			personality = ai_diplomat
			has_country_flag = is_kingdom_of_god_flag
			AND = {
				has_dlc = "Rights of Man"
				OR = {
					ruler_has_personality = zealot_personality
					ruler_has_personality = pious_personality
				}
			}
		}
		OR = {
			num_of_free_diplomatic_relations = 1
			FROM = {
				religion = ROOT
				OR = {
					government = theocracy
					is_papal_controller = yes
					is_defender_of_faith = yes
					crusade_target = {
						is_neighbor_of = PREV
					}
				}
			}
		}
		FROM = {
			is_emperor = no
			NOT = { total_development = 125 }
			OR = {
				NOT = { has_country_flag = declined_establish_papal_sanctuary_subject_@ROOT }
				had_country_flag = { flag = declined_establish_papal_sanctuary_subject_@ROOT days = 1825 }
			}
		}
	}
}

ask_for_papal_sanctuary_subject = {
	category = influence

	alert_index = 6
	alert_tooltip = ask_for_papal_sanctuary_subject_alert_tooltip

	require_acceptance = yes

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

	is_allowed = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = papal_sanctuary_subject
			}
		}
		NOT = { truce_with = FROM }
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		FROM = {
			has_opinion = {
				who = ROOT
				value = 100
			}
		}
		religious_unity = 0.9
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = papal_sanctuary_subject
					}
				}
				NOT = { truce_with = FROM }
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				FROM = {
					has_opinion = {
						who = ROOT
						value = 100
					}
				}
				religious_unity = 0.9
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = papal_sanctuary_subject
					keep_liberty_desire = yes
				}
			}
			add_truce_with = FROM
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = papal_sanctuary_subject
					}
				}
				NOT = { truce_with = FROM }
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				FROM = {
					has_opinion = {
						who = ROOT
						value = 100
					}
				}
				religious_unity = 0.9
			}
			clr_country_flag = declined_establish_papal_sanctuary_subject_@FROM
			set_country_flag = declined_establish_papal_sanctuary_subject_@FROM
			add_opinion = {
				who = FROM
				modifier = declined_ask_for_papal_sanctuary_subject_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_allied }
						ai_attitude = { who = ROOT attitude = attitude_friendly }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_threatened }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = ROOT_IS_EMPIRE_RANK
			limit = {
				government_rank = 3
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_IS_KINGDOM_RANK
			limit = {
				government_rank = 2
				NOT = { government_rank = 3 }
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		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 = ROOT_IS_HRE_MEMBER
			limit = {
				is_part_of_hre = yes
				FROM = {
					is_part_of_hre = no
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_HRE_MEMBER
			limit = {
				is_part_of_hre = yes
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_CURIA_CONTROLLER
			limit = {
				is_papal_controller = yes
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
		}
		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 = -3 }
		}
		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 = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = -2 }
		}
		add_entry = {
			name = ROOT_FROM_ARE_ALLIED
			limit = {
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_ROOT_ARE_RIVALS
			limit = {
				OR = {
					is_rival = FROM
					is_enemy = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			divide_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_MONARCHY
			limit = {
				government = monarchy
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_A_REPUBLIC
			limit = {
				government = republic
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_A_THEOCRACY
			limit = {
				government = theocracy
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_AMOUNT_OF_INVESTED_PAPAL_INFLUENCE
			limit = {
				FROM = {
					invested_papal_influence = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:invested_papal_influence
				who = FROM
			}
			divide_variable = { which = ai_value value = 2 }
		}
		add_entry = {
			name = ROOT_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				OR = {
					ruler_has_personality = zealot_personality
					ruler_has_personality = pious_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				ruler_has_personality = sinner_personality
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					OR = {
						ruler_has_personality = zealot_personality
						ruler_has_personality = pious_personality
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					ruler_has_personality = sinner_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_DEFENDER_OF_FAITH
			limit = {
				is_defender_of_faith = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = STATEGIC_VALUE
			limit = {
				NOT = {
					FROM = {
						OR = {
							is_defender_of_faith = yes
							is_papal_controller = yes
							personality = ai_diplomat
							has_country_flag = is_kingdom_of_god_flag
							AND = {
								has_dlc = "Rights of Man"
								OR = {
									ruler_has_personality = zealot_personality
									ruler_has_personality = pious_personality
								}
							}
						}
					}
					OR = {
						FROM = {
							num_of_free_diplomatic_relations = 1
						}
						AND = {
							religion = FROM
							OR = {
								government = theocracy
								is_papal_controller = yes
								is_defender_of_faith = yes
								crusade_target = {
									is_neighbor_of = ROOT
								}
							}
						}
					}
					is_emperor = no
					NOT = { total_development = 125 }
					OR = {
						NOT = { has_country_flag = declined_establish_papal_sanctuary_subject_@FROM }
						had_country_flag = { flag = declined_establish_papal_sanctuary_subject_@FROM days = 1825 }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		NOT = { total_development = 125 }
		NOT = { government_rank = 3 }
		is_emperor = no
		is_elector = no
		NOT = { has_reform = free_city }
		invested_papal_influence = 5
		OR = {
			government = theocracy
			alliance_with = FROM
		}
		OR = {
			ai_attitude = { who = FROM attitude = attitude_threatened }
			ai_attitude = { who = FROM attitude = attitude_allied }
			ai_attitude = { who = FROM attitude = attitude_friendly }
		}
		NOT = { is_rival = FROM }
		NOT = { is_enemy = FROM }
		NOT = { army_size = FROM }
		FROM = {
			is_subject = no
			OR = {
				is_papal_controller = yes
				is_defender_of_faith = yes
				has_country_flag = is_kingdom_of_god_flag
				alliance_with = ROOT
			}
		}
		OR = {
			NOT = { has_country_flag = declined_establish_papal_sanctuary_subject_@FROM }
			had_country_flag = { flag = declined_establish_papal_sanctuary_subject_@FROM days = 1825 }
		}
	}
}

request_curia_money_from_papal_sanctuary_subject = {
	category = papacy

	alert_index = 6
	alert_tooltip = request_curia_money_from_papal_sanctuary_subject_alert_tooltip

	require_acceptance = yes

	is_visible = {
		has_dlc = "Emperor"
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = papal_sanctuary_subject
		}
	}

	is_allowed = {
		hidden_trigger = {
			has_dlc = "Emperor"
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = papal_sanctuary_subject
			}
		}
		is_papal_controller = yes
		FROM = {
			has_regency = no
		}
		FROM = {
			custom_trigger_tooltip = {
				tooltip = DID_NOT_REQUEST_CURIA_MONEY_FROM_THIS_RULER
				NOT = { has_ruler_flag = requested_curia_money_from_papal_sanctuary_subject }
			}
		}
		FROM = {
			if = {
				limit = {
					total_development = 300
				}
				treasury = 250
			}
			else_if = {
				limit = {
					total_development = 250
				}
				treasury = 200
			}
			else_if = {
				limit = {
					total_development = 200
				}
				treasury = 150
			}
			else_if = {
				limit = {
					total_development = 100
				}
				treasury = 100
			}
			else = {
				treasury = 50
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				has_dlc = "Emperor"
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = papal_sanctuary_subject
				}
				is_papal_controller = yes
				FROM = {
					has_regency = no
				}
				FROM = {
					NOT = { has_ruler_flag = requested_curia_money_from_papal_sanctuary_subject }
				}
				FROM = {
					if = {
						limit = {
							total_development = 300
						}
						treasury = 250
					}
					else_if = {
						limit = {
							total_development = 250
						}
						treasury = 200
					}
					else_if = {
						limit = {
							total_development = 200
						}
						treasury = 150
					}
					else_if = {
						limit = {
							total_development = 100
						}
						treasury = 100
					}
					else = {
						treasury = 50
					}
				}
			}
			FROM = {
				add_papal_influence = 5
				set_ruler_flag = requested_curia_money_from_papal_sanctuary_subject
				if = {
					limit = {
						total_development = 300
					}
					add_treasury = -250
					add_curia_treasury = 250
				}
				else_if = {
					limit = {
						total_development = 250
					}
					add_treasury = -200
					add_curia_treasury = 200
				}
				else_if = {
					limit = {
						total_development = 200
					}
					add_treasury = -150
					add_curia_treasury = 150
				}
				else_if = {
					limit = {
						total_development = 100
					}
					add_treasury = -100
					add_curia_treasury = 100
				}
				else = {
					add_treasury = -50
					add_curia_treasury = 50
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				has_dlc = "Emperor"
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = papal_sanctuary_subject
				}
				is_papal_controller = yes
				FROM = {
					has_regency = no
				}
				FROM = {
					NOT = { has_ruler_flag = requested_curia_money_from_papal_sanctuary_subject }
				}
				FROM = {
					if = {
						limit = {
							total_development = 300
						}
						treasury = 250
					}
					else_if = {
						limit = {
							total_development = 250
						}
						treasury = 200
					}
					else_if = {
						limit = {
							total_development = 200
						}
						treasury = 150
					}
					else_if = {
						limit = {
							total_development = 100
						}
						treasury = 100
					}
					else = {
						treasury = 50
					}
				}
			}
			FROM = {
				set_ruler_flag = requested_curia_money_from_papal_sanctuary_subject
			}
			add_opinion = {
				who = ROOT
				modifier = declined_request_curia_money_from_papal_sanctuary_subject_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
			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 = 5
			}
		}
		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 = -5 }
		}
		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 = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = -2 }
		}
		add_entry = {
			name = FROM_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					OR = {
						ruler_has_personality = zealot_personality
						ruler_has_personality = pious_personality
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					ruler_has_personality = sinner_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_DEFENDER_OF_FAITH
			limit = {
				is_defender_of_faith = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_HAS_ESTABLISHED_THE_KINGDOM_OF_GOD
			limit = {
				has_country_flag = is_kingdom_of_god_flag
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_HAS_NOT_MUCH_MONEY
			limit = {
				FROM = {
					OR = {
						AND = {
							total_development = 300
							NOT = { treasury = 1000 }
						}
						AND = {
							NOT = { total_development = 300 }
							total_development = 250
							NOT = { treasury = 800 }
						}
						AND = {
							NOT = { total_development = 250 }
							total_development = 200
							NOT = { treasury = 600 }
						}
						AND = {
							NOT = { total_development = 200 }
							total_development = 150
							NOT = { treasury = 500 }
						}
						AND = {
							NOT = { total_development = 150 }
							total_development = 100
							NOT = { treasury = 400 }
						}
						AND = {
							NOT = { total_development = 100 }
							NOT = { treasury = 300 }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_HAS_ALREAD_CONTRIBUTED_MUCH_TO_CURIA_TREASURY
			limit = {
				FROM = {
					curia_treasury_contribution = 0.5
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				FROM = {
					liberty_desire = 50
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		OR = {
			personality = ai_capitalist
			AND = {
				ruler_has_personality = pious_personality
				FROM = {
					ruler_has_personality = pious_personality
				}
			}
			FROM = {
				is_defender_of_faith = yes
			}
		}
	}
}

make_papal_sanctuary_subject_to_theocracy = {
	category = subject_interactions

	alert_index = 6
	alert_tooltip = make_papal_sanctuary_subject_to_theocracy_alert_tooltip

	require_acceptance = yes

	is_visible = {
		can_be_overlord = papal_sanctuary_subject
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = papal_sanctuary_subject
			NOT = { government = theocracy }
		}
	}

	is_allowed = {
		hidden_trigger = {
			can_be_overlord = papal_sanctuary_subject
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = papal_sanctuary_subject
				NOT = { government = theocracy }
			}
		}
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		religion = catholic
		FROM = {
			religion = catholic
		}
		FROM = {
			papal_influence = 10
		}
		FROM = {
			has_regency = no
		}
	}

	on_accept = {
		if = {
			limit = {
				hidden_trigger = {
					can_be_overlord = papal_sanctuary_subject
					FROM = {
						is_subject_of = ROOT
						is_subject_of_type = papal_sanctuary_subject
						NOT = { government = theocracy }
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				religion = catholic
				FROM = {
					religion = catholic
				}
				FROM = {
					papal_influence = 10
				}
				FROM = {
					has_regency = no
				}
			}
			FROM = {
				change_government = theocracy
				add_government_reform = leading_clergy_reform
				add_country_modifier = {
					name = papal_sanctuary_subject_converted_to_theocracy_modifier
					duration = 1825
				}
				add_papal_influence = -10
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				hidden_trigger = {
					can_be_overlord = papal_sanctuary_subject
					FROM = {
						is_subject_of = ROOT
						is_subject_of_type = papal_sanctuary_subject
						NOT = { government = theocracy }
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				religion = catholic
				FROM = {
					religion = catholic
				}
				FROM = {
					papal_influence = 10
				}
				FROM = {
					has_regency = no
				}
			}
			add_prestige = -10
			FROM = {
				add_country_modifier = {
					name = cooldown_papal_sanctuary_subject_converted_to_theocracy_modifier
					duration = 1825
					hidden = yes
				}
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 10 }
		}
		add_entry = {
			name = FROM_LIBERTY_DESIRE
			limit = {
				FROM = {
					NOT = { liberty_desire = 50 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:liberty_desire
				who = FROM
			}
			#subtract_variable = { which = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				FROM = {
					liberty_desire = 50
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			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 }

					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_ELECTOR
			limit = {
				NOT = { hre_reform_passed = erbkaisertum }
				NOT = { hre_reform_passed = emperor_erbkaisertum }
				FROM = {
					is_elector = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			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_HAS_SUBJECTS
			limit = {
				FROM = {
					num_of_subjects = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_CURIA_CONTROLLER
			limit = {
				is_papal_controller = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		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 = -3 }
		}
		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 = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = -3 }
		}
		add_entry = {
			name = FROM_IS_IMPERIAL_CITY
			limit = {
				has_reform = free_city
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_MONARCHY
			limit = {
				FROM = {
					government = monarchy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			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_AMOUNT_OF_INVESTED_PAPAL_INFLUENCE
			limit = {
				FROM = {
					invested_papal_influence = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:invested_papal_influence
				who = FROM
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				OR = {
					ruler_has_personality = zealot_personality
					ruler_has_personality = pious_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				ruler_has_personality = sinner_personality
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					OR = {
						ruler_has_personality = zealot_personality
						ruler_has_personality = pious_personality
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
		}
		add_entry = {
			name = FROM_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					ruler_has_personality = sinner_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_SUBJECT
			limit = {
				is_subject = yes
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_DEFENDER_OF_FAITH
			limit = {
				is_defender_of_faith = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_HAS_ESTABLISHED_THE_KINGDOM_OF_GOD
			limit = {
				has_country_flag = is_kingdom_of_god_flag
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_HAS_A_HEIR
			limit = {
				FROM = {
					government = monarchy
					has_heir = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_NO_HEIR
			limit = {
				FROM = {
					government = monarchy
					has_heir = no
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = FROM_WAS_RECENTLY_ASKED_TO_BECOME_THEOCRACY
			limit = {
				FROM = {
					OR = {
						has_country_modifier = papal_sanctuary_subject_converted_to_theocracy_modifier
						has_country_modifier = cooldown_papal_sanctuary_subject_converted_to_theocracy_modifier
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		OR = {
			is_defender_of_faith = yes
			is_papal_controller = yes
			has_country_flag = is_kingdom_of_god_flag
		}
		FROM = {
			NOT = { liberty_desire = 25 }
			NOT = { has_country_modifier = papal_sanctuary_subject_converted_to_theocracy_modifier }
			NOT = { has_country_modifier = cooldown_papal_sanctuary_subject_converted_to_theocracy_modifier }
		}
	}
}

make_papal_sanctuary_subject_to_vassal = {
	category = influence

	alert_index = 6
	alert_tooltip = make_papal_sanctuary_subject_to_vassal_alert_tooltip

	require_acceptance = yes

	is_visible = {
		can_be_overlord = papal_sanctuary_subject
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = papal_sanctuary_subject
		}
	}

	is_allowed = {
		hidden_trigger = {
			can_be_overlord = papal_sanctuary_subject
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = papal_sanctuary_subject
			}
		}
		is_at_war = no
		religion = catholic
		FROM = {
			religion = catholic
		}
		FROM = {
			is_at_war = no
		}
		FROM = {
			papal_influence = 10
		}
		FROM = {
			years_in_vassalage_under = {
				who = ROOT
				years = 5
				all_subject_country = yes
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				hidden_trigger = {
					can_be_overlord = papal_sanctuary_subject
					FROM = {
						is_subject_of = ROOT
						is_subject_of_type = papal_sanctuary_subject
					}
				}
				is_at_war = no
				religion = catholic
				FROM = {
					religion = catholic
				}
				FROM = {
					is_at_war = no
				}
				FROM = {
					papal_influence = 10
				}
				FROM = {
					years_in_vassalage_under = {
						who = ROOT
						years = 5
						all_subject_country = yes
					}
				}
			}
			FROM = {
				grant_independence = yes
				add_papal_influence = -10
			}
			vassalize = FROM
		}
	}

	on_decline = {
		if = {
			limit = {
				hidden_trigger = {
					can_be_overlord = papal_sanctuary_subject
					FROM = {
						is_subject_of = ROOT
						is_subject_of_type = papal_sanctuary_subject
					}
				}
				is_at_war = no
				religion = catholic
				FROM = {
					religion = catholic
				}
				FROM = {
					is_at_war = no
				}
				FROM = {
					papal_influence = 10
				}
				FROM = {
					years_in_vassalage_under = {
						who = ROOT
						years = 5
						all_subject_country = yes
					}
				}
			}
			add_prestige = -10
			FROM = {
				clr_country_flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT
				set_country_flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT
			}
			add_casus_belli = {
				target = FROM
				type = cb_vassalize_papal_sanctuary_subject
				months = 12
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = FROM_LIBERTY_DESIRE
			limit = {
				FROM = {
					NOT = { liberty_desire = 50 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:liberty_desire
				who = FROM
			}
			#subtract_variable = { which = ai_value value = 1 }
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				FROM = {
					liberty_desire = 50
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			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 }

					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_ELECTOR
			limit = {
				NOT = { hre_reform_passed = erbkaisertum }
				NOT = { hre_reform_passed = emperor_erbkaisertum }
				FROM = {
					is_elector = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			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_HAS_SUBJECTS
			limit = {
				FROM = {
					num_of_subjects = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_CURIA_CONTROLLER
			limit = {
				is_papal_controller = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		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 = -3 }
		}
		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 = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = -3 }
		}
		add_entry = {
			name = FROM_IS_IMPERIAL_CITY
			limit = {
				has_reform = free_city
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_MONARCHY
			limit = {
				FROM = {
					government = monarchy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			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 = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_AMOUNT_OF_INVESTED_PAPAL_INFLUENCE
			limit = {
				FROM = {
					invested_papal_influence = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:invested_papal_influence
				who = FROM
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				OR = {
					ruler_has_personality = zealot_personality
					ruler_has_personality = pious_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 5
			}
		}
		add_entry = {
			name = ROOT_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				ruler_has_personality = sinner_personality
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_RULER_IS_RELIGIOUS
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					OR = {
						ruler_has_personality = zealot_personality
						ruler_has_personality = pious_personality
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
		}
		add_entry = {
			name = FROM_RULER_IS_SINNER
			limit = {
				has_dlc = "Rights of Man"
				FROM = {
					ruler_has_personality = sinner_personality
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_SUBJECT
			limit = {
				is_subject = yes
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_DEFENDER_OF_FAITH
			limit = {
				is_defender_of_faith = yes
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_HAS_ESTABLISHED_THE_KINGDOM_OF_GOD
			limit = {
				has_country_flag = is_kingdom_of_god_flag
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_WAS_RECENTLY_ASKED_TO_BECOME_A_VASSAL
			limit = {
				FROM = {
					has_country_flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT
					NOT = { had_country_flag = { flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT days = 1825 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_WAS_RECENTLY_ASKED_TO_BECOME_THEOCRACY
			limit = {
				FROM = {
					OR = {
						has_country_modifier = papal_sanctuary_subject_converted_to_theocracy_modifier
						has_country_modifier = cooldown_papal_sanctuary_subject_converted_to_theocracy_modifier
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		OR = {
			is_papal_controller = yes
			has_country_flag = is_kingdom_of_god_flag
		}
		OR = {
			num_of_free_diplomatic_relations = 1
			FROM = {
				OR = {
					NOT = { religion = ROOT }
					NOT = {
						government = theocracy
						is_papal_controller = yes
						is_defender_of_faith = yes
						crusade_target = {
							is_neighbor_of = PREV
						}
					}
				}
			}
		}
		is_neighbor_of = FROM
		FROM = {
			NOT = { total_development = 100 }
			OR = {
				NOT = { has_country_flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT }
				had_country_flag = { flag = decline_make_papal_sanctuary_subject_to_vassal_@ROOT days = 1825 }
			}
		}
	}
}

papal_sanctuary_subject_become_independent = {
	category = influence

	require_acceptance = no

	is_visible = {
		is_subject_of = FROM
		is_subject_of_type = papal_sanctuary_subject
	}

	is_allowed = {
		hidden_trigger = {
			is_subject_of = FROM
			is_subject_of_type = papal_sanctuary_subject
		}
		OR = {
			NOT = { government = theocracy }
			NOT = { religion = FROM }
			FROM = {
				NOT = { can_be_overlord = papal_sanctuary_subject }
			}
		}
		NOT = { truce_with = FROM }
		OR = {
			is_excommunicated = yes
			NOT = { religion = FROM }
			FROM = {
				is_excommunicated = yes
			}
			AND = {
				liberty_desire = 50
				has_country_modifier = the_statue_in_restraint_of_appeals
			}
			liberty_desire = 65
			FROM = {
				NOT = { can_be_overlord = papal_sanctuary_subject }
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				is_subject_of = FROM
				is_subject_of_type = papal_sanctuary_subject
				OR = {
					NOT = { government = theocracy }
					NOT = { religion = FROM }
					FROM = {
						NOT = { can_be_overlord = papal_sanctuary_subject }
					}
				}
				NOT = { truce_with = FROM }
				OR = {
					is_excommunicated = yes
					NOT = { religion = FROM }
					FROM = {
						is_excommunicated = yes
					}
					AND = {
						liberty_desire = 50
						has_country_modifier = the_statue_in_restraint_of_appeals
					}
					liberty_desire = 65
					FROM = {
						NOT = { can_be_overlord = papal_sanctuary_subject }
					}
				}
			}
			FROM = {
				ROOT = { grant_independence = yes }
				country_event = { id = subjects_expanded_papal_sanctuary_subject_events.1 }
				add_casus_belli = {
					target = ROOT
					type = cb_insult
					months = 72
				}
			}
			add_truce_with = FROM
			if = {
				limit = {
					is_excommunicated = no
				}
				excommunicate = ROOT
			}
		}
	}

	ai_will_do = {
		OR = {
			NOT = { has_dlc = "Rights of Man" }
			AND = {
				NOT = { ruler_has_personality = zealot_personality }
				NOT = { ruler_has_personality = pious_personality }
			}
		}
		OR = {
			is_excommunicated = yes
			NOT = { religion = FROM }
			FROM = {
				is_excommunicated = yes
			}
			AND = {
				liberty_desire = 55
				has_country_modifier = the_statue_in_restraint_of_appeals
			}
			liberty_desire = 75
			FROM = {
				NOT = { can_be_overlord = papal_sanctuary_subject }
			}
		}
	}
}

cancel_papal_sanctuary_subject = {
	category = influence

	require_acceptance = no

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

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

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = papal_sanctuary_subject
				}
				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
			}
		}
	}
}