
fort_decisions = {
    #FROM = decision taker
    #I assume: ROOT = province
    allow_hedgehogg_to_stay = {
        is_high_prio = yes
        ai_check_interval = 60 #every years

        filter = owned
        ai_target_filter = owned
        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
                    }
                    FROM = { ai = no }
                }
            }
            NOT = { Is_really_animal_trigger = yes }
            hedgehog_can_live_in_this_province_trigger = yes
        }
        allow = {
            hidden_tooltip = {
                FROM = {
                    OR = {
                        ai = no
                        ai_rationality < 0
                    }
                }
            }
            FROM = { has_regent = no }
            custom_tooltip = {
                text = HERGEHOG_LIVE_HERE
                always = yes # tested in potential session
            }
            custom_tooltip = {
                text = HEDGEHOG_NOT_ALREADY_INSTALLED
                NOT = { has_hedgehog_in_province_trigger = yes }
            }
            fort_has_building = fo_fortification_human
        }

        effect = {
            if = {
                limit = {
                    has_game_rule = {
                        name = animals_conversion_ways
                        value = animal_decision
                    }
                }
                add_province_modifier = {
                    name = hedge_hedgehog_inhabitant
                    duration = -1
                }
            }
            else = {
                random_list = {
                    1 = {
                        trigger = {
                            hedgehog_common_can_live_in_province_trigger = yes
                        }
                        culture = hedgehog_culture
                        FROM = { culture = hedgehog_culture }
                    }
                    1 = {
                        trigger = {
                            hedgehog_desert_can_live_in_province_trigger = yes
                        }
                        culture = hedgehog_desert
                        FROM = { culture = hedgehog_desert }
                    }
                }
            }
        }

        ai_will_do = {
            factor = 0.2

            modifier = {
                factor = 0
                FROM = { NOT = { trait = lunatic } }
                FROM = { NOT = {culture_group = hedgehog_group } }
            }
            modifier = {
                factor = 4.5
                FROM = { culture_group = hedgehog_group }
            }
        }
    }

    chase_hedgehogg_on_fort = {
        is_high_prio = no
        ai_check_interval = 12

        filter = owned
        ai_target_filter = owned
        only_playable = yes

        potential = {
            has_hedgehog_in_province_trigger = yes
        }
        allow = {
            OR = {
                has_province_modifier = hedge_hedgehog_inhabitant
                has_province_modifier = hedge_hedgehog_friendly_inhabitant
            }
            FROM = {
                prestige = 150
                wealth = 100
            }
        }
        effect = {
            FROM = {
                prestige = -150
                wealth = -100
            }
            if = {
                limit = {
                    has_province_modifier = hedge_hedgehog_friendly_inhabitant
                }
                remove_province_modifier = hedge_hedgehog_friendly_inhabitant
                add_province_modifier = {
                    name = hedge_friendly_gone
                    years = 5
                }
            }
            else = {
                remove_province_modifier = hedge_hedgehog_inhabitant
            }
        }
        ai_will_do = {
            factor = 1.0

            modifier = {
                factor = 0.05
                has_province_modifier = hedge_hedgehog_inhabitant
            }
            modifier = {
                factor = 0.95
                has_province_modifier = hedge_hedgehog_friendly_inhabitant
            }
        }
    }
}

targetted_decisions = {
    hedgehog_revolt_conversion = {
        is_high_prio = no
        ai_check_interval =  6

        filter = court
        ai_target_filter = court
        only_rulers = yes
        from_potential = {
            culture_group = hedgehog_group
            has_earmarked_regiments = hedge_hostility_revolt_army
        }
        potential = {
            NOT = { culture_group = hedgehog_group }
            prisoner = yes
            is_playable = yes
            NOR = {
                is_feudal = yes
                primary_title = { is_landless_type_title = no }
            }
        }
        allow = {
            FROM = {
                is_incapable = no
                is_ill = no
                custom_tooltip = {
                    text = HAS_HEDGEHOG_HOSTILITY_REVOLUTIONARY_ARMY
                    # has_earmarked_regiments = hedge_hostility_revolt_army
                    always = yes #tested un from_potential scope
                }
                is_adult = yes
            }
            ROOT = {
                NOT = { Is_really_animal_trigger = yes }
                is_adult = yes
            }

            custom_tooltip = {
                text = SAME_GENDER_TOOLTIP
                OR = {
                    AND = {
                        ROOT = { is_female = yes }
                        FROM = { is_female = yes }
                    }
                    AND = {
                        ROOT = { is_female = no }
                        FROM = { is_female = no }
                    }
                }
            }
        }
        effect = {
            imprison = no
            character_event = { id = ani_plus.063 months = 6 random = 90 } #6 to 9 months
        }
        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0
                ROOT = {
                    is_landed = no
                }
            }
        }
    }
    hedgehog_building_character_conversion = {
        is_high_prio = no
        ai_check_interval = 9

        filter = all
        ai_target_filter = sub_realm
        only_rulers = yes
        from_potential = {
            culture_group = hedgehog_group
            is_within_diplo_range = ROOT
        }
        potential = {
            NOT = { culture_group = hedgehog_group }
            ai = yes
        }
        allow = {
            location = {
                has_fort = yes
                custom_tooltip = {
                    text = HAS_CLONNING_BUILDING_ACTIVE
                    fort_has_building = fo_clonning_room
                    hedgehog_clonning_room_trigger = yes
                }
                fort_owner = {
                    OR = {
                        is_vassal_or_below_of = FROM
                        character = FROM
                    }
                }
            }
            FROM = {
                is_incapable = no
                has_regent = no
                prestige = 500
                piety = 200
                religion = Hedge_religion
            }
        }
        ai_acceptance = {
            factor = -30
            yes_threshold = 0
            show_maybe_for_human = no

            additive_modifier = {
                value = 60
                is_friend = FROM
            }
            additive_modifier = {
                value = 150
                prisoner = yes
            }
            additive_modifier = {
                value = 50
                opinion = {
                    who = FROM
                    value = 80
                }
            }
            additive_modifier = {
                value = 30
                opinion = {
                    who = FROM
                    value = 20
                }
            }
            additive_modifier = {
                value = 20
                opinion = {
                    who = FROM
                    value = 40
                }
            }
            additive_modifier = {
                value = 30
                opinion = {
                    who = FROM
                    value = 60
                }
            }
            additive_modifier = {
                value = -30
                opinion = {
                    who = FROM
                    value < 0
                }
            }
            additive_modifier = {
                value = -50
                opinion = {
                    who = FROM
                    value < -80
                }
            }
            additive_modifier = {
                value = 35
                owes_favor_to = FROM
            }
            additive_modifier = {
                value = 10
                FROM = {
                    is_liege_of = ROOT
                }
            }
            additive_modifier = {
                value = 10
                FROM = {
                    is_liege_or_above_of = ROOT
                }
            }
        }
        effect = {
            FROM = {
                prestige = -500
                piety = -200
            }
            culture = FROM
            if = {
                limit = {
                    age = 22
                }
                add_age = -6
            }
            else_if = {
                limit = {
                    age = 19
                }
                add_age = -3
            }
            hidden_effect = { imprison = no }
        }
        ai_will_do = { factor = 1 } #will most likely never do this since AI dosn't build fort and i don't now if I can change that
    }
}

decisions = {
    adopt_hedge_religion = {
        is_high_prio = yes
        ai_check_interval = 3

        potential = {
            culture_group = hedgehog_group
            NOT = { religion = Hedge_religion }
            can_change_religion = yes
        }
        allow = {
            is_adult = yes
            culture_group = hedgehog_group
            has_regent = no
            is_incapable = no
            can_change_religion = yes
        }
        effect = {
            religion = Hedge_religion
            if = {
                limit = {
                    OR = {
                        independent = yes
                        liege = { NOT = {religion = Hedge_religion } }
                    }
                }
                if = {
                    limit = {
                        has_game_rule = {
                            name = animals_bonus_levy
                            value = Few
                        }
                    }
                    spawn_unit = {
                        province = capital_scope
                        home = capital_scope
                        owner = ROOT
                        leader = none
                        troops = {
                            pikemen = { 1500 1500 }
                        }
                        attrition = 0.1
                        maintenance = no

                    }
                }
                else_if = {
                    limit = {
                        has_game_rule = {
                            name = animals_bonus_levy
                            value = Normal
                        }
                    }
                    spawn_unit = {
                        province = capital_scope
                        home = capital_scope
                        owner = ROOT
                        leader = none
                        troops = {
                            pikemen = { 4000 4000 }
                        }
                        attrition = 0.1
                        maintenance = no

                    }
                }
                else_if = {
                    limit = {
                        has_game_rule = {
                            name = animals_bonus_levy
                            value = Many
                        }
                    }
                    spawn_unit = {
                        province = capital_scope
                        home = capital_scope
                        owner = ROOT
                        leader = none
                        troops = {
                            pikemen = { 10000 10000 }
                        }
                        attrition = 0.1
                        maintenance = no

                    }
                }
            }
            if = {
                limit = {
                    is_feudal = yes
                }
                set_government_type = Hedge_feudal_gov
            }
        }
        ai_will_do = {
            factor = 1

            modifier = {
                 factor = 0

                independent = no
                liege = {
                    NOT = { religion = Hedge_religion }
                }
            }
        }
    }

    create_spiked_ball = {
        only_playable = yes
        ai_check_interval = 30

        is_high_prio = yes

        potential = {
            NOT = { is_title_active = d_spike_ball }
            independent = yes
            religion = Hedge_religion
            culture_group = hedgehog_group
            NOT = {	has_alternate_start_parameter = { key = religion_names value = random } }
        }
        allow = {
            higher_tier_than = DUKE
            war = no
            piety = 350
        }
        effect = {
            piety = -350
            prestige = 600
            custom_tooltip = {
                text = CREATED_HOLY_ORDER_HEDGE_TOOLTIP

                activate_title = { title = d_spike_ball status = yes }
                create_character = {
                    random_traits = no
                    dynasty = random
                    religion = ROOT
                    culture = hedgehog_culture
                    female = no
                    age = 25
                    trait = brilliant_strategist
                    trait = zealous
                    trait = humble
                    trait = ambitious
                    trait = strategist
                    trait = holy_warrior
                }
                new_character = {
                    wealth = 500
                    d_spike_ball = {
                        grant_title = PREV
                    }
                    set_government_type = feudal_government
                    create_character = {
                        random_traits = yes
                        dynasty = random
                        religion = ROOT
                        culture = ROOT
                        female = no
                        age = 20
                    }
                    create_character = {
                        random_traits = yes
                        dynasty = random
                        religion = ROOT
                        culture = ROOT
                        female = no
                        age = 19
                    }
                    create_character = {
                        random_traits = yes
                        dynasty = random
                        religion = ROOT
                        culture = ROOT
                        female = no
                        age = 18
                    }
                    create_character = {
                        random_traits = yes
                        dynasty = random
                        religion = ROOT
                        culture = ROOT
                        female = no
                        age = 17
                    }
                    create_character = {
                        random_traits = yes
                        dynasty = random
                        religion = ROOT
                        culture = ROOT
                        female = no
                        age = 16
                    }
                }
                any_player = {
                    narrative_event = { id = ani_plus.070 }
                }
            }
        }
        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0.4
            }
            modifier = {
                factor = 0.5
                trait = cynical
            }
        }
    }
}

title_decisions = {
    hedgehog_province_conversion_from_fort_building = {
        is_high_prio = no
        ai_check_interval = 12

        filter = sub_realm_owned
        ai_target_filter = owned
        only_playable = yes
        potential = {
            tier = COUNT
            FROM = { culture_group = hedgehog_group }
            location = {
                NOT = { culture_group = hedgehog_group }
                NOR = {
                    has_province_modifier = hedgehog_province_in_motion_1
                    has_province_modifier = hedgehog_province_in_motion_2
                }
            }
        }
        allow = {
            holder_scope = {
                OR = {
                    character = FROM
                    is_vassal_or_below_of = FROM
                }
            }
            location = {
                has_fort = yes
                fort_owner = {
                    OR = {
                        is_vassal_or_below_of = FROM #not assieged one
                        character = FROM
                    }
                }
                custom_tooltip = {
                    text = HAS_HEDGE_HOME_ACTIVE
                    fort_has_building = fo_hedgehog_home_01
                    hedgehog_home_01_trigger = yes
                }
                conditional_tooltip = {
                    trigger = {
                        fort_has_building = fo_hedgehog_home_02
                        hedgehog_home_02_trigger = yes
                    }
                    FROM = {
                        prestige = 250
                        piety = 50
                    }
                }
                conditional_tooltip = {
                    trigger = {
                        NAND = {
                            fort_has_building = fo_hedgehog_home_02
                            hedgehog_home_02_trigger = yes
                        }
                    }
                    FROM = {
                        prestige = 500
                        piety = 500
                    }
                }
            }
            FROM = {
                has_regent = no
                is_incapable = no
            }
        }

        effect = {
            if = {
                limit = {
                    location = {
                        fort_has_building = fo_hedgehog_home_02
                        hedgehog_home_02_trigger = yes
                    }
                }
                FROM = {
                    prestige = -250
                    piety = -50
                }
                location = {
                    add_province_modifier = {
                        name = hedgehog_province_in_motion_2
                        years = 2
                    }
                }
            }
            else = {
                FROM = {
                    prestige = -500
                    piety = -500
                }
                location = {
                    add_province_modifier = {
                        name = hedgehog_province_in_motion_1
                        years = 2
                    }
                }
            }
            location = {
                show_scope_change = no
                province_event = { id = ani_plus.065 years = 1 }
            }
        }
        ai_will_do = {
            factor = 1
        }
    }

    ##decision done to allow AI to construct fort on its own province as modifying fort construction condition for AI dosn't seems easy
    hedgehog_ai_construct_fort = {
        is_high_prio = no
        ai_check_interval = 6

        filter = owned
        ai_target_filter = owned
        only_playable = yes

        potential = {
            FROM = {
                ai = yes
                wealth = 20
                war = no
            }
            tier = COUNT
            location = { has_fort = no }
        }
        allow = {
            always = yes
        }
        effect = {
            location = {
                FROM = {
                    wealth = -20
                    create_fort = PREV
                }
            }
        }
        ai_will_do = {
            factor = 1

            modifier = {
                factor = 0

                FROM = {
                    OR = {
                        government = nomadic_government
                        government = dragon_tribal_gov
                    }
                }
            }
            modifier = {
                factor = 0
                FROM = {
                    NOR = {
                        culture_group = hedgehog_group
                        trait = administrator
                        trait = impaler
                        trait = architect
                    }
                }
            }
            modifier = {
                factor = 0.10

                FROM = {
                    NOR = {
                        culture_group = hedgehog_group
                        culture_group = dragon_group
                    }
                }
            }
        }
    }
}
