establish_protectorate = {
	category = influence

	alert_index = 4
	alert_tooltip = establish_protectorate_alert_tooltip

	require_acceptance = yes

	is_visible = {
		can_create_subject_type = {
			subject = FROM
			subject_type = protectorate
		}
	}

	is_allowed = {
		can_create_subject_type = {
			subject = FROM
			subject_type = protectorate
		}
		is_at_war = no
		FROM = { is_at_war = no }
		FROM = {
			capital_scope = { trade_range = ROOT }
		}
	}

	on_accept = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = protectorate
				}
				is_at_war = no
				FROM = { is_at_war = no }
				FROM = {
					capital_scope = { trade_range = ROOT }
				}
			}
			create_subject = {
				subject = FROM
				subject_type = protectorate
				keep_liberty_desire = yes
			}
			if = {
				limit = {
					any_country = {
						is_subject_of = FROM
						is_colonial_nation = no
						NOT = { is_any_dominion_subject = yes }
					}
				}
				every_country = {
					limit = {
						is_subject_of = FROM
						is_colonial_nation = no
						NOT = { is_any_dominion_subject = yes }
					}
					FROM = {
						PREV = { grant_independence = yes }
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = protectorate
				}
				is_at_war = no
				FROM = { is_at_war = no }
				FROM = {
					capital_scope = { trade_range = ROOT }
				}
			}
			FROM = {
				clr_country_flag = declined_establish_protectorate_@ROOT
				set_country_flag = declined_establish_protectorate_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_establish_protectorate_opinion
			}
		}
	}

	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_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 = 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 = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 1 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 2 } }
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 2 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 3 } }
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 3 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 4 } }
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 4 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 5 } }
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 5 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 6 } }
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 6 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 7 } }
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 7 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 8 } }
			}
			export_to_variable = {
				which = ai_value
				value = 70
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 8 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 9 } }
			}
			export_to_variable = {
				which = ai_value
				value = 80
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 9 }
				NOT = { calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 10 } }
			}
			export_to_variable = {
				which = ai_value
				value = 90
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_PROTECTORATES
			limit = {
				calc_true_if = { all_subject_country = { is_subject_of_type = protectorate } amount = 10 }
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_MERCHANT_REPUBLIC
			limit = {
				has_reform = merchants_reform
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_TOTAL_DEVELOPMENT_OVER_200
			limit = {
				FROM = { total_development = 200 }
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_SUBJECTS
			limit = {
				any_country = {
					is_subject_of = 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
			}
			multiply_variable = { which = ai_value value = -0.5 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					NOT = { check_variable = { which = military_power value = -39 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = -39 }
					NOT = { check_variable = { which = military_power value = 30 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 0
			}
			export_to_variable = {
				which = our_mil_tech
				value = trigger_value:mil_tech
			}
			export_to_variable = {
				which = their_mil_tech
				value = trigger_value:mil_tech
				who = FROM
			}
			export_to_variable = {
				which = our_army_size
				value = trigger_value:army_size
			}
			export_to_variable = {
				which = their_army_size
				value = trigger_value:army_size
				who = FROM
			}
			divide_variable = { which = our_army_size value = 10 }
			divide_variable = { which = their_army_size value = -10 }
			change_variable = { which = our_army_size which = their_army_size }
			multiply_variable = { which = their_mil_tech value = -1 }
			change_variable = { which = our_mil_tech which = their_mil_tech }
			multiply_variable = { which = our_mil_tech value = 3 }
			change_variable = { which = ai_value which = our_army_size }
			change_variable = { which = ai_value which = our_mil_tech }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = 30 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					check_variable = { which = eco_power value = -89 }
					NOT = { check_variable = { which = eco_power value = 30 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
			export_to_variable = {
				which = our_total_development
				value = trigger_value:total_development
			}
			export_to_variable = {
				which = their_total_development
				value = trigger_value:total_development
				who = FROM
			}
			multiply_variable = { which = their_total_development which = their_total_development }
			divide_variable = { which = our_total_development which = their_total_development }
			multiply_variable = { which = ai_value which = our_total_development }
			change_variable = { which = ai_value value = -90 }
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					NOT = { check_variable = { which = eco_power value = -89 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 90
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					check_variable = { which = eco_power value = 30 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
		}
	}

	ai_will_do = {
		NOT = {
			has_casus_belli = {
				type = cb_imperial
				target = FROM
			}
		}
		FROM = {
			total_development = 70
			NOT = { total_development = 200 }
			OR = {
				NOT = { has_country_flag = declined_establish_protectorate_@ROOT }
				had_country_flag = { flag = declined_establish_protectorate_@ROOT days = 1825 }
			}
			NOT = { adm_tech = ROOT }
			NOT = { dip_tech = ROOT }
			NOT = { mil_tech = ROOT }
			capital_scope = {
				NOT = { continent = north_america }
				NOT = { continent = south_america }
				region_for_scope_province = {
					type = all
					OR = {
						is_empty = yes
						is_wasteland = yes
						owner = {
							NOT = { is_subject_of = ROOT }
						}
					}
				}
			}
		}
		institution_difference = { who = FROM value = 1 }
		has_opinion = { who = FROM value = 50 }
		OR = {
			ai_attitude = { who = FROM attitude = attitude_friendly }
			ai_attitude = { who = FROM attitude = attitude_allied }
			ai_attitude = { who = FROM attitude = attitude_neutral }
		}
		OR = {
			NOT = { has_casus_belli_against = FROM }
			FROM = {
				NOT = {
					num_of_owned_provinces_with = {
						value = 3
						OR = {
							is_claim = ROOT
							is_core = ROOT
							any_country = {
								is_subject_of = ROOT
								PREV = { is_claim = PREV }
							}
							any_country = {
								is_subject_of = ROOT
								PREV = { is_core = PREV }
							}
						}
					}
				}
			}
		}
	}
}

ask_to_become_protectorate = {
	category = influence

	alert_index = 4
	alert_tooltip = ask_to_become_protectorate_alert_tooltip

	require_acceptance = yes

	is_visible = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = protectorate
			}
		}
	}

	is_allowed = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = protectorate
			}
		}
		is_at_war = no
		FROM = { is_at_war = no }
		capital_scope = { trade_range = FROM }
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = protectorate
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
				capital_scope = { trade_range = FROM }
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = protectorate
					keep_liberty_desire = yes
				}
			}
			if = {
				limit = {
					any_country = {
						is_subject_of = ROOT
						is_colonial_nation = no
						NOT = { is_any_dominion_subject = yes }
					}
				}
				every_country = {
					limit = {
						is_subject_of = ROOT
						is_colonial_nation = no
						NOT = { is_any_dominion_subject = yes }
					}
					ROOT = {
						PREV = { grant_independence = yes }
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = protectorate
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
				capital_scope = { trade_range = FROM }
			}
			FROM = {
				clr_country_flag = declined_become_protectorate_@ROOT
				set_country_flag = declined_become_protectorate_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_ask_to_become_protectorate
			}
		}
	}

	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 = -0.5 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					NOT = { check_variable = { which = military_power value = -349 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 350
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = -349 }
					NOT = { check_variable = { which = military_power value = 60 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 0
			}
			export_to_variable = {
				which = our_mil_tech
				value = trigger_value:mil_tech
			}
			export_to_variable = {
				which = their_mil_tech
				value = trigger_value:mil_tech
				who = FROM
			}
			export_to_variable = {
				which = our_army_size
				value = trigger_value:army_size
			}
			export_to_variable = {
				which = their_army_size
				value = trigger_value:army_size
				who = FROM
			}
			divide_variable = { which = our_army_size value = 10 }
			divide_variable = { which = their_army_size value = -10 }
			change_variable = { which = our_army_size which = their_army_size }
			multiply_variable = { which = their_mil_tech value = -1 }
			change_variable = { which = our_mil_tech which = their_mil_tech }
			multiply_variable = { which = our_mil_tech value = 3 }
			change_variable = { which = ai_value which = our_army_size }
			change_variable = { which = ai_value which = our_mil_tech }
		}
		add_entry = {
			name = ROOT_FROM_MILITARY_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = our_mil_tech
						value = trigger_value:mil_tech
					}
					export_to_variable = {
						which = their_mil_tech
						value = trigger_value:mil_tech
						who = FROM
					}
					export_to_variable = {
						which = our_army_size
						value = trigger_value:army_size
					}
					export_to_variable = {
						which = their_army_size
						value = trigger_value:army_size
						who = FROM
					}
					export_to_variable = {
						which = military_power
						value = 0
					}
					divide_variable = { which = our_army_size value = 10 }
					divide_variable = { which = their_army_size value = -10 }
					change_variable = { which = our_army_size which = their_army_size }
					multiply_variable = { which = their_mil_tech value = -1 }
					change_variable = { which = our_mil_tech which = their_mil_tech }
					multiply_variable = { which = our_mil_tech value = 3 }
					change_variable = { which = military_power which = our_army_size }
					change_variable = { which = military_power which = our_mil_tech }
					check_variable = { which = military_power value = 60 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					check_variable = { which = eco_power value = -349 }
					NOT = { check_variable = { which = eco_power value = 60 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
			export_to_variable = {
				which = our_total_development
				value = trigger_value:total_development
			}
			export_to_variable = {
				which = their_total_development
				value = trigger_value:total_development
				who = FROM
			}
			multiply_variable = { which = their_total_development which = their_total_development }
			divide_variable = { which = our_total_development which = their_total_development }
			multiply_variable = { which = ai_value which = our_total_development }
			change_variable = { which = ai_value value = -90 }
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					NOT = { check_variable = { which = eco_power value = -349 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 350
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_ECONOMIC_POWER_COMPARED
			limit = {
				variable_arithmetic_trigger = {
					export_to_variable = {
						which = eco_power
						value = 60
					}
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = FROM
					}
					multiply_variable = { which = their_total_development which = their_total_development }
					divide_variable = { which = our_total_development which = their_total_development }
					multiply_variable = { which = eco_power which = our_total_development }
					change_variable = { which = eco_power value = -90 }

					check_variable = { which = eco_power value = 60 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
		}
	}

	ai_will_do = {
		total_development = 70
		NOT = { total_development = 200 }
		NOT = { adm_tech = FROM }
		NOT = { dip_tech = FROM }
		NOT = { mil_tech = FROM }
		NOT = { num_of_subjects = 1 }
		has_opinion = { who = FROM value = 50 }
		FROM = {
			OR = {
				NOT = { has_country_flag = declined_become_protectorate_@ROOT }
				had_country_flag = { flag = declined_become_protectorate_@ROOT days = 1825 }
			}
			institution_difference = { who = ROOT value = 1 }
			OR = {
				ai_attitude = { who = ROOT attitude = attitude_friendly }
				ai_attitude = { who = ROOT attitude = attitude_allied }
				ai_attitude = { who = ROOT attitude = attitude_neutral }
				ai_attitude = { who = ROOT attitude = attitude_threatened }
			}
			OR = {
				NOT = { has_casus_belli_against = ROOT }
				ROOT = {
					NOT = {
						num_of_owned_provinces_with = {
							value = 3
							OR = {
								is_claim = FROM
								is_core = FROM
								any_country = {
									is_subject_of = FROM
									PREV = { is_claim = PREV }
								}
								any_country = {
									is_subject_of = FROM
									PREV = { is_core = PREV }
								}
							}
						}
					}
				}
			}
		}
		OR = {
			FROM = { ai = no }
			AND = {
				FROM = {
					NOT = {
						has_casus_belli = {
							type = cb_imperial
							target = FROM
						}
					}
				}
				capital_scope = {
					NOT = { continent = north_america }
					NOT = { continent = south_america }
					region_for_scope_province = {
						type = all
						OR = {
							is_empty = yes
							is_wasteland = yes
							owner = {
								NOT = { is_subject_of = FROM }
							}
						}
					}
				}
			}
		}
	}
}

cancel_protectorate = {
	category = influence

	require_acceptance = no

	is_visible = {
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = protectorate
		}
	}

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = protectorate
			}
		}
		is_at_war = no
		FROM = { is_at_war = no }
		NOT = { truce_with = FROM }
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = protectorate
				}
				is_at_war = no
				FROM = { is_at_war = no }
				NOT = { truce_with = FROM }
			}
			if = {
				limit = {
					NOT = { full_idea_group = diplomatic_ideas }
				}
				add_stability = -1
			}
			FROM = {
				grant_independence = yes
				country_event = { id = subjects_expanded_protectorate_events.2 }
				add_opinion = {
					who = ROOT
					modifier = released_protectorate
				}
			}
		}
	}
	ai_will_do = {
		OR = {
			stability = 2
			adm_power = 300
			full_idea_group = diplomatic_ideas
			FROM = {
				liberty_desire = 100
				years_in_vassalage_under = {
					who = ROOT
					years = 50
					all_subject_country = yes
				}
			}
		}
		OR = {
			AND = {
				FROM = {
					all_owned_province = {
						all_neighbor_province = {
							OR = {
								owned_by = FROM
								owned_by = ROOT
								owner = {
									is_subject_of = ROOT
									NOT = { liberty_desire = 50 }
								}
							}
						}
					}
				}
				has_casus_belli_against = FROM
			}
			AND = {
				FROM = { liberty_desire = 80 }
				NOT = {
					calc_true_if = {
						all_province = {
							OR = {
								owned_by = ROOT
								owner = {
									NOT = { tag = FROM }
									is_subject_of = ROOT
								}
							}
							same_continent = FROM
						}
						amount = 15
					}
				}
				OR = {
					is_year = 1800
					current_age = age_of_revolutions
				}
			}
		}
	}
}