namespace = HF

# Written by Joachim
# HF.40000 - HF.40099

# A character is eligible for Beatification
character_event = {
	id = HF.40000

	is_triggered_only = yes # on_death
	hide_window = yes

	only_playable = yes
	religion_group = christian
	has_dlc = "Holy Fury"
	min_age = 16

	trigger = {
		has_virtue_trigger = yes
		is_benevolent_trigger = yes
		is_pious_trigger = yes
		has_vice_trigger = no
		is_any_kinslayer_trigger = no
		death_in_china_trigger = no
		death_no_trace_trigger = no
		is_antipope = no

		NOR = {
			trait = excommunicated
			trait = drunkard
			trait = hedonist
			trait = cannibal
			religion = waldensian
			has_character_modifier = voice_of_satan
			has_character_modifier = known_satanist
			has_character_modifier = suspected_demon_spawn
			has_character_modifier = suspected_witch
			has_character_modifier = known_witch
			has_character_modifier = crazy_cannibal
			has_character_modifier = demon_child_non_pagan
			has_character_modifier = corrupting_magic_minor
			has_character_modifier = corrupting_magic_major
		}

		OR = {
			trigger_if = {
				limit = { real_tier = EMPEROR }
				piety >= 1250
			}
			trigger_else_if = {
				limit = { real_tier = KING }
				piety >= 1000
			}
			trigger_else_if = {
				limit = { real_tier = DUKE }
				piety >= 750
			}
			trigger_else_if = {
				limit = { real_tier = COUNT }
				piety >= 500
			}

			has_character_modifier = true_christian_knight
			has_any_opinion_modifier = opinion_baptism_sponsor_target
		}
	}

	immediate = {
		# Beatification
		save_event_target_as = saint_person

		capital_scope = {
			save_event_target_as = saint_capital
		}

		random_demesne_province = {
			limit = {
				owned_by = PREV

				NOR = {
					has_province_modifier = tomb_of_a_saint
					has_province_modifier = pillaged_tomb_of_a_saint
				}
			}

			save_event_target_as = random_saint_demesne_province
		}

		random_realm_province = {
			limit = {
				NOR = {
					has_province_modifier = tomb_of_a_saint
					has_province_modifier = pillaged_tomb_of_a_saint
					province = event_target:random_saint_demesne_province
				}

				held_under_PREV = yes
			}

			save_event_target_as = random_saint_realm_province
		}

		random = {
			chance = 100

			mult_modifier = {
				factor = 0.25

				any_owned_bloodline = {
					has_bloodline_flag = saintly_bloodline
					bloodline_is_active_for = PREV
				}
			}

			mult_modifier = {
				factor = 0.8
				trait = cynical
			}

			# Potential for sainthood
			deciding_upon_saint_effect = yes

			# Path to beatification
			random_realm_lord = {
				limit = {
					is_theocracy = yes
					is_landed = yes
					religion = ROOT
					NOT = { trait = bad_priest_christian }
				}

				random_realm_province = {
					preferred_limit = { held_under_PREV = yes }
					province_event = { id = HF.40001 }
				}
			}
		}

		if = {
			limit = { ai = no }
			add_trait = i_used_to_be_a_player
		}
	}
}

# Decision if to be Beatified
province_event = {
	id = HF.40001

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = { has_global_flag = qa_testing }

			province_event = {
				id = HF.40002
				days = 3
			}
		}
		else = {
			province_event = {
				id = HF.40002
				days = 180
				random = 360
			}
		}
	}
}

# Decision has been made to be Beatified
province_event = {
	id = HF.40002

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		owner = {
			if = {
				limit = {
					has_global_flag = only_papal_saints

					event_target:saint_person = {
						religion = catholic
					}
				}

				# Try to stay in the same realm, accounting for potential antipopes
				if = {
					limit = {
						top_liege = {
							any_realm_character = {
								religion = catholic
							}
						}
					}

					top_liege = {
						random_realm_character = {
							limit = { religion = catholic }

							rightful_religious_head_scope = {
								character_event = { id = HF.40005 }
							}
						}
					}
				}
				# Then look closeby
				else_if = {
					limit = {
						top_liege = {
							any_neighbor_independent_ruler = {
								any_realm_character = {
									religion = catholic
								}
							}
						}
					}

					top_liege = {
						random_neighbor_independent_ruler = {
							limit = {
								any_realm_character = {
									religion = catholic
								}
							}

							random_realm_character = {
								limit = { religion = catholic }

								rightful_religious_head_scope = {
									character_event = { id = HF.40005 }
								}
							}
						}
					}
				}
				# Then further out still
				else_if = {
					limit = {
						any_independent_ruler = {
							any_realm_character = {
								religion = catholic
							}
						}
					}

					random_independent_ruler = {
						limit = {
							any_realm_character = {
								religion = catholic
							}
						}

						random_realm_character = {
							limit = { religion = catholic }

							rightful_religious_head_scope = {
								character_event = { id = HF.40005 }
							}
						}
					}
				}
				else = { # Can't find anyone, just get the Pope to do it
					event_target:saint_person = {
						religion_head = {
							character_event = { id = HF.40005 }
						}
					}
				}
			}
			else = {
				# Try to stay in the same subrealm
				if = {
					limit = {
						any_realm_lord = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}
					}

					random_realm_lord = {
						limit = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}

						character_event = { id = HF.40003 }
					}
				}
				# Try to stay in the same realm
				else_if = {
					limit = {
						top_liege = {
							any_realm_lord = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}
						}
					}

					top_liege = {
						random_realm_lord = {
							limit = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}

							character_event = { id = HF.40003 }
						}
					}
				}
				# Then look closeby
				else_if = {
					limit = {
						top_liege = {
							any_neighbor_independent_ruler = {
								any_realm_lord = {
									is_theocracy = yes
									is_landed = yes
									religion = event_target:saint_person
									NOT = { trait = bad_priest_christian }
								}
							}
						}
					}

					top_liege = {
						random_neighbor_independent_ruler = {
							limit = {
								any_realm_lord = {
									is_theocracy = yes
									is_landed = yes
									religion = event_target:saint_person
									NOT = { trait = bad_priest_christian }
								}
							}

							random_realm_lord = {
								limit = {
									is_theocracy = yes
									is_landed = yes
									religion = event_target:saint_person
									NOT = { trait = bad_priest_christian }
								}

								character_event = { id = HF.40003 }
							}
						}
					}
				}
				# Then further out still
				else_if = {
					limit = {
						any_independent_ruler = {
							any_realm_lord = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}
						}
					}

					random_independent_ruler = {
						limit = {
							any_realm_lord = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}
						}

						random_realm_lord = {
							limit = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}

							character_event = { id = HF.40003 }
						}
					}
				}
				# Can't find anyone, let's hope this religion has a religious head
				else = {
					event_target:saint_person = {
						religion_head = {
							character_event = { id = HF.40003 }
						}
					}
				}
			}
		}
	}
}

# Local priest sends out letters declaring beatification
character_event = {
	id = HF.40003

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		save_event_target_as = bishopric_holder

		event_target:saint_person = {
			add_trait = beatified

			if = {
				limit = { is_female = yes }
				set_special_character_title = BLESSED_TITLE_FEMALE
			}
			else = {
				set_special_character_title = BLESSED_TITLE
			}
		}

		top_liege = {
			any_realm_character = {
				limit = {
					religion_group = ROOT
					NOT = { dynasty = event_target:saint_person }
				}

				narrative_event = { id = HF.40004 }
			}
		}

		event_target:saint_person = {
			any_dynasty_member = {
				limit = { religion_group = ROOT }
				narrative_event = { id = HF.40004 }
			}
		}
	}
}

# Beatification is made official
narrative_event = {
	id = HF.40004
	title = TITLEHF.40004
	desc = EVTDESC_HF_40004
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	portrait = event_target:saint_person

	is_triggered_only = yes

	option = {
		name = EVTOPTAHF.40004

		if = {
			limit = { dynasty = event_target:saint_person }
			piety = 50
		}

		show_portrait = event_target:bishopric_holder
	}
}

# Pope sends out letters declaring beatification
character_event = {
	id = HF.40005

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		event_target:saint_person = {
			add_trait = beatified

			if = {
				limit = { is_female = yes }
				set_special_character_title = BLESSED_TITLE_FEMALE
			}
			else = {
				set_special_character_title = BLESSED_TITLE
			}
		}

		event_target:saint_person = {
			primary_title = {
				holder_scope = {
					any_realm_character = {
						limit = {
							religion_group = ROOT
							NOT = { dynasty = event_target:saint_person }
						}

						narrative_event = { id = HF.40006 }
					}

					top_liege = {
						if = {
							limit = {
								religion_group = ROOT
								NOT = { dynasty = event_target:saint_person }
							}

							narrative_event = { id = HF.40006 }
						}
					}
				}
			}

			any_dynasty_member = {
				limit = { religion_group = ROOT }
				narrative_event = { id = HF.40006 }
			}
		}
	}
}

# Papal beatification Event
narrative_event = {
	id = HF.40006
	desc = EVTDESC_HF_40006
	title = TITLEHF.40006
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	portrait = event_target:saint_person

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HF_40006

		if = {
			limit = { dynasty = event_target:saint_person }

			piety = 250

			rightful_religious_head_scope = {
				show_scope_change = no

				opinion = {
					name = opinion_family_saint
					who = ROOT
					years = 10
				}
			}

			random_vassal = {
				show_scope_change = no

				limit = {
					is_priest = yes
					NOT = { rightful_religious_head = THIS }
				}

				opinion = {
					name = opinion_family_saint
					who = ROOT
					years = 10
				}
			}
		}

		show_portrait = FROM
	}
}

# Checking time left to Canonization
province_event = {
	id = HF.40010

	is_triggered_only = yes # deciding_upon_saint_effect
	hide_window = yes

	immediate = {
		if = {
			limit = {
				OR = {
					has_global_flag = qa_testing

					event_target:saint_person = {
						has_religion_feature = religion_beatification
						has_religion_feature = religion_feature_egyptian
					}
				}
			}

			province_event = {
				id = HF.40015
				days = 5
			}
		}
		else_if = {
			limit = {
				event_target:saint_person = {
					trait = i_used_to_be_a_player
				}
			}

			province_event = {
				id = HF.40015
				days = 1000
				random = 1000
			}
		}
		else = {
			province_event = {
				id = HF.40015
				days = 1000
				random = 10000
			}
		}
	}
}

# Preparing Canonization
province_event = {
	id = HF.40015

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		event_target:saint_person = {
			OR = {
				trait = beatified
				has_religion_feature = religion_beatification
				has_religion_feature = religion_feature_egyptian
			}

			NOT = { has_character_flag = blessed_ancestor_prestige }
		}
	}

	immediate = {
		event_target:saint_capital = {
			if = {
				limit = {
					owner = {
						religion = event_target:saint_person
					}
				}

				owner = {
					rightful_religious_head_scope = {
						character_event = { id = HF.40020 }
					}
				}
			}

			else = {
				event_target:saint_person = {
					rightful_religious_head_scope = {
						character_event = { id = HF.40020 }
					}
				}
			}
		}
	}
}

# Canonization
character_event = {
	id = HF.40020
	picture = GFX_evt_council

	desc = {
		text = EVTDESC_HF_40020_A
		trigger = {
			event_target:saint_person = {
				religion_group = christian
			}
		}
	}
	desc = {
		text = EVTDESC_HF_40020_B
		trigger = {
			event_target:saint_person = {
				religion_group = pagan_group
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		save_event_target_as = canonizer_person
	}

	option = {
		name = EVTOPTA_HF_40020

		if = {
			limit = { religion_group = christian }
			custom_tooltip = { text = pope_cannonize_choice_TT }
		}
		else = {
			custom_tooltip = { text = pagan_pope_cannonize_choice_TT }
		}

		hidden_effect = {
			event_target:saint_person = {
				# Find Miracle - Christian only
				if = {
					limit = { religion_group = christian }

					# Global variable used in localisation
					random_list = {
						# Stigmata
						100 = {
							set_variable = { which = global_miracle value = 1 }
							give_nickname = nick_the_god_bearing
						}

						# Incorruptible body
						100 = {
							set_variable = { which = global_miracle value = 2 }
							give_nickname = nick_the_myrrh_streaming
						}

						# Miraculous healing
						800 = {
							trigger = { trait = physician }

							set_variable = { which = global_miracle value = 3 }

							if = {
								limit = { trait = charitable }
								give_nickname = nick_the_unmercenary_healer
							}
							else = {
								give_nickname = nick_the_healer
							}
						}

						# Prophetic Foresight
						200 = {
							trigger = {
								OR = {
									trait = mystic
									trait = possessed
								}
							}

							set_variable = { which = global_miracle value = 4 }
							give_nickname = nick_the_prophet
						}

						# Mindreading
						100 = {
							set_variable = { which = global_miracle value = 5 }
							give_nickname = nick_the_understanding
						}

						# Exorciser
						100 = {
							trigger = { trait = zealous }

							set_variable = { which = global_miracle value = 6 }
							give_nickname = nick_the_righteous
						}

						# Angel talker
						100 = {
							set_variable = { which = global_miracle value = 7 }
							give_nickname = nick_the_apostle
						}

						# Waterwalker
						50 = {
							set_variable = { which = global_miracle value = 8 }
							give_nickname = nick_the_confessor
						}

						# Heard after death
						50 = {
							set_variable = { which = global_miracle value = 9 }
							give_nickname = nick_the_venerable
						}

						# Creating fire
						25 = {
							set_variable = { which = global_miracle value = 10 }
							give_nickname = nick_the_spark_of_god
						}

						# Praying heavy object away
						50 = {
							set_variable = { which = global_miracle value = 11 }
							give_nickname = nick_the_right_believing
						}

						# Being seen after death
						25 = {
							trigger = { martyrs_death_trigger = yes }

							set_variable = { which = global_miracle value = 12 }
							give_nickname = nick_the_martyr
						}

						# Blessing local water with the power of love
						25 = {
							set_variable = { which = global_miracle value = 13 }
							give_nickname = nick_the_miracle_worker
						}

						# Rats
						25 = {
							trigger = { trait = lunatic }

							set_variable = { which = global_miracle value = 14 }
							give_nickname = nick_the_fool_for_christ
						}

						# Wise dog
						25 = {
							set_variable = { which = global_miracle value = 15 }
							give_nickname = nick_the_merciful
						}

						# Flying
						25 = {
							set_variable = { which = global_miracle value = 16 }
							give_nickname = nick_the_pious
						}
					}
				}

				# Give nickname - Pagan only
				else_if = {
					limit = {
						trigger_if = {
							limit = { has_nickname = yes }
							has_nickname = nick_the_blessed
						}
					}

					random_list = {
						1 = { give_nickname = nick_the_noble }
						1 = { give_nickname = nick_the_gentle }

						3 = {
							trigger = { trait = chaste }
							give_nickname = nick_the_chaste
						}

						3 = {
							trigger = { trait = just }
							give_nickname = nick_the_just
						}

						3 = {
							trigger = { trait = attractive }
							give_nickname = nick_the_fair
						}

						3 = {
							trigger = { trait = malnourished }
							give_nickname = nick_the_hollow
						}

						3 = {
							trigger = {
								OR = {
									trait = genius
									trait = shrewd
									trait = quick
									learning >= 15
								}
							}

							give_nickname = nick_the_wise
						}

						3 = {
							trigger = { trait = one_eyed }
							give_nickname = nick_one_eye
						}

						3 = {
							trigger = {
								OR = {
									trait = strong
									trait = brawny
								}
							}

							give_nickname = nick_the_bear
						}

						3 = {
							trigger = { trait = brave }
							give_nickname = nick_the_bold
						}

						15 = {
							trigger = {
								trait = hunter
								trait = brilliant_strategist
								culture_group = altaic
							}

							give_nickname = nick_the_wolf
						}
					}
				}
			}

			# Messages
			any_playable_ruler = {
				limit = {
					religion = ROOT
					NOT = { dynasty = event_target:saint_person }
				}

				narrative_event = { id = HF.40025 }
			}

			event_target:saint_person = {
				any_dynasty_member = {
					limit = { religion_group = ROOT }
					narrative_event = { id = HF.40025 }
				}
			}

			narrative_event = { id = HF.40025 }

			# Trait change
			event_target:saint_person = {
				if = {
					limit = { religion_group = christian }

					remove_trait = beatified
					add_trait = saint

					if = {
						limit = { is_female = yes }
						set_special_character_title = SAINT_TITLE_FEMALE
					}
					else = {
						set_special_character_title = SAINT_TITLE
					}
				}
				else = {
					add_trait = blessed_ancestor
					set_special_character_title = BLESSED_TITLE
				}
			}

			# Burial Site setting - Christian only
			if = {
				limit = {
					event_target:saint_person = {
						religion_group = christian
					}
				}

				# Confirm that a burial site exists, for pilgrimage
				# set_global_flag = saintly_burial_sites_exist # Not used because fallback saintly pilgrimages were added

				event_target:saint_capital = {
					owner = {
						save_event_target_as = saint_capital_owner
					}

					if = {
						limit = {
							NOR = {
								has_province_modifier = tomb_of_a_saint
								has_province_modifier = pillaged_tomb_of_a_saint
							}
						}

						setting_up_saintly_burial_site_effect = yes
					}
					else_if = {
						limit = {
							any_neighbor_province = {
								owned_by = event_target:saint_capital_owner

								NOR = {
									has_province_modifier = tomb_of_a_saint
									has_province_modifier = pillaged_tomb_of_a_saint
								}
							}
						}

						random_neighbor_province = {
							limit = {
								owned_by = event_target:saint_capital_owner

								NOR = {
									has_province_modifier = tomb_of_a_saint
									has_province_modifier = pillaged_tomb_of_a_saint
								}
							}

							setting_up_saintly_burial_site_effect = yes
						}
					}
					else_if = {
						limit = {
							event_target:random_saint_demesne_province = {
								NOR = {
									has_province_modifier = tomb_of_a_saint
									has_province_modifier = pillaged_tomb_of_a_saint
								}
							}
						}

						event_target:random_saint_demesne_province = {
							setting_up_saintly_burial_site_effect = yes
						}
					}
					else_if = {
						limit = {
							event_target:random_saint_realm_province = {
								NOR = {
									has_province_modifier = tomb_of_a_saint
									has_province_modifier = pillaged_tomb_of_a_saint
								}
							}
						}

						event_target:random_saint_realm_province = {
							setting_up_saintly_burial_site_effect = yes
						}
					}
				}
			}

			# Bloodline creation
			event_target:saint_person = {
				random_list = {
					20 = {
						trigger = {
							OR = {
								trait = zealous
								trait = holy_warrior
							}
						}

						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_01
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_01
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_01
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { religion = norse_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_germanic_01
									religion = norse_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_germanic_01
									religion = norse_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = baltic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_romuva_01
									religion = baltic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_romuva_01
									religion = baltic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = slavic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_slavic_01
									religion = slavic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_slavic_01
									religion = slavic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = tengri_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_tengri_01
									religion = tengri_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_tengri_01
									religion = tengri_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = finnish_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_suomenusko_01
									religion = finnish_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_suomenusko_01
									religion = finnish_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = aztec_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_aztec_01
									religion = aztec_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_aztec_01
									religion = aztec_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = west_african_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_african_01
									religion = west_african_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_african_01
									religion = west_african_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = zun_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_zun_01
									religion = zun_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_zun_01
									religion = zun_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = hellenic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_hellenic_01
									religion = hellenic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_hellenic_01
									religion = hellenic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = bon_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_bon_01
									religion = bon_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_bon_01
									religion = bon_pagan_reformed
								}
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_01
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}

					20 = {
						trigger = {
							has_dlc = "Mystics"

							OR = {
								trait = celibate
								trait = monk
								trait = nun
							}

							OR = {
								religion_group = christian
								religion = hellenic_pagan_reformed
							}
						}

						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_02
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_02
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_02
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_02
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}

					5 = {
						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_03
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_03
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_03
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { religion = norse_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_germanic_03
									religion = norse_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_germanic_03
									religion = norse_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = baltic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_romuva_03
									religion = baltic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_romuva_03
									religion = baltic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = slavic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_slavic_03
									religion = slavic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_slavic_03
									religion = slavic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = tengri_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_tengri_03
									religion = tengri_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_tengri_03
									religion = tengri_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = finnish_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_suomenusko_03
									religion = finnish_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_suomenusko_03
									religion = finnish_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = aztec_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_aztec_03
									religion = aztec_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_aztec_03
									religion = aztec_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = west_african_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_african_03
									religion = west_african_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_african_03
									religion = west_african_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = zun_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_zun_03
									religion = zun_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_zun_03
									religion = zun_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = hellenic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_hellenic_03
									religion = hellenic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_hellenic_03
									religion = hellenic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = bon_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_bon_03
									religion = bon_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_bon_03
									religion = bon_pagan_reformed
								}
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_03
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}

					5 = {
						mult_modifier = {
							factor = 4

							OR = {
								trait = zealous
								trait = holy_warrior
							}
						}

						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_04
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_04
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_04
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { religion = norse_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_germanic_04
									religion = norse_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_germanic_04
									religion = norse_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = baltic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_romuva_04
									religion = baltic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_romuva_04
									religion = baltic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = slavic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_slavic_04
									religion = slavic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_slavic_04
									religion = slavic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = {
								religion = tengri_pagan_reformed
							}
							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_tengri_04
									religion = tengri_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_tengri_04
									religion = tengri_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = finnish_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_suomenusko_04
									religion = finnish_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_suomenusko_04
									religion = finnish_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = aztec_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_aztec_04
									religion = aztec_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_aztec_04
									religion = aztec_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = west_african_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_african_04
									religion = west_african_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_african_04
									religion = west_african_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = zun_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_zun_04
									religion = zun_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_zun_04
									religion = zun_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = hellenic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_hellenic_04
									religion = hellenic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_hellenic_04
									religion = hellenic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = bon_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_bon_04
									religion = bon_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_bon_04
									religion = bon_pagan_reformed
								}
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_04
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}

					30 = {
						trigger = { trait = sympathy_judaism }

						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_05
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_05
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_05
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { religion = norse_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_germanic_05
									religion = norse_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_germanic_05
									religion = norse_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = baltic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_romuva_05
									religion = baltic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_romuva_05
									religion = baltic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = slavic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_slavic_05
									religion = slavic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_slavic_05
									religion = slavic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = tengri_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_tengri_05
									religion = tengri_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_tengri_05
									religion = tengri_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = finnish_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_suomenusko_05
									religion = finnish_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_suomenusko_05
									religion = finnish_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = aztec_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_aztec_05
									religion = aztec_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_aztec_05
									religion = aztec_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = west_african_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_african_05
									religion = west_african_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_african_05
									religion = west_african_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = zun_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_zun_05
									religion = zun_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_zun_05
									religion = zun_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = hellenic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_hellenic_05
									religion = hellenic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_hellenic_05
									religion = hellenic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = bon_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_bon_05
									religion = bon_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_bon_05
									religion = bon_pagan_reformed
								}
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_05
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}

					5 = {
						if = {
							limit = { is_orthodox_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_orthodox_06
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_nestorian_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_nestorian_06
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { is_miaphysite_branch = yes }

							create_bloodline = {
								type = saintly_bloodline_coptic_06
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}
						else_if = {
							limit = { religion = norse_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_germanic_06
									religion = norse_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_germanic_06
									religion = norse_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = baltic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_romuva_06
									religion = baltic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_romuva_06
									religion = baltic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = slavic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_slavic_06
									religion = slavic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_slavic_06
									religion = slavic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = tengri_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_tengri_06
									religion = tengri_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_tengri_06
									religion = tengri_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = finnish_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_suomenusko_06
									religion = finnish_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_suomenusko_06
									religion = finnish_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = aztec_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_aztec_06
									religion = aztec_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_aztec_06
									religion = aztec_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = west_african_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_african_06
									religion = west_african_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_african_06
									religion = west_african_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = zun_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_zun_06
									religion = zun_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_zun_06
									religion = zun_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = hellenic_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_hellenic_06
									religion = hellenic_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_hellenic_06
									religion = hellenic_pagan_reformed
								}
							}
						}
						else_if = {
							limit = { religion = bon_pagan_reformed }

							if = {
								limit = { is_female = yes }

								create_bloodline = {
									type = saintly_bloodline_bon_06
									religion = bon_pagan_reformed
									inheritance = matrilineal
								}
							}
							else = {
								create_bloodline = {
									type = saintly_bloodline_bon_06
									religion = bon_pagan_reformed
								}
							}
						}
						else = {
							create_bloodline = {
								type = saintly_bloodline_catholic_06
								religion = event_target:saint_person
								inheritance = patrilineal
							}
						}

						if = {
							limit = { religion_group = christian }

							new_bloodline = {
								set_name = saintly_bloodline_name
								set_description = saintly_bloodline_description
							}
						}
						else = {
							new_bloodline = {
								set_name = blessed_bloodline_name
								set_description = blessed_bloodline_description
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB_HF_40020

		ai_chance = { factor = 0 }
	}
}

# Notification sent out to all players
character_event = {
	id = HF.40022
	desc = EVTDESC_HF_40022
	picture = GFX_evt_large_army

	is_triggered_only = yes
	notification = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = OK
	}
}

# Canonization Official
narrative_event = {
	id = HF.40025
	title = EVTTITLE_HF_40025
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	portrait = event_target:saint_person

	desc = {
		text = EVTDESC_HF_40025
		picture = GFX_evt_beatification
		trigger = {
			event_target:saint_person = {
				religion_group = christian
			}
		}
	}
	desc = {
		text = EVTDESC_HF_40025_B
		picture = GFX_evt_pagan_reformation
		trigger = {
			event_target:saint_person = {
				religion_group = pagan_group
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				event_target:saint_person = {
					religion_group = christian
				}
			}

			sound_effect = saint_proclaimed
		}

		opinion = {
			name = opinion_very_grateful_donation
			who = FROM
			years = 30
		}
	}

	option = {
		name = EVTOPTA_HF_40025

		show_portrait = FROM

		if = {
			limit = { dynasty = event_target:saint_person }

			piety = 100

			if = {
				limit = { religion_group = christian }
				custom_tooltip = { text = TT_CANONIZATION_FAMILY }
			}
			else = {
				custom_tooltip = { text = TT_PAGAN_CANONIZATION_FAMILY }
			}
		}
	}
}

# Bad Beatification
character_event = {
	id = HF.40050

	is_triggered_only = yes # on_death, random_events
	hide_window = yes

	religion = catholic
	has_dlc = "Holy Fury"
	min_age = 16

	trigger = {
		OR = {
			trait = drunkard
			trait = hedonist
		}

		year >= 900
		NOT = { has_global_flag = only_papal_saints }

		rightful_religious_head_scope = {
			controls_religion = yes
		}
	}

	weight_multiplier = {
		factor = 1

		# After the year 950
		mult_modifier = {
			factor = 2
			year >= 950
			year < 1000
		}

		# After the year 1000
		mult_modifier = {
			factor = 3
			year >= 1000
			year <  1050
		}

		# After the year 1050
		mult_modifier = {
			factor = 4
			year >= 1050
			year <  1110
		}

		# After the year 1110
		mult_modifier = {
			factor = 5
			year >= 1100
			year <  1150
		}

		# After the year 1150
		mult_modifier = {
			factor = 6
			year >= 1150
			year <  1200
		}

		# After the year 1200
		mult_modifier = {
			factor = 7
			year >= 1200
			year <  1250
		}

		# After the year 1250
		mult_modifier = {
			factor = 8
			year >= 1250
		}
	}

	immediate = {
		save_event_target_as = saint_person

		random_realm_lord = {
			limit = {
				is_theocracy = yes
				religion = ROOT
				is_landed = yes
			}

			save_event_target_as = bishopric_holder

			random_realm_province = {
				preferred_limit = { held_under_PREV = yes }
				province_event = { id = HF.40051 }
			}
		}
	}
}

# Bishop considers making a sinful Beatified
province_event = {
	id = HF.40051

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = { has_global_flag = qa_testing }

			province_event = {
				id = HF.40052
				days = 3
			}
		}
		else = {
			province_event = {
				id = HF.40052
				days = 180
				random = 500
			}
		}
	}
}

# Bishop decided to make a Sinful Beatified
province_event = {
	id = HF.40052

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		event_target:saint_person = {
			NOR = {
				trait = beatified
				trait = saint
			}
		}
	}

	immediate = {
		owner = {
			# Try to stay within the subrealm
			if = {
				limit = {
					any_realm_lord = {
						is_theocracy = yes
						is_landed = yes
						religion = event_target:saint_person
						NOT = { trait = bad_priest_christian }
					}
				}

				random_realm_lord = {
					limit = {
						is_theocracy = yes
						is_landed = yes
						religion = event_target:saint_person
						NOT = { trait = bad_priest_christian }
					}

					character_event = { id = HF.40053 }
				}
			}
			# Then look within the entire realm
			else_if = {
				limit = {
					top_liege = {
						any_realm_lord = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}
					}
				}

				top_liege = {
					random_realm_lord = {
						limit = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}

						character_event = { id = HF.40053 }
					}
				}
			}
			# Then look in nearby realms
			else_if = {
				limit = {
					top_liege = {
						any_neighbor_independent_ruler = {
							any_realm_lord = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}
						}
					}
				}

				top_liege = {
					random_independent_ruler = {
						limit = {
							any_realm_lord = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}
						}

						random_realm_lord = {
							limit = {
								is_theocracy = yes
								is_landed = yes
								religion = event_target:saint_person
								NOT = { trait = bad_priest_christian }
							}

							character_event = { id = HF.40053 }
						}
					}
				}
			}
			# Then look further still
			else_if = {
				limit = {
					any_independent_ruler = {
						any_realm_lord = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}
					}
				}

				random_independent_ruler = {
					limit = {
						any_realm_lord = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}
					}

					random_realm_lord = {
						limit = {
							is_theocracy = yes
							is_landed = yes
							religion = event_target:saint_person
							NOT = { trait = bad_priest_christian }
						}

						character_event = { id = HF.40053 }
					}
				}
			}
			# No papal fallback, popes can already declare wicked saints which skip beatification
		}
	}
}

# Bishop sends out the letters with the news of the sinful Beatification
character_event = {
	id = HF.40053

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		rightful_religious_head_scope = {
			controls_religion = yes
		}

		NOR = {
			has_global_flag = only_papal_saints
			has_global_flag = bad_beatification_completed
		}
	}

	immediate = {
		religion_authority = {
			name = impious_beatification
		}

		save_event_target_as = bishopric_holder

		event_target:saint_person = {
			add_trait = beatified

			if = {
				limit = { is_female = yes }
				set_special_character_title = BLESSED_TITLE_FEMALE
			}
			else = {
				set_special_character_title = BLESSED_TITLE
			}
		}

		any_realm_character = {
			limit = {
				religion_group = ROOT
				NOT = { dynasty = event_target:saint_person }
			}

			narrative_event = { id = HF.40055 }
		}

		event_target:saint_person = {
			any_dynasty_member = {
				limit = { religion_group = ROOT }
				narrative_event = { id = HF.40055 }
			}
		}

		top_liege = {
			if = {
				limit = {
					religion_group = ROOT
					NOT = { dynasty = event_target:saint_person }
				}

				narrative_event = { id = HF.40055 }
			}
		}

		# Lead up to Pope's response
		random_realm_province = {
			preferred_limit = { held_under_PREV = yes }
			province_event = { id = HF.40056 }
		}

		set_global_flag = bad_beatification_completed
	}
}

# Sinful Beatification event
narrative_event = {
	id = HF.40055
	title = TITLEHF.40055
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	portrait = event_target:saint_person

	# Disapprove of sinful Blessed
	desc = {
		text = EVTDESCA_HF_40055
		trigger = {
			# Dislike sinful beatified
			NOR = {
				trait = drunkard
				trait = hedonist
			}
		}
	}

	# Approve of sinful beatified
	desc = {
		text = EVTDESCB_HF_40055
		trigger = {
			# Similar
			OR = {
				trait = drunkard
				trait = hedonist
			}
		}
	}

	is_triggered_only = yes

	option = {
		# Stranger and disapprove
		name = {
			text = EVTOPTA_HF_40055
			trigger = {
				NOR = {
					trait = drunkard
					trait = hedonist
					dynasty = event_target:saint_person
				}
			}
		}

		# Stranger and approve
		name = {
			text = EVTOPTB_HF_40055
			trigger = {
				OR = {
					trait = drunkard
					trait = hedonist
				}

				NOT = { dynasty = event_target:saint_person }
			}
		}

		# Family and disapprove
		name = {
			text = EVTOPTC_HF_40055
			trigger = {
				dynasty = event_target:saint_person

				NOR = {
					trait = drunkard
					trait = hedonist
				}
			}
		}

		# Family and approve
		name = {
			text = EVTOPTD_HF_40055
			trigger = {
				dynasty = event_target:saint_person

				OR = {
					trait = drunkard
					trait = hedonist
				}
			}
		}

		show_portrait = event_target:bishopric_holder
	}
}

# Pope preparing a response
province_event = {
	id = HF.40056

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = { has_global_flag = qa_testing }

			province_event = {
				id = HF.40057
				days = 5
			}
		}
		else = {
			province_event = {
				id = HF.40057
				days = 180
				random = 500
			}
		}
	}
}

# Pope finished response
province_event = {
	id = HF.40057

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		event_target:saint_person = {
			religion_head = {
				character_event = { id = HF.40058 }
			}
		}
	}
}

# Pope sending out letters
character_event = {
	id = HF.40058

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		NOT = { has_global_flag = only_papal_saints }
	}

	immediate = {
		set_global_flag = only_papal_saints
		log = "Only Papal Beatifications, declared by [Root.GetTitledName]"

		any_playable_ruler = {
			limit = { religion = catholic }
			narrative_event = { id = HF.40060 }
		}
	}
}

# Vatican Outrage over Sinful Beatification
narrative_event = {
	id = HF.40060
	title = TITLEHF.40060
	picture = GFX_evt_church_council
	border = GFX_event_narrative_frame_religion

	# Approve of Papal decision
	desc = {
		text = EVTDESCA_HF_40060
		trigger = {
			# Dislike sinful beatified
			NOR = {
				trait = drunkard
				trait = hedonist
			}
		}
	}

	# Disapprove of Papal decision
	desc = {
		text = EVTDESCB_HF_40060
		trigger = {
			# Similar
			OR = {
				trait = drunkard
				trait = hedonist
			}
		}
	}

	is_triggered_only = yes

	option = {
		name = {
			text = EVTOPTA_HF_40060 # Stranger and approve of Papal decision
			trigger = {
				NOT = { dynasty = event_target:saint_person }
			}
		}
		name = {
			text = EVTOPTC_HF_40060 # Family and approve of Papal decision
			trigger = { dynasty = event_target:saint_person }
		}

		trigger = {
			NOR = {
				trait = drunkard
				trait = hedonist
			}
		}

		show_portrait = event_target:saint_person
	}

	option = {
		name = {
			text = EVTOPTB_HF_40060 # Stranger and disapprove of Papal decision
			trigger = {
				NOT = { dynasty = event_target:saint_person }
			}
		}
		name = {
			text = EVTOPTD_HF_40060 # Family and disapprove of Papal decision
			trigger = { dynasty = event_target:saint_person }
		}

		trigger = {
			OR = {
				trait = drunkard
				trait = hedonist
			}
		}

		show_portrait = event_target:saint_person

		opinion = {
			name = insulted
			who = FROM
		}

		reverse_opinion = {
			name = insulted
			who = FROM
		}
	}

	after = {
		custom_tooltip = { text = impious_beatification_tooltip }
	}
}

# Bad Papal saint
character_event = {
	id = HF.40090

	is_triggered_only = yes # on_death
	hide_window = yes

	religion = catholic
	min_age = 16

	trigger = {
		death_in_china_trigger = no
		death_no_trace_trigger = no

		religion_head = {
			trait = bad_priest_christian
			independent = yes
			opinion = {
				who = ROOT
				value >= 50
			}
		}

		NOT = { trait = excommunicated }

		OR = {
			AND = {
				trait = impaler
				religion_head = { trait = impaler }
			}
			AND = {
				trait = hedonist
				religion_head = { trait = hedonist }
			}
			AND = {
				trait = cannibal
				religion_head = { trait = cannibal }
			}
			AND = {
				trait = lunatic
				religion_head = { trait = lunatic }
			}
			AND = {
				trait = drunkard
				religion_head = { trait = drunkard }
			}
			AND = {
				trait = homosexual

				religion_head = {
					is_lover = ROOT
					trait = homosexual
					trait = lustful
				}
			}
			AND = {
				trait = hedonist
				religion_head = { trait = hedonist }
			}
			AND = {
				trait = cannibal
				religion_head = { trait = cannibal }
			}
			AND = {
				trait = lunatic
				religion_head = { trait = lunatic }
			}
			AND = {
				trait = drunkard
				religion_head = { trait = drunkard }
			}
			AND = {
				trait = homosexual

				religion_head = {
					is_lover = ROOT
					trait = homosexual
					trait = lustful
				}
			}
			AND = {
				trait = lustful

				religion_head = {
					is_lover = ROOT
					trait = lustful
					NOT = { trait = homosexual }
				}
			}
			AND = {
				OR = {
					trait = master_seducer
					trait = master_seductress
				}

				religion_head = {
					OR = {
						trait = master_seducer
						trait = master_seductress
					}
				}
			}
		}
	}

	immediate = {
		save_event_target_as = saint_person

		random = {
			chance = 20

			religion_head = {
				character_event = { id = HF.40091 }
			}
		}
	}
}

# Bad Papal Saint decision
character_event = {
	id = HF.40091

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = { has_global_flag = qa_testing }

			character_event = {
				id = HF.40092
				days = 5
			}
		}
		else = {
			character_event = {
				id = HF.40092
				days = 180
				random = 300
			}
		}
	}
}

# Pope sends out letters deciding bad Saint
character_event = {
	id = HF.40092

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		OR = {
			AND = {
				trait = impaler
				event_target:saint_person = { trait = impaler }
			}
			AND = {
				trait = hedonist
				event_target:saint_person = { trait = hedonist }
			}
			AND = {
				trait = cannibal
				event_target:saint_person = { trait = cannibal }
			}
			AND = {
				trait = lunatic
				event_target:saint_person = { trait = lunatic }
			}
			AND = {
				trait = drunkard
				event_target:saint_person = { trait = drunkard }
			}
			AND = {
				trait = homosexual
				event_target:saint_person = { trait = homosexual }
			}
			AND = {
				trait = lustful
				NOT = { trait = homosexual }

				event_target:saint_person = { trait = lustful }
			}
			AND = {
				OR = {
					trait = master_seducer
					trait = master_seductress
				}

				event_target:saint_person = {
					OR = {
						trait = master_seducer
						trait = master_seductress
					}
				}
			}
		}

		NOT = { has_character_flag = impious_canonization_done }
	}

	immediate = {
		religion_authority = {
			name = impious_canonization
		}

		any_playable_ruler = {
			limit = { religion = ROOT }
			narrative_event = { id = HF.40098 }
		}

		log = "Bad Saint canonized by [Root.GetTitledName]"
		set_character_flag = impious_canonization_done
		set_global_flag = pre_catholic_civil_war

		event_target:saint_person = {
			remove_trait = beatified
			add_trait = saint

			create_bloodline = {
				type = saintly_bloodline_07
				religion = event_target:saint_person
				inheritance = patrilineal
			}

			event_target:saint_person = {
				trigger_switch = {
					on_trigger = trait

					impaler           = { give_nickname = nick_gods_torturer       new_bloodline = { set_description = saintly_impaler_description } }
					hedonist          = { give_nickname = nick_gods_hedonist       new_bloodline = { set_description = saintly_hedonist_description } }
					cannibal          = { give_nickname = nick_gods_cannibal       new_bloodline = { set_description = saintly_cannibal_description } }
					lunatic           = { give_nickname = nick_the_fool_for_christ new_bloodline = { set_description = saintly_lunatic_description } }
					drunkard          = { give_nickname = nick_gods_drunkard       new_bloodline = { set_description = saintly_drunkard_description } }
					homosexual        = { give_nickname = nick_papal_lover         new_bloodline = { set_description = saintly_homosexual_description } }
					lustful           = { give_nickname = nick_papal_lover         new_bloodline = { set_description = saintly_lustful_description } }
					master_seducer    = { give_nickname = nick_gods_seducer        new_bloodline = { set_description = saintly_seducer_description } }
					master_seductress = { give_nickname = nick_gods_seducer        new_bloodline = { set_description = saintly_seducer_description } }
				}
			}

			if = {
				limit = { is_female = yes }
				set_special_character_title = SAINT_TITLE_FEMALE
			}
			else = {
				set_special_character_title = SAINT_TITLE
			}
		}

		if = {
			limit = {
				independent = yes

				any_independent_ruler = {
					higher_real_tier_than = DUKE
					religion = ROOT
					is_within_diplo_range = ROOT
					NOT = { trait = cynical }
					war = no
					ai = yes
				}
			}

			random_independent_ruler = {
				limit = {
					higher_real_tier_than = DUKE
					religion = ROOT
					is_within_diplo_range = ROOT
					NOT = { trait = cynical }
					war = no
					ai = yes
				}

				preferred_limit = {
					real_tier = EMPEROR
				}

				save_event_target_as = papal_attacker
				add_trait = zealous

				war = {
					target = ROOT
					casus_belli = depose_impious_pope
				}
			}

			any_playable_ruler = {
				limit = {
					religion = ROOT
					NOT = { character = event_target:papal_attacker }
				}

				narrative_event = {
					id = HF.40093
					days = 15
				}
			}
		}
	}
}

# Bad Papal Saint main event
narrative_event = {
	id = HF.40098
	title = TITLEHF.40098
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
	portrait = event_target:saint_person
	sound = saint_proclaimed

	desc = {
		text = EVTDESCA_HF_40098
		trigger = { FROM = { trait = impaler } }
	}
	desc = {
		text = EVTDESCB_HF_40098
		trigger = { FROM = { trait = hedonist } }
	}
	desc = {
		text = EVTDESCC_HF_40098
		trigger = { FROM = { trait = cannibal } }
	}
	desc = {
		text = EVTDESCD_HF_40098
		trigger = { FROM = { trait = lunatic } }
	}
	desc = {
		text = EVTDESCE_HF_40098
		trigger = { FROM = { trait = drunkard } }
	}
	desc = {
		text = EVTDESCF_HF_40098
		trigger = { FROM = { trait = homosexual } }
	}
	desc = {
		text = EVTDESCG_HF_40098
		trigger = {
			FROM = {
				trait = lustful
				NOT = { trait = homosexual }
			}
		}
	}
	desc = {
		text = EVTDESCH_HF_40098
		trigger = {
			FROM = {
				OR = {
					trait = master_seducer
					trait = master_seductress
				}
			}
		}
	}

	is_triggered_only = yes

	# Disgruntled at the Pope's unebelievable actions
	option = {
		name = EVTOPTA_HF_40098

		custom_tooltip = { text = impious_canonization_tooltip }

		ai_chance = {
			factor = 80

			trigger = {
				NAND = {
					independent = yes
					trait = zealous
				}
			}

			mult_modifier = {
				factor = 0.25

				OR = {
					trait = cannibal
					trait = impaler
					trait = hedonist
					trait = drunkard
					trait = master_seducer
					trait = lustful
					trait = lunatic
				}
			}
		}
	}

	# Side with the Pope
	option = {
		name = EVTOPTC_HF_40098

		trigger = {
			NOT = { trait = zealous }
		}

		show_portrait = FROM

		random = {
			chance = 50

			if = {
				limit = {
					FROM = {
						OR = {
							trait = impaler
							trait = cannibal
						}
					}

					NOT = { trait = cruel }
				}

				remove_trait_silently_kind_effect = yes
				add_trait = cruel
			}
			else_if = {
				limit = {
					FROM = {
						OR = {
							trait = hedonist
							trait = drunkard
						}
					}

					NOT = { trait = gluttonous }
				}

				add_trait_fully_silently_gluttonous_effect = yes # Includes weight changes
			}
			else_if = {
				limit = {
					FROM = {
						OR = {
							trait = master_seducer
							trait = master_seductress
							trait = lustful
						}
					}

					NOT = { trait = lustful }
				}

				remove_trait_silently_chaste_effect = yes
				add_trait = lustful
			}
			else_if = {
				limit = {
					FROM = { trait = lunatic }
					NOT = { trait = lunatic }
				}

				add_trait = lunatic
			}
		}

		custom_tooltip = {
			text = impious_canonization_tooltip
			set_character_flag = supported_impious_pope
		}

		ai_chance = {
			factor = 20

			trigger = { independent = yes }

			mult_modifier = {
				factor = 4

				OR = {
					trait = cannibal
					trait = impaler
					trait = hedonist
					trait = drunkard
					trait = master_seducer
					trait = lustful
					trait = lunatic
				}
			}
		}
	}
}

# War against the Pope
narrative_event = {
	id = HF.40093
	desc = EVTDESC_HF_40093
	title = EVTTITLE_HF_40093
	picture = GFX_evt_large_army
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes

	trigger = {
		FROM = {
			controls_religion = yes

			any_war = {
				using_cb = depose_impious_pope

				defender = {
					character = PREVPREV
				}
			}
		}

		event_target:papal_attacker = {
			is_alive = yes
		}
	}

	immediate = {
		clr_global_flag = pre_catholic_civil_war
	}

	# Support the war to depose the Pope
	option = {
		name = EVTOPTA_HF_40093

		trigger = {
			independent = yes

			NOR = {
				trait = cynical
				has_character_flag = supported_impious_pope

				any_war = {
					using_cb = depose_impious_pope
				}
			}
		}

		custom_tooltip = {
			text = join_war_to_despose_pope_TT

			event_target:papal_attacker = {
				show_scope_change = no

				any_war = {
					limit = {
						using_cb = depose_impious_pope
						is_primary_war_attacker = yes
					}

					ROOT = {
						show_scope_change = no

						join_attacker_wars = PREV
					}
				}
			}
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 5

				OR = {
					trait = zealous
					trait = holy_warrior
				}
			}
		}
	}

	# Support the Pope
	option = {
		name = EVTOPTB_HF_40093

		trigger = {
			independent = yes

			NOR = {
				trait = zealous
				trait = holy_warrior

				any_war = {
					using_cb = depose_impious_pope
				}
			}
		}

		custom_tooltip = {
			text = join_war_to_defend_pope_TT

			FROMFROM = {
				any_war = {
					limit = { using_cb = depose_impious_pope }

					ROOT = {
						show_scope_change = no

						join_defender_wars = PREV
					}
				}
			}
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 5
				has_character_flag = supported_impious_pope
			}
		}
	}

	# Take neither side
	option = {
		name = EVTOPTC_HF_40093

		trigger = {
			independent = yes

			NOT = {
				any_war = { using_cb = depose_impious_pope }
			}
		}

		custom_tooltip = { text = EVTOPTC_HF_40093_TT }

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 3

				NOR = {
					has_character_flag = supported_impious_pope
					trait = zealous
					trait = holy_warrior
				}
			}
		}
	}

	# Already in the war
	option = {
		name = EVTOPTD_HF_40093

		trigger = {
			any_war = { using_cb = depose_impious_pope }
		}
	}

	# Not independent
	option = {
		name = EVTOPTE_HF_40093

		trigger = { independent = no }
	}
}

# The Pope loses and have to abdicate
narrative_event = {
	id = HF.40094
	title = EVTTITLE_HF_40094
	desc = EVTDESC_HF_40094
	picture = GFX_evt_church_council
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # depose_impious_pope

	immediate = {
		k_papacy = {
			holder_scope = {
				save_event_target_as = current_pope
			}
		}
	}

	option = {
		name = {
			text = EVTOPTA_HF_40094
			trigger = {
				NOT = { has_character_flag = impious_papal_defender }
			}
		}
		name = {
			text = EVTOPTB_HF_40094
			trigger = { has_character_flag = impious_papal_defender }
		}

		clr_character_flag = impious_papal_defender
		show_portrait = event_target:current_pope
	}
}

# The Pope wins
narrative_event = {
	id = HF.40095
	title = EVTTITLE_HF_40095
	desc = EVTDESC_HF_40095
	picture = GFX_evt_church_council
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # depose_impious_pope

	option = {
		name = {
			text = EVTOPTA_HF_40095
			trigger = {
				NOT = { has_character_flag = impious_papal_defender }
			}
		}
		name = {
			text = EVTOPTB_HF_40095
			trigger = { has_character_flag = impious_papal_defender }
		}

		clr_character_flag = impious_papal_defender
	}
}