decisions = {
    dragon_lay_egg = {
        is_high_prio = yes
        ai_check_interval = 10

        only_playable = yes

        potential = {
            culture_group = dragon_group
            OR = {
                is_landed = yes
                father = {
                    is_landed = yes
                }
                mother = {
                    is_landed = yes
                }
            }
        }
        allow = {
            culture_group = dragon_group
            NOT = { culture = dragon_culture }
            war = no
            is_incapable = no
            is_married = yes
            conditional_tooltip = {
                trigger = { is_married = yes }
                spouse = {
                    culture_group = dragon_group
                }
            }
            custom_tooltip = { # max one every 2 years
                text = TT_dragon_did_not_lay_egg_recently
                
                NOT = {
                    had_character_flag = {
                        flag = dragon_layed_egg
                        years <= 2
                    }
                }
            }
            #in_command = no
            dragon_is_adult_trigger = yes
            NOT = {
                trait = celibate
            }
        }

        effect = {
            if = {
                limit = {
                    is_female = yes
                }

                create_character = {
                    age = 0
                    random_traits = no
                    female = random
                    culture = dragon_culture
                    religion = Dragon_religion
                    dynasty = ROOT

                    genetic_father = spouse
                    genetic_mother = ROOT
                }
                spouse = {
                    new_character = {
                        set_mother = ROOT
                        set_father = PREV
                    }
                }
            }
            else = {
                create_character = {
                    age = 0
                    random_traits = no
                    female = random
                    culture = dragon_culture
                    religion = Dragon_religion
                    dynasty = ROOT

                    genetic_father = ROOT
                    genetic_mother = spouse
                }
                spouse = {
                    new_character = {
                        set_father = ROOT
                        set_mother = PREV
                    }
                }
            }

            hidden_tooltip = {
                clr_character_flag = dragon_layed_egg
                set_character_flag = dragon_layed_egg
                spouse = {
                    clr_character_flag = dragon_layed_egg
                    set_character_flag = dragon_layed_egg
                }

                new_character = {
                    set_father_dragon_flag_effect = yes
                    set_mother_dragon_flag_effect = yes

                    set_government_type = dragon_tribal_gov
                }

                recalc_succession = yes
            }
        }

        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0.01
                has_living_children = yes
            }
            modifier = {
                factor = 20

                has_living_children = yes
                is_landed = yes
            }
        }
    }
    go_search_for_dragon_egg = {

        is_high_prio = yes
        ai_check_interval = 45

        only_playable = yes

        potential = {
            OR = {
                has_game_rule = {
                    name = animals_conversion_ways
                    value = animal_decision
                }
                AND = {
                    has_game_rule = {
                        name = animals_conversion_ways
                        value = animal_instant
                    }
                    ai = no
                }
            }

            Is_really_animal_trigger = no
            NOT = {
                has_artifact = dragon_egg_artifact
            }
        }
        allow = {
            is_adult = yes
            is_incapable = no
            has_regent = no
            in_command = no
            
            wealth = 1000

            OR = {
                trait = impaler
                lifestyle_traits == 0
            }

            capital_scope = {
                has_fort = yes
                OR = {
                    is_black_dragon_province_trigger = yes
                    is_white_dragon_province_trigger = yes
                    is_red_dragon_province_trigger = yes
                    is_blue_dragon_province_trigger = yes
                    is_yellow_dragon_province_trigger = yes
                }
            }
        }

        effect = {
            wealth = -1000
            if = {
                limit = {
                    has_game_rule = {
                        name = animals_conversion_ways
                        value = animal_decision
                    }
                }
                add_artifact = dragon_egg_artifact
            }
            else = {
                convert_to_dragon_culture_effect = yes
            }
        }
        ai_will_do = {
            factor = 1
            modifier = {
                factor = 0.001

                always = yes
            }
        }
    }

    dragon_goes_battlefield = {
        is_high_prio = yes
        ai_check_interval = 10

        only_playable = yes

        potential = {
            government = dragon_tribal_gov
            NOT = { has_character_flag = formed_dragon_retinue }
        }
        allow = {
            ruled_years = 1
            dragon_is_adult_trigger = yes
        }

        effect = {
            if = {
                limit = {
                    has_dlc = "Legacy of Rome"
                }
                create_retinue = RETTYPE_CUL_DRAGON
            }
            else = {
                spawn_unit = {
                    province = capital_scope
                    owner = ROOT
                    troops = {
                        knights = { 100 100 }
                    }
                    cannot_inherit = no
                    reinforces = yes
                    reinforce_rate_multiplier = 0.1
                    maintenance_multiplier = 0.5
                }
            }
            set_character_flag = formed_dragon_retinue
        }

        ai_will_do = {
            factor = 1
        }
    }

    dragon_do_education_trial = {
        is_high_prio = yes
        ai_check_interval = 6

        potential = {
            culture_group = dragon_group
            NOT = { has_character_flag = is_true_dragon_adult }
            NOR = {
                trait = misguided_warrior
                trait = tough_soldier
                trait = skilled_tactician
                trait = brilliant_strategist
                trait = indulgent_wastrel
                trait = thrifty_clerk
                trait = fortune_builder
                trait = midas_touched
                trait = naive_appeaser
                trait = underhanded_rogue
                trait = charismatic_negotiator
                trait = grey_eminence
                trait = detached_priest
                trait = martial_cleric
                trait = scholarly_theologian
                trait = mastermind_theologian
                trait = amateurish_plotter
                trait = flamboyant_schemer
                trait = intricate_webweaver
                trait = elusive_shadow
            }
        }
        allow = {
            war = no
            is_adult = yes # adult without dragon education

            trigger_if = {
                limit = {
                    is_ruler = yes
                }
                has_assigned_minor_title = title_dragon_alternate_space_master
            }
            trigger_else = {
                liege = {
                    has_assigned_minor_title = title_dragon_alternate_space_master
                }
            }
            custom_tooltip = {
                text = TT_dragon_did_not_take_decision_in_year
                NOT = {
                    had_character_flag = {
                        flag = dragon_education_trial_CD
                        years < 1
                    }
                }
            }
        }

        effect = {
            hidden_effect = {
                clr_character_flag = dragon_education_trial_CD
                set_character_flag = dragon_education_trial_CD

                random_list = {
                    1 = { # snow trial
                        trigger = {
                            NOT = {
                                has_character_flag = snow_trial_realized
                            }
                        }
                        set_character_flag = snow_trial_realized
                        character_event = { id = ani_plus.208 }
                    }
                    1 = { # fire trial
                        trigger = {
                            NOT = {
                                has_character_flag = fire_trial_realized
                            }
                        }
                        set_character_flag = fire_trial_realized
                        character_event = { id = ani_plus.210 }
                    }
                    1 = { # water trial
                        trigger = {
                            NOT = {
                                has_character_flag = water_trial_realized
                            }
                        }
                        set_character_flag = water_trial_realized
                        character_event = { id = ani_plus.212 }
                    }
                    1 = { # sand trial
                        trigger = {
                            NOT = {
                                has_character_flag = sand_trial_realized
                            }
                        }
                        set_character_flag = sand_trial_realized
                        character_event = { id = ani_plus.214 }
                    }
                    1 = { # poison trial
                        trigger = {
                            NOT = {
                                has_character_flag = poison_trial_realized
                            }
                        }
                        set_character_flag = poison_trial_realized
                        character_event = { id = ani_plus.216 }
                    }
                }
            }
        }
        ai_will_do = {
            factor = 1
        }
    }

    dragon_ai_get_education = {
        is_high_prio = yes
        ai_check_interval = 11

        potential = {
            ai = yes
            culture_group = dragon_group
            NOT = { has_character_flag = is_true_dragon_adult }
        }
        allow = {
            OR = {
                trait = misguided_warrior
                trait = tough_soldier
                trait = skilled_tactician
                trait = brilliant_strategist
                trait = indulgent_wastrel
                trait = thrifty_clerk
                trait = fortune_builder
                trait = midas_touched
                trait = naive_appeaser
                trait = underhanded_rogue
                trait = charismatic_negotiator
                trait = grey_eminence
                trait = detached_priest
                trait = martial_cleric
                trait = scholarly_theologian
                trait = mastermind_theologian
                trait = amateurish_plotter
                trait = flamboyant_schemer
                trait = intricate_webweaver
                trait = elusive_shadow
            }
        }

        effect = {
            set_character_flag = is_true_dragon_adult
        }

        ai_will_do = {
            factor = 1
        }
    }

    dragon_get_married = {
        is_high_prio = yes
        ai_check_interval = 11

        potential = {
            culture_group = dragon_group
            is_playable = yes
            government = dragon_tribal_gov
            is_married = no
        }
        allow = {
            dragon_is_adult_trigger = yes
            is_married = no
        }
        effect = {
            if = {
                limit = {
                    is_female = yes
                }

                create_character = {
                    random_traits = yes
                    attributes = {
                        martial = 6
                        diplomacy = 6
                        stewardship = 6
                        intrigue = 6
                        learning = 6
                    }
                    female = no
                    employer = ROOT
                    religion = ROOT
                    culture = ROOT
                    dynasty = none
                }
                add_spouse_matrilineal = new_character
            }
            else = {
                create_character = {
                    random_traits = yes
                    attributes = {
                        martial = 6
                        diplomacy = 6
                        stewardship = 6
                        intrigue = 6
                        learning = 6
                    }
                    female = yes
                    employer = ROOT
                    religion = ROOT
                    culture = ROOT
                    dynasty = none
                }
                add_spouse = new_character
            }
            hidden_tooltip = {
                generate_tooltip = no
                new_character = {
                    random_list = {
                        9 = {
                            add_trait = quick
                        }
                        1 = {
                            add_trait = genius
                        }
                    }
                }
            }
        }
        ai_will_do = {
            factor = 1
        }
    }

    dragon_ai_grant_space_master_title = {
        is_high_prio = no
        ai_check_interval = 11

        potential = {
            is_playable = yes
            can_grant_title = title_dragon_alternate_space_master
            is_adult = yes
            ai = yes
        }
        allow = {
            always = yes
        }
        effect = {
            create_character = {
                random_traits = yes
                attributes = {
                    martial = 6
                    diplomacy = 6
                    stewardship = 6
                    intrigue = 6
                    learning = 6
                }
                female = yes
                employer = ROOT
                religion = ROOT
                culture = ROOT
                dynasty = none
            }
            new_character = {
                give_minor_title = title_dragon_alternate_space_master
            }
        }
    }
}

settlement_decisions = {
    dragon_convert_to_tribal = {
        is_high_prio = yes
        ai_check_interval = 10

        filter = sub_realm_owned
        ai_target_filter = owned
        only_playable = yes
        
        potential = {
            FROM = {
                culture_group = dragon_group
            }
            ROOT = {
                is_capital = yes
                location = {
                    culture_group = dragon_group
                }
                NOT = { holding_type = tribal }
                holder_scope = { # had to add it as the filter sub_realmowned dosn't work in multiplayer
                    OR = {
                        character = FROM
                        any_liege = {
                            character = FROM
                        }
                    }
                }
            }
        }
        allow = {
            FROM = {
                dragon_is_adult_trigger = yes
                war = no
            }

            location = {
                show_scope_change = no
                has_fort = yes
            }
        }
        effect = {
            FROM = {
                wealth = 1000
            }
            if = {
                limit = {
                    location = {
                        has_tribal = yes
                    }
                }

                location = {
                    any_province_holding = {
                        limit = {
                            holding_type = tribal
                        }
                        destroy_settlement = yes
                    }
                }
            }

            convert_to = tribal
        }
        ai_will_do = {
            factor = 1
        }
    }
}

title_decisions = {
    dragon_start_to_loot_tributary_province = {
        is_high_prio = no
        ai_check_interval = 50
        
        # as the decision is concerning tributaries and their are no filter for them,
        # I put 'all' pre-filter with a high ai_check_interval value
        filter = all
        ai_target_filter = all
        only_playable = yes

        potential = {
            FROM = {
                culture_group = dragon_group
                independent = yes
            }
            ROOT = {
                tier = COUNT

                holder_scope = {
                    top_liege = {
                        is_tributary = yes
                        suzerain = {
                            character = FROM
                        }
                    }
                }

                location = {
                    has_fort = no
                }

                FROM_can_integrate_title_trigger = yes
            }
        }
        allow = {
            FROM = {
                dragon_is_adult_trigger = yes

                prestige = 500
                wealth = 100
            }
            ROOT = {
                show_scope_change = no
                owner = {
                    show_scope_change = no
                    top_liege = {
                        is_tributary = {
                            type = dragon_vassal_tributary
                            suzerain = FROM
                        }
                    }
                }
            }
        }
        effect = {
            FROM = {
                prestige = -500
                wealth = -100
            }

            create_fort = location
        }
        ai_will_do = {
            factor = 1
            
            modifier = {
                factor = 0.05
                always = yes
            }
        }
    }

    dragon_convert_to_culture = {
        is_high_prio = yes
        ai_check_interval = 12

        filter = owned
        ai_target_filter = owned
        only_playable = yes

        potential = {
            tier = COUNT
            FROM = { culture_group = dragon_group }
            FROM = { is_adult = yes }
            location = {
                NOT = {
                    culture = FROM
                }
                culture_group = dragon_group
            }
            holder_scope = {
                character = FROM
            }
        }
        allow = {
            always = yes
        }

        effect = {
            location = {
                culture = FROM
            }
        }

        ai_will_do = {
            factor = 1
        }
    }
}

fort_decisions = {
    dragon_increase_fort_fortification = {
        is_high_prio = no
        ai_check_interval = 12
        only_playable = yes

        potential = {
            FROM = {
                culture_group = dragon_group
                independent = yes
            }
            ROOT = {
                fort_owner = {
                    top_liege = {
                        is_tributary = yes
                        suzerain = {
                            character = FROM
                        }
                    }
                }

                FROM_can_integrate_title_trigger = yes
            }
        }
        allow = {
            FROM = {
                dragon_is_adult_trigger = yes
                
                trigger_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_09
                        }
                    }
                    wealth = 1000
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_08
                        }
                    }
                    wealth = 900
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_07
                        }
                    }
                    wealth = 800
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_06
                        }
                    }
                    wealth = 700
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_05
                        }
                    }
                    wealth = 600
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_04
                        }
                    }
                    wealth = 500
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_03
                        }
                    }
                    wealth = 400
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_02
                        }
                    }
                    wealth = 300
                }
                trigger_else_if = {
                    limit = {
                        ROOT = {
                            fort_has_building = fo_drg_guardian_01
                        }
                    }
                    wealth = 200
                }
                trigger_else = {
                    wealth = 100
                }
                
                has_regent = no
            }


            custom_tooltip = {
                text = TT_dragon_not_max_fortif
                NOT = { fort_has_building = fo_drg_guardian_10 }
            }
            
            custom_tooltip = {
                text = TT_dragon_did_not_take_decision_in_year
                NOT = {
                    had_province_flag = {
                        flag = dragon_increased_influence
                        years < 1
                    }
                }
            }

            ROOT = {
                show_scope_change = no
                owner = {
                    show_scope_change = no
                    top_liege = {
                        is_tributary = {
                            type = dragon_vassal_tributary
                            suzerain = FROM
                        }
                    }
                }
            }
        }
        effect = {
            clr_province_flag = dragon_increased_influence
            set_province_flag = dragon_increased_influence
            trigger_switch = {
                on_trigger = fort_has_building
                fo_drg_guardian_09 = {
                    FROM = { wealth = -1000 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_10
                    }
                }
                fo_drg_guardian_08 = {
                    FROM = { wealth = -900 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_09
                    }
                }
                fo_drg_guardian_07 = {
                    FROM = { wealth = -800 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_08
                    }
                }
                fo_drg_guardian_06 = {
                    FROM = { wealth = -700 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_07
                    }
                }
                fo_drg_guardian_05 = {
                    FROM = { wealth = -600 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_06
                    }
                }
                fo_drg_guardian_04 = {
                    FROM = { wealth = -500 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_05
                    }
                }
                fo_drg_guardian_03 = {
                    FROM = { wealth = -400 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_04
                    }
                }
                fo_drg_guardian_02 = {
                    FROM = { wealth = -300 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_03
                    }
                }
                fo_drg_guardian_01 = {
                    FROM = { wealth = -200 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_02
                    }
                }
                fallback = {
                    FROM = { wealth = -100 }
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_01
                    }
                }
            }
        }
        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0.5
                fort_has_building = fo_drg_guardian_05
            }
            modifier = {
                factor = 0.5
                fort_has_building = fo_drg_guardian_06
            }
            modifier = {
                factor = 0.5
                fort_has_building = fo_drg_guardian_07
            }
            modifier = {
                factor = 0.5
                fort_has_building = fo_drg_guardian_08
            }
            modifier = {
                factor = 0.5
                fort_has_building = fo_drg_guardian_09
            }
        }
    }
}

targetted_decisions = {
    dragon_vassal_take_independence = {
        is_high_prio = no
        ai_check_interval = 1

        filter = independent_rulers
        ai_target_filter = independent_rulers
        only_playable = yes

        from_potential = {
            NOT = { culture_group = dragon_group }
            higher_tier_than = BARON
        }

        potential = {
            government = dragon_tribal_gov
            culture_group = dragon_group
            is_liege_or_above_of = FROM
        }

        allow = {
            FROM = {
                #war = no
                has_regent = no
            }
            ROOT = {
                #war = no
            }
        }

        effect = {
            FROM = {
                set_defacto_liege = THIS
            }

            custom_tooltip = {
                text = TT_force_to_become_tributary
                letter_event = { id = ani_plus.235 days = 2 random = 5 }
            }
        }

        ai_will_do = {
            factor = 1 # ai will always take the decision
        }
    }

    dragon_vassal_unsatisfied = {
        is_high_prio = no
        ai_check_interval = 12

        filter = liege
        ai_target_filter = liege
        only_playable = yes

        from_potential = {
            government = dragon_tribal_gov
            higher_tier_than = BARON
        }
        potential = {
            government = dragon_tribal_gov
            NOT = {
                had_character_flag = {
                    flag = dragon_vassal_instability_decision
                    months < 6
                }
            }
        }

        allow = {
            FROM = {
                dragon_is_adult_trigger = yes
                has_regent = no
                NOT = {
                    opinion = {
                        who = ROOT
                        value = 0
                    }
                }
                custom_tooltip = {
                    text = TT_dragon_not_done_in_1_years
                    NOT = {
                        had_character_flag = {
                            flag = dragon_vassal_instability_decision
                            years < 1
                        }
                    }
                }
                # ruled_years = 5
            }
        }

        effect = {
            FROM = {
                clr_character_flag = dragon_vassal_instability_decision
                set_character_flag = dragon_vassal_instability_decision
            }

            ROOT = {
                custom_tooltip = {
                    text = TT_dragon_receive_ultimatum

                    character_event = { id = ani_plus.238 days = 1 random = 3 }
                }
            }
        }

        ai_will_do = {
            factor = 1

            modifier = { # 50% per years
                factor = 0.5

                always = yes
            }

            modifier = {
                factor = 0

                capital_scope = {
                    fort_has_building = fo_drg_heart_1
                }
                reverse_personal_opinion = {
                    who = FROM
                    value = -30
                }
            }
            modifier = {
                factor = 0

                capital_scope = {
                    fort_has_building = fo_drg_heart_2
                }
                reverse_personal_opinion = {
                    who = FROM
                    value = -60
                }
            }
            modifier = {
                factor = 0

                capital_scope = {
                    fort_has_building = fo_drg_heart_3
                }
                reverse_personal_opinion = {
                    who = FROM
                    value = -90
                }
            }
        }
    }

    dragon_enslave_human = {
        is_high_prio = no
        ai_check_interval = 6

        filter = court
        ai_target_filter = court
        only_playable = yes

        from_potential = {
            government = dragon_tribal_gov
            higher_tier_than = BARON
        }
        potential = {
            NOT = { culture_group = dragon_group }
            prisoner = yes
            host = {
                character = FROM
            }
            NOT = {
                has_character_modifier = dragon_enslaved
            }
        }
        allow = {
            FROM = {
                OR = {
                    has_law = tribal_organization_3
                    has_law = tribal_organization_4
                }
                trigger_if = {
                    limit = {
                        has_dlc = "Zeus"
                    }
                    has_law = banish_voting_power_0
                }

                dragon_is_adult_trigger = yes
                has_assigned_minor_title = title_dragon_alternate_space_master
                has_regent = no
                war = no
            }

            NOT = { culture_group = dragon_group }
            prisoner = yes
            is_adult = yes
        }
        effect = {
            add_character_modifier = {
                name = dragon_enslaved
                duration = -1
            }
            save_event_target_as = slave

            FROM = {
                custom_tooltip = {
                    text = TT_dragon_slave_revenue
                    character_event = { id = ani_plus.248 months = 1 }
                }
            }
        }
        ai_will_do = {
            factor = 0
        }
    }

    dragon_judgement_dragon = {
        is_high_prio = no
        ai_check_interval = 12

        filter = court
        ai_target_filter = court
        only_playable = yes

        from_potential = {
            government = dragon_tribal_gov
            higher_tier_than = BARON
        }
        potential = {
            culture_group = dragon_group
            prisoner = yes
            host = {
                character = FROM
            }
            NOT = {
                has_character_flag = dragon_judgment_in_motion
            }
        }
        allow = {
            FROM = {
                has_law = tribal_organization_4
                trigger_if = {
                    limit = {
                        has_dlc = "Zeus"
                    }
                    has_law = execution_voting_power_0
                }

                dragon_is_adult_trigger = yes
                has_assigned_minor_title = title_dragon_alternate_space_master
                has_regent = no
                war = no
            }

            culture_group = dragon_group
            prisoner = yes
            is_adult = yes
        }

        effect = {
            set_character_flag = dragon_judgment_in_motion

            custom_tooltip = {
                text = TT_dragon_judgement_start
                character_event = { id = ani_plus.250 days = 1 }
            }
        }
        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0.1
                always = yes
            }
        }
    }
}