qyv_heir_quality_score = {
    trigger = {
        is_child = yes
        OR = {
            AND = { NOT = { has_trait = slow } NOT = { has_trait = stupid } NOT = { has_trait = weak } NOT = { has_trait = sickly } NOT = { has_trait = clubfooted } NOT = { has_trait = hunchbacked } NOT = { has_trait = ugly } NOT = { has_trait = imbecile } NOT = { has_trait = incapable } }
            has_trait = intelligent
            has_trait = quick
            has_trait = genius
            has_trait = attractive
            has_trait = handsome
            has_trait = beautiful
            has_trait = hale
            has_trait = robust
            has_trait = giant
            has_trait = fecund
            has_trait = bloodline_founder
            has_trait = melusine
            has_trait = fylgia
            has_trait = kishin
            has_trait = draconic
            has_trait = olympian
        }
    }
}

qyv_heir_quality_score_high = {
    trigger = {
        is_child = yes
        num_of_traits = { value = 3 comparator = at_least }
        OR = {
            has_trait = intelligent
            has_trait = quick
            has_trait = genius
            has_trait = attractive
            has_trait = handsome
            has_trait = beautiful
            has_trait = hale
            has_trait = robust
            has_trait = giant
            has_trait = fecund
            has_trait = bloodline_founder
            has_trait = melusine
            has_trait = fylgia
            has_trait = kishin
            has_trait = draconic
            has_trait = olympian
        }
        NOT = { has_trait = slow }
        NOT = { has_trait = stupid }
        NOT = { has_trait = weak }
        NOT = { has_trait = sickly }
        NOT = { has_trait = clubfooted }
        NOT = { has_trait = hunchbacked }
        NOT = { has_trait = ugly }
        NOT = { has_trait = imbecile }
        NOT = { has_trait = incapable }
    }
}

qyv_has_bad_heir = {
    trigger = {
        is_ruler = yes
        any_child = {
            is_heir = yes
            OR = {
                has_trait = stupid
                has_trait = imbecile
                has_trait = incapable
                has_trait = slow
                has_trait = weak
                has_trait = sickly
                AND = { age >= 16 NOT = { any_trait = { intelligent quick genius attractive handsome beautiful hale robust giant fecund } } }
            }
        }
    }
}

qyv_has_better_spare = {
    trigger = {
        is_ruler = yes
        any_child = {
            is_heir = no
            age >= 8
            NOT = { is_married = yes }
            OR = {
                has_trait = intelligent
                has_trait = quick
                has_trait = genius
                has_trait = attractive
                has_trait = handsome
                has_trait = beautiful
                has_trait = hale
                has_trait = robust
                has_trait = giant
                has_trait = fecund
            }
            NOT = { has_trait = slow }
            NOT = { has_trait = stupid }
            NOT = { has_trait = weak }
            NOT = { has_trait = sickly }
        }
        any_child = {
            is_heir = yes
            OR = {
                has_trait = stupid
                has_trait = imbecile
                has_trait = incapable
                has_trait = slow
                has_trait = weak
                has_trait = sickly
            }
        }
    }
}

qyv_should_switch_succession = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { has_government = theocracy }
        OR = {
            AND = { has_law = male_only_succession has_faith = { has_doctrine = gender_equality } }
            AND = { has_law = female_only_succession has_faith = { has_doctrine = gender_equality } }
            AND = { realm_size >= 50 has_law = confederate_partition }
            AND = { realm_size >= 100 has_law = partition }
            AND = { realm_size < 30 has_law = house_seniority }
            AND = { culture = { has_tradition = equal_inheritance } has_law = partition }
        }
    }
}

qyv_ai_education_focus_martial = {
    trigger = {
        is_child = yes
        NOT = { has_education_focus = yes }
        OR = {
            OR = { has_trait = brave has_trait = strong has_trait = robust has_trait = giant has_trait = hale }
            AND = { martial_education >= 10 father = { martial >= 16 } }
            AND = { any_parent = { martial >= 18 } }
        }
        NOT = { has_trait = weak }
        NOT = { has_trait = sickly }
        NOT = { has_trait = clubfooted }
    }
}

qyv_ai_education_focus_stewardship = {
    trigger = {
        is_child = yes
        NOT = { has_education_focus = yes }
        OR = {
            OR = { has_trait = intelligent has_trait = quick has_trait = genius has_trait = thrifty has_trait = architect }
            AND = { stewardship_education >= 10 father = { stewardship >= 16 } }
            AND = { any_parent = { stewardship >= 18 } }
        }
    }
}

qyv_ai_education_focus_diplomacy = {
    trigger = {
        is_child = yes
        NOT = { has_education_focus = yes }
        OR = {
            OR = { has_trait = gregarious has_trait = diplomat has_trait = attractive has_trait = handsome has_trait = beautiful }
            AND = { diplomacy_education >= 10 father = { diplomacy >= 16 } }
            AND = { any_parent = { diplomacy >= 18 } }
        }
    }
}

qyv_ai_education_focus_intrigue = {
    trigger = {
        is_child = yes
        NOT = { has_education_focus = yes }
        OR = {
            OR = { has_trait = devious has_trait = schemer has_trait = shy has_trait = cynical }
            AND = { intrigue_education >= 10 father = { intrigue >= 16 } }
            AND = { any_parent = { intrigue >= 18 } }
        }
    }
}

qyv_ai_education_focus_learning = {
    trigger = {
        is_child = yes
        NOT = { has_education_focus = yes }
        OR = {
            OR = { has_trait = intelligent has_trait = quick has_trait = genius has_trait = scholarly has_trait = erudite }
            AND = { learning_education >= 10 father = { learning >= 16 } }
            AND = { any_parent = { learning >= 18 } }
        }
    }
}

qyv_ai_wants_primogeniture = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { has_government = theocracy }
        realm_size >= 30
        OR = {
            has_law = partition
            has_law = confederate_partition
            has_law = house_seniority
            has_law = male_only_succession
            has_law = female_only_succession
        }
        has_crown_law = { law = primogeniture_succession }
        NOT = { has_faith = { has_doctrine = gender_equality } }
    }
}

qyv_ai_wants_ultimogeniture = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { has_government = theocracy }
        realm_size >= 30
        OR = {
            has_law = partition
            has_law = confederate_partition
            has_law = house_seniority
        }
        has_crown_law = { law = ultimogeniture_succession }
        NOT = { has_faith = { has_doctrine = gender_equality } }
    }
}

qyv_ai_wants_house_seniority = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { has_government = theocracy }
        realm_size < 30
        OR = {
            has_law = partition
            has_law = confederate_partition
            has_law = male_only_succession
            has_law = female_only_succession
        }
        has_crown_law = { law = house_seniority }
    }
}

qyv_ai_wants_elective = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        NOT = { has_government = theocracy }
        has_crown_law = { law = feudal_elective_succession }
        OR = {
            AND = { has_faith = { has_doctrine = gender_equality } NOT = { has_law = primogeniture_succession } }
            AND = { culture = { has_tradition = equal_inheritance } }
        }
    }
}

qyv_candidate_strong_genetics = {
    trigger = {
        is_adult = yes
        is_married = no
        OR = {
            has_trait = intelligent
            has_trait = quick
            has_trait = genius
            has_trait = attractive
            has_trait = handsome
            has_trait = beautiful
            has_trait = hale
            has_trait = robust
            has_trait = giant
            has_trait = fecund
            has_trait = bloodline_founder
            has_trait = melusine
            has_trait = fylgia
            has_trait = kishin
            has_trait = draconic
            has_trait = olympian
        }
        NOT = { has_trait = slow }
        NOT = { has_trait = stupid }
        NOT = { has_trait = weak }
        NOT = { has_trait = sickly }
        NOT = { has_trait = clubfooted }
        NOT = { has_trait = hunchbacked }
        NOT = { has_trait = ugly }
        NOT = { has_trait = imbecile }
        NOT = { has_trait = incapable }
    }
}

qyv_ai_realm_needs_stability = {
    trigger = {
        is_ruler = yes
        is_independent_ruler = yes
        OR = {
            num_active_factions > 0
            liberty_desire >= 50
            any_vassal = { opinion_of_liege < -25 }
        }
    }
}

qyv_ai_dynasty_needs_bloodline = {
    trigger = {
        is_ruler = yes
        NOT = { dynasty = { has_bloodline = yes } }
        prestige >= 1000
    }
}