namespace = HF

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

#A character is eligible for Beatification
character_event = {
	id = HF.40000
	hide_window = yes
	is_triggered_only = yes
	min_age = 16
    only_playable = yes
	religion_group = christian
	has_dlc = "Holy Fury"

	trigger = {
		death_in_china_trigger = no
		death_no_trace_trigger = no
		NOR = {
			trait = excommunicated
			trait = drunkard
			trait = hedonist
			trait = cannibal_trait
			#controls_religion = yes
            religion = waldensian
			religion = mandean
            is_any_kinslayer_trigger = yes
            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
            
            any_claim = { title = k_papal_state } # Antipopes
            any_claim = { title = d_fraticelli } # Antipopes
		}
		OR = {
			AND = {
				tier = Emperor
				piety >= 1250
			}

			AND = {
				tier = King
				piety >= 1000
			}
			AND = {
				tier = Duke
				piety >= 750
			}
			AND = {
				tier = Count
				piety >= 500
			}
			has_character_modifier = true_christian_knight
            has_any_opinion_modifier = opinion_baptism_sponsor_target
		}
		has_vice_trigger = no
		is_benevolent_trigger = yes
		is_pious_trigger = yes
		has_virtue_trigger = yes
		is_adult = yes
	}

	immediate = {
        #Beatification
        save_event_target_as = saint_person
        event_target:saint_person = {
        	capital_scope = {
        		save_event_target_as = saint_capital
        	}
        }
        random_demesne_province = {
        	limit = {
        		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
        		}
        	}
        	save_event_target_as = random_saint_realm_province
        }
        if = {
            limit = {
                religion_group = christian
            }
            random_realm_character = {
                limit = {
                    is_theocracy = yes
                    religion = event_target:saint_person
                    NOT = {
                        trait = bad_priest_christian
                    }
                    is_landed = yes
                }
                random = {
                    chance = 100
                    modifier = {
                        factor = 0.25
                        event_target:saint_person = {
                            any_owned_bloodline = {
                                has_bloodline_flag = saintly_bloodline
                            }
                        }
                    }
                    modifier = {
                        factor = 0.8
                        event_target:saint_person = {
                            trait = cynical
                        }
                    }
                    random_realm_province = {
                        province_event = { id = HF.40001 }
                    }
                    event_target:saint_person = {
                        set_character_flag = beatified
                    }
                }
            }
        }

        if = {
            limit = {
                event_target:saint_person = {
                    ai = no
                }
            }
            event_target:saint_person = {
                add_trait = i_used_to_be_a_player
            }
        }
        #Potential for sainthood
        deciding_upon_saint_effect = yes
	}
}

#Decision if to be Beatified
province_event = {
	id = HF.40001
    hide_window = yes
	is_triggered_only = yes
    has_dlc = "Holy Fury"

	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
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    immediate = {
        holder_scope = {
        	if = {
        		limit = {
        			has_global_flag = only_papal_saints
        			event_target:saint_person = {
        				religion = catholic
        			}
        		}
        		rightful_religious_head_scope = {
    				character_event = { id = HF.40005 }
        		}
        	}
        	else = {
	            random_realm_character = {
	                limit = {
	                    is_theocracy = yes
	                    religion = event_target:saint_person
	                    NOT = {
	                        trait = bad_priest_christian
	                    }
                        is_landed = yes
	                }
	                character_event = { id = HF.40003 }
	            }
            }
        }
    }
}

#Local priest sends out letters declaring beatification
character_event = {
    id = HF.40003
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

    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 = {
                    NOT = {
                        family = event_target:saint_person
                    }
        			religion_group = ROOT
        		}
        		narrative_event = { id = HF.40004 }
                set_character_flag = had_beatification_notification #Flags to make sure you only get the event once
            }
    	}
        event_target:saint_person = {
            any_dynasty_member = {
                limit = {
                    religion_group = ROOT
                    NOT = { has_character_flag = had_beatification_notification }
                }
                narrative_event = { id = HF.40004 }
                set_character_flag = had_beatification_notification
            }
        }
        top_liege = {
            if = {
                limit = {
                    NOR = {
                        family = event_target:saint_person
                        has_character_flag = had_beatification_notification
                    }
                    religion_group = ROOT
                }
                narrative_event = { id = HF.40004 }
            }
        }
    }
    after = { #To remove the flags
        any_realm_character = {
            limit = {
                has_character_flag = had_beatification_notification
            }
            clr_character_flag = had_beatification_notification
        }
        event_target:saint_person = {
            any_dynasty_member = {
                limit = {
                    has_character_flag = had_beatification_notification
                }
                clr_character_flag = had_beatification_notification
            }
        }
        top_liege = {
            if = {
                limit = {
                    has_character_flag = had_beatification_notification
                }
                clr_character_flag = had_beatification_notification
            }
        }
    }
}

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

	option = {
		name = EVTOPTAHF.40004
        if = {
            limit = {
                event_target:saint_person = {
                    family = ROOT
                }
            }
            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
    has_dlc = "Holy Fury"

    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 = {
                            NOT = {
                                family = event_target:saint_person
                            }
                           religion_group = ROOT
                        }
                        narrative_event = { id = HF.40006 }
                    }
                }
            }
        }
        event_target:saint_person = {
            any_dynasty_member = {
                limit = {
                    religion_group = ROOT
                }
                narrative_event = { id = HF.40006 }
            }
        }
        event_target:saint_person = {
            primary_title = {
                holder_scope = {
                    top_liege = {
                        if = {
                            limit = {
                                NOT = {
                                    family = event_target:saint_person
                                }
                                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
    is_triggered_only = yes
	portrait = event_target:saint_person
    has_dlc = "Holy Fury"

    option = {      
        name = EVTOPTA_HF_40006
        if = {
            limit = {
                event_target:saint_person = {
                    family = ROOT
                }
            }
            piety = 250
			religion_head = {
				opinion = {
					modifier = opinion_family_saint
					who = ROOT
					years = 10
				}
			}
			random_vassal = {
				limit = {
					is_priest = yes
					religion_head = { NOT = { character = PREV } }
				}
				opinion = {
					modifier = opinion_family_saint
					who = ROOT
					years = 10
				}
			}
        }
        show_portrait = FROM
    }
}

#Checking time left to Canonization
character_event = {
    id = HF.40010
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"
    immediate = {
        if = {
            limit = {
                OR = {
                    has_global_flag = qa_testing
                    event_target:saint_person = {
                        has_religion_feature = religion_beatification
                    }
                }
            }
            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
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"
    trigger = {
        event_target:saint_person = {
            OR = {
                trait = beatified
                has_religion_feature = religion_beatification
            }
            NOT = {
                has_character_flag = blessed_ancestor_prestige
            }
        }
    }

    immediate = { 
        if = {
            limit = {
                event_target:saint_capital = {
                    owner = {
                        religion = event_target:saint_person
                    }
                }
            }
            event_target:saint_capital = {
                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
    desc = {
        trigger = {
            event_target:saint_person = {
                religion_group = christian
            }
        }
        text = EVTDESC_HF_40020_A
    } 
    desc = {
        trigger = {
            event_target:saint_person = {
                religion_group = pagan_group
            }
        }
        text = EVTDESC_HF_40020_B
    }
    picture = GFX_evt_council
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    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_if = {
            limit = {
                religion_group = pagan_group
            }
            custom_tooltip = {
                text = pagan_pope_cannonize_choice_TT
            }
        }

        hidden_tooltip = {
            # Find Miracle - Christian only
            if = {
                limit = {
                    event_target:saint_person = {
                        religion_group = christian
                    }
                }
                random_list = {
                    #Stigmata
                    100 = {
                        set_variable = { which = global_miracle value = 1 }
                        event_target:saint_person = {
                            give_nickname = nick_the_god_bearing
                        }
                    }
                    #Incorruptible body
                    100 = {
                        set_variable = { which = global_miracle value = 2 }
                        event_target:saint_person = {
                            give_nickname = nick_the_myrrh_streaming
                        }
                    }
                    #Miraculous healing
                    800 = {
                        trigger = {
                            event_target:saint_person = {
                                trait = physician
                            }
                        }
                        set_variable = { which = global_miracle value = 3 }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    trait = charitable
                                }
                            }
                            event_target:saint_person = {
                                give_nickname = nick_the_unmercenary_healer
                            }
                        }
                        else = {
                            event_target:saint_person = {
                                give_nickname = nick_the_healer
                            }
                        }
                    }
                    #Prophetic Foresight
                    200 = {
                        trigger = {
                            event_target:saint_person = {
                                OR = {
                                    trait = mystic
                                    trait = possessed
                                }
                            }
                        }
                        set_variable = { which = global_miracle value = 4 }
                        event_target:saint_person = {
                            give_nickname = nick_the_prophet
                        }
                    }
                    #Mindreading
                    100 = {
                        set_variable = { which = global_miracle value = 5 }
                        event_target:saint_person = {
                            give_nickname = nick_the_understanding
                        }
                    }
                    #Exorciser
                    100 = {
                        trigger = {
                            event_target:saint_person = {
                                trait = zealous
                            }
                        }
                        set_variable = { which = global_miracle value = 6 }
                        event_target:saint_person = {
                            give_nickname = nick_the_righteous
                        }
                    }
                    #Angel talker
                    100 = {
                        set_variable = { which = global_miracle value = 7 }
                        event_target:saint_person = {
                            give_nickname = nick_the_apostle
                        }
                    }
                    #Waterwalker
                    50 = {
                        set_variable = { which = global_miracle value = 8 }
                        event_target:saint_person = {
                            give_nickname = nick_the_confessor
                        }
                    }
                    #Heard after death
                    50 = {
                        set_variable = { which = global_miracle value = 9 }
                        event_target:saint_person = {
                            give_nickname = nick_the_venerable
                        }
                    }
                    #Creating fire
                    25 = {
                        set_variable = { which = global_miracle value = 10 }
                        event_target:saint_person = {
                            give_nickname = nick_the_spark_of_god
                        }
                    }
                    #Praying heavy object away
                    50 = {
                        set_variable = { which = global_miracle value = 11 }
                        event_target:saint_person = {
                            give_nickname = nick_the_right_believing
                        }
                    }
                    #Being seen after death
                    25 = {
                        trigger = {
                            event_target:saint_person = {
                                martyrs_death_trigger = yes
                            }
                        }
                        set_variable = { which = global_miracle value = 12 }
                        event_target:saint_person = {
                            give_nickname = nick_the_martyr
                        } 
                    }
                    #Blessing local water with the power of love
                    25 = {
                        set_variable = { which = global_miracle value = 13 }
                        event_target:saint_person = {
                            give_nickname = nick_the_miracle_worker 
                        }
                    }
                    #Rats
                    25 = {
                        trigger = {
                            event_target:saint_person = {
                                trait = lunatic
                            }
                        }
                        set_variable = { which = global_miracle value = 14 }
                        event_target:saint_person = {
                            give_nickname = nick_the_fool_for_christ
                        }
                    }
                    #Wise dog
                    25 = {
                        set_variable = { which = global_miracle value = 15 }
                        event_target:saint_person = {
                            give_nickname = nick_the_merciful 
                        }
                    }
                    #Flying
                    25 = {
                        set_variable = { which = global_miracle value = 16 }
                        event_target:saint_person = {
                            give_nickname = nick_the_pious
                        }
                    }
                }
            }
            # Give nickname - Pagan only
            if = {
                limit = {
                    event_target:saint_person = {
                        religion_group = pagan_group
                        OR = {
                            has_nickname = no
                            has_nickname = nick_the_blessed
                        }
                    }
                }
                event_target:saint_person = {
                    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 = fair
                            }
                            give_nickname = nick_the_fair
                        }
                        3 = {
                            trigger = {
                                trait = is_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 = robust
                                }
                            }
                            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 = {
                    NOT = {
                        family = event_target:saint_person
                    }
                    religion = ROOT
                }
                narrative_event = { id = HF.40025 }
            }
            event_target:saint_person = {
                any_dynasty_member = {
                    limit = {
                        religion_group = ROOT
                    }
                    narrative_event = { id = HF.40025 }
                }
            }
            ROOT = {
                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_if = {
                    limit = {
                        religion_group = pagan_group
                    }
                    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
                event_target:saint_capital = {
                    owner = {
                        save_event_target_as = saint_capital_owner
                    }
                }
                if = {
                    limit = {
                        NOR = {
                            event_target:saint_capital = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:saint_capital = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:saint_capital = {
                        setting_up_saintly_burial_site_effect = yes
                    }
                }
                else_if = {
                    limit = {
                        event_target:saint_capital = {
                            any_neighbor_province = {
                                owner = {
                                    character = event_target:saint_capital_owner
                                }
                                NOR = {
                                    has_province_modifier = tomb_of_a_saint
                                    has_province_modifier = pillaged_tomb_of_a_saint
                                }
                            }
                        }
                    }
                    event_target:saint_capital = {
                        random_neighbor_province = {
                            limit = {
                                owner = {
                                    character = 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 = {
                        NOR = {
                            event_target:random_saint_demesne_province = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:random_saint_demesne_province = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:random_saint_demesne_province = {
                        setting_up_saintly_burial_site_effect = yes
                    }
                }
                else_if = {
                    limit = {
                        NOR = {
                            event_target:random_saint_realm_province = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:random_saint_realm_province = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:random_saint_realm_province = {
                        setting_up_saintly_burial_site_effect = yes             
                    }
                }
            }
            # Bloodline creation
            random_list = {
                20 = {
                    trigger = {
                        event_target:saint_person = {
                            OR = {
                                trait = zealous
                                trait = holy_warrior
                            }
                        }
                    }
                    event_target:saint_person = {
                        if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_01
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_01
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_01
                                    religion = aztec_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_01
                                    religion = aztec_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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_bon_01
                                    religion = bon_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_bon_01
                                    religion = bon_reformed
                                }
                            }
                        }
                        else = {
                            create_bloodline = {
                                type = saintly_bloodline_catholic_01
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
                20 = {
                    trigger = {
                        has_dlc = "Mystics"
                        OR = {
                            event_target:saint_person = {
                                trait = celibate
                            }
                            event_target:saint_person = {
                                trait = monk
                            }
                            event_target:saint_person = {
                                trait = nun
                            }
                        }
                        OR = {
                            event_target:saint_person = {
                                religion_group = christian
                            }
                            event_target:saint_person = {
                                religion = hellenic_pagan_reformed
                            }
                        }
                    }
                    event_target:saint_person = {
                         if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_02
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
								OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_02
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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 = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    event_target:saint_person = {
                        if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_03
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_03
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_03
                                    religion = aztec_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_03
                                    religion = aztec_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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_bon_03
                                    religion = bon_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_bon_03
                                    religion = bon_reformed
                                }
                            }
                        }
                        else = {
                            create_bloodline = {
                                type = saintly_bloodline_catholic_03
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    modifier = {
                        factor = 4
                        OR = {
                            event_target:saint_person = {
                                trait = zealous
                            }
                            event_target:saint_person = {
                                trait = holy_warrior
                            }
                        }
                    }
                    event_target:saint_person = {
                        if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_04
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_04
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_04
                                    religion = aztec_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_04
                                    religion = aztec_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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_bon_04
                                    religion = bon_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_bon_04
                                    religion = bon_reformed
                                }
                            }
                        }
                        else = {
                            create_bloodline = {
                                type = saintly_bloodline_catholic_04
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
                30 = {
                    trigger = {
                        event_target:saint_person = {
                            trait = sympathy_judaism
                        }
                    }
                    event_target:saint_person = {
                        if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_05
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_05
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_05
                                    religion = aztec_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_05
                                    religion = aztec_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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_bon_05
                                    religion = bon_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_bon_05
                                    religion = bon_reformed
                                }
                            }
                        }
                        else = {
                            create_bloodline = {
                                type = saintly_bloodline_catholic_05
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    event_target:saint_person = {
                        if = {
                            limit = {
                                OR = {
                                    religion = orthodox
                                    religion = iconoclast
                                    religion = paulician
                                    religion = monothelite
									religion = barlaamite
                                }
                            }
                            create_bloodline = {
                                type = saintly_bloodline_orthodox_06
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
									religion = nestorian
									religion = chaldean
									religion = apollinarian
								}
                            }
                            create_bloodline = {
                                type = saintly_bloodline_nestorian_06
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        else_if = {
                            limit = {
                                OR = {
                                    religion = miaphysite
                                    religion = monophysite
									religion = judaizer
                                }
                            }
                            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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_06
                                    religion = aztec_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_aztec_06
                                    religion = aztec_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_reformed
                            }
                            if = {
                                limit = {
                                    is_female = yes
                                }
                                create_bloodline = {
                                    type = saintly_bloodline_bon_06
                                    religion = bon_reformed
                                    inheritance = matrilineal
                                }
                            }
                            else = {
                                create_bloodline = {
                                    type = saintly_bloodline_bon_06
                                    religion = bon_reformed
                                }
                            }
                        }
                        else = {
                            create_bloodline = {
                                type = saintly_bloodline_catholic_06
                                religion = event_target:saint_person
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                        else_if = {
                            limit = {
                                event_target:saint_person = {
                                    religion_group = pagan_group
                                }
                            }
                            new_bloodline = {
                                set_name = blessed_bloodline_name
                                set_description = blessed_bloodline_description
                            }
                        }
                    }
                }
            }
        }

        ai_chance = {
            factor = 1
        }
    }

    option = {
        name = EVTOPTB_HF_40020

        ai_chance = {
            factor = 0
        }
    }
}

#Notification about Burial Site
province_event = {
    id = HF.40021
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

   	immediate = {
   		owner = {
			character_event = { id = HF.40022 }
   		}
   	}
}

#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
    has_dlc = "Holy Fury"

    option = {      
        name = OK
    }
}

#Canonization Official
narrative_event = {
    id = HF.40025
    desc = {
        trigger = {
            event_target:saint_person = {
                religion_group = christian
            }
        }
        text = EVTDESC_HF_40025
        picture = GFX_evt_beatification
    }
    desc = {
        trigger = {
            event_target:saint_person = {
                religion_group = pagan_group
            }
        }
        text = EVTDESC_HF_40025_B
        picture = GFX_evt_pagan_reformation
    }
    title = EVTTITLE_HF_40025
    portrait = event_target:saint_person
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    has_dlc = "Holy Fury"
    
    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 = {
                event_target:saint_person = {
                    family = ROOT
                }
            }
            piety = 100
            if = {
                limit = {
                    religion_group = christian
                }
                custom_tooltip = { text = TT_CANONIZATION_FAMILY }
            }
            else_if = {
                limit = {
                    religion_group = pagan_group
                }
                custom_tooltip = { text = TT_PAGAN_CANONIZATION_FAMILY}
            }
        }
    }
}

#Bad Beatification
character_event = {
    id = HF.40050
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"
    min_age = 16
    religion = catholic

    trigger = {
    	OR = {
   	    	trait = drunkard
   	    	trait = hedonist
    	}
    	year = 900
    	NOT = {
    		has_global_flag = only_papal_saints
    	}
        rightful_religious_head_scope = {
            has_landed_title = k_papal_state
        }
    }

	weight_multiplier = {
		days = 1
		#After the year 950
		modifier = {
			factor = 2
			year = 950
			NOT = {
				year = 1000
			}
		}
		#After the year 1000
		modifier = {
			factor = 3
			year = 1000
			NOT = {
				year = 1050
			}
		}
		#After the year 1050
		modifier = {
			factor = 4
			year = 1050
			NOT = {
				year = 1110
			}
		}
		#After the year 1110
		modifier = {
			factor = 5
			year = 1100
			NOT = {
				year = 1150
			}
		}
		#After the year 1150
		modifier = {
			factor = 6
			year = 1150
			NOT = {
				year = 1200
			}
		}
		#After the year 1200
		modifier = {
			factor = 7
			year = 1200
			NOT = {
				year = 1250
			}
		}
		#After the year 1250
		modifier = {
			factor = 8
			year = 1250
		}
	}

    immediate = {
		save_event_target_as = saint_person
		random_realm_character = {
			limit = {
				is_theocracy = yes
				religion = ROOT
			}
			save_event_target_as = bishopric_holder 
			primary_title = {
				save_event_target_as = bishopric_title
			}
            random_realm_province = {
                province_event = { id = HF.40051 }
            }
		}
    }
}

#Bishop considers making a sinful Beatified
province_event = {
    id = HF.40051
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

    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
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"
    immediate = {
        holder_scope = {
            random_realm_character = {
                limit = {
                    is_theocracy = yes
                    religion = event_target:saint_person
                    NOT = {
                        trait = bad_priest_christian
                    }
                    NOR = {
                    	event_target:saint_person = {
                    		trait = beatified
                    	}
                    	event_target:saint_person = {
                    		trait = saint
                    	}
                    }
                }
                character_event = { id = HF.40053 }
            }
        }
    }
}

#Bishop sends out the letters with the news of the sinful Beatification
character_event = {
    id = HF.40053
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

    trigger = {
        rightful_religious_head_scope = {
            has_landed_title = k_papal_state
        }
        NOT = {
            has_global_flag = only_papal_saints
        }
        NOT = {
            has_global_flag = bad_beatification_completed
        }
    }

    immediate = {
        religion_authority = {
            modifier = 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 = {
                NOT = {
                    family = event_target:saint_person
                }
               religion_group = ROOT
            }
            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 = {
                    NOT = {
                        family = event_target:saint_person
                    }
                    religion_group = ROOT
                }
                narrative_event = { id = HF.40055}
            }
        }
        random_realm_province = {
            province_event = { id = HF.40056 }
        }
        set_global_flag = bad_beatification_completed
    }
}

#Sinful Beatification event
narrative_event = {
    id = HF.40055

    #Disapprove of sinful Blessed
    desc = {
    	trigger = {
	    	OR = {
	    		#Stranger, and dislike sinful beatified
		    	AND = {
		    		NOR = {
	    				trait = drunkard
	    				trait = hedonist
	    			    event_target:saint_person = {
	    				   family = ROOT
                        }
	    			}
	    		}
	    		#Family member, and disapprove of sinful beatified
	    		AND = {
					NOR = {
							trait = drunkard
							trait = hedonist
					}
					event_target:saint_person = {
						family = ROOT
					}
	    		}
	    	}
    	}
    	text = EVTDESCA_HF_40055
    }

    #Approve of sinful beatified
	desc = {
		trigger = {
			OR = {
				#Not family member, but similar
				AND = {
					OR = {
						trait = drunkard
						trait = hedonist
					}
					NOT = {
						event_target:saint_person = {
							family = ROOT
						}
					}
				}
				#Family Member and similar
				AND = {
					OR = {
						trait = drunkard
						trait = hedonist
					}
					event_target:saint_person = {
						family = ROOT
					}
				}
			}
		}
		text = EVTDESCB_HF_40055
	} 

    title = TITLEHF.40055
	portrait = event_target:saint_person
    picture = GFX_evt_beatification	
    border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    #Stranger and disapprove
    option = {
        name = EVTOPTA_HF_40055
        trigger = {
        	NOT = {
    			OR = {
					trait = drunkard
					trait = hedonist
    			}        		
    			event_target:saint_person = {
        			family = ROOT
        		}
        	}
        }
        show_portrait = bishopric_holder
    }

    #Stranger and approve
    option = {
    	name = EVTOPTB_HF_40055
    	trigger = {
			OR = {
				trait = drunkard
				trait = hedonist
			}    		
    		NOT = {
    			event_target:saint_person = {
    				family = ROOT
    			}
    		}
    	}
        show_portrait = bishopric_holder
    }

    #Family and disapprove
    option = {
    	name = EVTOPTC_HF_40055
    	trigger = {
    		event_target:saint_person = {
    			family = ROOT
    		}
    		NOT = {
    			OR = {
					trait = drunkard
					trait = hedonist
    			}
    			
    		}
    	}
        show_portrait = bishopric_holder
    }

    #Family and approve
    option = {
    	name = EVTOPTD_HF_40055
    	trigger = {
			OR = {
				trait = drunkard
				trait = hedonist
			}    		
			event_target:saint_person = {
    			family = ROOT
    		}
    	}
        show_portrait = bishopric_holder
    }
}

#Pope preparing a response
province_event = {
    id = HF.40056
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

    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
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"
    immediate = {
        k_papal_state = { 
            holder_scope = {
                character_event = { id = HF.40058 }
            }
        }
    }
}

#Pope sending out letters
character_event = {
    id = HF.40058
    hide_window = yes
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    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

    #Approve of Papal decision
    desc = {
    	trigger = {
	    	OR = {
	    		#Stranger, and dislike sinful beatified
	    		NOR = {
    				trait = drunkard
    				trait = hedonist
	    			event_target:saint_person = {
	    				family = ROOT
	    			}
	    		}
	    		#Family member, and dislike sinful beatified
	    		AND = {
					NOR = {
						trait = drunkard
						trait = hedonist
					}
					event_target:saint_person = {
						family = ROOT
					}
	    		}
	    	}
    	}
    	text = EVTDESCA_HF_40060
    }

    #Disapprove of Papal decision
	desc = {
		trigger = {
			OR = {
				#Not family member of Saint, but similar
				AND = {
					OR = {
						trait = drunkard
						trait = hedonist
					}
					NOT = {
						event_target:saint_person = {
							family = ROOT
						}
					}
				}
				#Family Member of Saint and similar
				AND = {
					OR = {
						trait = drunkard
						trait = hedonist
					}
					event_target:saint_person = {
						family = ROOT
					}
				}
			}
		}
		text = EVTDESCB_HF_40060
	} 

    title = TITLEHF.40060
    picture = GFX_evt_church_council
	border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    #Stranger and approve of Papal decision
    option = {
        name = EVTOPTA_HF_40060
        trigger = {
        	NOR = {
				trait = drunkard
				trait = hedonist
    			event_target:saint_person = {
        			family = ROOT
        		}
        	}
        }
        custom_tooltip = { text = impious_beatification_tooltip }
        show_portrait = event_target:saint_person
    }

    #Stranger and disapprove of Papal decision
    option = {
    	name = EVTOPTB_HF_40060
    	trigger = {
			OR = {
				trait = drunkard
				trait = hedonist
			}    		
    		NOT = {
    			event_target:saint_person = {
    				family = ROOT
    			}
    		}
    	}
        opinion = {
            modifier = insulted
            who = FROM
        }
        FROM = {
            show_scope_change = no
            opinion = {
                modifier = insulted
                who = ROOT
            }
        }
        custom_tooltip = { text = impious_beatification_tooltip }
        show_portrait = event_target:saint_person
    }

    #Family and approve of Papal decision
    option = {
    	name = EVTOPTC_HF_40060
    	trigger = {
    		event_target:saint_person = {
    			family = ROOT
    		}
    		NOR = {
				trait = drunkard
				trait = hedonist
    		}
    	}
        custom_tooltip = { text = impious_beatification_tooltip }
        show_portrait = event_target:saint_person
    }

    #Family and disapprove of Papal decision 
    option = {
    	name = EVTOPTD_HF_40060
    	trigger = {
			OR = {
				trait = drunkard
				trait = hedonist
			}    		
			event_target:saint_person = {
    			family = ROOT
    		}
    	}
        opinion = {
            modifier = insulted
            who = FROM
        }        
        FROM = {
            show_scope_change = no
            opinion = {
                modifier = insulted
                who = ROOT
            }
        }
        custom_tooltip = { text = impious_beatification_tooltip }
        show_portrait = event_target:saint_person
    }
}

#Bad Papal saint
character_event = {
    id = HF.40090
    hide_window = yes
    is_triggered_only = yes
    religion = catholic
    min_age = 16
    has_dlc = "Holy Fury"

    trigger = {
    	death_in_china_trigger = no
		death_no_trace_trigger = no
    	k_papal_state = {
    		holder_scope = {
    			trait = bad_priest_christian
                independent = yes
                opinion = {
                    who = ROOT
                    value = 50
                }
    		}
    	}
    	religion = catholic
    	NOT = {
    		trait = excommunicated
    	}
    	OR = {
    		AND = {
    			trait = impaler
    			k_papal_state = {
    				holder_scope = {
    					trait = impaler
    				}
    			}
    		}
    		AND = {
    			trait = hedonist
    			k_papal_state = {
    				holder_scope = {
    					trait = hedonist
    				}
    			}
    		}
    		AND = {
    			trait = cannibal_trait
    			k_papal_state = {
    				holder_scope = {
    					trait = cannibal_trait
    				}
    			}
    		}
    		AND = {
    			trait = lunatic
    			k_papal_state = {
    				holder_scope = {
    					trait = lunatic
    				}
    			}
    		}
    		AND = {
    			trait = drunkard
    			k_papal_state = {
    				holder_scope = {
    					trait = drunkard
    				}
    			}
    		}
    		AND = {
    			trait = homosexual
    			k_papal_state = {
    				holder_scope = {
    					trait = homosexual
    					is_lover = ROOT
    					trait = lustful
    				}
    			}
    		}
    		AND = {
    			trait = lustful
    			k_papal_state = {
    				is_lover = ROOT
    				trait = lustful
    				NOT = {
    					trait = homosexual
    				}
    			}
    		}
    		AND = {
    			OR = {
    				trait = seducer
    				trait = seductress
    			}
    			k_papal_state = {
    				holder_scope = {
    					trait = seducer
    				}
    			}
    		}
    	}
    }

    immediate = {
    	save_event_target_as = saint_person
    	random = {
    		chance = 20
    		k_papal_state = {
    			holder_scope = {
    				character_event = { id = HF.40091 }
    			}
    		}
    	}
    }
}

#Bad Papal Saint decision
character_event = {
    id = HF.40091
    is_triggered_only = yes
    hide_window = yes
    has_dlc = "Holy Fury"

    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
    has_dlc = "Holy Fury"
    trigger = {
    	OR = {
    		AND = {
    			event_target:saint_person = {
    				trait = impaler
    			}
    			trait = impaler
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = hedonist
    			}
    			trait = hedonist
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = cannibal_trait
    			}
    			trait = cannibal_trait
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = lunatic
    			}
    			trait = lunatic
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = drunkard
    			}
    			trait = drunkard
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = homosexual
    			}
    			trait = homosexual
    		}
    		AND = {
    			event_target:saint_person = {
    				trait = lustful
    			}
    			trait = lustful
    			NOT = {
    				trait = homosexual
    			}
    		}
    		AND = {
    			event_target:saint_person = {
    				OR = {
    					trait = seducer
    					trait = seductress
    				}
    			}
    			trait = seducer
    		}
    	}
        NOT = {
            has_character_flag = impious_canonization_done
        }
    }

    immediate = {
        religion_authority = {
            modifier = 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_trait = { 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 } } 
        			seducer = { give_nickname = nick_gods_seducer new_bloodline = { set_description = saintly_seducer_description } }
        			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_playable_ruler = {
                    independent = yes
                    OR = {
                        tier = KING
                        tier = EMPEROR
                    }
                    NOT = { trait = cynical }
                    war = no
                    ai = yes
                    religion = ROOT
                    is_within_diplo_range = ROOT
                }
            }
            random_playable_ruler = {
                limit = {
                    independent = yes
                    OR = {
                        tier = KING
                        tier = EMPEROR
                    }
                    NOT = { trait = cynical }
                    war = no
                    ai = yes
                    religion = ROOT
                    is_within_diplo_range = ROOT
                }
                preferred_limit = {
                    tier = EMPEROR
                }
                save_event_target_as = papal_attacker
                add_trait = zealous
                unsafe_war = {
                    target = ROOT
                    casus_belli = depose_impious_pope
                }
            }
            any_playable_ruler = {
                limit = {  
                    religion = ROOT
                    event_target:papal_attacker = {
                        NOT = {
                            character = PREV
                        }
                    }
                }
                narrative_event = { id = HF.40093 days = 15 }
            }
        }
    }
}

#Bad Papal Saint main event
narrative_event = {
    id = HF.40098
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = impaler
    			}
    		}
    	} 
    	text = EVTDESCA_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = hedonist
    			}
    		}
    	}
    	text = EVTDESCB_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = cannibal_trait
    			}
    		}
    	}
    	text = EVTDESCC_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = lunatic
    			}
    		}
    	}
    	text = EVTDESCD_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = drunkard
    			}
    		}
    	}
    	text = EVTDESCE_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = homosexual
    			}
    		}
    	}
    	text = EVTDESCF_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = lustful
    				NOT = {
    					trait = homosexual
    				}
    			}
    		}
    	}
    	text = EVTDESCG_HF_40098
    }
    desc = {
    	trigger = {
    		k_papal_state = {
    			holder_scope = {
    				trait = seducer
    			}
    		}
    	}
    	text = EVTDESCH_HF_40098
    }
    title = TITLEHF.40098
    picture = GFX_evt_beatification
    border = GFX_event_narrative_frame_religion
    portrait = event_target:saint_person
	sound = saint_proclaimed
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    #Disgruntled at the Pope's unebelievable actions
    option = {
        name = EVTOPTA_HF_40098
        custom_tooltip = { text = impious_canonization_tooltip }

        ai_chance = {
            factor = 80

            modifier = {
                factor = 0
                AND = {
                    independent = yes
                    ai = yes
                    trait = zealous
                }
            }

            modifier = {
                factor = 0.25
                OR = {
                    trait = cannibal_trait
                    trait = impaler
                    trait = hedonist
                    trait = drunkard
                    trait = seducer
                    trait = lustful
                    trait = lunatic                
                }
            }
        }
    }

    #Side with the Pope
    option = {
        name = EVTOPTC_HF_40098
        show_portrait = FROM
        trigger = {
            NOT = { trait = zealous }
            or = {
                independent = yes
                ai = no
            }
        }
        random = {
            chance = 50
            FROM = {
                trigger_switch = {
                    on_trigger = trait
                    cannibal_trait = { ROOT = { add_trait = cruel } }
                    impaler = { ROOT = { add_trait = cruel } }
                    hedonist = { ROOT = { add_trait = gluttonous } }
                    drunkard = { ROOT = { add_trait = gluttonous } }
                    seducer = { ROOT = { add_trait = lustful } }
                    lustful = { ROOT = { add_trait = lustful } }
                    lunatic = { ROOT = { add_trait = lunatic } }
                }
            }
        }
        custom_tooltip = { text = impious_canonization_tooltip }

        ai_chance = {
            factor = 20 
            modifier = {
                factor = 4
                OR = {
                    trait = cannibal_trait
                    trait = impaler
                    trait = hedonist
                    trait = drunkard
                    trait = seducer
                    trait = lustful
                    trait = lunatic
                }
            }
        }

        set_character_flag = supported_impious_pope
    }
}

#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
    has_dlc = "Holy Fury"
    trigger = {
        FROM = {
            has_landed_title = k_papal_state
            any_war = {
                using_cb = depose_impious_pope
                is_primary_war_defender = yes
            }
        }
        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
            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
            modifier = {
                factor = 5
                has_character_flag = supported_impious_pope
            }
        }
    }
    #Take neither side
    option = {
        name = EVTOPTC_HF_40093
        trigger = {
            independent = yes
            NOR = {
                any_war = {
                    using_cb = depose_impious_pope
                }
            }
        }
        custom_tooltip = { text = EVTOPTC_HF_40093_TT }

        ai_chance = {
            factor = 10
            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
    desc = EVTDESC_HF_40094
    title = EVTTITLE_HF_40094
    picture = GFX_evt_church_council
    border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    has_dlc = "Holy Fury"

    immediate = {
        k_papal_state = {
            owner = {
                save_event_target_as = current_pope
            }
        }
    }

    option = {      
        name = EVTOPTA_HF_40094
        trigger = {
            NOT = {
                has_character_flag = impious_papal_defender
            }
        }
        show_portrait = event_target:current_pope
    }

    option = {
        name = 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
    desc = EVTDESC_HF_40095
    title = EVTTITLE_HF_40095
    picture = GFX_evt_church_council
    border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    has_dlc = "Holy Fury"

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

    option = {
        name = EVTOPTB_HF_40095
        trigger = {
            has_character_flag = impious_papal_defender
        }
        clr_character_flag = impious_papal_defender
    }
}

# TEST SCRIPT
character_event = {
    id = HF.40097
    hide_window = yes
    is_triggered_only = yes
    trigger = {
    
    }

    immediate = {
        rightful_religious_head_scope = {
            piety = 5000
        }
    }
}

#Setting up Saintly Burial Site in a province
province_event = {
	id = HF.40099
	hide_window = yes
	is_triggered_only = yes
    has_dlc = "Holy Fury"

	immediate = {
		add_province_modifier = {
			name = tomb_of_a_saint
			duration = -1
		}
	}
}