establish_sister_republic = {
	category = influence

	alert_index = 6
	alert_tooltip = establish_sister_republic_alert_tooltip

	require_acceptance = yes

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

	is_allowed = {
		can_create_subject_type = {
			subject = FROM
			subject_type = sister_republic
		}
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		has_opinion = {
			who = FROM
			value = 100
		}
		reverse_has_opinion = {
			who = FROM
			value = 150
		}
		total_development = FROM
		FROM = {
			variable_arithmetic_trigger = {
				custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
				export_to_variable = {
					which = our_total_development
					value = trigger_value:total_development
				}
				#subtract_variable = { which = our_total_development value = 1 }
				export_to_variable = {
					which = their_total_development
					value = trigger_value:total_development
					who = PREV
				}
				#subtract_variable = { which = their_total_development value = 1 }
				divide_variable = { which = their_total_development value = 3 }
				check_variable = { which = our_total_development which = their_total_development }
			}
		}
		if = {
			limit = {
				OR = {
					has_dlc = "The Cossacks"
					has_dlc = "Leviathan"
				}
				OR = {
					ai = yes
					FROM = {
						ai = yes
					}
				}
				NOT = { overlord_of = FROM }
			}
			if = {
				limit = {
					ai = yes
				}
				trust = {
					who = FROM
					value = 60
				}
			}
			FROM = {
				if = {
					limit = {
						ai = yes
					}
					trust = {
						who = ROOT
						value = 60
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { overlord_of = FROM }
			}
			alliance_with = FROM
		}
		else = {
			FROM = {
				NOT = { liberty_desire = 50 }
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = sister_republic
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				has_opinion = {
					who = FROM
					value = 100
				}
				reverse_has_opinion = {
					who = FROM
					value = 150
				}
				total_development = FROM
				FROM = {
					variable_arithmetic_trigger = {
						custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
						export_to_variable = {
							which = our_total_development
							value = trigger_value:total_development
						}
						#subtract_variable = { which = our_total_development value = 1 }
						export_to_variable = {
							which = their_total_development
							value = trigger_value:total_development
							who = PREV
						}
						#subtract_variable = { which = their_total_development value = 1 }
						divide_variable = { which = their_total_development value = 3 }
						check_variable = { which = our_total_development which = their_total_development }
					}
				}
				if = {
					limit = {
						OR = {
							has_dlc = "The Cossacks"
							has_dlc = "Leviathan"
						}
						OR = {
							ai = yes
							FROM = {
								ai = yes
							}
						}
						NOT = { overlord_of = FROM }
					}
					if = {
						limit = {
							ai = yes
						}
						trust = {
							who = FROM
							value = 60
						}
					}
					FROM = {
						if = {
							limit = {
								ai = yes
							}
							trust = {
								who = ROOT
								value = 60
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { overlord_of = FROM }
					}
					alliance_with = FROM
				}
				else = {
					FROM = {
						NOT = { liberty_desire = 50 }
					}
				}
			}
			create_subject = {
				subject = FROM
				subject_type = sister_republic
				keep_liberty_desire = yes
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				can_create_subject_type = {
					subject = FROM
					subject_type = sister_republic
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				has_opinion = {
					who = FROM
					value = 100
				}
				reverse_has_opinion = {
					who = FROM
					value = 150
				}
				total_development = FROM
				FROM = {
					variable_arithmetic_trigger = {
						custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
						export_to_variable = {
							which = our_total_development
							value = trigger_value:total_development
						}
						#subtract_variable = { which = our_total_development value = 1 }
						export_to_variable = {
							which = their_total_development
							value = trigger_value:total_development
							who = PREV
						}
						#subtract_variable = { which = their_total_development value = 1 }
						divide_variable = { which = their_total_development value = 3 }
						check_variable = { which = our_total_development which = their_total_development }
					}
				}
				if = {
					limit = {
						OR = {
							has_dlc = "The Cossacks"
							has_dlc = "Leviathan"
						}
						OR = {
							ai = yes
							FROM = {
								ai = yes
							}
						}
						NOT = { overlord_of = FROM }
					}
					if = {
						limit = {
							ai = yes
						}
						trust = {
							who = FROM
							value = 60
						}
					}
					FROM = {
						if = {
							limit = {
								ai = yes
							}
							trust = {
								who = ROOT
								value = 60
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { overlord_of = FROM }
					}
					alliance_with = FROM
				}
				else = {
					FROM = {
						NOT = { liberty_desire = 50 }
					}
				}
			}
			FROM = {
				clr_country_flag = declined_establish_sister_republic_@ROOT
				set_country_flag = declined_establish_sister_republic_@ROOT
			}
			add_opinion = {
				who = FROM
				modifier = declined_establish_sister_republic_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = base_values
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_VASSAL_OF_ROOT
			limit = {
				overlord_of = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		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 = 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 = 15
			}
		}
		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 = 100
			}
			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 = 15
			}
		}
		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 = 2000
			}
			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_FROM_DIFF_OF_GOV_RANKS
			export_to_variable = {
				which = ai_value
				value = trigger_value:government_rank
			}
			export_to_variable = {
				which = ai_value_2
				value = trigger_value:government_rank
				who = FROM
			}
			subtract_variable = { which = ai_value which = ai_value_2 }
			multiply_variable = { which = ai_value value = 10 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION_GROUP
			limit = {
				NOT = { religion_group = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION
			limit = {
				religion_group = FROM
				NOT = { religion = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_MERCHANT_REPUBLIC
			limit = {
				FROM = {
					has_reform = merchants_reform
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			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_IS_HRE_MEMBER
			limit = {
				NOT = { overlord_of = FROM }
				is_part_of_hre = no
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 75
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_HRE_MEMBER
			limit = {
				NOT = { overlord_of = FROM }
				is_part_of_hre = yes
				FROM = {
					is_part_of_hre = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 25
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_HRE_ELECTOR
			limit = {
				NOT = { overlord_of = FROM }
				NOT = { hre_reform_passed = erbkaisertum }
				NOT = { hre_reform_passed = emperor_erbkaisertum }
				FROM = {
					is_elector = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_SUBJECTS
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					num_of_subjects = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_PAPAL_STATE
			limit = {
				NOT = { overlord_of = FROM }
				FROM = {
					tag = PAP
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_MORE_THAN_200_TOTAL_DEVELOPMENT
			limit = {
				FROM = {
					total_development = 200
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		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 = -2 }
		}
		add_entry = {
			name = FROM_IS_IMPERIAL_CITY
			limit = {
				FROM = {
					has_reform = free_city
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_A_THEOCRACY
			limit = {
				FROM = {
					government = theocracy
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = ROOT
				with = FROM
			}
			divide_variable = { which = ai_value value = 5 }
		}
	}

	ai_will_do = {
		FROM = {
			NOT = { is_subject_of = ROOT }
			is_neighbor_of = ROOT
			OR = {
				NOT = { has_country_flag = declined_establish_sister_republic_@ROOT }
				had_country_flag = { flag = declined_establish_sister_republic_@ROOT days = 1825 }
			}
		}
	}
}

ask_for_sister_republic = {
	category = influence

	alert_index = 6
	alert_tooltip = ask_for_sister_republic_alert_tooltip

	require_acceptance = yes

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

	is_allowed = {
		FROM = {
			can_create_subject_type = {
				subject = ROOT
				subject_type = sister_republic
			}
		}
		is_at_war = no
		FROM = {
			is_at_war = no
		}
		has_opinion = {
			who = FROM
			value = 100
		}
		reverse_has_opinion = {
			who = FROM
			value = 150
		}
		FROM = {
			total_development = ROOT
		}
		FROM = {
			ROOT = {
				variable_arithmetic_trigger = {
					custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
					export_to_variable = {
						which = our_total_development
						value = trigger_value:total_development
					}
					#subtract_variable = { which = our_total_development value = 1 }
					export_to_variable = {
						which = their_total_development
						value = trigger_value:total_development
						who = PREV
					}
					#subtract_variable = { which = their_total_development value = 1 }
					divide_variable = { which = their_total_development value = 3 }
					check_variable = { which = our_total_development which = their_total_development }
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_dlc = "The Cossacks"
					has_dlc = "Leviathan"
				}
				OR = {
					ai = yes
					FROM = {
						ai = yes
					}
				}
				NOT = { is_subject_of = FROM }
			}
			if = {
				limit = {
					ai = yes
				}
				trust = {
					who = FROM
					value = 60
				}
			}
			FROM = {
				if = {
					limit = {
						ai = yes
					}
					trust = {
						who = ROOT
						value = 60
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { is_subject_of = FROM }
			}
			alliance_with = FROM
		}
		else = {
			NOT = { liberty_desire = 50 }
		}
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = sister_republic
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				has_opinion = {
					who = FROM
					value = 100
				}
				reverse_has_opinion = {
					who = FROM
					value = 150
				}
				FROM = {
					total_development = ROOT
				}
				FROM = {
					ROOT = {
						variable_arithmetic_trigger = {
							custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
							export_to_variable = {
								which = our_total_development
								value = trigger_value:total_development
							}
							#subtract_variable = { which = our_total_development value = 1 }
							export_to_variable = {
								which = their_total_development
								value = trigger_value:total_development
								who = PREV
							}
							#subtract_variable = { which = their_total_development value = 1 }
							divide_variable = { which = their_total_development value = 3 }
							check_variable = { which = our_total_development which = their_total_development }
						}
					}
				}
				if = {
					limit = {
						OR = {
							has_dlc = "The Cossacks"
							has_dlc = "Leviathan"
						}
						OR = {
							ai = yes
							FROM = {
								ai = yes
							}
						}
						NOT = { is_subject_of = FROM }
					}
					if = {
						limit = {
							ai = yes
						}
						trust = {
							who = FROM
							value = 60
						}
					}
					FROM = {
						if = {
							limit = {
								ai = yes
							}
							trust = {
								who = ROOT
								value = 60
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { is_subject_of = FROM }
					}
					alliance_with = FROM
				}
				else = {
					NOT = { liberty_desire = 50 }
				}
			}
			FROM = {
				create_subject = {
					subject = ROOT
					subject_type = sister_republic
					keep_liberty_desire = yes
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					can_create_subject_type = {
						subject = ROOT
						subject_type = sister_republic
					}
				}
				is_at_war = no
				FROM = {
					is_at_war = no
				}
				has_opinion = {
					who = FROM
					value = 100
				}
				reverse_has_opinion = {
					who = FROM
					value = 150
				}
				FROM = {
					total_development = ROOT
				}
				FROM = {
					ROOT = {
						variable_arithmetic_trigger = {
							custom_tooltip = HAS_AT_LEAST_ONE_THIRD_OF_PREV_TOTAL_DEVELOPMENT
							export_to_variable = {
								which = our_total_development
								value = trigger_value:total_development
							}
							#subtract_variable = { which = our_total_development value = 1 }
							export_to_variable = {
								which = their_total_development
								value = trigger_value:total_development
								who = PREV
							}
							#subtract_variable = { which = their_total_development value = 1 }
							divide_variable = { which = their_total_development value = 3 }
							check_variable = { which = our_total_development which = their_total_development }
						}
					}
				}
				if = {
					limit = {
						OR = {
							has_dlc = "The Cossacks"
							has_dlc = "Leviathan"
						}
						OR = {
							ai = yes
							FROM = {
								ai = yes
							}
						}
						NOT = { is_subject_of = FROM }
					}
					if = {
						limit = {
							ai = yes
						}
						trust = {
							who = FROM
							value = 60
						}
					}
					FROM = {
						if = {
							limit = {
								ai = yes
							}
							trust = {
								who = ROOT
								value = 60
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { is_subject_of = FROM }
					}
					alliance_with = FROM
				}
				else = {
					NOT = { liberty_desire = 50 }
				}
			}
			clr_country_flag = declined_establish_sister_republic_@FROM
			set_country_flag = declined_establish_sister_republic_@FROM
			add_opinion = {
				who = FROM
				modifier = declined_ask_for_sister_republic_opinion
			}
		}
	}

	ai_acceptance = {
		add_entry = {
			name = STRATEGIC_VALUE
			limit = {
				NOT = {
					AND = {
						NOT = { is_subject_of = FROM }
						is_neighbor_of = FROM
						OR = {
							NOT = { has_country_flag = declined_establish_sister_republic_@FROM }
							had_country_flag = { flag = declined_establish_sister_republic_@FROM days = 1825 }
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = base_values
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_IS_VASSAL_OF_FROM
			limit = {
				is_subject_of = FROM
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
		}
		add_entry = {
			name = ROOT_LIBERTY_DESIRE_TOO_HIGH
			limit = {
				is_subject_of = FROM
				liberty_desire = 50
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		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 = 15
			}
		}
		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 = 100
			}
			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 = 15
			}
		}
		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 = 2000
			}
			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_FROM_NOT_SAME_RELIGION_GROUP
			limit = {
				NOT = { religion_group = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_FROM_NOT_SAME_RELIGION
			limit = {
				religion_group = FROM
				NOT = { religion = FROM }
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_MERCHANT_REPUBLIC
			limit = {
				FROM = {
					has_reform = merchants_reform
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			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 = ROOT_HAS_MORE_THAN_200_TOTAL_DEVELOPMENT
			limit = {
				total_development = 200
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_OWNS_FROM_CORE_PROVINCES
			limit = {
				NOT = { is_subject_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 = -2 }
		}
		add_entry = {
			name = OPINION
			export_to_variable = {
				which = ai_value
				value = opinion
				who = ROOT
				with = FROM
			}
			divide_variable = { which = ai_value value = 5 }
		}
	}

	ai_will_do = {
		NOT = { has_reform = free_city }
		NOT = { num_of_subjects = 1 }
		OR = {
			is_subject_of = FROM
			AND = {
				is_part_of_hre = no
				FROM = { is_part_of_hre = no }
			}
			AND = {
				is_part_of_hre = yes
				FROM = { is_part_of_hre = yes }
			}
		}
		OR = {
			AND = {
				NOT = { government_rank = 3 }
				FROM = { government_rank = 3 }
			}
			AND = {
				NOT = { government_rank = 2 }
				FROM = { government_rank = 2 }
			}
		}
		government = republic
		NOT = { total_development = 200 }
		is_neighbor_of = FROM
		historical_friend_with = FROM
		NOT = { army_size = FROM }
		OR = {
			NOT = { has_country_flag = declined_establish_sister_republic_@FROM }
			had_country_flag = { flag = declined_establish_sister_republic_@FROM days = 1825 }
		}
	}
}

sister_republic_ask_overlord_to_join_war = {
	category = alliance

	alert_index = 6
	alert_tooltip = sister_republic_ask_overlord_to_join_war_alert_tooltip

	require_acceptance = yes

	is_visible = {
		FROM = {
			is_subject = no
			overlord_of = ROOT
		}
		is_subject_of_type = sister_republic
		any_country = {
			is_subject = no
			is_in_war = {
				defender_leader = THIS
				attacker_leader = ROOT
			}
		}
	}

	is_allowed = {
		hidden_trigger = {
			FROM = {
				is_subject = no
				overlord_of = ROOT
			}
			is_subject_of_type = sister_republic
			any_country = {
				is_subject = no
				is_in_war = {
					defender_leader = THIS
					attacker_leader = ROOT
				}
			}
		}
		FROM = {
			custom_trigger_tooltip = {
				tooltip = DID_NOT_DECLINE_A_CALL_TO_ARMS_OF_A_SUBJECT_WITHIN_LAST_1_YEAR
				OR = {
					NOT = { has_country_flag = declined_sister_republic_offensive_call_to_arms }
					had_country_flag = { flag = declined_sister_republic_offensive_call_to_arms days = 365 }
				}
			}
		}
	}

	on_accept = {
		if = {
			limit = {
				FROM = {
					is_subject = no
					overlord_of = ROOT
				}
				is_subject_of_type = sister_republic
				any_country = {
					is_subject = no
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
				}
				FROM = {
					OR = {
						NOT = { has_country_flag = declined_sister_republic_offensive_call_to_arms }
						had_country_flag = { flag = declined_sister_republic_offensive_call_to_arms days = 365 }
					}
				}
			}
			FROM = {
				join_all_offensive_wars_of = ROOT
				clr_country_flag = accepted_sister_republic_offensive_call_to_arms
				set_country_flag = accepted_sister_republic_offensive_call_to_arms
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				FROM = {
					is_subject = no
					overlord_of = ROOT
				}
				is_subject_of_type = sister_republic
				any_country = {
					is_subject = no
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
				}
				FROM = {
					OR = {
						NOT = { has_country_flag = declined_sister_republic_offensive_call_to_arms }
						had_country_flag = { flag = declined_sister_republic_offensive_call_to_arms days = 365 }
					}
				}
			}
			FROM = {
				clr_country_flag = declined_sister_republic_offensive_call_to_arms
				set_country_flag = declined_sister_republic_offensive_call_to_arms
			}
			add_liberty_desire = 10
		}
	}

	ai_acceptance = {
		add_entry = {
			name = FROM_RULER_MIL_SKILL
			export_to_variable = {
				which = ai_value
				value = MIL
				who = FROM
			}
			multiply_variable = { which = ai_value value = 2 }
		}
		add_entry = {
			name = MODIFIER_DIPLO_SKILL
			export_to_variable = {
				which = ai_value
				value = modifier:diplomatic_reputation
			}
			multiply_variable = { which = ai_value value = 5 }
		}
		add_entry = {
			name = TRUST
			export_to_variable = {
				which = ai_value
				value = trust
				who = FROM
				with = ROOT
			}
			subtract_variable = { which = ai_value value = 50 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_defensive }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 30
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_threatened }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 120
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_ROOT
			limit = {
				FROM = {
					ai_attitude = { who = ROOT attitude = attitude_hostile }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 150
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = ROOT_ATTITUDE_TOWARDS_FROM
			limit = {
				ai_attitude = { who = FROM attitude = attitude_loyal }
			}
			export_to_variable = {
				which = ai_value
				value = 10
			}
		}
		add_entry = {
			name = ROOT_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 = FROM_ATTITUDE_TOWARDS_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					FROM = {
						ai_attitude = { who = PREV attitude = atittude_rivalry }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					FROM = {
						ai_attitude = { who = PREV attitude = attitude_hostile }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					FROM = {
						ai_attitude = { who = PREV attitude = attitude_threatened }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 40
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ATTITUDE_TOWARDS_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					FROM = {
						ai_attitude = { who = PREV attitude = attitude_friendly }
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 60
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_ALREADY_FIGHTING_IN_A_WAR
			limit = {
				FROM = {
					is_at_war = yes
				}
			}
			export_to_variable = {
				which = ai_value
				value = 20
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALREADY_PARTICIPANT_IN_WAR_WITH_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					is_in_war = {
						participants = FROM
						participants = THIS
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_HAS_TRUCE_WITH_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					truce_with = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALLIED_TO_COALITION_TARGET
			limit = {
				any_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
					alliance_with = FROM
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_ALREADY_JOINED_A_WAR_AGAINST_A_COALITION_TARGET_OF_ROOT_WITHIN_LAST_365_DAYS
			limit = {
				FROM = {
					has_country_flag = accepted_sister_republic_offensive_call_to_arms
					NOT = { had_country_flag = { flag = accepted_sister_republic_offensive_call_to_arms days = 365 } }
				}
			}
			export_to_variable = {
				which = ai_value
				value = 1000
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_WOULD_GET_STABILITY_HIT
			limit = {
				OR = {
					any_country = {
						is_in_war = {
							defender_leader = THIS
							attacker_leader = ROOT
						}
						OR = {
							marriage_with = FROM
							truce_with = FROM
						}
					}
				}
			}
			export_to_variable = {
				which = ai_value
				value = 50
			}
			multiply_variable = { which = ai_value value = -1 }
		}
		add_entry = {
			name = FROM_IS_IN_DEBT
			limit = {
				FROM = {
					num_of_loans = 1
				}
			}
			export_to_variable = {
				which = ai_value
				value = trigger_value:num_of_loans
				who = FROM
			}
			multiply_variable = { which = ai_value value = -10 }
		}
		add_entry = {
			name = FROM_WAR_EXHAUSTION
			export_to_variable = {
				which = ai_value
				value = trigger_value:war_exhaustion
				who = FROM
			}
			multiply_variable = { which = ai_value value = -10 }
		}
	}

	ai_will_do = {
		overlord = {
			is_at_war = no
		}
		any_country = {
			is_subject = no
			is_in_war = {
				defender_leader = THIS
				attacker_leader = ROOT
			}
			war_score_against = { who = ROOT value = 25 }
		}
		NOT = {
			calc_true_if = {
				all_country = {
					is_in_war = {
						defender_leader = THIS
						attacker_leader = ROOT
					}
				}
				amount = 3
			}
		}
	}
}

cancel_sister_republic = {
	category = influence

	require_acceptance = no

	is_visible = {
		NOT = { has_dlc = "Rights of Man" }
		FROM = {
			is_subject_of = ROOT
			is_subject_of_type = sister_republic
		}
	}

	is_allowed = {
		hidden_trigger = {
			NOT = { has_dlc = "Rights of Man" }
			FROM = {
				is_subject_of = ROOT
				is_subject_of_type = sister_republic
			}
		}
		NOT = { truce_with = FROM }
		prestige = 0
	}

	on_accept = {
		if = {
			limit = {
				NOT = { has_dlc = "Rights of Man" }
				FROM = {
					is_subject_of = ROOT
					is_subject_of_type = sister_republic
				}
				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 = 90
				all_subject_country = yes
			}
		}
	}
}