establish_trade_outpost = {
	category = influence

	alert_index = 6
	alert_tooltip = establish_trade_outpost_alert_tooltip

	require_acceptance = yes

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

	is_allowed = {
		can_create_subject_type = {
			subject = FROM
			subject_type = trade_outpost
		}
		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 = trade_outpost
				}
				is_at_war = no
				FROM = { is_at_war = no }
				FROM = {
					capital_scope = { trade_range = ROOT }
				}
			}
			create_subject = {
				subject = FROM
				subject_type = trade_outpost
				keep_liberty_desire = yes
			}
			add_truce_with = FROM
			FROM = {
				if = {
					limit = {
						capital_scope = {
							NOT = {
								has_trade_modifier = {
									who = ROOT
									key = trade_outpost_overlord_trade_modifier
								}
							}
						}
					}
					capital_scope = {
						add_trade_modifier = {
							who = ROOT
							power = 35
							key = trade_outpost_overlord_trade_modifier
							duration = -1
						}
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = trade_outpost
				}
				is_at_war = no
				FROM = { is_at_war = no }
				FROM = {
					capital_scope = { trade_range = ROOT }
				}
			}
			FROM = {
				clr_country_flag = declined_establish_trade_outpost_@ROOT
				set_country_flag = declined_establish_trade_outpost_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_establish_trade_outpost_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 4 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				NOT = { overlord_of = FROM }
				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 = {
				NOT = { overlord_of = FROM }
				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 = {
				NOT = { overlord_of = FROM }
				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
			limit = {
				NOT = { overlord_of = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				has_subject_of_type = trade_outpost
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 2
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 2
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 3
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 3
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 4
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 4
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 5
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 5
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 6
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 6
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 7
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 7
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 8
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 70
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 8
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 9
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 80
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 9
				}
				NOT = {
					calc_true_if = {
						all_subject_country = {
							is_subject_of_type = trade_outpost
						}
						amount = 10
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 90
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = NUM_OF_TRADE_OUTPOSTS
			limit = {
				calc_true_if = {
					all_subject_country = {
						is_subject_of_type = trade_outpost
					}
					amount = 10
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_MERCHANT_REPUBLIC
			limit = {
				NOT = { overlord_of = FROM }
				has_reform = merchants_reform
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_IS_MERCHANT_REPUBLIC
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					has_reform = merchants_reform
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_HAS_SUBJECTS
			limit = {
				NOT = { overlord_of = FROM }
				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
			limit = {
				NOT = { overlord_of = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = border_distance
				who = FROM
				with = ROOT
			}
			multiply_variable = { which = ai_value value = -0.5 }
		}
		add_entry = {
			name = FROM_IS_KINGDOM_RANK
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					government_rank = 2
					NOT = { government_rank = 3 }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_EMPIRE_RANK
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					government_rank = 3
				}
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_DEVELOPMENT
			limit = {
				NOT = { overlord_of = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:total_development
				who = FROM
			}
			#subtract_variable = { which = ai_value value = 1 }
			divide_variable = { which = ai_value 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 = ROOT_FROM_ARE_ALLIED
			limit = {
				NOT = { overlord_of = FROM }
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_FRIENDS
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					historical_friend_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_RIVALS
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					historical_rival_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_AI_PERSONALITY
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					personality = ai_militarist
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_AI_PERSONALITY
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					personality = ai_capitalist
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_IS_VASSAL_OF_ROOT
			limit = {
				overlord_of = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 100
			}
		}
		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 }
		}
	}

	ai_will_do = {
		OR = {
			NOT = { overlord_of = FROM }
			FROM = {
				NOT = {
					years_in_vassalage_under = {
						who = ROOT
						years = 5
						all_subject_country = yes
					}
				}
			}
		}
		FROM = {
			NOT = { total_development = 100 }
			OR = {
				NOT = { has_country_flag = declined_establish_trade_outpost_@ROOT }
				had_country_flag = { flag = declined_establish_trade_outpost_@ROOT days = 1825 }
			}
			capital_scope = {
				has_merchant = ROOT
			}
		}
		OR = {
			AND = {
				NOT = { has_dlc = "Wealth of Nations" }
				NOT = { has_dlc = "Dharma" }
			}
			FROM = {
				capital_scope = {
					NOT = { superregion = india_superregion }
					NOT = { superregion = china_superregion }
					NOT = { region = japan_region }
					NOT = { continent = oceania }
					NOT = { superregion = east_indies_superregion }
					NOT = { continent = africa }
				}
			}
		}
	}
}

ask_to_become_trade_outpost = {
	category = influence

	alert_index = 6
	alert_tooltip = ask_to_become_trade_outpost_alert_tooltip

	require_acceptance = yes

	is_visible = {
		is_subject = no
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = trade_outpost
			}
		}
	}

	is_allowed = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = trade_outpost
			}
		}
		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 = trade_outpost
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
				capital_scope = { trade_range = FROM }
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = trade_outpost
					keep_liberty_desire = yes
				}
			}
			add_truce_with = FROM
			if = {
				limit = {
					capital_scope = {
						NOT = {
							has_trade_modifier = {
								who = FROM
								key = trade_outpost_overlord_trade_modifier
							}
						}
					}
				}
				capital_scope = {
					add_trade_modifier = {
						who = FROM
						power = 35
						key = trade_outpost_overlord_trade_modifier
						duration = -1
					}
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = trade_outpost
					}
				}
				is_at_war = no
				FROM = { is_at_war = no }
				capital_scope = { trade_range = FROM }
			}
			clr_country_flag = declined_establish_trade_outpost_@FROM
			set_country_flag = declined_establish_trade_outpost_@FROM
			add_opinion = {
				who = FROM
				modifier = declined_ask_to_become_trade_outpost
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = FROM
				with = ROOT
			}
			divide_variable = { which = ai_value value = 4 }
		}
		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 = ROOT_IS_MERCHANT_REPUBLIC
			limit = {
				has_reform = merchants_reform
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = FROM_IS_MERCHANT_REPUBLIC
			limit = {
				FROM = {
					has_reform = merchants_reform
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		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 = FROM_DEVELOPMENT
			export_to_variable = {
				which = ai_value
				value = trigger_value:total_development
				who = FROM
			}
			#subtract_variable = { which = ai_value value = 1 }
			divide_variable = { which = ai_value value = -3 }
		}
		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_ARE_ALLIED
			limit = {
				alliance_with = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 15
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_FRIENDS
			limit = {
				FROM = {
					historical_friend_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_FROM_ARE_HISTORICAL_RIVALS
			limit = {
				FROM = {
					historical_rival_with = ROOT
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_AI_PERSONALITY
			limit = {
				FROM = {
					personality = ai_militarist
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_AI_PERSONALITY
			limit = {
				FROM = {
					personality = ai_capitalist
				}
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = STATEGIC_VALUE
			limit = {
				NOT = {
					OR = {
						FROM = {
							NOT = { overlord_of = ROOT }
						}
						NOT = {
							years_in_vassalage_under = {
								who = FROM
								years = 5
								all_subject_country = yes
							}
						}
					}
					NOT = { total_development = 100 }
					OR = {
						AND = {
							NOT = { has_dlc = "Wealth of Nations" }
							NOT = { has_dlc = "Dharma" }
						}
						capital_scope = {
							NOT = { superregion = india_superregion }
							NOT = { superregion = china_superregion }
							NOT = { region = japan_region }
							NOT = { continent = oceania }
							NOT = { superregion = east_indies_superregion }
							NOT = { continent = africa }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_NO_MERCHANT_IN_OUR_HOME_TRADE_NODE
			limit = {
				capital_scope = {
					NOT = { has_merchant = FROM }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
	}

	ai_will_do = {
		NOT = { num_of_subjects = 1 }
		OR = {
			NOT = { has_country_flag = declined_establish_trade_outpost_@FROM }
			had_country_flag = { flag = declined_establish_trade_outpost_@FROM days = 1825 }
		}
		FROM = {
			OR = {
				is_great_power = yes
				total_development = 300
			}
		}
		OR = {
			AND = {
				government = monarchy
				FROM = { government = monarchy }
			}
			AND = {
				government = republic
				FROM = { government = republic }
			}
			AND = {
				government = theocracy
				FROM = { government = theocracy }
			}
		}
		has_opinion = {
			who = FROM
			value = 100
		}
	}
}

improve_trade_outpost = {
	category = subject_interactions

	require_acceptance = no

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

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = trade_outpost
			}
		}
		is_at_war = no
		treasury = 500
		adm_power = 25
		dip_power = 50
		FROM = { is_at_war = no }
		FROM = {
			NOT = { liberty_desire = 75 }
		}
		FROM = {
			custom_trigger_tooltip = {
				tooltip = DID_NOT_IMPROVE_TRADE_OUTPOST_WITHIN_LAST_5_YEARS
				OR = {
					NOT = { has_country_flag = improved_trade_outpost_flag }
					had_country_flag = { flag = improved_trade_outpost_flag days = 1825 }
				}
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = trade_outpost
				}
				is_at_war = no
				treasury = 500
				adm_power = 25
				dip_power = 50
				FROM = { is_at_war = no }
				FROM = {
					NOT = { liberty_desire = 75 }
				}
				FROM = {
					custom_trigger_tooltip = {
						tooltip = DID_NOT_IMPROVE_TRADE_OUTPOST_WITHIN_LAST_5_YEARS
						NOT = { has_country_modifier = improved_trade_outpost_modifier }
					}
				}
			}
			add_treasury = -500
			add_adm_power = -25
			add_dip_power = -50
			FROM = {
				add_liberty_desire = -10
				add_country_modifier = {
					name = improved_trade_outpost_modifier
					duration = 730
				}
				capital_scope = {
					add_base_tax = 2
					add_base_production = 4
					add_trade_modifier = {
						who = ROOT
						power = 10
						key = improved_trade_outpost_trade_modifier
						duration = 730
					}
				}
				clr_country_flag = improved_trade_outpost_flag
				set_country_flag = improved_trade_outpost_flag
			}
		}
	}

	ai_will_do = {
		treasury = 2000
		adm_power = 100
		dip_power = 100
		FROM = {
			NOT = { liberty_desire = 40 }
			capital_scope = {
				has_merchant = ROOT
			}
		}
		NOT = {
			calc_true_if = {
				all_subject_country = {
					is_subject_of_type = trade_outpost
					has_country_modifier = improved_trade_outpost_modifier
				}
				amount = 3
			}
		}
	}
}

end_trade_outpost = {
	category = influence

	require_acceptance = no

	is_visible = {
		is_subject_of = FROM
		is_subject_of_type = trade_outpost
	}

	is_allowed = {
		is_subject_of = FROM
		is_subject_of_type = trade_outpost
		NOT = { truce_with = FROM }
		is_at_war = no
	}

	on_accept = {
		if = {
			limit = {
				is_subject_of = FROM
				is_subject_of_type = trade_outpost
				NOT = { truce_with = FROM }
				is_at_war = no
			}
			FROM = {
				ROOT = { grant_independence = yes }
				country_event = { id = subjects_expanded_trade_outpost_events.4 }
			}
			add_stability = -1
		}
	}

	ai_will_do = {
		liberty_desire = 70
	}
}

cancel_trade_outpost = {
	category = influence

	require_acceptance = no

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

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = trade_outpost
			}
		}
		NOT = { truce_with = FROM }
		prestige = 0
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = trade_outpost
				}
				NOT = { truce_with = FROM }
				prestige = 0
			}
			FROM = {
				if = {
					limit = {
						NOT = { liberty_desire = 50 }
					}
					add_opinion = {
						who = ROOT
						modifier = vassal_abandoned
					}
				}
				grant_independence = yes
				add_truce_with = ROOT
			}
			add_truce_with = FROM
			add_prestige = -25
		}
	}

	ai_will_do = {
		FROM = {
			liberty_desire = 100
			years_in_vassalage_under = {
				who = ROOT
				years = 25
				all_subject_country = yes
			}
		}
	}
}