scripted_diplomatic_actions = {

    BA_avoid_borders_diplomacy = {
	
        allowed = { always = yes }
        
        visible = { 
            OR = { 
                FROM = { OR = { is_in_faction_with = ROOT is_subject_of = ROOT } }
                ROOT = { is_subject_of = PREV } 
            }
        }

        selectable = {
            hidden_trigger = {
                ROOT = { NOT = { has_country_flag = BA_avoid_borders_diplomacy_REQUESTED } }
            }
        }

        requires_acceptance = no
        show_acceptance_on_action_button = no

        icon = 1

        complete_effect = {

            ROOT = { 

                set_country_flag = BA_show_border_avoidance_window

                clear_variable = BA_mode
                
                every_country = {
                    if = {
                        limit = {
                            OR = { 
                                is_in_faction_with = ROOT
                                is_subject_of = ROOT
                                ROOT = { is_subject_of = PREV }
                                has_military_access_to = ROOT
                            }

                            OR = {
                                check_variable = { BA_active_friendly_country_rules^num > 0 }
                                check_variable = { BA_active_other_country_rules^num > 0 }
                                check_variable = { BA_active_state_rules^num > 0 }
                            }
                        }

                        add_to_array = { ROOT.BA_countries_with_rules_array = THIS.id }
                    }
                }
            }
		}

        ai_acceptance = {
			BA_acceptance = {
                base = 1
            }
		}

        ai_desire = {
			factor = -1
		}
	}
}