# Written by Flavio (HFP.23001 - HFP.23027)

namespace = HFP
# Son/Daughter sent to the monastery.
character_event = {
	id = HFP.23001
	desc = {
		text = EVTDESCAHFP23001
		trigger = {
			FROM = {
				OR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				NOR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = no
			}
		}
	}
	desc = {
		text = EVTDESCBHFP23001
		trigger = {
			FROM = {
				OR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				NOR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = yes
			}
		}
	}
	desc = {
		text = EVTDESCCHFP23001
		trigger = {
			FROM = {
				NOR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				NOR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = no
			}
		}
	}
	desc = {
		text = EVTDESCDHFP23001
		trigger = {
			FROM = {
				NOR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				NOR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = yes
			}
		}
	}
	desc = {
		text = EVTDESCEHFP23001
		trigger = {
			FROM = {
				NOR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				OR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = no
			}
		}
	}
	desc = {
		text = EVTDESCFHFP23001
		trigger = {
			FROM = {
				NOR = {
					trait = ambitious
					trait = stubborn
					trait = wroth
				}
				OR = {
					trait = kind
					trait = humble
					trait = content
				}
				is_female = yes
			}
		}
	}

	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23001
		trigger = { is_evil_trigger = yes }
		if = { limit = { trait = stressed } random = { chance = 10 remove_trait = stressed } }
	}
	option = {
		name = EVTOPTBHFP23001
		trigger = { NOR = { is_evil_trigger = yes is_benevolent_trigger = yes } }
	}
	option = {
		name = EVTOPTCHFP23001
		trigger = { is_benevolent_trigger = yes }
		if = { limit = { NOT = { trait = stressed } } random = { chance = 10 add_trait = stressed } }
	}
}

#Hidden event assigning cooldown on Excommunication requests.
# Root = Excommunicated person
# From = Asker
# FromFrom = Pope
character_event = {
	id = HFP.23002
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		FROMFROM = {
			opinion = {
				modifier = opinion_requested_excommunication
				who = ROOT_FROM
				months = 6
			}
		}
	}
}

## New Lifting Excommunication Revamped event chain ##
#Religious Head receives event determining punishment.
#Changed by PDP to allow player pope to make his own choice.
character_event = {
	id = HFP.23003
	hide_window = no #Why hide this?
	is_triggered_only = yes
	desc = HFP.23003_desc
	picture = GFX_evt_knight_kneeling
	immediate = {
		random_list = {
			# Possible impositions:

			#Tiered Money #liftExcommunicationTieredMoney
			#Tiered Prestige #liftExcommunicationTieredPrestige
			#Vow of Celibacy #liftExcommunicationCelibacy
			#Son/Daughter must take vows. #liftExcommunicationSonToChurch
			#Abdication-> Become Monk/Nun #liftExcommunicationAbdication
			#Enforce Papal Succession (Kings/Emperors) #liftExcommunicationInvestiture
			#Change succession to Gavelkind (unless Elective or worse) (King/Emperors) #liftExcommunicationGavelkind
			#Give Italian lands back (Emperors) #liftExcommunicationItalianLand
			#Give Independence to Papacy (Emperors) #liftExcommunicationIndependence
			#Request vassalization (Italian Dukes) #liftExcommunicationVassalization

			30 = { #Pay tiered money.
				modifier = {
					factor = 0.5
					vassal_of = FROM
				}
				modifier = { 	#Supported Pope more likely to ask for little
					factor = 1.5
					has_opinion_modifier = {
						who = FROM
						modifier = opinion_supported_pope
					}
				}
				modifier = {
					factor = 0.25
					higher_tier_than = DUKE
					NOT = {
						wealth = 50
					}
				}
				modifier = {
					factor = 0.5
					higher_tier_than = DUKE
					NOT = {
						wealth = 250
					}
				}
				modifier = {
					factor = 0
					NOT = {
						opinion = {
							who = FROM
							value = -100
						}
					}
				}
				modifier = {
					factor = 0.2
					NOT = {
						opinion = {
							who = FROM
							value = -80
						}
					}
				}
				modifier = {
					factor = 0.3
					NOT = {
						opinion = {
							who = FROM
							value = -60
						}
					}
				}
				modifier = {
					factor = 0.4
					NOT = {
						opinion = {
							who = FROM
							value = -40
						}
					}
				}
				modifier = {
					factor = 0.5
					NOT = {
						opinion = {
							who = FROM
							value = -20
						}
					}
				}
				modifier = {
					factor = 0.6
					NOT = {
						opinion = {
							who = FROM
							value = 0
						}
					}
				}
				modifier = {
					factor = 1.25
					opinion = {
						who = FROM
						value = 20
					}
				}
				modifier = {
					factor = 1.5
					opinion = {
						who = FROM
						value = 40
					}
				}
				modifier = {
					factor = 1.5
					opinion = {
						who = FROM
						value = 60
					}
				}
				modifier = {
					factor = 1.5
					opinion = {
						who = FROM
						value = 80
					}
				}
				modifier = {
					factor = 1.5
					opinion = {
						who = FROM
						value = 100
					}
				}
				modifier = {
					factor = 1.5
					trait = greedy
				}
				modifier = {
					factor = 0.5
					trait = zealous
				}
				set_character_flag = liftExcommunicationTieredMoney
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23004 } } #Asks for Gold.
				}
			}
			30 = { #Pay tiered Prestige.
				trigger = {
					FROM = { higher_tier_than = DUKE }
				}
				modifier = {
					factor = 0.5
					vassal_of = FROM
				}
				modifier = {
					factor = 1.5
					trait = proud
				}
				modifier = {
					factor = 0.5
					trait = cynical
				}
				set_character_flag = liftExcommunicationTieredPrestige
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23006 } } #Asks for Prestige.
				}
			}

			20 = { #Impose celibacy
				trigger = {
					FROM = {
						NOR = {
							trait = celibate
							trait = eunuch
							trait = chaste
						}
					}
					FROM = { num_of_children = 1 }
				}
				modifier = {
					factor = 0.5
					vassal_of = FROM
				}
				modifier = {
					factor = 1.5
					trait = chaste
				}
				modifier = {
					factor = 1.5
					trait = celibate
				}
				modifier = {
					factor = 0.5
					trait = lustful
				}
				modifier = {
					factor = 0.5
					FROM = { trait = humble }
				}
				modifier = {
					factor = 1.5
					FROM = { trait = lustful }
				}
				modifier = {
					factor = 1.5
					FROM = { has_character_modifier = adulterer }
				}
				modifier = {
					factor = 1.5
					FROM = { has_character_modifier = adulteress }
				}
				modifier = {
					factor = 1.75
					FROM = { has_character_modifier = incestuous_adulterer }
				}
				modifier = {
					factor = 1.75
					FROM = { has_character_modifier = incestuous_adulteress }
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_celibacy
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationCelibacy
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23008 } } #Impose Celibacy.
				}
			}
			10 = { #Send Son/Daughter to monastery.
				trigger = {
					OR = {
						religion_group = christian
						has_religion_feature = religion_monastic
					}
					FROM = {
						any_child = {
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					FROM = {
						any_child = {
							count = 3
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					FROM = {
						any_child = {
							count = 4
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					FROM = {
						any_child = {
							count = 5
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					FROM = {
						any_child = {
							count = 6
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
				modifier = {
					factor = 0.25
					trait = cynical
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_child
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationSonToChurch
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23010 } } #Send child to monastery/nunnery.
				}
			}

			3 = {
				#Force abdication.
				trigger = {
					OR = {
						religion_group = christian
						has_religion_feature = religion_monastic
					}
					FROM = { higher_real_tier_than = DUKE player_heir = { dynasty = PREV } } #Do not impose a game over.
				}
				modifier = {
					factor = 0.15
					vassal_of = FROM
				}
				modifier = {
					factor = 10
					FROM = {
						OR = {
							trait = kinslayer
							trait = familial_kinslayer
							trait = dynastic_kinslayer
							has_character_modifier = rampant_sinner_christian
							has_character_modifier = rampant_sinner_dharmic
							has_character_modifier = known_satanist
							has_character_modifier = known_witch
						}
					}
				}
				modifier = {
					factor = 1.5
					trait = proud
				}
				modifier = {
					factor = 1.5
					trait = envious
				}
				modifier = {
					factor = 0.5
					trait = cynical
				}
				modifier = {
					factor = 0.5
					trait = kind
				}
				modifier = {
					factor = 1.5
					trait = zealous
				}
				modifier = {
					factor = 1.5
					is_rival = FROM
				}
				modifier = {
					factor = 0.25
					is_friend = FROM
				}
				modifier = {
					factor = 0.25
					is_lover = FROM
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -100
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -80
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -60
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -40
						}
					}
				}
				modifier = {
					factor = 1.25
					NOT = {
						opinion = {
							who = FROM
							value = -20
						}
					}
				}
				modifier = {
					factor = 1.25
					opinion = {
						who = FROM
						value = -20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 40
					}
				}
				modifier = {
					factor = 0.75
					opinion = {
						who = FROM
						value = 60
					}
				}
				modifier = {
					factor = 0.5
					opinion = {
						who = FROM
						value = 80
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = zealous
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = baptized_by_pope
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 100
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 150
					}
				}
				modifier = {
					factor = 0.8
					FROM = {
						piety = 250
					}
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_abdication
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationAbdication
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23012 } } #Impose abdication.
				}
			}
			30 = { #Impose Papal Investiture.
				modifier = {
					factor = 0
					FROM = { NOT = { primary_title = { has_law = investiture_law_1 } } }
				}
				modifier = {
					factor = 1.5
					FROM = { tier = EMPEROR }
				}
				modifier = {
					factor = 1.75
					FROM = { has_landed_title = e_hre }
				}
				modifier = {
					factor = 1.5
					tier = KING
				}
				modifier = {
					factor = 1.5
					trait = envious
				}
				modifier = {
					factor = 1.75
					independent = yes
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_investiture
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationInvestiture
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23014 } } #Impose Papal Investiture.
				}
			}
			5 = { #Impose Gavelkind
				trigger = {
					FROM = {
						realm_size = 100
						higher_real_tier_than = DUKE
						primary_title = {
							NOR = {
								has_law = succ_gavelkind
								has_law = succ_elective_gavelkind
								has_law = succ_feudal_elective
								has_law = succ_hre_elective
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					FROM = { tier = EMPEROR }
				}
				modifier = {
					factor = 2
					FROM = { trait = ambitious } #Hubris
				}
				modifier = {
					factor = 0.5
					FROM = { NOT = { num_of_children = 1 } }
				}
				modifier = {
					factor = 1.5
					FROM = { num_of_children = 3 }
				}
				modifier = {
					factor = 1.5
					FROM = { num_of_children = 5 }
				}
				modifier = {
					factor = 1.5
					FROM = { num_of_children = 7 }
				}
				modifier = {
					factor = 1.5
					FROM = { num_of_children = 9 }
				}
				modifier = {
					factor = 1.5
					tier = EMPEROR
				}
				modifier = {
					factor = 1.5
					trait = envious
				}
				modifier = {
					factor = 1.75
					independent = yes
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_gavelkind
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationGavelkind
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23016 } } #Impose Gavelkind.
				}
			}
			20 = { #Request Italian Lands.
				trigger = {
					religion_group = christian
					is_alternate_start = no #Only matters for historical Papacy.
					FROM = { #Check if you or your vassals hold lands within Italy
						higher_real_tier_than = KING
						OR = {
							any_demesne_title = {
								can_be_given_away = yes
								OR = {
									title = d_latium
									title = d_spoleto
									title = d_ancona
									title = d_ferrara
									title = d_benevento
									title = c_roma
								}
							}
							any_vassal = {
								any_demesne_title = {
									OR = {
										title = d_latium
										title = d_spoleto
										title = d_ancona
										title = d_ferrara
										title = d_benevento
										title = c_roma
									}
								}
							}
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -100
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -80
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -60
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -40
						}
					}
				}
				modifier = {
					factor = 1.25
					NOT = {
						opinion = {
							who = FROM
							value = -20
						}
					}
				}
				modifier = {
					factor = 1.25
					opinion = {
						who = FROM
						value = -20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 40
					}
				}
				modifier = {
					factor = 0.75
					opinion = {
						who = FROM
						value = 60
					}
				}
				modifier = {
					factor = 0.5
					opinion = {
						who = FROM
						value = 80
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = zealous
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = baptized_by_pope
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 100
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 150
					}
				}
				modifier = {
					factor = 0.8
					FROM = {
						piety = 250
					}
				}
				modifier = {
					factor = 0.7
					FROM = { primary_title = { has_law = investiture_law_0 } }
				}
				#Historical Pope will want historical Vatican lands.
				modifier = {
					factor = 1.5
					has_landed_title = k_papal_state
					FROM = { has_landed_title = c_roma }
				}
				modifier = {
					factor = 1.5
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_latium
							any_vassal = { has_landed_title = d_latium }
						}
					}
				}
				modifier = {
					factor = 1.45
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_spoleto
							any_vassal = { has_landed_title = d_spoleto }
						}
					}
				}
				modifier = {
					factor = 1.35
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_ancona
							any_vassal = { has_landed_title = d_ancona }
						}
					}
				}
				modifier = {
					factor = 1.25
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_ferrara
							any_vassal = { has_landed_title = d_ferrara }
						}
					}
				}
				modifier = {
					factor = 1.15
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_benevento
							any_vassal = { has_landed_title = d_benevento }
						}
					}
				}
				modifier = {
					factor = 1.25
					has_landed_title = k_papal_state
					FROM = { has_landed_title = e_hre }
				}
				modifier = { #If Papacy already controls historical provinces, it won't be interested in gaining even more land in Italy.
					factor = 0
					AND = {
						OR = {
							any_vassal = { has_landed_title = c_roma }
							has_landed_title = c_roma
						}
						OR = {
							any_vassal = { has_landed_title = d_latium }
							has_landed_title = d_latium
						}
						OR = {
							any_vassal = { has_landed_title = d_spoleto }
							has_landed_title = d_spoleto
						}
						OR = {
							any_vassal = { has_landed_title = d_ancona }
							has_landed_title = d_ancona
						}
						OR = {
							any_vassal = { has_landed_title = d_ferrara }
							has_landed_title = d_ferrara
						}
						OR = {
							any_vassal = { has_landed_title = d_benevento }
							has_landed_title = d_benevento
						}
					}
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_lands
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationItalianLand
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23018 } } #Request Italian lands.
				}
			}
			60 = {
				trigger = {
					vassal_of = FROM
				}
				modifier = {
					factor = 2
					has_opinion_modifier = { #Opinion modifier keeps track of the Pope's previous decision, should the player deny his first request and then attempt to ask again immediately after for a different result.
						who = FROM
						modifier = opinion_requested_independence
					}
				}
				modifier = {
					factor = 1.5
					has_landed_title = k_papal_state
				}
				modifier = {
					factor = 2
					NOT = {
						opinion = {
							who = FROM
							value = -100
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -80
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -60
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -40
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -20
						}
					}
				}
				modifier = {
					factor = 0.9
					opinion = {
						who = FROM
						value = 20
					}
				}
				modifier = {
					factor = 0.8
					opinion = {
						who = FROM
						value = 40
					}
				}
				modifier = {
					factor = 0.7
					opinion = {
						who = FROM
						value = 60
					}
				}
				modifier = {
					factor = 0.6
					opinion = {
						who = FROM
						value = 80
					}
				}
				modifier = {
					factor = 0.5
					opinion = {
						who = FROM
						value = 100
					}
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_independence
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationIndependence
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23020 } } #I want to be independent.
				}
			}
			10 = { #Requests Vassalization.
				trigger = {
					religion_group = christian
					is_alternate_start = no #Only matters for historical Papacy.
					higher_real_tier_than = DUKE
					FROM = { #Check if you or your vassals hold lands within Italy
						OR = {
							independent = yes
							liege = { ROOT = { vassal_of = PREV } }
						}
						lower_real_tier_than = KING
						any_neighbor_independent_ruler = { character = ROOT } #Avoid creating messy borders.
						OR = {
							any_demesne_title = {
								OR = {
									title = d_latium
									title = d_spoleto
									title = d_ancona
									title = d_ferrara
									title = d_benevento
									title = c_roma
								}
							}
							any_vassal = {
								any_demesne_title = {
									OR = {
										title = d_latium
										title = d_spoleto
										title = d_ancona
										title = d_ferrara
										title = d_benevento
										title = c_roma
									}
								}
							}
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -100
						}
					}
				}
				modifier = {
					factor = 1.75
					NOT = {
						opinion = {
							who = FROM
							value = -80
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -60
						}
					}
				}
				modifier = {
					factor = 1.5
					NOT = {
						opinion = {
							who = FROM
							value = -40
						}
					}
				}
				modifier = {
					factor = 1.25
					NOT = {
						opinion = {
							who = FROM
							value = -20
						}
					}
				}
				modifier = {
					factor = 1.25
					opinion = {
						who = FROM
						value = -20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 20
					}
				}
				modifier = {
					factor = 0.85
					opinion = {
						who = FROM
						value = 40
					}
				}
				modifier = {
					factor = 0.75
					opinion = {
						who = FROM
						value = 60
					}
				}
				modifier = {
					factor = 0.5
					opinion = {
						who = FROM
						value = 80
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = zealous
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						trait = baptized_by_pope
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 100
					}
				}
				modifier = {
					factor = 0.9
					FROM = {
						piety = 150
					}
				}
				modifier = {
					factor = 0.8
					FROM = {
						piety = 250
					}
				}
				modifier = {
					factor = 0.7
					FROM = { primary_title = { has_law = investiture_law_0 } }
				}
				#Historical Pope will want control over historical Vatican lands.
				modifier = {
					factor = 1.5
					has_landed_title = k_papal_state
					FROM = { has_landed_title = c_roma }
				}
				modifier = {
					factor = 1.5
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_latium
							any_vassal = { has_landed_title = d_latium }
						}
					}
				}
				modifier = {
					factor = 1.45
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_spoleto
							any_vassal = { has_landed_title = d_spoleto }
						}
					}
				}
				modifier = {
					factor = 1.35
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_ancona
							any_vassal = { has_landed_title = d_ancona }
						}
					}
				}
				modifier = {
					factor = 1.25
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_ferrara
							any_vassal = { has_landed_title = d_ferrara }
						}
					}
				}
				modifier = {
					factor = 1.15
					has_landed_title = k_papal_state
					FROM = {
						OR = {
							has_landed_title = d_benevento
							any_vassal = { has_landed_title = d_benevento }
						}
					}
				}
				modifier = { #If Papacy already controls historical provinces, it won't be interested in gaining even more land in Italy.
					factor = 0
					AND = {
						OR = {
							any_vassal = { has_landed_title = c_roma }
							has_landed_title = c_roma
						}
						OR = {
							any_vassal = { has_landed_title = d_latium }
							has_landed_title = d_latium
						}
						OR = {
							any_vassal = { has_landed_title = d_spoleto }
							has_landed_title = d_spoleto
						}
						OR = {
							any_vassal = { has_landed_title = d_ancona }
							has_landed_title = d_ancona
						}
						OR = {
							any_vassal = { has_landed_title = d_ferrara }
							has_landed_title = d_ferrara
						}
						OR = {
							any_vassal = { has_landed_title = d_benevento }
							has_landed_title = d_benevento
						}
					}
				}
				modifier = {
					factor = 10
					has_opinion_modifier = {
						modifier = opinion_pope_ex_demands_vassalization
						who = FROM
					}
				}
				set_character_flag = liftExcommunicationVassalization
				if = {
					limit = {ai = yes}
					FROM = { letter_event = { id = HFP.23022 } } #Request Vassalization.
				}
			}
		}
	}

	#do this for all non default options. Also make it so that it works for the ai again...
	option = { #ai has no choice
		name = PDP_lift_excommunication_opt_ai
		trigger = {
			ai = yes
		}
	}
	option = {
		name NO_AI
		trigger = {
			ai = no
			always = no
		}
		character_event = {}
	}
	option = {
		name = PDP_lift_excommunication_opt_gold
		trigger = {
			ai = no
		}
		FROM = { letter_event = { id = HFP.23004 } } #Asks for Gold.
	}
	option = {
		name = PDP_lift_excommunication_opt_prestige
		trigger = {
			ai = no
		}
		FROM = { letter_event = { id = HFP.23006 } } #Asks for Prestige.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationIndependence
			ai = no
		}
		name = PDP_lift_excommunication_opt_independence
		FROM = { letter_event = { id = HFP.23020 } } #I want to be independent.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationInvestiture
			ai = no
		}
		name = PDP_lift_excommunication_opt_investiture
		FROM = { letter_event = { id = HFP.23014 } } #Impose Papal Investiture.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationItalianLand
			ai = no
		}
		name = PDP_lift_excommunication_opt_italian_land
		FROM = { letter_event = { id = HFP.23018 } } #Request Italian lands.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationVassalization
			ai = no
		}
		name = PDP_lift_excommunication_opt_vassalization
		FROM = { letter_event = { id = HFP.23022 } } #Request Vassalization.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationAbdication
			ai = no
		}
		name = PDP_lift_excommunication_opt_abdication
		piety = -200
		prestige = 100
		FROM = { letter_event = { id = HFP.23012 } } #Impose abdication.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationCelibacy
			ai = no
		}
		name = PDP_lift_excommunication_opt_celibacy
		FROM = { letter_event = { id = HFP.23008 } } #Impose Celibacy.
	}
	option = {
		trigger = {
			has_character_flag = liftExcommunicationGavelkind
			ai = no
		}
		name = PDP_lift_excommunication_opt_gavelkind
		FROM = { letter_event = { id = HFP.23016 } } #Impose Gavelkind.
	}
	option = {
		trigger = {
			OR = {
				has_character_flag = liftExcommunicationSonToChurch
				AND = {
					FROM = {
						any_child = {
							count = 3
							age = 16
							is_married = no
							is_ruler = no
							prisoner = no
							NOT = { trait = incapable }
							FROM = {
								NOT = {
									current_heir = { character = PREVPREV }
								}
							}
							NOR = {
								trait = monk
								trait = nun
							}
						}
					}
				}
			}
			ai = no
		}
		name = PDP_lift_excommunication_opt_son_to_church
		FROM = { letter_event = { id = HFP.23010 } } #Send child to monastery/nunnery.
	}


	after = {
		clr_character_flag = liftExcommunicationTieredMoney #done
		clr_character_flag = liftExcommunicationTieredPrestige #done
		clr_character_flag = liftExcommunicationCelibacy #done
		clr_character_flag = liftExcommunicationSonToChurch #done
		clr_character_flag = liftExcommunicationAbdication #done
		clr_character_flag = liftExcommunicationInvestiture #done
		clr_character_flag = liftExcommunicationGavelkind #done
		clr_character_flag = liftExcommunicationItalianLand #done
		clr_character_flag = liftExcommunicationIndependence #done
		clr_character_flag = liftExcommunicationVassalization #done
	}
}

# Possible impositions:

#Tiered Money
#Tiered Prestige
#Vow of Celibacy
#Son/Daughter must take vows.
#Abdication-> Become Monk/Nun
#Enforce Papal Succession (Kings/Emperors)
#Change succession to Gavelkind (unless Elective or worse) (King/Emperors)
#Give Italian lands back (Emperors)
#Give Independence to Papacy (Emperors)
#Request vassalization (Italian Dukes)

#Tiered Money.
letter_event = {
	id = HFP.23004
	desc = EVTDESCAHFP23004
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23004
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Count tier
		if = {
			limit = { real_tier = COUNT }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2.5 min = 350 max = 800 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2 min = 300 max = 700 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.35 min = 250 max = 600 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.25 min = 200 max = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.0 min = 150 max = 450 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.95 min = 100 max = 400 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.85 min = 75 max = 350 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.75 min = 50 max = 300 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.65 min = 25 max = 250 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.5 min = 10 max = 150 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Duke tier
		if = {
			limit = { real_tier = DUKE }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2.5 min = 750 max = 1200 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2 min = 500 max = 700 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.35 min = 400 max = 600 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.25 min = 300 max = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.0 min = 250 max = 450 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.95 min = 200 max = 400 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.85 min = 150 max = 350 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.75 min = 100 max = 300 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.65 min = 75 max = 250 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.5 min = 50 max = 150 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - King tier
		if = {
			limit = { real_tier = KING }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2.5 min = 750 max = 1500 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2 min = 600 max = 1200 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.35 min = 500 max = 900 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.25 min = 400 max = 750 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.0 min = 350 max = 600 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.95 min = 300 max = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.85 min = 250 max = 400 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.75 min = 200 max = 350 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.65 min = 175 max = 300 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.5 min = 150 max = 250 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Emperor tier
		if = {
			limit = { real_tier = EMPEROR }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 3 min = 950 max = 1750 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2.5 min = 750 max = 1500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 2.0 min = 600 max = 1000 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.75 min = 500 max = 850 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.5 min = 450 max = 700 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.35 min = 400 max = 600 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 1.25 min = 350 max = 500 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.95 min = 300 max = 450 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.85 min = 275 max = 400 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				transfer_scaled_wealth = { to = FROM value = 0.75 min = 250 max = 350 }
			}
		}
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		ai_chance = { factor = 100 }
		hidden_tooltip = { character_event = { id = HFP.23005 } }
	}
	option = {
		name = EVTOPTBHFP23004
		ai_chance = { factor = 0 }
	}
}

#Excommunicated ruler forced to pay money.
character_event = {
	id = HFP.23005
	desc = {
		text = EVTDESCAHFP23005
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCBHFP23005
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCBHFP23005
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23005
		ai_chance = { factor = 100 }
	}
}

#Tiered Prestige.
letter_event = {
	id = HFP.23006
	desc = EVTDESCAHFP23006
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23006
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Count tier
		if = {
			limit = { real_tier = COUNT }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -700
				FROM = { prestige = 700 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -650
				FROM = { prestige = 650 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -600
				FROM = { prestige = 600 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -500
				FROM = { prestige = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -450
				FROM = { prestige = 450 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -400
				FROM = { prestige = 400 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -350
				FROM = { prestige = 350 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -300
				FROM = { prestige = 300 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -200
				FROM = { prestige = 200 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -100
				FROM = { prestige = 100 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Duke tier
		if = {
			limit = { real_tier = DUKE }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -1200
				FROM = { prestige = 1200 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -900
				FROM = { prestige = 900 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -700
				FROM = { prestige = 700 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -500
				FROM = { prestige = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -450
				FROM = { prestige = 450 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -400
				FROM = { prestige = 400 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -350
				FROM = { prestige = 350 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -300
				FROM = { prestige = 300 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -250
				FROM = { prestige = 250 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -150
				FROM = { prestige = 150 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - King tier
		if = {
			limit = { real_tier = KING }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -1500
				FROM = { prestige = 1500 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -1200
				FROM = { prestige = 1200 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -900
				FROM = { prestige = 900 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -750
				FROM = { prestige = 750 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -600
				FROM = { prestige = 600 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -500
				FROM = { prestige = 500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -400
				FROM = { prestige = 400 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -350
				FROM = { prestige = 350 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -300
				FROM = { prestige = 300 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -250
				FROM = { prestige = 250 }
			}
		}
		#Transfer scaled wealth based on Pope's opinion of you and your piety. - Emperor tier
		if = {
			limit = { real_tier = EMPEROR }
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -1800
				FROM = { prestige = 1800 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						NOT = {
							opinion = {
								who = ROOT
								value = -75
							}
						}
					}
				}
				prestige = -1500
				FROM = { prestige = 1500 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -1000
				FROM = { prestige = 1000 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -75
						}
						NOT = {
							opinion = {
								who = ROOT
								value = -25
							}
						}
					}
				}
				prestige = -800
				FROM = { prestige = 800 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -700
				FROM = { prestige = 700 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = -25
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 0
							}
						}
					}
				}
				prestige = -600
				FROM = { prestige = 600 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -500
				FROM = { prestige = 500 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 0
						}
						NOT = {
							opinion = {
								who = ROOT
								value = 50
							}
						}
					}
				}
				prestige = -450
				FROM = { prestige = 450 }
			}
			if = {
				limit = {
					NOT = {
						piety = 350
					}
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -400
				FROM = { prestige = 400 }
			}
			if = {
				limit = {
					piety = 350
					FROM = {
						opinion = {
							who = ROOT
							value = 50
						}
					}
				}
				prestige = -350
				FROM = { prestige = 350 }
			}
		}
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		ai_chance = { factor = 100 }
		hidden_tooltip = { character_event = { id = HFP.23007 } }
	}
	option = {
		name = EVTOPTBHFP23006
		ai_chance = { factor = 0 }
	}
}

#Excommunicated ruler forced to pay prestige.
character_event = {
	id = HFP.23007
	desc = {
		text = EVTDESCAHFP23007
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCBHFP23007
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCBHFP23007
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23007
		if = {
			limit = { NOT = { trait = stressed } }
			random = {
				chance = 5
				add_trait = stressed
			}
		}
		ai_chance = { factor = 100 }
	}
}

#Vow of celibacy.
letter_event = {
	id = HFP.23008
	desc = EVTDESCAHFP23008
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23008
		add_trait = celibate
		set_character_flag = flag_papal_celibacy
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		hidden_tooltip = { character_event = { id = HFP.23009 } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23008
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_celibacy
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Excommunicated ruler forced to become celibate.
character_event = {
	id = HFP.23009
	desc = {
		text = EVTDESCAHFP23009
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCAHFP23009
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCAHFP23009
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23009
		trigger = { intrigue = 20 }
		tooltip_info = intrigue
		remove_trait = celibate
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23009
		if = {
			limit = {
				NOT = { trait = depressed }
				OR = {
					trait = lustful
					trait = seducer
					trait = seductress
				}
			}
			random = {
				chance = 5
				add_trait = depressed
			}
		}
		ai_chance = { factor = 10 }
	}
}

#Forced to give up a son.
letter_event = {
	id = HFP.23010
	desc = EVTDESCHFPA23010
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}
	is_triggered_only = yes
	immediate = {
		random_child = {
			limit = {
				age = 16
				is_married = no
				is_ruler = no
				prisoner = no
				NOT = { trait = incapable }
				liege = { character = ROOT }
				ROOT = {
					NOT = {
						current_heir = { character = PREVPREV }
					}
				}
				NOR = {
					trait = monk
					trait = nun
				}
			}
			#The Pope is evil.
			preferred_limit = {
				is_smart_trigger = yes
				is_strong_trigger = yes
				is_attractive_trigger = yes
			}
			preferred_limit = {
				OR = {
					is_smart_trigger = yes
					is_strong_trigger = yes
					is_attractive_trigger = yes
				}
			}
			preferred_limit = {
				NOR = {
					is_dumb_trigger = yes
					is_weak_trigger = yes
					is_unattractive_trigger = yes
				}
			}
			save_event_target_as = son_monk_candidate
		}
	}

	option = {
		name = EVTOPTAHFP23010
		religion_head = {
			show_scope_change = no
			event_target:son_monk_candidate = {
				if = {
					limit = { is_female = yes }
					add_trait = nun
				}
				if = {
					limit = { is_female = no }
					add_trait = monk
				}
				move_character = PREV
			}
		}
		hidden_tooltip = { character_event = { id = HFP.23011 } }
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23010
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_child
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

character_event = {
	id = HFP.23011
	desc = {
		text = EVTDESCAHFP23011
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCAHFP23011
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCAHFP23011
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23011
		trigger = { trait = kind }
		tooltip_info = kind
		if = {
			limit = {
				NOT = { trait = depressed }
			}
			random = {
				chance = 5
				add_trait = depressed
			}
		}
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23011
		trigger = { NOT = { trait = kind } }
		ai_chance = { factor = 10 }
	}
}

#Forced abdication.
letter_event = {
	id = HFP.23012
	desc = EVTDESCAHFP23012
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23012
		tooltip = {
			if = {
				limit = { is_female = yes }
				add_trait = nun
			}
			if = {
				limit = { is_female = no }
				add_trait = monk
			}
			excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
			abdicate = yes
		}
		hidden_tooltip = { character_event = { id = HFP.23013 } }
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = proud
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 1.5
				trait = zealous
			}
			modifier = {
				factor = 1.5
				trait = content
			}
		}
	}
	option = {
		name = EVTOPTBHFP23012
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_abdication
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 50 }
	}
}

#Ruler forced to abdicate.
character_event = {
	id = HFP.23013
	desc = {
		text = EVTDESCAHFP23013
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCAHFP23013
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCAHFP23013
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23013
		if = {
			limit = { is_female = yes }
			add_trait = nun
		}
		if = {
			limit = { is_female = no }
			add_trait = monk
		}
		if = {
			limit = { can_apply_lame_nickname_trigger = yes }
			hidden_tooltip = {
				random_list = {
					20 = { give_nickname = nick_the_hermit }
					20 = { trigger = { is_female = no } give_nickname = nick_the_monk }
					20 = { trigger = { is_female = yes } give_nickname = nick_the_nun }
					20 = { give_nickname = nick_the_recluse }
					20 = { give_nickname = nick_the_absolved }
					20 = { }
				}
			}
		}
		hidden_tooltip = { #Send character to random theocracy within the realm.
			if = {
				limit = {
					any_realm_lord = { is_theocracy = yes religion = ROOT }
				}
				custom_tooltip = { text = tooltip_vows_monk_goes_to_theocracy }
				hidden_tooltip = {
					random_realm_lord = {
						limit = { is_theocracy = yes religion = ROOT }
						preferred_limit = {
							reverse_opinion = { who = FROM value = 20 }
							vassal_of = FROM
							same_society_as = ROOT #The one he just joined.
						}
						preferred_limit = {
							vassal_of = FROM
							same_society_as = ROOT #The one he just joined.
						}
						preferred_limit = {
							same_society_as = ROOT #The one he just joined.
						}
						preferred_limit = {
							vassal_of = FROM
						}
						save_event_target_as = target_theocracy_host
					}
				}
			}
		}
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			transfer_crown_on_abdication_effect = yes
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		abdicate = yes
		hidden_tooltip = { event_target:target_theocracy_host = { ROOT = { move_character = PREV } } }
		ai_chance = { factor = 100 }
	}
}

#Forced Papal Investiture.
letter_event = {
	id = HFP.23014
	desc = EVTDESCAHFP23014
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23014
		primary_title = {
			show_scope_change = no
			revoke_law = investiture_law_1
			add_law_w_cooldown = investiture_law_0
		}
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		hidden_tooltip = { character_event = { id = HFP.23015 } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23014
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_investiture
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Ruler forced to enact Papal Investiture.
character_event = {
	id = HFP.23015
	desc = {
		text = EVTDESCAHFP23015
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCBHFP23015
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCBHFP23015
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23015
		ai_chance = { factor = 100 }
	}
}

#Forced Gavelkind.
letter_event = {
	id = HFP.23016
	desc = EVTDESCAHFP23016
	border = GFX_event_letter_frame_religion

	trigger = {
		religion = FROM
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23016
		primary_title = {
			add_law = succ_gavelkind
		}
		hidden_tooltip = {
			any_demesne_title = {
				add_law = {
					law = succ_gavelkind
					opinion_effect = no
				}
			}
		}
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		hidden_tooltip = { character_event = { id = HFP.23017 } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23016
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_gavelkind
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Ruler forced to enact Gavelkind succession.
character_event = {
	id = HFP.23017
	desc = {
		text = EVTDESCAHFP23017
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCBHFP23017
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCBHFP23017
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23017
		ai_chance = { factor = 100 }
	}
}

#Pope wants a piece of Italy.
letter_event = {
	id = HFP.23018
	desc = EVTDESCHFPA23018
	border = GFX_event_letter_frame_religion

	trigger = {
		OR = {
			religion = catholic
			religion = fraticelli
		}
	}
	is_triggered_only = yes

	immediate = {

	}
	option = {
		name = EVTOPTAHFP23018
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		hidden_tooltip = { character_event = { id = HFP.23019 } }
		#First of all, if the Emperor has Rome, it is asked automatically as an additional gift.
		#Latium Check
		if  = {
			limit = { has_landed_title = c_roma }
			c_roma = {
				grant_title = FROM
				any_de_jure_vassal = { #Pope vassalizes all vassal titles in the scope
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = { #Pope takes over any titles under the title he's taking over from you.
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
		}
		#Secondly, check for all Duchies within the borders of the historical Donation of Pepin (Latium, Spoleto, Ancona, Ferrara, Benevento).
		#If the Emperor owns them directly, the Pope takes the title, if his vassals do, said vassals will become the Papacy's vassals.
		#Latium Check
		if  = {
			limit = {
				any_demesne_title = {
					can_be_given_away = yes
					tier = duke
					title = d_latium
				}
			}
			d_latium = {
				grant_title = FROM
				any_de_jure_vassal = {
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = {
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
			break = yes
		}
		if  = {
			limit = {
				any_vassal = {
					lower_tier_than = FROM
					any_demesne_title = {
						#can_be_given_away = yes #No need as he will only get vassalized.
						tier = duke
						title = d_latium
					}
				}
			}
			random_vassal = {
				limit = {
					has_landed_title = d_latium
					lower_tier_than = FROM
				}
				set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
			}
			break = yes
		}
		#Spoleto Check
		if  = {
			limit = {
				any_demesne_title = {
					can_be_given_away = yes
					tier = duke
					title = d_spoleto
				}
			}
			d_spoleto = {
				grant_title = FROM
				any_de_jure_vassal = {
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = {
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
			break = yes
		}
		if  = {
			limit = {
				any_vassal = {
					lower_tier_than = FROM
					any_demesne_title = {
						#can_be_given_away = yes
						tier = duke
						title = d_spoleto
					}
				}
			}
			random_vassal = {
				limit = {
					has_landed_title = d_spoleto
					lower_tier_than = FROM
				}
				set_defacto_liege = FROM
				hidden_tooltip = { character_event =  { id = HF.20230 } }
			}
			break = yes
		}
		#Ancona Check
		if  = {
			limit = {
				any_demesne_title = {
					can_be_given_away = yes
					tier = duke
					title = d_ancona
				}
			}
			d_ancona = {
				grant_title = FROM
				any_de_jure_vassal = {
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = {
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
			break = yes
		}
		if  = {
			limit = {
				any_vassal = {
					lower_tier_than = FROM
					any_demesne_title = {
						#can_be_given_away = yes
						tier = duke
						title = d_ancona
					}
				}
			}
			random_vassal = {
				limit = {
					has_landed_title = d_ancona
					lower_tier_than = FROM
				}
				set_defacto_liege = FROM
				hidden_tooltip = { character_event =  { id = HF.20230 } }
			}
			break = yes
		}
		#Ferrara
		if  = {
			limit = {
				any_demesne_title = {
					can_be_given_away = yes
					tier = duke
					title = d_ferrara
				}
			}
			d_ferrara = {
				grant_title = FROM
				any_de_jure_vassal = {
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = {
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
			break = yes
		}
		if  = {
			limit = {
				any_vassal = {
					lower_tier_than = FROM
					any_demesne_title = {
						#can_be_given_away = yes
						tier = duke
						title = d_ferrara
					}
				}
			}
			random_vassal = {
				limit = {
					has_landed_title = d_ferrara
					lower_tier_than = FROM
				}
				set_defacto_liege = FROM
				hidden_tooltip = { character_event =  { id = HF.20230 } }
			}
			break = yes
		}
		#Benevento
		if  = {
			limit = {
				any_demesne_title = {
					can_be_given_away = yes
					tier = duke
					title = d_benevento
				}
			}
			d_benevento = {
				grant_title = FROM
				any_de_jure_vassal = {
					limit = {
						vassal_of = ROOT
						NOT = { owner =  { character = ROOT } }
					}
					set_defacto_liege = FROM
					hidden_tooltip = { character_event =  { id = HF.20230 } }
				}
				any_de_jure_vassal_title = {
					limit = { owner =  { character = ROOT } }
					grant_title = FROM
				}
			}
			break = yes
		}
		if  = {
			limit = {
				any_vassal = {
					lower_tier_than = FROM
					any_demesne_title = {
						#can_be_given_away = yes
						tier = duke
						title = d_benevento
					}
				}
			}
			random_vassal = {
				limit = {
					has_landed_title = d_benevento
					lower_tier_than = FROM
				}
				set_defacto_liege = FROM
				hidden_tooltip = { character_event =  { id = HF.20230 } }
			}
			break = yes
		}
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23018
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_lands
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Ruler forced to give up Italian Lands.
character_event = {
	id = HFP.23019
	desc = EVTDESCAHFP23019
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23019
		ai_chance = { factor = 100 }
	}
}

#Pope requests independence.
letter_event = {
	id = HFP.23020
	desc = EVTDESCHFPA23020
	border = GFX_event_letter_frame_religion

	trigger = {
		OR = {
			religion = catholic
			religion = fraticelli
		}
	}
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23020
		custom_tooltip = { text = TT_EVTOPTAHFP23020 }
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		hidden_tooltip = {
       		FROM = {
       			character_event = { id = HF.20234 } #Independence.
       		}
       	}
		hidden_tooltip = { character_event = { id = HFP.23021 } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23020
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_independence
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Ruler forced to give independence to Papcy.
character_event = {
	id = HFP.23021
	desc = {
		text = EVTDESCAHFP23021
		trigger = {
			religion_group = christian
		}
		picture = GFX_evt_pope
	}
	desc = {
		text = EVTDESCBHFP23021
		trigger = {
			NOR = {
				religion_group = christian
				religion_group = pagan_group
			}
		}
		picture = GFX_evt_bishop
	}
	desc = {
		text = EVTDESCBHFP23021
		trigger = {
			religion_group = pagan_group
		}
		picture = GFX_evt_tribal_shrine
	}
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23021
		ai_chance = { factor = 100 }
	}
}

#Pope demands to become your liege.
letter_event = {
	id = HFP.23022
	desc = EVTDESCHFPA23022
	border = GFX_event_letter_frame_religion

	trigger = {
		OR = {
			religion = catholic
			religion = fraticelli
		}
	}
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23022
		excommunicate = no
		hidden_tooltip = {
			sound_effect = excommunication_lifted
			FROM = {
				opinion = {
					modifier = opinion_repented_sins
					who = ROOT
					years = 20
				}
			}
		}
		set_defacto_liege = FROM
		hidden_tooltip = { character_event = { id = HFP.23023 } }
		ai_chance = { factor = 100 }
	}
	option = {
		name = EVTOPTBHFP23022
		hidden_tooltip = {
			FROM = { #Pope remembers what you asked for, no use spamming the decision, cheaty player.
				opinion = {
					modifier = opinion_pope_ex_demands_vassalization
					who = ROOT
					years = 100
				}
			}
		}
		ai_chance = { factor = 0 }
	}
}

#Ruler forced to become Papal vassal.
character_event = {
	id = HFP.23023
	desc = EVTDESCAHFP23023
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion
	is_triggered_only = yes

	option = {
		name = EVTOPTAHFP23023
		ai_chance = { factor = 100 }
	}
}

#on_imprisoned: stop pilgrimage.
character_event = {
	id = HFP.23024
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		clr_character_flag = pilgrimage_to_canterbury
		clr_character_flag = pilgrimage_to_jerusalem
		clr_character_flag = pilgrimage_to_koln
		clr_character_flag = pilgrimage_to_rome
		clr_character_flag = pilgrimage_to_santiago
		clr_character_flag = pilgrimage_to_constantinople
		clr_character_flag = pilgrimage_to_axum
		clr_character_flag = pilgrimage_to_antioch
		clr_character_flag = abominable_pilgrimage
		clr_character_flag = do_not_disturb
		clr_character_flag = preparing_pilgrimage
		clr_character_flag = activated_pilgrimage
		hidden_tooltip = { remove_trait = on_pilgrimage }
	}
}


#on_war_ended_victory: restore spouse under enemy's concubinage.
# From = Attacker, Root = Defender
character_event = {
	id = HFP.23025
	hide_window = yes
	trigger = {
		ROOT = {
			any_consort = {
				FROM = {
					has_opinion_modifier = {
						modifier = opinion_abducted_spouse
						who = PREV
					}
				}
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		ROOT = {
			any_consort = {
				limit = {
					FROM = {
						has_opinion_modifier = {
							modifier = opinion_abducted_spouse
							who = PREV
						}
					}
				}
				ROOT = { remove_consort = PREV }
				move_character = FROM
			}
		}
	}
}

#on_war_ended_defeat: restore spouse under enemy's concubinage.
# From = Attacker, Root = Defender
character_event = {
	id = HFP.23026
	hide_window = yes
	trigger = {
		FROM = {
			any_consort = {
				ROOT = {
					has_opinion_modifier = {
						modifier = opinion_abducted_spouse
						who = PREV
					}
				}
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		FROM = {
			any_consort = {
				limit = {
					ROOT = {
						has_opinion_modifier = {
							modifier = opinion_abducted_spouse
							who = PREV
						}
					}
				}
				FROM = { remove_consort = PREV }
				move_character = ROOT
			}
		}
	}
}

# African rulers can pick a random Abrahamic sympathy.
character_event = {
	id = HFP.23027
	desc = EVTDESCHFP23027

	picture = GFX_evt_church_council
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = { #Christianity
		name = {
			text = EVTOPTAHF23003
			trigger = {
				is_alternate_start = no
			}
		}
		name = {
			text = EVTOPTAHF23003_ALT
			trigger = {
				is_alternate_start = yes
			}
		}
		trigger = {
			NOT = { religion_group = christian } #Random World safety check.
			OR = {
				any_neighbor_independent_ruler = {
					religion_group = christian
				}
				any_liege = {
					religion_group = christian
				}
			}
		}
		add_trait = sympathy_christendom
		clr_character_flag = flag_picking_sympathy
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				liege = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 0
				top_liege = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 0.25
				spouse = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 1.5
				any_demesne_province = {
					religion_group = christian
				}
			}
			modifier = {
				factor = 1.5
				any_courtier_or_vassal = {
					religion_group = christian
				}
			}
		}
	}
	option = { #Islam
		name = {
			text = EVTOPTBHF23003
			trigger = {
				is_alternate_start = no
			}
		}
		name = {
			text = EVTOPTBHF23003_ALT
			trigger = {
				is_alternate_start = yes
			}
		}
		trigger = {
			NOT = { religion_group = muslim } #Random World safety check.
			OR = {
				any_neighbor_independent_ruler = {
					religion_group = muslim
				}
				any_liege = {
					religion_group = muslim
				}
			}
		}
		add_trait = sympathy_islam
		clr_character_flag = flag_picking_sympathy
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				liege = {
					OR = {
						trait = sympathy_christendom
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 0
				top_liege = {
					OR = {
						trait = sympathy_christendom
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 0.25
				spouse = {
					OR = {
						trait = sympathy_christendom
						trait = sympathy_judaism
					}
				}
			}
			modifier = {
				factor = 1.5
				any_demesne_province = {
					religion_group = muslim
				}
			}
			modifier = {
				factor = 1.5
				any_courtier_or_vassal = {
					religion_group = muslim
				}
			}
		}
	}
	option = { #Jews
		name = {
			text = EVTOPTCHF23003
			trigger = {
				is_alternate_start = no
			}
		}
		name = {
			text = EVTOPTCHF23003_ALT
			trigger = {
				is_alternate_start = yes
			}
		}
		trigger = {
			NOT = { religion_group = jewish_group } #Random World safety check.
			OR = {
				any_neighbor_independent_ruler = {
					religion_group = jewish_group
				}
				any_liege = {
					religion_group = jewish_group
				}
			}
		}
		add_trait = sympathy_judaism
		clr_character_flag = flag_picking_sympathy
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				liege = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_christendom
					}
				}
			}
			modifier = {
				factor = 0
				top_liege = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_christendom
					}
				}
			}
			modifier = {
				factor = 0.25
				spouse = {
					OR = {
						trait = sympathy_islam
						trait = sympathy_christendom
					}
				}
			}
			modifier = {
				factor = 1.5
				any_demesne_province = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 1.5
				any_courtier_or_vassal = {
					religion_group = jewish_group
				}
			}
		}
	}
	option = { #Changed mind.
		name = EVTOPTDHFP23027
		ai_chance = {
			factor = 0
		}
	}
}

#On_startup:Cleanup the Maniots on Charlemagne start if Hellenism is off.
character_event = {
	id = HFP.23028
	hide_window = yes
	trigger = {
		has_game_rule = {
			name = hellenism_rule
			value = off
		}
		NOT = { year = 800 }
		is_save_game = no
		is_alternate_start = no
		has_landed_title = k_papal_state
	}

	is_triggered_only = yes

	immediate = {
		478 = { religion = orthodox }
	}
}
