# Triggers and effects will be given the Actor's scope, with the Recipient's as FROM

create_personal_union = {
	category = influence
	
	alert_index = 40
	alert_tooltip = create_personal_union_alert_tooltip
	
	require_acceptance = yes # Whether the recipient gets an option to decline
	
	is_visible = {
	    NOT = { is_subject_of_type = personal_union }
		government = monarchy
		FROM = {
		    NOT = { is_subject_of = ROOT }
			NOT = { is_subject_of_type = personal_union }
			NOT = { overlord_of = ROOT }
		}
	}
	is_allowed = {
		is_at_war = no
		num_of_cities = FROM
		prestige = FROM
		FROM = {
			is_at_war = no
			is_free_or_tributary_trigger = yes
			has_opinion = {
				who = ROOT
				value = 190
			}
			dynasty = ROOT
			government = monarchy
			is_emperor = no
			is_emperor_of_china = no
		}
	}
	on_accept = {
		create_subject = {
			subject_type = personal_union
			subject = FROM 
		}
		ROOT = {
		    hidden_effect = {
		    add_country_modifier = {
			    name = "ai_personal_union"
				duration = 3650
				hidden = yes
			}
			}
			if = {
				limit = {
					has_reform = elective_monarchy
				}
				add_stability = -1
			}
		}
	}
	on_decline = { 
	    ROOT = {
		    hidden_effect = {
		    add_country_modifier = {
			    name = "ai_personal_union"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	
	ai_acceptance = { 
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_allied }
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_threatened }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
						ai_attitude = { who = ROOT attitude = attitude_domineering }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_MARRIAGE_WITH_ROOT
			limit = {
				marriage_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
		}
		add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 50
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			divide_variable = { which = ai_value value = 5 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 30
					}
					NOT = {
						trust = {
							who = ROOT
							value = 50
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			multiply_variable = { which = ai_value value = 2.5 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					NOT = {
						trust = {
							who = ROOT
							value = 30
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION
			limit = {
				NOT = { religion = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = FROM
			}
			multiply_variable = { which = ai_value_2 value = 2.5 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				any_owned_province = {
					is_core = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
		name = BORDER_DISTANCE
		export_to_variable = {
			which = ai_value
			value = border_distance
			who = FROM
			with = ROOT
		}
		divide_variable = { which = ai_value value = -1.5 }
	    }
		add_entry = {
			name = ROOT_FROM_HAVE_SAME_PRIMARY_CULTURE
			limit = {
				primary_culture = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
		}
		add_entry = {
			name = FROM_HAS_MORE_THAN_500_TOTAL_DEVELOPMENT
			limit = {
				FROM = {
					total_development = 500
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = ELECTIVE_MONARCHY
			limit = {
				FROM = {
					has_reform = elective_monarchy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1.25 }
		}		 
	}

	ai_will_do = {
	    NOT = { has_country_modifier = ai_personal_union }
	}
}

create_holy_order_1 = {
	category = influence
	
	alert_index = 40
	alert_tooltip = create_holy_order_1_alert_tooltip
	
	require_acceptance = yes
	
	is_visible = {
		FROM = {
		    is_subject_of = ROOT
			NOT = { is_subject_of_type = holy_order_1 }
		}
	}
	is_allowed = {
	    ROOT = { NOT = { holy_order_1 = 11 } }
		is_at_war = no
        FROM = {
		is_at_war = no
		any_neighbor_country = {
		    NOT = { religion = FROM }
		}
		OR = {
	    is_subject_of_type = vassal
		is_subject_of_type = march
		}
		NOT = { government = native }
		is_subject_of = ROOT
		is_lesser_in_union = no
		}
	}
	on_accept = {
		create_subject = {
			subject_type = holy_order_1 
			subject = FROM 
		}
		FROM = {
		    change_government = theocracy
			set_legacy_government = theocratic_government
		    add_government_reform = monastic_order_reform
		    add_devotion = 100		
		}
		ROOT = {
		    hidden_effect = {
		    add_country_modifier = {
			    name = "ai_holy_order"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	on_decline = { 
	    ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_holy_order"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	
	ai_acceptance = { 
	    add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				overlord_of = FROM
				FROM = {
					liberty_desire = 50
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 50
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			divide_variable = { which = ai_value value = 5 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 30
					}
					NOT = {
						trust = {
							who = ROOT
							value = 50
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			multiply_variable = { which = ai_value value = 2 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					NOT = {
						trust = {
							who = ROOT
							value = 30
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION
			limit = {
				NOT = { religion = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				any_owned_province = {
					is_core = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_HAVE_SAME_PRIMARY_CULTURE
			limit = {
				primary_culture = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
				who = FROM
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
			}
			divide_variable = { which = ai_value value = 2 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = FROM_IS_NOT_SUBJECT_AT_RIVAL_BORDER
			limit = {
				FROM = {
					is_subject_of = ROOT
				}
				NOT = {
				OR = {
					any_rival_country = {
						is_neighbor_of = FROM
					}
					any_enemy_country = {
						is_neighbor_of = FROM
					}
				}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -100
			}
		}
	}

	ai_will_do = { 
		government = theocracy
		NOT = { has_country_modifier = ai_holy_order }
	}
}

ask_to_become_holy_order_1 = {
	category = influence
	
	alert_index = 40
	alert_tooltip = ask_to_become_holy_order_1_alert_tooltip
	
	require_acceptance = yes
	
	is_visible = {
		ROOT = {
		    NOT = { government = native }
		    is_subject_of = FROM
			NOT = { is_subject_of_type = holy_order_1 }
			OR = {
	        is_subject_of_type = vassal
		    is_subject_of_type = march
		    }
		}
	}
	is_allowed = {
	    FROM = { NOT = { holy_order_1 = 11 } }
		is_at_war = no
        ROOT = {
		is_at_war = no
		any_neighbor_country = {
		    NOT = { religion = ROOT }
		}
	    }
	}
	on_accept = {
	    FROM = {
		create_subject = {
			subject_type = holy_order_1 
			subject = ROOT 
		}
		}
		ROOT = {
		    change_government = theocracy
			set_legacy_government = theocratic_government
		    add_government_reform = monastic_order_reform
		    add_devotion = 100		
		}
		ROOT = {
		    hidden_effect = {
		    add_country_modifier = {
			    name = "ai_holy_order"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	on_decline = { 
	    ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_holy_order"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	
	ai_acceptance = { 
	    add_entry = {
			name = FROM_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				liberty_desire = 50
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 50
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			divide_variable = { which = ai_value value = 5 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 30
					}
					NOT = {
						trust = {
							who = ROOT
							value = 50
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			multiply_variable = { which = ai_value value = 2 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					NOT = {
						trust = {
							who = ROOT
							value = 30
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION
			limit = {
				NOT = { religion = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				any_owned_province = {
					is_core = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_HAVE_SAME_PRIMARY_CULTURE
			limit = {
				primary_culture = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
				who = FROM
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
			}
			divide_variable = { which = ai_value value = 2 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = FROM_IS_NOT_SUBJECT_AT_RIVAL_BORDER
			limit = {
				ROOT = {
					is_subject_of = FROM
				}
				NOT = {
				OR = {
					any_rival_country = {
						is_neighbor_of = ROOT
					}
					any_enemy_country = {
						is_neighbor_of = ROOT
					}
				}
				}
			}
			export_to_variable = {
				which = ai_value
				value = -100
			}
		}
	}

	ai_will_do = { 
		government = theocracy
		NOT = { has_country_modifier = ai_holy_order }
	}
}

create_native_reservation = {
	category = influence
	
	alert_index = 40
	alert_tooltip = create_native_reservation_alert_tooltip
	
	require_acceptance = yes
	
	is_visible = {
	    NOT = { government = native }
		FROM = { NOT = { is_subject_of_type = native_reservation } government = native NOT = { overlord_of = ROOT } }
	}
	is_allowed = {
	ROOT = {
	is_at_war = no
	}
    FROM = {
		OR = {
		is_subject_of = ROOT
		is_free_or_tributary_trigger = yes
		}
		is_lesser_in_union = no
		NOT = { federation_size = 2 }
		}
		is_at_war = no
	}
	on_accept = {
		create_subject = {
			subject_type = native_reservation
			subject = FROM 
		}
		ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_native_reservation"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	on_decline = { 
	    ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_native_reservation"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	
	ai_acceptance = { 
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_allied }
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_threatened }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1.5 }
		}
	    add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_rivalry }
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
						ai_attitude = { who = ROOT attitude = attitude_domineering }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 50
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			divide_variable = { which = ai_value value = 5 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					trust = {
						who = ROOT
						value = 30
					}
					NOT = {
						trust = {
							who = ROOT
							value = 50
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
			multiply_variable = { which = ai_value value = 2 }
		}
	    add_entry = {
			name = TRUST
			limit = {
				FROM = {
					NOT = {
						trust = {
							who = ROOT
							value = 30
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = FROM
			}
			multiply_variable = { which = ai_value_2 value = 1.0 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				NOT = { overlord_of = FROM }
				any_owned_province = {
					is_core = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
		name = BORDER_DISTANCE
		export_to_variable = {
			which = ai_value
			value = border_distance
			who = FROM
			with = ROOT
		}
		divide_variable = { which = ai_value value = -1.5 }
	    }
		add_entry = {
			name = FROM_HAS_MORE_THAN_500_TOTAL_DEVELOPMENT
			limit = {
				FROM = {
					total_development = 500
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1.5 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 2.5 }
		}
	}

	ai_will_do = {
	    NOT = { government = native }
		NOT = { has_country_modifier = ai_native_reservation }												
	}
}

ask_to_become_native_reservation = {
	category = influence
	
	alert_index = 40
	alert_tooltip = ask_to_become_native_reservation_alert_tooltip
	
	require_acceptance = yes
	
	is_visible = {
	   government = native
	   NOT = { is_subject_of_type = native_reservation }											 
	   FROM = { NOT = { is_subject_of_type = native_reservation } NOT = { government = native } }
	}
	is_allowed = {
        is_at_war = no
		FROM = { is_at_war = no }
		is_lesser_in_union = no
		NOT = { federation_size = 2 }
	}
	on_accept = {
	    FROM = {
		create_subject = {
			subject_type = native_reservation 
			subject = ROOT 
		}
		}
		ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_native_reservation"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	on_decline = { 
	    ROOT = {
			hidden_effect = {
		    add_country_modifier = {
			    name = "ai_native_reservation"
				duration = 3650
				hidden = yes
			}
			}
		}
	}
	
	ai_acceptance = { 
	    add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 0 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 100 } }
					has_opinion = { who = ROOT value = 0 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
			export_to_variable = {
				variable_name = ai_value_2
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value_2 value = 5 }
			change_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					has_opinion = { who = ROOT value = 100 }
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 10 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_domineering }
						ai_attitude = { who = ROOT attitude = attitude_protective }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10000
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_allied }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 2.5 }
		}
		add_entry = {
			name = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			multiply_variable = { which = ai_value value = -1.5 }
		}
		add_entry = {
			name = FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = ROOT
			}
			multiply_variable = { which = ai_value_2 value = 1.0 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = ROOT_HAS_MORE_THAN_500_TOTAL_DEVELOPMENT
			limit = {
				ROOT = {
					total_development = 500
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
	    NOT = { government = native }
	}
}

dissolve_holy_order_1  =  {
	category = influence
	require_acceptance = no
	is_visible = {
		overlord_of = FROM
		FROM = {
			is_subject_of_type = holy_order_1
		}
	}
	is_allowed = {
	    overlord_of = FROM
		is_at_war = no
		FROM = {
		    is_at_war = no
			is_subject_of_type = holy_order_1
		}
	}
	on_accept = {
		create_subject = {
			subject_type = vassal
			subject = FROM 
		}
	}
	ai_will_do = {
	    OR = {
		NOT = { government = theocracy }
		FROM = { NOT = { religion = ROOT } }
		holy_order_1 = 11
		FROM = { liberty_desire = 50 }
		}
	}
}

dissolve_native_reservation  =  {
	category = influence
	require_acceptance = no
	is_visible = {
		overlord_of = FROM
		FROM = {
			is_subject_of_type = native_reservation
		}
	}
	is_allowed = {
	    is_at_war = no
		FROM = { is_at_war = no }
	}
	on_accept = {
		FROM = {
		    overlord = {
            PREV = { grant_independence = yes }
            }
		}
	}
	ai_will_do = {
		government = native
	}
}

leave_native_reservation  =  {
	category = influence
	require_acceptance = yes
	alert_index = 40
	alert_tooltip = leave_native_reservation_alert_tooltip
	is_visible = {
		FROM = { overlord_of = ROOT }
		ROOT = {
			is_subject_of_type = native_reservation
		}
	}
	is_allowed = {
	    is_at_war = no
		FROM = { is_at_war = no }
		NOT = { has_country_modifier = war_for_independence }
	}
	on_accept = {
		ROOT = {
        grant_independence = yes
        }
    }
	on_decline = {
	    ROOT = {
		    add_country_modifier = {
			    name = "war_for_independence"
				duration = 9125
			}
		}
	}
	ai_acceptance = { 
	    add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 0 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 100 } }
					has_opinion = { who = ROOT value = 0 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
			export_to_variable = {
				variable_name = ai_value_2
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value_2 value = 4 }
			change_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					has_opinion = { who = ROOT value = 100 }
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 8 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_domineering }
						ai_attitude = { who = ROOT attitude = attitude_protective }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10000
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_allied }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = ROOT
			}
			multiply_variable = { which = ai_value_2 value = 1.5 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
	}
	ai_will_do = {
	    OR = {
		NOT = { government = native }
		liberty_desire = 95
		FROM = {
			NOT = { has_opinion = { who = ROOT value = 0 } }
		}
		}
	}
}

leave_tributary_state  =  {
	category = influence
	require_acceptance = yes
	alert_index = 40
	alert_tooltip = leave_tributary_state_alert_tooltip
	is_visible = {
		FROM = { overlord_of = ROOT }
		ROOT = {
			is_subject_of_type = tributary_state
		}
	}
	is_allowed = {
	    is_at_war = no
		FROM = { is_at_war = no }
		NOT = { has_country_modifier = war_for_independence }
	}
	on_accept = {
		ROOT = {
        grant_independence = yes
        }
    }
	on_decline = {
	    ROOT = {
		    add_country_modifier = {
			    name = "war_for_independence"
				duration = 9125
			}
		}
	}
	ai_acceptance = { 
	    add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 0 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 100 } }
					has_opinion = { who = ROOT value = 0 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
			export_to_variable = {
				variable_name = ai_value_2
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value_2 value = 4 }
			change_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					has_opinion = { who = ROOT value = 100 }
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 8 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_domineering }
						ai_attitude = { who = ROOT attitude = attitude_protective }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10000
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_allied }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = BORDER_DISTANCE
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			multiply_variable = { which = ai_value value = 1.0 }
		}
		add_entry = {
			name = FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = ROOT
			}
			multiply_variable = { which = ai_value_2 value = 1.5 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
	}
	ai_will_do = {
	    OR = {
		liberty_desire = 95
		FROM = {
			NOT = { has_opinion = { who = ROOT value = 0 } }
		}
		}
	}
}

leave_vassal  =  {
	category = influence
	require_acceptance = yes
	alert_index = 40
	alert_tooltip = leave_vassal_alert_tooltip
	is_visible = {
		FROM = { overlord_of = ROOT }
		ROOT = {
		    OR = {
			is_subject_of_type = vassal
			is_subject_of_type = daimyo_vassal
			is_subject_of_type = client_vassal
			}
		}
	}
	is_allowed = {
	    years_in_vassalage_under = {
	    who = FROM
	    years = 10
        }
	    is_at_war = no
		FROM = { is_at_war = no }
		NOT = { has_country_modifier = war_for_independence }
	}
	on_accept = {
		ROOT = {
        grant_independence = yes
        }
    }
	on_decline = {
	    ROOT = {
		    add_country_modifier = {
			    name = "war_for_independence"
				duration = 9125
			}
		}
	}
	ai_acceptance = { 
	    add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 0 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					NOT = { has_opinion = { who = ROOT value = 100 } }
					has_opinion = { who = ROOT value = 0 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
			export_to_variable = {
				variable_name = ai_value_2
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value_2 value = 4 }
			change_variable = { which = ai_value which = ai_value_2 }
		}
		add_entry = {
			name = OPINION
			limit = {
				FROM = {
					has_opinion = { who = ROOT value = 100 }
				}
			}
			export_to_variable = {
				variable_name = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 8 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_domineering }
						ai_attitude = { who = ROOT attitude = attitude_protective }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10000
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_friendly }
						ai_attitude = { who = ROOT attitude = attitude_allied }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_neutral }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					OR = {
						ai_attitude = { who = ROOT attitude = attitude_hostile }
						ai_attitude = { who = ROOT attitude = attitude_outraged }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 3 }
		}
		add_entry = {
			name = FROM_MILITARY_POWER_COMPARED
			export_to_variable = {
				which = ai_value
				value = army_size
			}
			export_to_variable = {
				which = ai_value_2
				value = army_size
				who = ROOT
			}
			multiply_variable = { which = ai_value_2 value = 1.5 }
			subtract_variable = { which = ai_value which = ai_value_2 }
		}
	}
	ai_will_do = {
	    OR = {
		liberty_desire = 95
		FROM = {
			NOT = { has_opinion = { who = ROOT value = 0 } }
		}
		}
	}
}