﻿split_noncontiguous_counties_from_revolt_effect = {
    # Start off by making a list of all disconnected Counties
    every_connected_county = {
        invert = yes
        max_naval_distance = 2000
        add_to_list = disconnected_counties
    }

    # Then release contiguous disconnected areas.
    every_in_list = {
        list = disconnected_counties

        if = {
            limit = {
                holder.top_liege = $FACTION_LEADER$
            }
            save_scope_as = county_of_origin

            create_character = {
                template = urf_default_template
                location = scope:county_of_origin.title_province
                culture = scope:county_of_origin.culture
                faith = scope:county_of_origin.faith
                gender_female_chance = 50
                age = 32
                save_scope_as = new_county_holder
            }

            create_title_and_vassal_change = {
                type = independency
                save_scope_as = exclave_change
                add_claim_on_loss = no
            }
            every_in_list = {
                list = disconnected_counties
                limit = {
                    holder.top_liege = $FACTION_LEADER$
                    is_connected_to = { target = scope:county_of_origin }
                }
                change_title_holder = {
                    holder = scope:new_county_holder
                    change = scope:exclave_change
                }
            }
            scope:new_county_holder = {
                becomes_independent = {
                    change = scope:exclave_change
                }
            }
            resolve_title_and_vassal_change = scope:exclave_change

            scope:new_county_holder = {
                if = { # Just in case they need to create a duchy
                    limit = {
                        gold < 500
                    }
                    add_gold = 500
                }
            }
        }
    }
}