@creatable_successor_empire_county_threshold = 15


# Give a suitable County to Genghis
give_temujin_land_effect = {
	if = {
		limit = {
			OR = {
				is_landed = no
				highest_held_title_tier < tier_county
			}
		}
		save_scope_as = genghis_khan

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		title:c_khentii = {
			change_title_holder = {
				holder = scope:genghis_khan
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	capital_county = { change_county_control = 100 }
}

# A wild Genghis Khan appears!
spawn_temujin_character_effect = {
	title:c_khentii.title_province = {
		save_scope_as = temujins_birthplace
	}
	if = {
		limit = {
			exists = character:125501
			character:125501 = {
				is_ai = no
			}
		}
		character:125501 = {
			save_scope_as = temujin
		}
		if = {
			limit = {
				#The DLC has our own BECOME GENGHIS stuff for players
				has_mpo_dlc_trigger = no
			}
			scope:temujin = {
				give_temujin_land_effect = yes
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}

				add_trait = greatest_of_khans
				form_the_mongol_empire_effect = yes
				add_prestige = 25000
				give_nickname = nick_genghis_khan
				trigger_event = conqueror.0001
			}
		}
		else = {
			scope:temujin = {
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}
				trigger_event = conqueror.0001
			}
		}
	}
	else_if = {
		limit = {
			exists = character:125501
			character:125501 = { is_physically_able_ai_adult = yes }
		}
		character:125501 = {
			save_scope_as = temujin
		}
		scope:temujin = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 15
			}

			add_trait = greatest_of_khans
			give_temujin_land_effect = yes
			add_gold = 5000
			add_dread = high_dread
			spawn_temujins_court_effect = yes
			form_the_mongol_empire_effect = yes
			add_prestige = 25000
			if = {
				limit = {
					has_mpo_dlc_trigger = no
					NOT = { has_perk = peacemaker_perk }
				}
				add_perk = peacemaker_perk
			}
			remove_trait = education_diplomacy_1
			remove_trait = education_diplomacy_2
			remove_trait = education_diplomacy_3
			remove_trait = education_diplomacy_4
			remove_trait = education_diplomacy_5
			remove_trait = education_intrigue_1
			remove_trait = education_intrigue_2
			remove_trait = education_intrigue_3
			remove_trait = education_intrigue_4
			remove_trait = education_intrigue_5
			remove_trait = education_stewardship_1
			remove_trait = education_stewardship_2
			remove_trait = education_stewardship_3
			remove_trait = education_stewardship_4
			remove_trait = education_stewardship_5
			remove_trait = education_learning_1
			remove_trait = education_learning_2
			remove_trait = education_learning_3
			remove_trait = education_learning_4
			remove_trait = education_learning_5
			remove_trait = education_martial_1
			remove_trait = education_martial_2
			remove_trait = education_martial_3
			remove_trait = education_martial_4
			add_trait = education_martial_5
			add_trait = flexible_leader
			add_trait = athletic
			if = {
				limit = { has_dlc_feature = tours_and_tournaments }
				add_trait = tourney_participant
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = lifestyle_hunter
					TRACK = hunter
					LEVEL_1 = yes
					LEVEL_3 = no
				}
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = tourney_participant
					TRACK = horse
					LEVEL_1 = yes
					LEVEL_3 = yes
				}
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = tourney_participant
					TRACK = bow
					LEVEL_1 = yes
					LEVEL_3 = yes
				}
			}
			dynasty = {
				add_dynasty_prestige_level = 5
				add_dynasty_prestige = 10000
				add_dynasty_perk = warfare_legacy_1
				add_dynasty_perk = warfare_legacy_2
				add_dynasty_perk = warfare_legacy_3
				add_dynasty_perk = warfare_legacy_4
				add_dynasty_perk = warfare_legacy_5
				if = {
					limit = {
						has_dlc_feature = hybridize_culture
					}
					add_dynasty_perk = ep1_culture_legacy_1
				}
			}
			give_nickname = nick_genghis_khan
		}
	}
	else_if = {
		limit = {
			exists = character:125501.dynasty
			character:125501.dynasty = {
				any_dynasty_member = {
					is_ai = no
					is_landed = yes
				}
			}
		}
		character:125501.dynasty = {
			random_dynasty_member = {
				limit = {
					is_ai = no
					is_landed = yes
				}
				save_scope_as = temujin
			}
		}
		if = {
			limit = { has_mpo_dlc_trigger = no }
			scope:temujin = {
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}

				add_trait = greatest_of_khans
				form_the_mongol_empire_effect = yes
				add_prestige = 25000
				give_nickname = nick_genghis_khan
				trigger_event = conqueror.0001
			}
		}
		else = {
			scope:temujin = {
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}
				trigger_event = conqueror.0001
			}
		}
	}
	else_if = {
		limit = {
			exists = character:125501.dynasty
			character:125501.dynasty = {
				any_dynasty_member = {
					is_physically_able_ai_adult = yes
				}
			}
		}
		character:125501.dynasty = {
			random_dynasty_member = {
				limit = {
					is_physically_able_ai_adult = yes
					is_landed = yes
				}
				alternative_limit = {
					is_physically_able_ai_adult = yes
				}
				save_scope_as = temujin
			}
		}
		scope:temujin = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 15
			}

			add_trait = greatest_of_khans
			give_temujin_land_effect = yes
			add_gold = 5000
			add_dread = high_dread
			spawn_temujins_court_effect = yes
			form_the_mongol_empire_effect = yes
			add_prestige = 25000
			if = {
				limit = {
					has_mpo_dlc_trigger = no
					NOT = { has_perk = peacemaker_perk }
				}
				add_perk = peacemaker_perk
			}
			remove_trait = education_diplomacy_1
			remove_trait = education_diplomacy_2
			remove_trait = education_diplomacy_3
			remove_trait = education_diplomacy_4
			remove_trait = education_diplomacy_5
			remove_trait = education_intrigue_1
			remove_trait = education_intrigue_2
			remove_trait = education_intrigue_3
			remove_trait = education_intrigue_4
			remove_trait = education_intrigue_5
			remove_trait = education_stewardship_1
			remove_trait = education_stewardship_2
			remove_trait = education_stewardship_3
			remove_trait = education_stewardship_4
			remove_trait = education_stewardship_5
			remove_trait = education_learning_1
			remove_trait = education_learning_2
			remove_trait = education_learning_3
			remove_trait = education_learning_4
			remove_trait = education_learning_5
			remove_trait = education_martial_1
			remove_trait = education_martial_2
			remove_trait = education_martial_3
			remove_trait = education_martial_4
			add_trait = education_martial_5
			add_trait = flexible_leader
			add_trait = athletic
			if = {
				limit = { has_dlc_feature = tours_and_tournaments }
				add_trait = tourney_participant
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = lifestyle_hunter
					TRACK = hunter
					LEVEL_1 = yes
					LEVEL_3 = no
				}
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = tourney_participant
					TRACK = horse
					LEVEL_1 = yes
					LEVEL_3 = yes
				}
				add_random_tiered_trait_track_xp_effect = {
					TRAIT = tourney_participant
					TRACK = bow
					LEVEL_1 = yes
					LEVEL_3 = yes
				}
			}
			dynasty = {
				add_dynasty_prestige_level = 5
				add_dynasty_prestige = 10000
				add_dynasty_perk = warfare_legacy_1
				add_dynasty_perk = warfare_legacy_2
				add_dynasty_perk = warfare_legacy_3
				add_dynasty_perk = warfare_legacy_4
				add_dynasty_perk = warfare_legacy_5
				if = {
					limit = {
						has_dlc_feature = hybridize_culture
					}
					add_dynasty_perk = ep1_culture_legacy_1
				}
			}
			give_nickname = nick_genghis_khan
		}
	}
	else_if = {
		limit = {
			#Generate Temujin if there has BEEN NO Temujin
			NOT = {
				has_global_variable = temujin_was_born
			}
		}
		if = {
			limit = { has_game_rule = inversed_gender_equality }
			create_character = {
				name = "Borte" # AKA: Genghis Khan's wife
				gender = female
				location = scope:temujins_birthplace
				template = borte_character_template
				save_scope_as = temujin
			}
			scope:temujin = {
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}

				add_trait = greatest_of_khans
				give_temujin_land_effect = yes
				add_gold = 5000
				add_dread = high_dread
				spawn_temujins_court_effect = yes
				form_the_mongol_empire_effect = yes
				add_prestige = 25000
				give_nickname = nick_genghis_khan
				if = {
					limit = {
						has_mpo_dlc_trigger = no
						NOT = { has_perk = peacemaker_perk }
					}
					add_perk = peacemaker_perk
				}
				dynasty = {
					add_dynasty_prestige_level = 5
					add_dynasty_prestige = 10000
					add_dynasty_perk = warfare_legacy_1
					add_dynasty_perk = warfare_legacy_2
					add_dynasty_perk = warfare_legacy_3
					add_dynasty_perk = warfare_legacy_4
					add_dynasty_perk = warfare_legacy_5
					if = {
						limit = {
							has_dlc_feature = hybridize_culture
						}
						add_dynasty_perk = ep1_culture_legacy_1
					}
				}
			}
		}
		else_if = {
			limit = { has_game_rule = full_gender_equality }
			random_list = {
				#Female Ghengis Khan.
				50 = {
					create_character = {
						name = "Borte" # AKA: Genghis Khan's wife
						gender = female
						location = scope:temujins_birthplace
						template = borte_character_template
						save_scope_as = temujin
					}
					scope:temujin = {
						# Make temporarily immune to disease
						add_character_flag = {
							flag = immune_to_disease
							years = 15
						}

						add_trait = greatest_of_khans
						give_temujin_land_effect = yes
						add_gold = 5000
						add_dread = high_dread
						spawn_temujins_court_effect = yes
						form_the_mongol_empire_effect = yes
						add_prestige = 25000
						give_nickname = nick_genghis_khan
						if = {
							limit = {
								has_mpo_dlc_trigger = no
								NOT = { has_perk = peacemaker_perk }
							}
							add_perk = peacemaker_perk
						}
						dynasty = {
							add_dynasty_prestige_level = 5
							add_dynasty_prestige = 10000
							add_dynasty_perk = warfare_legacy_1
							add_dynasty_perk = warfare_legacy_2
							add_dynasty_perk = warfare_legacy_3
							add_dynasty_perk = warfare_legacy_4
							add_dynasty_perk = warfare_legacy_5
							if = {
								limit = {
									has_dlc_feature = hybridize_culture
								}
								add_dynasty_perk = ep1_culture_legacy_1
							}
						}
					}
				}
				#Male Ghengis Khan.
				50 = {
					create_character = {
						name = "Temujin" # AKA: Genghis Khan
						location = scope:temujins_birthplace
						template = genghis_khan_character_template
						save_scope_as = temujin
					}
					scope:temujin = {
						# Make temporarily immune to disease
						add_character_flag = {
							flag = immune_to_disease
							years = 15
						}

						add_trait = greatest_of_khans
						give_temujin_land_effect = yes
						add_gold = 5000
						add_dread = high_dread
						spawn_temujins_court_effect = yes
						form_the_mongol_empire_effect = yes
						add_prestige = 25000
						give_nickname = nick_genghis_khan
						if = {
							limit = {
								has_mpo_dlc_trigger = no
								NOT = { has_perk = peacemaker_perk }
							}
							add_perk = peacemaker_perk
						}
						dynasty = {
							add_dynasty_prestige_level = 5
							add_dynasty_prestige = 10000
							add_dynasty_perk = warfare_legacy_1
							add_dynasty_perk = warfare_legacy_2
							add_dynasty_perk = warfare_legacy_3
							add_dynasty_perk = warfare_legacy_4
							add_dynasty_perk = warfare_legacy_5
							if = {
								limit = {
									has_dlc_feature = hybridize_culture
								}
								add_dynasty_perk = ep1_culture_legacy_1
							}
						}
					}
				}
			}
		}
		else = {
			create_character = {
				name = "Temujin" # AKA: Genghis Khan
				location = scope:temujins_birthplace
				template = genghis_khan_character_template
				save_scope_as = temujin
			}
			scope:temujin = {
				# Make temporarily immune to disease
				add_character_flag = {
					flag = immune_to_disease
					years = 15
				}

				add_trait = greatest_of_khans
				give_temujin_land_effect = yes
				add_gold = 5000
				add_dread = high_dread
				spawn_temujins_court_effect = yes
				form_the_mongol_empire_effect = yes
				add_prestige = 25000
				give_nickname = nick_genghis_khan
				if = {
					limit = {
						has_mpo_dlc_trigger = no
						NOT = { has_perk = peacemaker_perk }
					}
					add_perk = peacemaker_perk
				}
				dynasty = {
					add_dynasty_prestige_level = 5
					add_dynasty_prestige = 10000
					add_dynasty_perk = warfare_legacy_1
					add_dynasty_perk = warfare_legacy_2
					add_dynasty_perk = warfare_legacy_3
					add_dynasty_perk = warfare_legacy_4
					add_dynasty_perk = warfare_legacy_5
					if = {
						limit = {
							has_dlc_feature = hybridize_culture
						}
						add_dynasty_perk = ep1_culture_legacy_1
					}
				}
			}
		}
		set_global_variable = {
			name =  temujin_was_born
			value = scope:temujin
		}
	}
	#Create a character... but they're random, not Temujin
	else = {
		create_character = {
			location = scope:temujins_birthplace
			template = dynamic_genghis_character_template
			save_scope_as = temujin
		}
		scope:temujin = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 15
			}
			add_trait = greatest_of_khans
			give_temujin_land_effect = yes
			add_gold = 5000
			add_dread = high_dread
			spawn_dynamic_mongol_court_effect = yes
			form_the_mongol_empire_effect = yes
			add_prestige = 25000
			give_nickname = nick_genghis_khan
			if = {
				limit = {
					has_mpo_dlc_trigger = no
					NOT = { has_perk = peacemaker_perk }
				}
				add_perk = peacemaker_perk
			}
			dynasty = {
				add_dynasty_prestige_level = 5
				add_dynasty_prestige = 10000
				add_dynasty_perk = warfare_legacy_1
				add_dynasty_perk = warfare_legacy_2
				add_dynasty_perk = warfare_legacy_3
				add_dynasty_perk = warfare_legacy_4
				add_dynasty_perk = warfare_legacy_5
				if = {
					limit = {
						has_dlc_feature = hybridize_culture
					}
					add_dynasty_perk = ep1_culture_legacy_1
				}
			}
		}
	}
	
	if = {
		limit = {
			scope:temujin = {
				is_ai = yes 
			}
		}
		if = {
			limit = {
				situation:dynastic_cycle ?= {
					situation_top_has_catalyst = catalyst_event_mongol_empire_appears
				}
			}
			situation:dynastic_cycle = {
				trigger_situation_catalyst = {
					catalyst = catalyst_event_mongol_empire_appears
					character = scope:temujin
				}
			}
		}
		#Event for MPO dlc owners
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
			}
			every_player = {
				trigger_event = mpo_greatest_of_khans.1001 #Genghis notification event
			}
		}
		else = {
			#Normal event
			every_player = {
				limit = {
					NOT = {
						this = scope:temujin
					}
				}
				trigger_event = mongol_invasion.1002 # Mongol Empire spawned notification
			}
		}
	}
}


# Form the actual Mongol Empire...
form_the_mongol_empire_effect = {
	save_scope_as = mongol_founder

	if = {
		limit = {
			is_tributary = yes
		}
		end_tributary = yes
	}
	if = {
		limit = {
			is_confederation_member = yes
		}
		scope:mongol_founder.confederation = {
			remove_confederation_member = scope:mongol_founder
		}
		if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			show_as_tooltip = {
				remove_character_modifier = mpo_confederation_member_modifier
			}
		}
	}

	#Create the title
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_mongol_empire = {
		change_title_holder = {
			holder = scope:mongol_founder
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change


	if = {
		limit = {
			is_independent_ruler = no
		}
		create_title_and_vassal_change = {
			type = independency
			save_scope_as = indpendence_change
			add_claim_on_loss = no
		}
		becomes_independent = {
			change = scope:indpendence_change
		}
		resolve_title_and_vassal_change = scope:indpendence_change
	}

	if = {
		limit = {
			capital_county = {
				title_province = {
					has_holding_type = herder_holding
				}
			}
		}
		capital_county = {
			title_province = {
				set_holding_type = nomad_holding
			}
		}
	}
	if = {
		limit = {
			has_mpo_dlc_trigger = yes
			NOT = {
				government_has_flag = government_is_nomadic
			}
		}
		change_government = nomad_government
		add_trait_force_tooltip = nomadic_philosophy
	}
	else_if = {
		limit = {
			has_mpo_dlc_trigger = no
			NOT = {
				government_has_flag = government_is_tribal
			}
		}
		change_government = tribal_government
	}
	if = {
		limit = {
			government_has_flag = government_is_tribal
		}
		if = {
			limit = { has_realm_law = tribal_authority_0 }
			remove_realm_law = tribal_authority_0
		}
		if = {
			limit = { has_realm_law = tribal_authority_1 }
			remove_realm_law = tribal_authority_1
		}
		if = {
			limit = { has_realm_law = tribal_authority_3 }
			remove_realm_law = tribal_authority_3
		}
		add_realm_law_skip_effects = tribal_authority_2
	
		add_realm_law_skip_effects = high_partition_succession_law
	}
	if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		if = {
			limit = { has_realm_law = nomadic_authority_1 }
			remove_realm_law = nomadic_authority_1
		}
		if = {
			limit = { has_realm_law = nomadic_authority_2 }
			remove_realm_law = nomadic_authority_2
		}
		if = {
			limit = { has_realm_law = nomadic_authority_3 }
			remove_realm_law = nomadic_authority_3
		}
		if = {
			limit = { has_realm_law = nomadic_authority_4 }
			remove_realm_law = nomadic_authority_4
		}
		add_realm_law_skip_effects = nomadic_authority_5
		domicile ?= {
			switch = {
				trigger = has_domicile_building
				yurt_main_01 = {
					add_domicile_building = yurt_main_02
					add_domicile_building = yurt_main_03
					add_domicile_building = yurt_main_04
					add_domicile_building = yurt_main_05
				}
				yurt_main_02 = {
					add_domicile_building = yurt_main_03
					add_domicile_building = yurt_main_04
					add_domicile_building = yurt_main_05
				}
				yurt_main_03 = {
					add_domicile_building = yurt_main_04
					add_domicile_building = yurt_main_05
				}
				yurt_main_04 = {
					add_domicile_building = yurt_main_05
				}
			}
		}
		if = {
			limit = {
				exists = domicile
				domicile = {
					free_external_domicile_building_slots >= 1
					NOT = {
						has_domicile_building_or_higher = mass_warfare_yurt_01
					}
				}
			}
			domicile = {
				add_domicile_building = mass_warfare_yurt_01
				add_domicile_building = mass_warfare_yurt_02
				add_domicile_building = mass_warfare_yurt_03
				add_domicile_building = mass_warfare_yurt_04
			}
		}
		if = {
			limit = {
				exists = domicile
				domicile = {
					free_external_domicile_building_slots >= 1
					NOT = {
						has_domicile_building_or_higher = character_warfare_yurt_03
					}
				}
			}
			domicile = {
				add_domicile_building = character_warfare_yurt_01
				add_domicile_building = character_warfare_yurt_02
				add_domicile_building = character_warfare_yurt_03
				add_domicile_building = character_warfare_yurt_04
			}
		}
		domicile = {
			change_herd = {
				add = nomadic_authority_level_5_requirement
			}
		}
	}

	assert_if = {
		limit = { NOT = { exists = title:e_mongol_empire } }
		text = "Mongol Empire title was not created!"
	}

	hidden_effect = { set_primary_title_to = title:e_mongol_empire }

	every_held_title = {
		title_tier = empire
		limit = {
			NOT = { this = title:e_mongol_empire }
		}
		scope:mongol_founder = {
			destroy_title = prev
		}
	}

	spawn_mongol_troops_effect = yes

	set_global_variable = {
		name = mongol_empire_has_spawned
		value = yes
	}

	#Make sure that Genghis is crowned
	#Anointed if he must be anointed
	if = {
		limit = {
			OR = {
				has_realm_law = uncrowned
				has_realm_law = crowned_king
			}
			faith = { has_doctrine = doctrine_imperial_anointment }
		}
		if = {
			limit = {
				NOT = {
					has_game_rule = coronation_laws_off
				}
			}
			add_realm_law = crowned_emperor
		}
		set_variable = crowned_emperor_var
		if = {
			limit = {
				has_variable = crowned_king_var
			}
			remove_variable = crowned_king_var
		}
	}
	else_if = {
		limit = {
			has_realm_law = uncrowned
		}
		if = {
			limit = {
				NOT = {
					has_game_rule = coronation_laws_off
				}
			}
			add_realm_law = crowned_king
		}
		set_variable = crowned_king_var
	}
}

# Make sure the Empire has troops...
spawn_mongol_troops_effect = {
	if = {
		limit = {
			has_mpo_dlc_trigger = yes
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = mangudai
				stacks = 14
			}
			men_at_arms = {
				type = heavy_horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = mangudai
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = mangudai
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = mangudai
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = heavy_horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 10
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 20
			}
			men_at_arms = {
				type = torch_bearers
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 20
			}
			men_at_arms = {
				type = torch_bearers
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
	}
	else = {
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			men_at_arms = {
				type = horse_archers
				stacks = 14
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = armored_horsemen
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			levies = {
				value = 5000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = armored_horsemen
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			levies = {
				value = 5000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = armored_horsemen
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			levies = {
				value = 5000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = horse_archers
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = armored_horsemen
				stacks = 3
			}
			men_at_arms = {
				type = trebuchet
				stacks = 5
			}
			location = capital_province
			origin = capital_province
		}
	}
}

spawn_mongol_troops_condensed_effect = {
	if = {
		limit = {
			has_mpo_dlc_trigger = yes
		}
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			men_at_arms = {
				type = horse_archers
				stacks = 40
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 100
			}
			men_at_arms = {
				type = heavy_horse_archers
				stacks = 20
			}
			men_at_arms = {
				type = mangudai
				stacks = 44
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 14
			}
			men_at_arms = {
				type = trebuchet
				stacks = 25
			}
			men_at_arms = {
				type = torch_bearers
				stacks = 10
			}
			location = capital_province
			origin = capital_province
		}
	}
	else = {
		spawn_army = {
			uses_supply = no
			inheritable = no
			name = mongol_event_troops
			levies = {
				value = 15000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 74
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 70
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 10
			}
			men_at_arms = {
				type = armored_horsemen
				stacks = 14
			}
			men_at_arms = {
				type = trebuchet
				stacks = 25
			}
			location = capital_province
			origin = capital_province
		}
	}
}

spawn_mongol_successor_state_troops_effect = {
	if = {
		limit = {
			has_mpo_dlc_trigger = yes
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = nomadic_riders
				stacks = 7
			}
			men_at_arms = {
				type = mangudai
				stacks = 5
			}
			men_at_arms = {
				type = steppe_raiders
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = nomadic_riders
				stacks = 7
			}
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = nomad_lancers
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			men_at_arms = {
				type = nomadic_riders
				stacks = 7
			}
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = heavy_horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
	}
	else = {
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			levies = {
				value = 1000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			levies = {
				value = 1000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
		spawn_army = {
			uses_supply = no
			inheritable = yes
			name = mongol_event_troops
			levies = {
				value = 1000
			}
			men_at_arms = {
				type = horse_archers
				stacks = 5
			}
			men_at_arms = {
				type = light_horsemen
				stacks = 5
			}
			men_at_arms = {
				type = trebuchet
				stacks = 3
			}
			location = capital_province
			origin = capital_province
		}
	}
	
}

### Populating the life of Temujin...
spawn_temujins_court_effect = {
	add_character_flag = is_temujin
	if = {
		limit = {
			is_married = no
		}
		if = {
			limit = {
				scope:temujin = { is_female = yes }
			}
			# Create Temujin (husband)...
			create_character = {
				template = genghis_khan_character_template
				name = "Temujin" # Husband of Temujin
				employer = scope:temujin
				save_scope_as = borte
			}
		}
		else = {
			# Create Borte (wife)...
			create_character = {
				template = borte_character_template
				name = "Borte" # Wife of Temujin
				gender = female
				employer = scope:temujin
				save_scope_as = borte
			}
		}
		scope:borte = {
			marry = scope:temujin
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}
		}
		if = {
			limit = {
				scope:temujin = { is_male = yes }
			}
			scope:temujin = { save_scope_as = great_khan_family_father }
			scope:borte = { save_scope_as = great_khan_family_mother }
		}
		else = {
			scope:temujin = { save_scope_as = great_khan_family_mother }
			scope:borte = { save_scope_as = great_khan_family_father }		
		}

		# Create Jochi (son)...
		create_character = {
			template = jochi_character_template
			name = "Jochi" # (Oldest son of Temujin and Borte)
			employer = scope:temujin
			mother = scope:great_khan_family_mother
			father = scope:great_khan_family_father
			save_scope_as = jochi
		}
		scope:jochi = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}
		}

		# Create Tolui (son)...
		create_character = {
			template = tolui_character_template
			name = "Tolui" # (Son of Temujin and Borte)
			employer = scope:temujin
			mother = scope:great_khan_family_mother
			father = scope:great_khan_family_father
			save_scope_as = tolui
		}

		scope:tolui = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}
		}

		# Create Chagatai (son)...
		create_character = {
			template = chagatai_character_template
			name = "Chagatai"  # (Son of Temujin and Borte)
			employer = scope:temujin
			mother = scope:great_khan_family_mother
			father = scope:great_khan_family_father
			save_scope_as = chagatai
		}

		scope:chagatai = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}

			#Make it more likely that he gets a good martial education
			hidden_effect = {
				education_point_acquisition_effect = yes
				education_point_acquisition_effect = yes
			}
		}

		# Create Ögedei (son)...
		create_character = {
			template = ogodei_character_template
			name = "Ogodei" # Ögedei Khan (# Son of Temujin and Borte)
			employer = scope:temujin
			mother = scope:great_khan_family_mother
			father = scope:great_khan_family_father
			save_scope_as = ogodei
		}

		scope:ogodei = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}

			#Make it more likely that he gets a good martial education
			hidden_effect = {
				education_point_acquisition_effect = yes
				education_point_acquisition_effect = yes
			}
		}

		# Create Altun Begi (Daughter)...
		create_character = {
			template = altun_begi_character_template
			name = "Altun_Begi" # (Daughter of Temujin)
			employer = scope:temujin
			gender = female
			father = scope:great_khan_family_father
			save_scope_as = altun_begi
		}

		scope:altun_begi = {
			# Make temporarily immune to disease
			add_character_flag = {
				flag = immune_to_disease
				years = 10
			}
		}
	}

	# Create Subutai (Commander)...
	create_character = {
		template = subutai_character_template
		name = "Subutai" # (Temujin's Commander of armies)
		employer = scope:temujin
		save_scope_as = subutai
	}

	scope:subutai = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
		# Set friendship with Temujin
		set_random_friendship_reason = { TARGET = scope:temujin }
	}
	
	# Spawn some generic Bagathurs
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	
	# Spawn some captured Han siege engineers
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
}

### Populating the life of Temujin...
spawn_dynamic_mongol_court_effect = {
	add_character_flag = is_temujin

	if = {
		limit = {
			scope:temujin = {
				is_female = no
			}
		}
		save_scope_as = great_khan_family_father
	}
	else = {
		save_scope_as = great_khan_family_mother
	}
	if = {
		limit = {
			exists = scope:great_khan_family_father
		}
		create_character = {
			template = dynamic_genghis_spouse_template
			gender = female
			employer = scope:temujin
			save_scope_as = genghis_spouse
		}
		scope:genghis_spouse = {
			save_scope_as = great_khan_family_mother
		}
	}
	else = {
		create_character = {
			template = dynamic_genghis_spouse_template
			gender = male
			employer = scope:temujin
			save_scope_as = genghis_spouse
		}
		scope:genghis_spouse = {
			save_scope_as = great_khan_family_father
		}
	}
	scope:genghis_spouse = {
		marry = scope:temujin
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}
	create_character = {
		template = dynamic_genghis_child_template
		employer = scope:temujin
		father = scope:great_khan_family_father
		mother = scope:great_khan_family_mother
		dynasty = inherit
		save_scope_as = genghis_child_1
	}
	scope:genghis_child_1 = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}
	create_character = {
		template = dynamic_genghis_child_template
		employer = scope:temujin
		father = scope:great_khan_family_father
		mother = scope:great_khan_family_mother
		dynasty = inherit
		save_scope_as = genghis_child_2
	}
	scope:genghis_child_2 = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}
	create_character = {
		template = dynamic_genghis_child_template
		employer = scope:temujin
		father = scope:great_khan_family_father
		mother = scope:great_khan_family_mother
		dynasty = inherit
		save_scope_as = genghis_child_3
	}
	scope:genghis_child_3 = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}
	create_character = {
		template = dynamic_genghis_child_template
		employer = scope:temujin
		father = scope:great_khan_family_father
		mother = scope:great_khan_family_mother
		dynasty = inherit
		save_scope_as = genghis_child_4
	}
	scope:genghis_child_4 = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}
	create_character = {
		template = dynamic_genghis_child_template
		employer = scope:temujin
		father = scope:great_khan_family_father
		mother = scope:great_khan_family_mother
		dynasty = inherit
		save_scope_as = genghis_child_5
	}
	scope:genghis_child_5 = {
		# Make temporarily immune to disease
		add_character_flag = {
			flag = immune_to_disease
			years = 10
		}
	}

	recruit_three_nomadic_capital_characters_effect = {
		NOMAD_TEMPLATE_CHARACTER = nomadic_commander_template
	}
	
	# Spawn some generic Bagathurs
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_warrior_character
		faith = scope:temujin.faith
		culture = scope:temujin.culture
	}
	
	# Spawn some captured Han siege engineers
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
	create_character = {
		gender_female_chance = temujin_soldier_female_chance
		employer = scope:temujin
		template = new_siege_engineer
		faith = faith:shangqing
		culture = culture:han
	}
}

### Start war of conquest for the Mongolian heartland
start_wars_for_mongolia_effect = {
	save_temporary_scope_as = mongol_conqueror
	# Build a list of potential targets
	every_neighboring_top_liege_realm_owner = {
		limit = {
			any_sub_realm_county = {
				is_landless_type_title = no
				title_province = { geographical_region = special_mongol_empire_start_region }
			}
			is_landed = yes
		}
		if = {
			limit = { NOT = { is_in_list = top_liege_targets } }
			add_to_temporary_list = top_liege_targets
		}
	}
	every_in_list = {
		list = top_liege_targets
		if = {
			limit = {
				government_has_flag = government_is_herder
			}
			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
				add_claim_on_loss = no
			}
			change_liege = {
				liege = scope:mongol_conqueror
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
		}
		else = {
			save_temporary_scope_as = new_war_target
			capital_county.empire = { save_temporary_scope_as = war_target_title }
			# Declare the war
			scope:mongol_conqueror = {
				start_war = {
					cb = mongol_realm_invasion_war
					target = scope:new_war_target.top_liege
					target_title = scope:war_target_title
				}
			}
		}
	}
}

# Send subjugation demand effect
send_mongol_subjugation_demand_effect = {
	if = {
		limit = {
			NOT = { is_allied_to = scope:mongol_emperor }
		}
		trigger_event = {
			id = mongol_invasion.2001
			days = { 3 12 }
		}

		save_temporary_scope_as = subjugation_offer_recipient
		scope:mongol_emperor = {
			add_to_variable_list = {
				name = subjugation_offer_under_consideration
				target = scope:subjugation_offer_recipient
			}
		}
	}
	else = {
		if = {
			limit = {
				highest_held_title_tier >= tier_empire
			}
			trigger_event = {
				id = mongol_invasion.2111
				days = { 3 12 }
			}
		}
		else = {
			trigger_event = {
				id = mongol_invasion.2101
				days = { 3 12 }
			}
		}
	}
}


### Mongol war target evaluation and declaration
mongol_war_target_evaluation_and_declaration_effect = {
	# Set the Mongol Emperor as reference point
	save_scope_as = mongol_emperor
	add_character_flag = {
		flag = free_mongol_cb
		days = 14
	}
	# Select a new target
	random_neighboring_top_liege_realm_owner = {
		limit = {
			NOT = { is_allied_to = scope:mongol_emperor }
			this != scope:mongol_emperor
			top_liege != scope:mongol_emperor
			save_temporary_scope_as = truce_check
			NOT = {
				scope:mongol_emperor = {
					any_truce_target = {
						this = scope:truce_check
					}
				}
			}
			trigger_if = { # We don't want the Byzantine empire to get annihilated immediately
				limit = {
					OR = {
						has_primary_title = title:e_byzantium
						has_primary_title = title:e_latin_empire
					}
				}
				OR = {
					current_year >= 1279 # Roughly when the mongols should fracture historically
					scope:mongol_emperor = {
						completely_controls_region = special_mongol_empire_golden_horde_region # Controls all of Russia and the Steppe
					}
					any_realm_county = { # Byzantium is expansionist
						count >= 50
						title_province = {
							OR = {
								geographical_region = special_mongol_empire_conquest_region_prio_5
								geographical_region = special_mongol_empire_conquest_region_prio_4
								geographical_region = special_mongol_empire_conquest_region_prio_3
								geographical_region = special_mongol_empire_conquest_region_prio_2
								geographical_region = special_mongol_empire_conquest_region_prio_1
								geographical_region = special_mongol_empire_conquest_region_prio_1_alpha
							}
						}
					}
				}
			}
		}
		weight = {
			base = 0
			modifier = {
				add = mongol_invasion_target_character_weight
				always = yes
			}
		}
		save_temporary_scope_as = next_invasion_target
		primary_title = {
			save_temporary_scope_as = next_invasion_title_target
		}
	}
	if = {
		limit = {
			exists = scope:next_invasion_target
		}
		if = {
			limit = { # Declare war on every same-tier count or duke in same empire
				scope:next_invasion_target = {
					OR = {
						highest_held_title_tier = tier_county
						highest_held_title_tier = tier_duchy
					}
				}
			}
			scope:next_invasion_title_target = {
				add_to_temporary_list = all_titles_to_declare_on
				empire = {
					every_in_de_jure_hierarchy = { # Find all other same-tier titles in same de jure empire
						continue = {
							tier > tier_county
							# Stop searching if you hit the Mongol Emperor's territory at any point
							trigger_if = {
								limit = { exists = holder }
								holder != scope:mongol_emperor
								holder.top_liege != scope:mongol_emperor
							}
						}
						limit = {
							exists = this
							OR = {
								tier = tier_county
								tier = tier_duchy
							}
							holder ?= {
								top_liege = this
								this != scope:mongol_emperor
								top_liege != scope:mongol_emperor
								NOT = { is_at_war_with = scope:mongol_emperor }
								NOT = { is_allied_to = scope:mongol_emperor }
								save_temporary_scope_as = truce_check
								NOT = {
									scope:mongol_emperor = {
										any_truce_target = {
											this = scope:truce_check
										}
									}
								}
							}
						}
						add_to_temporary_list = all_titles_to_declare_on
					}
				}
			}
			every_in_list = {
				list = all_titles_to_declare_on
				limit = {
					holder = {
						# An extra check to make sure we haven't snuck any Mongol territory in
						this != scope:mongol_emperor
						top_liege != scope:mongol_emperor

						# Standard conditions
						NOT = { is_at_war_with = scope:mongol_emperor }
						NOT = {
							is_in_list = has_been_sent_subjugation_offer
						}
						save_temporary_scope_as = truce_check
					}
					NOT = {
						scope:mongol_emperor = {
							any_truce_target = {
								this = scope:truce_check
							}
						}
					}
				}

				holder = {
					add_to_temporary_list = has_been_sent_subjugation_offer
					send_mongol_subjugation_demand_effect = yes
				}
			}
		}
		else_if = {
			limit = {
				scope:next_invasion_target = {
					highest_held_title_tier < tier_empire
				}
			}
			scope:next_invasion_target = {
				send_mongol_subjugation_demand_effect = yes
			}
		}
		else = { # Emperors are not offered ways out
			start_war = {
				cb = mongol_realm_invasion_war
				target = scope:next_invasion_target
				target_title = scope:next_invasion_title_target.empire
			}
		}
	}
}

mongols_devastate_county_effect = {
	change_development_level = {
		subtract = scope:county.development_level
		multiply = 0.5
		floor = yes
	}
	random = {
		chance = 25
		random_county_province = {
			limit = {
				has_holding = yes
				num_buildings >= 2
			}
			destroy_random_building_variable_effect = yes
			destroy_random_building_effect = yes
		}
	}
	# Silk Road
	scope:county = {
		tgp_silk_road_mongol_devastation_effect = yes
	}
}


### MONGOL EMPIRE BREAKUP EFFECTS ###

### Title creation effects
assign_core_mongol_titles_to_heir_effect = {
	save_temporary_scope_as = candidate

	if = { # Check whether everything is grantable
		limit = {
			NOT = { exists = global_var:handed_out_mongolia_in_mongol_succession }
			NOT = { exists = title:e_mongolia.holder }
		}
		
		# If the character doesn't hold any titles in the relevant
		if = {
			limit = {
				NOT = {
					any_held_title = {
						title_tier = county
						is_landless_type_title = no
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
					}
				}
			}
			scope:old_mongol_emperor = {
				random_sub_realm_county = {
					limit = {
						is_landless_type_title = no
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
					}
					save_scope_as = county_to_transfer
				}
			}
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			scope:county_to_transfer = {
				change_title_holder = {
					holder = scope:candidate
					change = scope:title_change
				}
			}
			resolve_title_and_vassal_change = scope:title_change
		}
		
		# Create and grant title
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		title:e_mongolia = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
		# Move de jure back from Mongol Empire to Mongolia
		title:e_mongol_empire = {
			every_in_de_jure_hierarchy = {
				limit = {
					tier = tier_kingdom
				}
				set_de_jure_liege_title = title:e_mongolia
			}
		}
		# Used to check whether e_mongol_empire can be safely destroyed
		set_global_variable = {
			name = handed_out_mongolia_in_mongol_succession
			value = yes
		}
	}
	save_scope_as = mongolia_ruler
	add_to_list = candidate_granted_title
	
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_mongolia.title_capital_county
		}
		set_realm_capital = title:e_mongolia.title_capital_county
	}
	#The primary heir of the Mongol emperor will likely be inheriting big special armies if MPO is active
	if = {
		limit = {
			has_mpo_dlc_trigger = no
			NOT = {
				is_primary_heir_of = scope:old_mongol_emperor
			}
		}
		spawn_mongol_successor_state_troops_effect = yes
	}
	if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		domicile = {
			change_herd = 5000
		}
	} 
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		if = {
			limit = { has_realm_law = nomadic_authority_1 }
			remove_realm_law = nomadic_authority_1
		}
		if = {
			limit = { has_realm_law = nomadic_authority_2 }
			remove_realm_law = nomadic_authority_2
		}
		if = {
			limit = { has_realm_law = nomadic_authority_3 }
			remove_realm_law = nomadic_authority_3
		}
		if = {
			limit = { has_realm_law = nomadic_authority_5 }
			remove_realm_law = nomadic_authority_5
		}
		add_realm_law = nomadic_authority_4
		if = {
			limit = {
				exists = domicile
				domicile = {
					free_external_domicile_building_slots >= 1
					NOT = {
						has_domicile_building_or_higher = mass_warfare_yurt_01
					}
				}
			}
			domicile = {
					add_domicile_building = mass_warfare_yurt_01
					add_domicile_building = mass_warfare_yurt_02
					add_domicile_building = mass_warfare_yurt_03
			}
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_allows_nomad_domicile_titles }
				NOT = {
					any_held_title = {
						is_nomad_title = yes
					}
				}
			}
			save_scope_as = holder
			create_nomad_title = {
				name = nomad_title_name
				holder = scope:holder
				government = nomad_government
				save_scope_as = new_nomad_title
			}
		}
	}
}

grant_mongol_successor_nomadic_bonuses_effect = {
	if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		#They might not have a nomadic camp title, create if needed
		if = {
			limit = {
				NOT = { government_has_flag = government_allows_nomad_domicile_titles }
				NOT = {
					any_held_title = {
						is_nomad_title = yes
					}
				}
			}
			save_scope_as = holder
			create_nomad_title = {
				name = nomad_title_name
				holder = scope:holder
				government = nomad_government
				save_scope_as = new_nomad_title
			}
		}
		if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			if = {
				limit = { has_realm_law = nomadic_authority_1 }
				remove_realm_law = nomadic_authority_1
			}
			if = {
				limit = { has_realm_law = nomadic_authority_2 }
				remove_realm_law = nomadic_authority_2
			}
			if = {
				limit = { has_realm_law = nomadic_authority_3 }
				remove_realm_law = nomadic_authority_3
			}
			if = {
				limit = { has_realm_law = nomadic_authority_5 }
				remove_realm_law = nomadic_authority_5
			}
			add_realm_law = nomadic_authority_4
			if = {
				limit = {
					exists = domicile
					domicile = {
						free_external_domicile_building_slots >= 1
						NOT = {
							has_domicile_building_or_higher = mass_warfare_yurt_01
						}
					}
				}
				domicile = {
					add_domicile_building = mass_warfare_yurt_01
					add_domicile_building = mass_warfare_yurt_02
					add_domicile_building = mass_warfare_yurt_03
				}
			}
			domicile = {
				change_herd = {
					value = monumental_herd_value
					multiply = 1.5
				} 
			}
		}
	}
}

grant_ilkhanate_effect = {
	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_ilkhanate_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_ilkhanate_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_ilkhanate = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = ilkhanate_ruler
	}
	set_global_variable = {
		name = ilkhanate_handed_out
		value = yes
	}

	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_ilkhanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_ilkhanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_ilkhanate.title_capital_county
		}
		set_realm_capital = title:e_ilkhanate.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_ilkhanate_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_ilkhanate_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_ilkhanate_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_golden_horde_effect = {
	debug_log = "Golden Horde about to be created"
	debug_log_scopes = no

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_golden_horde_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_golden_horde_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_golden_horde = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = golden_horde_ruler
	}

	set_global_variable = {
		name = golden_horde_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_golden_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_golden_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_golden_horde.title_capital_county
		}
		set_realm_capital = title:e_golden_horde.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_golden_horde_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_golden_horde_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_golden_horde_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_chagatai_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_chagatai_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_chagatai_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_chagatai = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = chagatai_ruler
	}

	set_global_variable = {
		name = chagatai_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_chagatai.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_chagatai.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_chagatai.title_capital_county
		}
		set_realm_capital = title:e_chagatai.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_chagatai_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_chagatai_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_chagatai_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_red_horde_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_red_horde_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_red_horde_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_red_horde = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = red_horde_ruler
	}

	set_global_variable = {
		name = red_horde_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_red_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_red_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_red_horde.title_capital_county
		}
		set_realm_capital = title:e_red_horde.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_red_horde_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_red_horde_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_red_horde_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_white_horde_effect = {
	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_white_horde_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_white_horde_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_white_horde = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = white_horde_ruler
	}

	set_global_variable = {
		name = white_horde_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_white_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_white_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_white_horde.title_capital_county
		}
		set_realm_capital = title:e_white_horde.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_white_horde_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_white_horde_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_white_horde_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_aarlud_khanate_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_aarlud_khanate_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_aarlud_khanate_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_aarlud_khanate = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = aarlud_khanate_ruler
	}

	set_global_variable = {
		name = aarlud_khanate_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_aarlud_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_aarlud_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_aarlud_khanate.title_capital_county
		}
		set_realm_capital = title:e_aarlud_khanate.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_aarlud_khanate_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_aarlud_khanate_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_aarlud_khanate_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_togskol_khanate_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_togskol_khanate_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_togskol_khanate_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_togskol_khanate = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = togskol_khanate_ruler
	}

	set_global_variable = {
		name = togskol_khanate_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_togskol_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_togskol_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_togskol_khanate.title_capital_county
		}
		set_realm_capital = title:e_togskol_khanate.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_togskol_khanate_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_togskol_khanate_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_togskol_khanate_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_baruun_khanate_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_baruun_khanate_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_baruun_khanate_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_baruun_khanate = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = baruun_khanate_ruler
	}

	set_global_variable = {
		name = baruun_khanate_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_baruun_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_baruun_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_baruun_khanate.title_capital_county
		}
		set_realm_capital = title:e_baruun_khanate.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_baruun_khanate_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_baruun_khanate_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_baruun_khanate_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_great_yuan_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_great_yuan_region
					}
				}
			}
		}
		#Prefer biggest available chinese empire
		if = {
			limit = {
				scope:old_mongol_emperor = {
					any_sub_realm_empire = {
						any_this_title_or_de_jure_above = {
							this = title:h_china
						}
					}
				}
			}
			scope:old_mongol_emperor = {
				#Prioritize Chinese empire they have the most titles in
				ordered_sub_realm_empire = {
					order_by = {
						every_de_jure_county = {
							limit = {
								is_landless_type_title = no
								holder.top_liege ?= scope:old_mongol_emperor
								title_province ?= {
									geographical_region = special_mongol_empire_great_yuan_region
								}
							}
							add = 1
						}
					}
					limit = {
						any_this_title_or_de_jure_above = {
							this = title:h_china
						}
					}
					random_de_jure_county = {
						limit = {
							is_landless_type_title = no
							title_province = {
								geographical_region = special_mongol_empire_great_yuan_region
							}
						}
					}
					save_scope_as = county_to_transfer
				}
			}
		}
		#Or just any county in Great Yuan region
		else = {
			scope:old_mongol_emperor = {
				random_sub_realm_county = {
					limit = {
						is_landless_type_title = no
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
					}
					save_scope_as = county_to_transfer
				}
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}

	#First - give Hegemony of China if it's empty and Mongols have enough China!
	if = {
		limit = {
			has_tgp_dlc_trigger = yes
			NOT = {
				exists = title:h_china.holder
			}
			title:h_china ?= {
				any_de_jure_county = {
					percent >= claim_mandate_china_county_percentage_value
					holder.top_liege = {
						OR = {
							this = scope:old_mongol_emperor
							is_tributary_of_suzerain_or_above = scope:old_mongol_emperor
						}
					}
				}
			}
		}
		title:h_china = {
			save_scope_as = great_yuan_title
		}
	}
	#Give appropriate Chinese empire so that they aren't disturbed by a weird Yuan being created
	else_if = {
		limit = {
			scope:old_mongol_emperor = {
				any_realm_de_jure_empire = {
					any_this_title_or_de_jure_above = {
						this = title:h_china
					}
					OR = {
						NOT = {
							exists = holder
						}
						holder = scope:old_mongol_emperor
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			ordered_realm_de_jure_empire = {
				order_by = {
					every_de_jure_county = {
						limit = {
							holder.top_liege ?= scope:old_mongol_emperor
							title_province ?= {
								geographical_region = special_mongol_empire_great_yuan_region
							}
						}
						add = 1
					}
				}
				limit = {
					any_this_title_or_de_jure_above = {
						this = title:h_china
					}
					OR = {
						NOT = {
							exists = holder
						}
						holder = scope:old_mongol_emperor
					}
				}
				save_scope_as = great_yuan_title
			}
		}
	}
	#Give any Empire in Great Yuan region, I guess that will do
	else_if = {
		limit = {
			scope:old_mongol_emperor = {
				any_realm_de_jure_empire = {
					any_de_jure_county = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
					}
					OR = {
						NOT = {
							exists = holder
						}
						holder = scope:old_mongol_emperor
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			ordered_realm_de_jure_empire = {
				order_by = {
					every_de_jure_county = {
						limit = {
							holder.top_liege ?= scope:old_mongol_emperor
							title_province ?= {
								geographical_region = special_mongol_empire_great_yuan_region
							}
						}
						add = 1
					}
				}
				limit = {
					any_de_jure_county = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
					}
					OR = {
						NOT = {
							exists = holder
						}
						holder = scope:old_mongol_emperor
					}
				}
				save_scope_as = great_yuan_title
			}
		}
	}
	#Give Great Yuan title
	else = {
		title:e_great_yuan = {
			save_scope_as = great_yuan_title
		}
	}

	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	scope:great_yuan_title = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	#Put great yuan under h_china if it was just made
	if = {
		limit = {
			scope:great_yuan_title = title:e_great_yuan
		}
		title:e_great_yuan = {
			set_de_jure_liege_title = title:h_china
		}
	}

	scope:candidate = {
		save_scope_as = great_yuan_ruler
	}

	set_global_variable = {
		name = great_yuan_handed_out
		value = yes
	}

	#If Hegemony or Great Yuan created, give appropriate capital for great yuan
	if = {
		limit = {
			scope:great_yuan_title = {
				OR = {
					this = title:h_china
					this = title:e_great_yuan
				}
			}
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_great_yuan.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_great_yuan.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	# Give the character the appropriate dynamic capital area, if possible
	else_if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = scope:great_yuan_title.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = scope:great_yuan_title.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	#If has Hegemony or Great Yuan, set Yuan capital as capital
	if = {
		limit = {
			scope:great_yuan_title = {
				OR = {
					this = title:h_china
					this = title:e_great_yuan
				}
			}
			has_title = title:e_great_yuan.title_capital_county
		}
		set_realm_capital = title:e_great_yuan.title_capital_county
	}
	else_if = {
		limit = {
			has_title = scope:great_yuan_title.title_capital_county
		}
		set_realm_capital = scope:great_yuan_title.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_great_yuan_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_great_yuan_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_great_yuan_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100

	#The Yuan Emperor should get the story that drives him to become Celestial Hegemon, if he isn't already and it's chaos phase
	if = {
		limit = {
			scope:great_yuan_title = {
				NOT = {
					this = title:h_china
				}
			}
			any_character_situation = {
				situation_type = dynastic_cycle
				situation_current_phase = situation_dynastic_cycle_phase_chaos
			}
		}
		create_story = story_take_mandate_of_heaven
		if = {
			limit = {
				has_treasury = yes
			}
			add_treasury = 2000
		}
		else = {
			add_gold = 2000
		}
	}
	else = {
		create_story = story_conqueror
	}

	#Cycle handling
	if = {
		limit = {
			scope:great_yuan_title = title:h_china
		}
		title:h_china.holder = { tgp_claim_mandate_of_heaven_effect = yes }
	}
}

grant_blue_horde_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_blue_horde_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_blue_horde_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_blue_horde = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = blue_horde_ruler
	}

	set_global_variable = {
		name = blue_horde_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_blue_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_blue_horde.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_blue_horde.title_capital_county
		}
		set_realm_capital = title:e_blue_horde.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_blue_horde_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_blue_horde_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_blue_horde_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

grant_omnod_dalai_khanate_effect = {

	# If the character doesn't hold any titles in the relevant
	if = {
		limit = {
			NOT = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_omnod_dalai_khanate_region
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			random_sub_realm_county = {
				limit = {
					is_landless_type_title = no
					title_province = {
						geographical_region = special_mongol_empire_omnod_dalai_khanate_region
					}
				}
				save_scope_as = county_to_transfer
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		scope:county_to_transfer = {
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_omnod_dalai_khanate = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	scope:candidate = {
		save_scope_as = omnod_dalai_khanate_ruler
	}

	set_global_variable = {
		name = omnod_dalai_khanate_handed_out
		value = yes
	}
	
	# Give the character the appropriate capital area, if possible
	if = {
		limit = {
			scope:old_mongol_emperor = {
				any_sub_realm_county = {
					duchy = title:e_omnod_dalai_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		scope:old_mongol_emperor = {
			every_sub_realm_county = {
				limit = {
					duchy = title:e_omnod_dalai_khanate.title_capital_county.duchy
					NOR = {
						holder = scope:candidate
						holder = { # Don't steal the player's lands
							is_ai = no
						}
						holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
				add_to_list = titles_taken
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:candidate
				change = scope:title_change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
	every_character_war = {
		end_war = white_peace
	}
	if = {
		limit = {
			has_title = title:e_omnod_dalai_khanate.title_capital_county
		}
		set_realm_capital = title:e_omnod_dalai_khanate.title_capital_county
	}
	else_if = {
		limit = {
			NOT = {
				capital_county.title_province = {
					geographical_region = special_mongol_empire_omnod_dalai_khanate_region
				}
			}
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_omnod_dalai_khanate_region
				}
			}
		}
		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				title_province = {
					geographical_region = special_mongol_empire_omnod_dalai_khanate_region
				}
			}
			scope:candidate = {
				set_realm_capital = prev
			}
		}
	}
	spawn_mongol_successor_state_troops_effect = yes
	add_gold = 1000
	add_dread = 100
	create_story = story_conqueror
	grant_mongol_successor_nomadic_bonuses_effect = yes
}

# Effect to clean up borders a little
pick_up_remaining_counties_effect = {
	### Ilkhanate
	if = {
		limit = {
			NOT = { exists = global_var:ilkhanate_handed_out }
			any_in_list = {
				list = ilkhanate_counties
				count > 0
			}
		}
		# Try giving them to Chagatai
		if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = ilkhanate_counties
				add_to_list = chagatai_counties
			}
		}
		# Try Red Horde
		else_if = {
			limit = {
				exists = global_var:red_horde_handed_out
			}
			every_in_list = {
				list = ilkhanate_counties
				add_to_list = red_horde_counties
			}
		}
		# Try Golden Horde
		else_if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = ilkhanate_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try Baruun
		else_if = {
			limit = {
				exists = global_var:baruun_khanate_handed_out
			}
			every_in_list = {
				list = ilkhanate_counties
				add_to_list = baruun_khanate_counties
			}
		}
	}
	### End Ilkhanate

	### Golden Horde
	if = {
		limit = {
			NOT = { exists = global_var:golden_horde_handed_out }
			any_in_list = {
				list = golden_horde_counties
				count > 0
			}
		}
		# Try giving them to White Horde
		if = {
			limit = {
				exists = global_var:white_horde_handed_out
			}
			every_in_list = {
				list = golden_horde_counties
				add_to_list = white_horde_counties
			}
		}
		# Try Aarlud Khanate
		else_if = {
			limit = {
				exists = global_var:aarlud_khanate_handed_out
			}
			every_in_list = {
				list = golden_horde_counties
				add_to_list = aarlud_khanate_counties
			}
		}
		# Try Chagatai
		else_if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = golden_horde_counties
				add_to_list = chagatai_counties
			}
		}
		# Try Ilkhanate
		else_if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = golden_horde_counties
				add_to_list = ilkhanate_counties
			}
		}
	}
	### End Golden Horde

	### Chagatai
	if = {
		limit = {
			NOT = { exists = global_var:chagatai_handed_out }
			any_in_list = {
				list = chagatai_counties
				count > 0
			}
		}
		# Try giving them to Golden Horde
		if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = chagatai_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try Ilkhanate
		else_if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = chagatai_counties
				add_to_list = ilkhanate_counties
			}
		}
		#Try Great Yuan
		if = {
			limit = {
				exists = global_var:great_yuan_handed_out
			}
			every_in_list = {
				list = chagatai_counties
				add_to_list = great_yuan_counties
			}
		}
	}
	### End Chagatai

	### Great Yuan
	if = {
		limit = {
			NOT = { exists = global_var:great_yuan_handed_out }
			any_in_list = {
				list = great_yuan_counties
				count > 0
			}
		}
		# Try giving them to Chagatai
		if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = chagatai_counties
			}
		}
		# Try Red Horde
		else_if = {
			limit = {
				exists = global_var:red_horde_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = red_horde_counties
			}
		}
		# Try Blue Horde
		else_if = {
			limit = {
				exists = global_var:blue_horde_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = blue_horde_counties
			}
		}
		#Try Omnod Dalai Khanate
		if = {
			limit = {
				exists = global_var:omnod_dalai_khanate_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = omnod_dalai_khanate_counties
			}
		}
		# Try giving them to Golden Horde
		if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try giving them to Ilkhanate
		if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = great_yuan_counties
				add_to_list = ilkhanate_counties
			}
		}
	}
	### End Great Yuan

	### Red Horde
	if = {
		limit = {
			NOT = { exists = global_var:red_horde_handed_out }
			any_in_list = {
				list = red_horde_counties
				count > 0
			}
		}
		# Try giving them to Ilkhanate
		if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = ilkhanate_counties
			}
		}
		# Try Chagatai
		else_if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = chagatai_counties
			}
		}
		#Try Great Yuan
		if = {
			limit = {
				exists = global_var:great_yuan_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = great_yuan_counties
			}
		}
		#Try Omnod Dalai Khanate
		if = {
			limit = {
				exists = global_var:omnod_dalai_khanate_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = omnod_dalai_khanate_counties
			}
		}
		# Try Baruun
		else_if = {
			limit = {
				exists = global_var:baruun_khanate_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = baruun_khanate_counties
			}
		}
	}
	### End Red Horde

	### White Horde
	if = {
		limit = {
			NOT = { exists = global_var:white_horde_handed_out }
			any_in_list = {
				list = white_horde_counties
				count > 0
			}
		}
		# Try giving them to Golden Horde
		if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = white_horde_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try Ilkhanate
		else_if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = white_horde_counties
				add_to_list = ilkhanate_counties
			}
		}
		# Try Aarlud Khanate
		else_if = {
			limit = {
				exists = global_var:aarlud_khanate_handed_out
			}
			every_in_list = {
				list = white_horde_counties
				add_to_list = aarlud_khanate_counties
			}
		}
		# Try Togskol
		else_if = {
			limit = {
				exists = global_var:togskol_khanate_handed_out
			}
			every_in_list = {
				list = white_horde_counties
				add_to_list = togskol_khanate_counties
			}
		}
		# Try Chagatai
		else_if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = white_horde_counties
				add_to_list = chagatai_counties
			}
		}
	}
	### End White Horde

	### Blue Horde
	if = {
		limit = {
			NOT = { exists = global_var:blue_horde_handed_out }
			any_in_list = {
				list = blue_horde_counties
				count > 0
			}
		}
		#Try Great Yuan
		if = {
			limit = {
				exists = global_var:great_yuan_handed_out
			}
			every_in_list = {
				list = blue_horde_counties
				add_to_list = great_yuan_counties
			}
		}
		#Try Omnod Dalai Khanate
		if = {
			limit = {
				exists = global_var:omnod_dalai_khanate_handed_out
			}
			every_in_list = {
				list = blue_horde_counties
				add_to_list = omnod_dalai_khanate_counties
			}
		}
		# Try Chagatai
		else_if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = blue_horde_counties
				add_to_list = chagatai_counties
			}
		}
		# Try giving them to Golden Horde
		if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = red_horde_counties
				add_to_list = golden_horde_counties
			}
		}
	}
	### End Blue Horde

	### Omnod Dalai Khanate
	if = {
		limit = {
			NOT = { exists = global_var:omnod_dalai_khanate_handed_out }
			any_in_list = {
				list = omnod_dalai_khanate_counties
				count > 0
			}
		}
		#Try Great Yuan
		if = {
			limit = {
				exists = global_var:great_yuan_handed_out
			}
			every_in_list = {
				list = omnod_dalai_khanate_counties
				add_to_list = great_yuan_counties
			}
		}
		#Try Blue Horde
		if = {
			limit = {
				exists = global_var:blue_horde_handed_out
			}
			every_in_list = {
				list = omnod_dalai_khanate_counties
				add_to_list = blue_horde_counties
			}
		}
		#Try Red Horde
		if = {
			limit = {
				exists = global_var:red_horde_handed_out
			}
			every_in_list = {
				list = omnod_dalai_khanate_counties
				add_to_list = red_horde_counties
			}
		}
		# Try Ilkhanate
		else_if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = omnod_dalai_khanate_counties
				add_to_list = ilkhanate_counties
			}
		}
		# Try Chagatai
		else_if = {
			limit = {
				exists = global_var:chagatai_handed_out
			}
			every_in_list = {
				list = omnod_dalai_khanate_counties
				add_to_list = chagatai_counties
			}
		}
	}
	### End Omnod Dalai Khanate

	### Aarlud Khanate
	if = {
		limit = {
			NOT = { exists = global_var:aarlud_khanate_handed_out }
			any_in_list = {
				list = aarlud_khanate_counties
				count > 0
			}
		}
		# Try giving them to White Horde
		if = {
			limit = {
				exists = global_var:white_horde_handed_out
			}
			every_in_list = {
				list = aarlud_khanate_counties
				add_to_list = white_horde_counties
			}
		}
		# Try Golden Horde
		else_if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = aarlud_khanate_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try Togskol
		else_if = {
			limit = {
				exists = global_var:togskol_khanate_handed_out
			}
			every_in_list = {
				list = aarlud_khanate_counties
				add_to_list = togskol_khanate_counties
			}
		}
	}
	### End Aarlud Khanate

	### Togskol Khanate
	if = {
		limit = {
			NOT = { exists = global_var:togskol_khanate_handed_out }
			any_in_list = {
				list = togskol_khanate_counties
				count > 0
			}
		}
		# Try giving them to White Horde
		if = {
			limit = {
				exists = global_var:white_horde_handed_out
			}
			every_in_list = {
				list = togskol_khanate_counties
				add_to_list = white_horde_counties
			}
		}
		# Try Aarlud
		else_if = {
			limit = {
				exists = global_var:aarlud_khanate_handed_out
			}
			every_in_list = {
				list = togskol_khanate_counties
				add_to_list = aarlud_khanate_counties
			}
		}
		# Try Golden Horde
		else_if = {
			limit = {
				exists = global_var:golden_horde_handed_out
			}
			every_in_list = {
				list = togskol_khanate_counties
				add_to_list = golden_horde_counties
			}
		}
		# Try Baruun
		else_if = {
			limit = {
				exists = global_var:baruun_khanate_handed_out
			}
			every_in_list = {
				list = togskol_khanate_counties
				add_to_list = baruun_khanate_counties
			}
		}
	}
	### End Togskol Khanate

	### Baruun Khanate
	if = {
		limit = {
			NOT = { exists = global_var:baruun_khanate_handed_out }
			any_in_list = {
				list = baruun_khanate_counties
				count > 0
			}
		}
		# Try giving them to Ilkhanate
		if = {
			limit = {
				exists = global_var:ilkhanate_handed_out
			}
			every_in_list = {
				list = baruun_khanate_counties
				add_to_list = ilkhanate_counties
			}
		}
		# Try Togskol
		else_if = {
			limit = {
				exists = global_var:togskol_khanate_handed_out
			}
			every_in_list = {
				list = baruun_khanate_counties
				add_to_list = togskol_khanate_counties
			}
		}
		# Try Red Horde
		else_if = {
			limit = {
				exists = global_var:red_horde_handed_out
			}
			every_in_list = {
				list = baruun_khanate_counties
				add_to_list = red_horde_counties
			}
		}
		#Try Omnod Dalai Khanate
		if = {
			limit = {
				exists = global_var:omnod_dalai_khanate_handed_out
			}
			every_in_list = {
				list = baruun_khanate_counties
				add_to_list = omnod_dalai_khanate_counties
			}
		}
	}
	### End Baruun Khanate
}

# Set up all vassals and assign them flags for the "correct" Khanate
set_correct_mongol_breakup_vassalage_effect = {
	scope:old_mongol_emperor = {
		every_vassal = {
			limit = {
				NOT = { is_in_list = selected_mongol_heirs }
				is_playable_character = yes
				highest_held_title_tier >= tier_county
			}
			debug_log = "Trying to assign correct vassalage placement for:"
			debug_log_scopes = no

			save_scope_as = vassal
			
			# Note: the variables for counting counties is set before checking whether the relevant title will be created, to prevent null-reference errors later
			set_global_variable = {
				name = ilkhanate_county_count
				value = 0
			}
			if = { # Count Ilkhanate Counties
				limit = {
					exists = global_var:ilkhanate_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = ilkhanate_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = ilkhanate_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = golden_horde_county_count
				value = 0
			}
			if = { # Count Golden Horde Counties
				limit = {
					exists = global_var:golden_horde_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = golden_horde_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = golden_horde_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = chagatai_county_count
				value = 0
			}
			if = { # Count Chagatai Counties
				limit = {
					exists = global_var:chagatai_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = chagatai_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = chagatai_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = great_yuan_county_count
				value = 0
			}
			if = { # Count Great Yuan Counties
				limit = {
					exists = global_var:great_yuan_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = great_yuan_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = great_yuan_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = red_horde_county_count
				value = 0
			}
			if = { # Count Red Horde counties
				limit = {
					exists = global_var:red_horde_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = red_horde_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = red_horde_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = white_horde_county_count
				value = 0
			}
			if = { # Count White Horde counties
				limit = {
					exists = global_var:white_horde_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = white_horde_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = white_horde_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = blue_horde_county_count
				value = 0
			}
			if = { # Count Blue Horde counties
				limit = {
					exists = global_var:blue_horde_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = blue_horde_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = blue_horde_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = omnod_dalai_khanate_county_count
				value = 0
			}
			if = { # Count Omnod Dalai Khanate counties
				limit = {
					exists = global_var:omnod_dalai_khanate_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = omnod_dalai_khanate_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = omnod_dalai_khanate_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = aarlud_khanate_county_count
				value = 0
			}
			if = { # Count Aarlud Khanate counties
				limit = {
					exists = global_var:aarlud_khanate_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = aarlud_khanate_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = aarlud_khanate_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = togskol_khanate_county_count
				value = 0
			}
			if = { # Count Tögsköl Khanate counties
				limit = {
					exists = global_var:togskol_khanate_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = togskol_khanate_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = togskol_khanate_county_count
							add = 1
						}
					}
				}
			}
			set_global_variable = {
				name = baruun_khanate_county_count
				value = 0
			}
			if = { # Count Baruun Khanate counties
				limit = {
					exists = global_var:baruun_khanate_handed_out
				}
				every_sub_realm_county = {
					limit = {
						is_in_list = baruun_khanate_counties
					}
					scope:vassal = {
						change_global_variable = {
							name = baruun_khanate_county_count
							add = 1
						}
					}
				}
			}
			# Find any counties not in any lists
			set_global_variable = {
				name = leftover_mongol_county_count
				value = 0
			}
			every_sub_realm_county = {
				limit = {
					trigger_if = {
						limit = { exists = global_var:ilkhanate_handed_out }
						NOT = { is_in_list = ilkhanate_counties }
					}
					trigger_if = {
						limit = { exists = global_var:golden_horde_handed_out }
						NOT = { is_in_list = golden_horde_counties }
					}
					trigger_if = {
						limit = { exists = global_var:chagatai_handed_out }
						NOT = { is_in_list = chagatai_counties }
					}
					trigger_if = {
						limit = { exists = global_var:great_yuan_handed_out }
						NOT = { is_in_list = great_yuan_counties }
					}
					trigger_if = {
						limit = { exists = global_var:red_horde_handed_out }
						NOT = { is_in_list = red_horde_counties }
					}
					trigger_if = {
						limit = { exists = global_var:white_horde_handed_out }
						NOT = { is_in_list = white_horde_counties }
					}
					trigger_if = {
						limit = { exists = global_var:aarlud_khanate_handed_out }
						NOT = { is_in_list = aarlud_khanate_counties }
					}
					trigger_if = {
						limit = { exists = global_var:togskol_khanate_handed_out }
						NOT = { is_in_list = togskol_khanate_counties }
					}
					trigger_if = {
						limit = { exists = global_var:baruun_khanate_handed_out }
						NOT = { is_in_list = baruun_khanate_counties }
					}
					trigger_if = {
						limit = { exists = global_var:blue_horde_handed_out }
						NOT = { is_in_list = blue_horde_counties }
					}
					trigger_if = {
						limit = { exists = global_var:omnod_dalai_khanate_handed_out }
						NOT = { is_in_list = omnod_dalai_khanate_counties }
					}
				}
				scope:vassal = {
					change_global_variable = {
						name = leftover_mongol_county_count
						add = 1
					}
				}
			}

			### Mark vassals for the correct liege empire
			if = {
				limit = {
					global_var:leftover_mongol_county_count >= global_var:ilkhanate_county_count
					global_var:leftover_mongol_county_count >= global_var:golden_horde_county_count
					global_var:leftover_mongol_county_count >= global_var:chagatai_county_count
					global_var:leftover_mongol_county_count >= global_var:red_horde_county_count
					global_var:leftover_mongol_county_count >= global_var:white_horde_county_count
					global_var:leftover_mongol_county_count >= global_var:aarlud_khanate_county_count
					global_var:leftover_mongol_county_count >= global_var:togskol_khanate_county_count
					global_var:leftover_mongol_county_count >= global_var:baruun_khanate_county_count
					global_var:leftover_mongol_county_count >= global_var:great_yuan_county_count
					global_var:leftover_mongol_county_count >= global_var:blue_horde_county_count
					global_var:leftover_mongol_county_count >= global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_mongolia
			}
			else_if = {
				limit = {
					global_var:ilkhanate_county_count > global_var:leftover_mongol_county_count
					global_var:ilkhanate_county_count > global_var:golden_horde_county_count
					global_var:ilkhanate_county_count > global_var:chagatai_county_count
					global_var:ilkhanate_county_count > global_var:red_horde_county_count
					global_var:ilkhanate_county_count > global_var:white_horde_county_count
					global_var:ilkhanate_county_count > global_var:aarlud_khanate_county_count
					global_var:ilkhanate_county_count > global_var:togskol_khanate_county_count
					global_var:ilkhanate_county_count > global_var:baruun_khanate_county_count
					global_var:ilkhanate_county_count > global_var:great_yuan_county_count
					global_var:ilkhanate_county_count > global_var:blue_horde_county_count
					global_var:ilkhanate_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_ilkhanate
			}
			else_if = {
				limit = {
					global_var:golden_horde_county_count > global_var:leftover_mongol_county_count
					global_var:golden_horde_county_count > global_var:ilkhanate_county_count
					global_var:golden_horde_county_count > global_var:chagatai_county_count
					global_var:golden_horde_county_count > global_var:red_horde_county_count
					global_var:golden_horde_county_count > global_var:white_horde_county_count
					global_var:golden_horde_county_count > global_var:aarlud_khanate_county_count
					global_var:golden_horde_county_count > global_var:togskol_khanate_county_count
					global_var:golden_horde_county_count > global_var:baruun_khanate_county_count
					global_var:golden_horde_county_count > global_var:great_yuan_county_count
					global_var:golden_horde_county_count > global_var:blue_horde_county_count
					global_var:golden_horde_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_golden_horde
			}
			else_if = {
				limit = {
					global_var:chagatai_county_count > global_var:leftover_mongol_county_count
					global_var:chagatai_county_count > global_var:ilkhanate_county_count
					global_var:chagatai_county_count > global_var:golden_horde_county_count
					global_var:chagatai_county_count > global_var:red_horde_county_count
					global_var:chagatai_county_count > global_var:white_horde_county_count
					global_var:chagatai_county_count > global_var:aarlud_khanate_county_count
					global_var:chagatai_county_count > global_var:togskol_khanate_county_count
					global_var:chagatai_county_count > global_var:baruun_khanate_county_count
					global_var:chagatai_county_count > global_var:great_yuan_county_count
					global_var:chagatai_county_count > global_var:blue_horde_county_count
					global_var:chagatai_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_chagatai
			}
			else_if = {
				limit = {
					global_var:great_yuan_county_count > global_var:leftover_mongol_county_count
					global_var:great_yuan_county_count > global_var:ilkhanate_county_count
					global_var:great_yuan_county_count > global_var:chagatai_county_count
					global_var:great_yuan_county_count > global_var:golden_horde_county_count
					global_var:great_yuan_county_count > global_var:red_horde_county_count
					global_var:great_yuan_county_count > global_var:white_horde_county_count
					global_var:great_yuan_county_count > global_var:aarlud_khanate_county_count
					global_var:great_yuan_county_count > global_var:togskol_khanate_county_count
					global_var:great_yuan_county_count > global_var:baruun_khanate_county_count
					global_var:great_yuan_county_count > global_var:blue_horde_county_count
					global_var:great_yuan_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_great_yuan
			}
			else_if = {
				limit = {
					global_var:red_horde_county_count > global_var:leftover_mongol_county_count
					global_var:red_horde_county_count > global_var:ilkhanate_county_count
					global_var:red_horde_county_count > global_var:golden_horde_county_count
					global_var:red_horde_county_count > global_var:chagatai_county_count
					global_var:red_horde_county_count > global_var:white_horde_county_count
					global_var:red_horde_county_count > global_var:aarlud_khanate_county_count
					global_var:red_horde_county_count > global_var:togskol_khanate_county_count
					global_var:red_horde_county_count > global_var:baruun_khanate_county_count
					global_var:red_horde_county_count > global_var:great_yuan_county_count
					global_var:red_horde_county_count > global_var:blue_horde_county_count
					global_var:red_horde_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_red_horde
			}
			else_if = {
				limit = {
					global_var:white_horde_county_count > global_var:leftover_mongol_county_count
					global_var:white_horde_county_count > global_var:ilkhanate_county_count
					global_var:white_horde_county_count > global_var:golden_horde_county_count
					global_var:white_horde_county_count > global_var:chagatai_county_count
					global_var:white_horde_county_count > global_var:red_horde_county_count
					global_var:white_horde_county_count > global_var:aarlud_khanate_county_count
					global_var:white_horde_county_count > global_var:togskol_khanate_county_count
					global_var:white_horde_county_count > global_var:baruun_khanate_county_count
					global_var:white_horde_county_count > global_var:great_yuan_county_count
					global_var:white_horde_county_count > global_var:blue_horde_county_count
					global_var:white_horde_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_white_horde
			}
			else_if = {
				limit = {
					global_var:blue_horde_county_count > global_var:leftover_mongol_county_count
					global_var:blue_horde_county_count > global_var:ilkhanate_county_count
					global_var:blue_horde_county_count > global_var:golden_horde_county_count
					global_var:blue_horde_county_count > global_var:chagatai_county_count
					global_var:blue_horde_county_count > global_var:red_horde_county_count
					global_var:blue_horde_county_count > global_var:white_horde_county_count
					global_var:blue_horde_county_count > global_var:white_horde_county_count
					global_var:blue_horde_county_count > global_var:togskol_khanate_county_count
					global_var:blue_horde_county_count > global_var:baruun_khanate_county_count
					global_var:blue_horde_county_count > global_var:great_yuan_county_count
					global_var:blue_horde_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_blue_horde
			}
			else_if = {
				limit = {
					global_var:omnod_dalai_khanate_county_count > global_var:leftover_mongol_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:ilkhanate_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:golden_horde_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:chagatai_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:red_horde_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:white_horde_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:white_horde_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:togskol_khanate_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:baruun_khanate_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:great_yuan_county_count
					global_var:omnod_dalai_khanate_county_count > global_var:blue_horde_county_count
				}
				add_character_flag = should_be_vassalized_by_omnod_dalai_khanate
			}
			else_if = {
				limit = {
					global_var:aarlud_khanate_county_count > global_var:leftover_mongol_county_count
					global_var:aarlud_khanate_county_count > global_var:ilkhanate_county_count
					global_var:aarlud_khanate_county_count > global_var:golden_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:chagatai_county_count
					global_var:aarlud_khanate_county_count > global_var:red_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:white_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:togskol_khanate_county_count
					global_var:aarlud_khanate_county_count > global_var:baruun_khanate_county_count
					global_var:aarlud_khanate_county_count > global_var:great_yuan_county_count
					global_var:aarlud_khanate_county_count > global_var:blue_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_aarlud_khanate
			}
			else_if = {
				limit = {
					global_var:aarlud_khanate_county_count > global_var:leftover_mongol_county_count
					global_var:aarlud_khanate_county_count > global_var:ilkhanate_county_count
					global_var:aarlud_khanate_county_count > global_var:golden_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:chagatai_county_count
					global_var:aarlud_khanate_county_count > global_var:red_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:white_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:togskol_khanate_county_count
					global_var:aarlud_khanate_county_count > global_var:baruun_khanate_county_count
					global_var:aarlud_khanate_county_count > global_var:great_yuan_county_count
					global_var:aarlud_khanate_county_count > global_var:blue_horde_county_count
					global_var:aarlud_khanate_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_aarlud_khanate
			}
			else_if = {
				limit = {
					global_var:togskol_khanate_county_count > global_var:leftover_mongol_county_count
					global_var:togskol_khanate_county_count > global_var:ilkhanate_county_count
					global_var:togskol_khanate_county_count > global_var:golden_horde_county_count
					global_var:togskol_khanate_county_count > global_var:chagatai_county_count
					global_var:togskol_khanate_county_count > global_var:red_horde_county_count
					global_var:togskol_khanate_county_count > global_var:white_horde_county_count
					global_var:togskol_khanate_county_count > global_var:aarlud_khanate_county_count
					global_var:togskol_khanate_county_count > global_var:baruun_khanate_county_count
					global_var:togskol_khanate_county_count > global_var:great_yuan_county_count
					global_var:togskol_khanate_county_count > global_var:blue_horde_county_count
					global_var:togskol_khanate_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_togskol_khanate
			}
			else_if = {
				limit = {
					global_var:baruun_khanate_county_count > global_var:leftover_mongol_county_count
					global_var:baruun_khanate_county_count > global_var:ilkhanate_county_count
					global_var:baruun_khanate_county_count > global_var:golden_horde_county_count
					global_var:baruun_khanate_county_count > global_var:chagatai_county_count
					global_var:baruun_khanate_county_count > global_var:red_horde_county_count
					global_var:baruun_khanate_county_count > global_var:white_horde_county_count
					global_var:baruun_khanate_county_count > global_var:aarlud_khanate_county_count
					global_var:baruun_khanate_county_count > global_var:togskol_khanate_county_count
					global_var:baruun_khanate_county_count > global_var:great_yuan_county_count
					global_var:baruun_khanate_county_count > global_var:blue_horde_county_count
					global_var:baruun_khanate_county_count > global_var:omnod_dalai_khanate_county_count
				}
				add_character_flag = should_be_vassalized_by_baruun_khanate
			}
			else = {
				add_character_flag = should_be_vassalized_by_mongolia
			}
		}
	}
}

# Forcibly shift counties around as appropriate
shift_counties_on_mongol_succession_effect = {
	every_in_list = {
		list = selected_mongol_heirs
		every_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
			}
			if = {
				limit = {
					exists = global_var:ilkhanate_handed_out
					is_in_list = ilkhanate_counties
					NOT = { holder = { has_title = title:e_ilkhanate } }
				}
				add_to_list = ilkhanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = ilkhanate_titles_for_transfer
					}
				}
			}
			if = {
				limit = {
					exists = global_var:golden_horde_handed_out
					is_in_list = golden_horde_counties
					NOT = { holder = { has_title = title:e_golden_horde } }
				}
				add_to_list = golden_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = golden_horde_titles_for_transfer
					}
				}
			}
			if = {
				limit = {
					exists = global_var:chagatai_handed_out
					is_in_list = chagatai_counties
					NOT = { holder = { has_title = title:e_chagatai } }
				}
				add_to_list = chagatai_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = chagatai_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:great_yuan_handed_out
					is_in_list = great_yuan_counties
					NOT = { holder = { has_title = scope:great_yuan_title } }
				}
				add_to_list = great_yuan_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = great_yuan_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:red_horde_handed_out
					is_in_list = red_horde_counties
					NOT = { holder = { has_title = title:e_red_horde } }
				}
				add_to_list = red_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = red_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:white_horde_handed_out
					is_in_list = white_horde_counties
					NOT = { holder = { has_title = title:e_white_horde } }
				}
				add_to_list = white_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = white_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:blue_horde_handed_out
					is_in_list = blue_horde_counties
					NOT = { holder = { has_title = title:e_blue_horde } }
				}
				add_to_list = blue_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = blue_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:omnod_dalai_khanate_handed_out
					is_in_list = omnod_dalai_khanate_counties
					NOT = { holder = { has_title = title:e_omnod_dalai_khanate } }
				}
				add_to_list = omnod_dalai_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = omnod_dalai_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:aarlud_khanate_handed_out
					is_in_list = aarlud_khanate_counties
					NOT = { holder = { has_title = title:e_aarlud_khanate } }
				}
				add_to_list = aarlud_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = aarlud_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:togskol_khanate_handed_out
					is_in_list = togskol_khanate_counties
					NOT = { holder = { has_title = title:e_togskol_khanate } }
				}
				add_to_list = togskol_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = togskol_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:baruun_khanate_handed_out
					is_in_list = baruun_khanate_counties
					NOT = { holder = { has_title = title:e_baruun_khanate } }
				}
				add_to_list = baruun_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = baruun_khanate_titles_for_transfer
					}
				}
				
			}
		}
	}
	scope:old_mongol_emperor = {
		every_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
			}
			if = {
				limit = {
					exists = global_var:ilkhanate_handed_out
					is_in_list = ilkhanate_counties
					NOT = { holder = { has_title = title:e_ilkhanate } }
				}
				add_to_list = ilkhanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = ilkhanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:golden_horde_handed_out
					is_in_list = golden_horde_counties
					NOT = { holder = { has_title = title:e_golden_horde } }
				}
				add_to_list = golden_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = golden_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:chagatai_handed_out
					is_in_list = chagatai_counties
					NOT = { holder = { has_title = title:e_chagatai } }
				}
				add_to_list = chagatai_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = chagatai_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:great_yuan_handed_out
					is_in_list = great_yuan_counties
					NOT = { holder = { has_title = scope:great_yuan_title } }
				}
				add_to_list = great_yuan_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = great_yuan_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:red_horde_handed_out
					is_in_list = red_horde_counties
					NOT = { holder = { has_title = title:e_red_horde } }
				}
				add_to_list = red_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = red_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:white_horde_handed_out
					is_in_list = white_horde_counties
					NOT = { holder = { has_title = title:e_white_horde } }
				}
				add_to_list = white_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = white_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:blue_horde_handed_out
					is_in_list = blue_horde_counties
					NOT = { holder = { has_title = title:e_blue_horde } }
				}
				add_to_list = blue_horde_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = blue_horde_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:omnod_dalai_khanate_handed_out
					is_in_list = omnod_dalai_khanate_counties
					NOT = { holder = { has_title = title:e_omnod_dalai_khanate } }
				}
				add_to_list = omnod_dalai_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = omnod_dalai_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:aarlud_khanate_handed_out
					is_in_list = aarlud_khanate_counties
					NOT = { holder = { has_title = title:e_aarlud_khanate } }
				}
				add_to_list = aarlud_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = aarlud_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:togskol_khanate_handed_out
					is_in_list = togskol_khanate_counties
					NOT = { holder = { has_title = title:e_togskol_khanate } }
				}
				add_to_list = togskol_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = togskol_khanate_titles_for_transfer
					}
				}
				
			}
			if = {
				limit = {
					exists = global_var:baruun_khanate_handed_out
					is_in_list = baruun_khanate_counties
					NOT = { holder = { has_title = title:e_baruun_khanate } }
				}
				add_to_list = baruun_khanate_titles_for_transfer
				# Also mark duchies for transfer if relevant
				if = {
					limit = {
						exists = duchy.holder
						holder = duchy.holder
					}
					duchy = {
						add_to_list = baruun_khanate_titles_for_transfer
					}
				}
				
			}
		}
	}
	create_title_and_vassal_change = {
		type = granted
		save_scope_as = mongol_succession
		add_claim_on_loss = no
	}
	
	# Ilkhanate
	if = {
		limit = {
			exists = scope:ilkhanate_ruler
		}
		every_in_list = {
			list = ilkhanate_titles_for_transfer
			change_title_holder = {
				holder = scope:ilkhanate_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_ilkhanate
				}
				change_liege = {
					liege = scope:ilkhanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Golden Horde
	if = {
		limit = {
			exists = scope:golden_horde_ruler
		}
		every_in_list = {
			list = golden_horde_titles_for_transfer
			change_title_holder = {
				holder = scope:golden_horde_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_golden_horde
				}
				change_liege = {
					liege = scope:golden_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Chagatai
	if = {
		limit = {
			exists = scope:chagatai_ruler
		}
		every_in_list = {
			list = chagatai_titles_for_transfer
			change_title_holder = {
				holder = scope:chagatai_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_chagatai
				}
				change_liege = {
					liege = scope:chagatai_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Great Yuan
	if = {
		limit = {
			exists = scope:great_yuan_ruler
		}
		every_in_list = {
			list = great_yuan_titles_for_transfer
			change_title_holder = {
				holder = scope:great_yuan_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_great_yuan
				}
				change_liege = {
					liege = scope:great_yuan_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Red Horde
	if = {
		limit = {
			exists = scope:red_horde_ruler
		}
		every_in_list = {
			list = red_horde_titles_for_transfer
			change_title_holder = {
				holder = scope:red_horde_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_red_horde
				}
				change_liege = {
					liege = scope:red_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# White Horde
	if = {
		limit = {
			exists = scope:white_horde_ruler
		}
		every_in_list = {
			list = white_horde_titles_for_transfer
			change_title_holder = {
				holder = scope:white_horde_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_white_horde
				}
				change_liege = {
					liege = scope:white_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Blue Horde
	if = {
		limit = {
			exists = scope:blue_horde_ruler
		}
		every_in_list = {
			list = blue_horde_titles_for_transfer
			change_title_holder = {
				holder = scope:blue_horde_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_blue_horde
				}
				change_liege = {
					liege = scope:blue_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Omnod Dalai Khanate
	if = {
		limit = {
			exists = scope:omnod_dalai_khanate_ruler
		}
		every_in_list = {
			list = omnod_dalai_khanate_titles_for_transfer
			change_title_holder = {
				holder = scope:omnod_dalai_khanate_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
				}
				change_liege = {
					liege = scope:omnod_dalai_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Aarlud Khanate
	if = {
		limit = {
			exists = scope:aarlud_khanate_ruler
		}
		every_in_list = {
			list = aarlud_khanate_titles_for_transfer
			change_title_holder = {
				holder = scope:aarlud_khanate_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_aarlud_khanate
				}
				change_liege = {
					liege = scope:aarlud_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Togskol Khanate
	if = {
		limit = {
			exists = scope:togskol_khanate_ruler
		}
		every_in_list = {
			list = togskol_khanate_titles_for_transfer
			change_title_holder = {
				holder = scope:togskol_khanate_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_togskol_khanate
				}
				change_liege = {
					liege = scope:togskol_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Baruun Khanate
	if = {
		limit = {
			exists = scope:baruun_khanate_ruler
		}
		every_in_list = {
			list = baruun_khanate_titles_for_transfer
			change_title_holder = {
				holder = scope:baruun_khanate_ruler
				change = scope:mongol_succession
			}
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_baruun_khanate
				}
				change_liege = {
					liege = scope:baruun_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Mongolia
	if = {
		limit = {
			exists = scope:mongolia_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal_or_below = {
				limit = {
					has_character_flag = should_be_vassalized_by_mongolia
				}
				change_liege = {
					liege = scope:mongolia_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	
	# Extra backup safety
	# Ilkhanate
	if = {
		limit = {
			exists = scope:ilkhanate_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_ilkhanate_region
					}
				}
				change_liege = {
					liege = scope:ilkhanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Golden Horde
	if = {
		limit = {
			exists = scope:golden_horde_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_golden_horde_region
					}
				}
				change_liege = {
					liege = scope:golden_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Chagatai
	if = {
		limit = {
			exists = scope:chagatai_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_chagatai_region
					}
				}
				change_liege = {
					liege = scope:chagatai_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Great Yuan
	if = {
		limit = {
			exists = scope:great_yuan_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_great_yuan_region
					}
				}
				change_liege = {
					liege = scope:great_yuan_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Red Horde
	if = {
		limit = {
			exists = scope:red_horde_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_red_horde_region
					}
				}
				change_liege = {
					liege = scope:red_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# White Horde
	if = {
		limit = {
			exists = scope:white_horde_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_white_horde_region
					}
				}
				change_liege = {
					liege = scope:white_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Blue Horde
	if = {
		limit = {
			exists = scope:blue_horde_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_blue_horde_region
					}
				}
				change_liege = {
					liege = scope:blue_horde_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Omnod Dalai Khanate
	if = {
		limit = {
			exists = scope:omnod_dalai_khanate_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_omnod_dalai_khanate_region
					}
				}
				change_liege = {
					liege = scope:omnod_dalai_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Aarlud Khanate
	if = {
		limit = {
			exists = scope:aarlud_khanate_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_aarlud_khanate_region
					}
				}
				change_liege = {
					liege = scope:aarlud_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Togskol Khanate
	if = {
		limit = {
			exists = scope:togskol_khanate_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_togskol_khanate_region
					}
				}
				change_liege = {
					liege = scope:togskol_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Baruun Khanate
	if = {
		limit = {
			exists = scope:baruun_khanate_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						geographical_region = special_mongol_empire_baruun_khanate_region
					}
				}
				change_liege = {
					liege = scope:baruun_khanate_ruler
					change = scope:mongol_succession
				}
			}
		}
	}
	# Mongolia
	if = {
		limit = {
			exists = scope:mongolia_ruler
		}
		scope:old_mongol_emperor = {
			every_vassal = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
					capital_province = {
						NOR = {
							geographical_region = special_mongol_empire_ilkhanate_region
							geographical_region = special_mongol_empire_golden_horde_region
							geographical_region = special_mongol_empire_chagatai_region
							geographical_region = special_mongol_empire_red_horde_region
							geographical_region = special_mongol_empire_white_horde_region
							geographical_region = special_mongol_empire_aarlud_khanate_region
							geographical_region = special_mongol_empire_togskol_khanate_region
							geographical_region = special_mongol_empire_baruun_khanate_region
							geographical_region = special_mongol_empire_great_yuan_region
							geographical_region = special_mongol_empire_blue_horde_region
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						} 
					}
				}
				change_liege = {
					liege = scope:mongolia_ruler
					change = scope:mongol_succession
				}
			}
		}
	}

	resolve_title_and_vassal_change = scope:mongol_succession
	
	# Extra-extra cleanup
	create_title_and_vassal_change = {
		type = granted
		save_scope_as = mongol_cleanup_succession
		add_claim_on_loss = no
	}
	# Mongolia
	if = {
		limit = {
			exists = scope:mongolia_ruler
		}
		scope:mongolia_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Ilkhanate
	if = {
		limit = {
			exists = scope:ilkhanate_ruler
		}
		scope:ilkhanate_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Golden Horde
	if = {
		limit = {
			exists = scope:golden_horde_ruler
		}
		scope:golden_horde_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Chagatai
	if = {
		limit = {
			exists = scope:chagatai_ruler
		}
		scope:chagatai_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}

	# Great Yuan
	if = {
		limit = {
			exists = scope:great_yuan_ruler
		}
		scope:great_yuan_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Red Horde
	if = {
		limit = {
			exists = scope:red_horde_ruler
		}
		scope:red_horde_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# White Horde
	if = {
		limit = {
			exists = scope:white_horde_ruler
		}
		scope:white_horde_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}

	# Blue Horde
	if = {
		limit = {
			exists = scope:blue_horde_ruler
		}
		scope:blue_horde_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Omnod Dalai Khanate
	if = {
		limit = {
			exists = scope:omnod_dalai_khanate_ruler
		}
		scope:omnod_dalai_khanate_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Aarlud Khanate
	if = {
		limit = {
			exists = scope:aarlud_khanate_ruler
		}
		scope:aarlud_khanate_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Togskol Khanate
	if = {
		limit = {
			exists = scope:togskol_khanate_ruler
		}
		scope:togskol_khanate_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_liege = {
						liege = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_baruun_khanate_region
						}
						exists = scope:baruun_khanate_ruler
					}
					change_title_holder = {
						holder = scope:baruun_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	# Baruun Khanate
	if = {
		limit = {
			exists = scope:baruun_khanate_ruler
		}
		scope:mongolia_ruler = {
			every_vassal_or_below = {
				limit = {
					NOR = {
						has_character_flag = should_be_vassalized_by_ilkhanate
						has_character_flag = should_be_vassalized_by_golden_horde
						has_character_flag = should_be_vassalized_by_chagatai
						has_character_flag = should_be_vassalized_by_red_horde
						has_character_flag = should_be_vassalized_by_white_horde
						has_character_flag = should_be_vassalized_by_aarlud_khanate
						has_character_flag = should_be_vassalized_by_togskol_khanate
						has_character_flag = should_be_vassalized_by_baruun_khanate
						has_character_flag = should_be_vassalized_by_mongolia
						has_character_flag = should_be_vassalized_by_great_yuan
						has_character_flag = should_be_vassalized_by_blue_horde
						has_character_flag = should_be_vassalized_by_omnod_dalai_khanate
					}
				}
				if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_liege = {
						liege = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_liege = {
						liege = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_liege = {
						liege = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_liege = {
						liege = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_liege = {
						liege = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_liege = {
						liege = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_liege = {
						liege = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_liege = {
						liege = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_liege = {
						liege = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_liege = {
						liege = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						capital_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_liege = {
						liege = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
			every_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_ilkhanate_region
						}
						exists = scope:ilkhanate_ruler
					}
					change_title_holder = {
						holder = scope:ilkhanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_golden_horde_region
						}
						exists = scope:golden_horde_ruler
					}
					change_title_holder = {
						holder = scope:golden_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_chagatai_region
						}
						exists = scope:chagatai_ruler
					}
					change_title_holder = {
						holder = scope:chagatai_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_great_yuan_region
						}
						exists = scope:great_yuan_ruler
					}
					change_title_holder = {
						holder = scope:great_yuan_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_red_horde_region
						}
						exists = scope:red_horde_ruler
					}
					change_title_holder = {
						holder = scope:red_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_white_horde_region
						}
						exists = scope:white_horde_ruler
					}
					change_title_holder = {
						holder = scope:white_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_blue_horde_region
						}
						exists = scope:blue_horde_ruler
					}
					change_title_holder = {
						holder = scope:blue_horde_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_omnod_dalai_khanate_region
						}
						exists = scope:omnod_dalai_khanate_ruler
					}
					change_title_holder = {
						holder = scope:omnod_dalai_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_aarlud_khanate_region
						}
						exists = scope:aarlud_khanate_ruler
					}
					change_title_holder = {
						holder = scope:aarlud_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				if = {
					limit = {
						title_province = {
							geographical_region = special_mongol_empire_togskol_khanate_region
						}
						exists = scope:togskol_khanate_ruler
					}
					change_title_holder = {
						holder = scope:togskol_khanate_ruler
						change = scope:mongol_cleanup_succession
					}
				}
				else_if = {
					limit = {
						title_province = {
							NOR = {
								geographical_region = special_mongol_empire_ilkhanate_region
								geographical_region = special_mongol_empire_golden_horde_region
								geographical_region = special_mongol_empire_chagatai_region
								geographical_region = special_mongol_empire_red_horde_region
								geographical_region = special_mongol_empire_white_horde_region
								geographical_region = special_mongol_empire_aarlud_khanate_region
								geographical_region = special_mongol_empire_togskol_khanate_region
								geographical_region = special_mongol_empire_baruun_khanate_region
								geographical_region = special_mongol_empire_great_yuan_region
								geographical_region = special_mongol_empire_blue_horde_region
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						exists = scope:mongolia_ruler
					}
					change_title_holder = {
						holder = scope:mongolia_ruler
						change = scope:mongol_cleanup_succession
					}
				}
			}
		}
	}
	resolve_title_and_vassal_change = scope:mongol_cleanup_succession
	
	every_in_list = { # If tengri, switch to an organized faith in your new realm
		list = selected_mongol_heirs
		limit = {
			primary_title.tier = tier_empire
			faith = { has_doctrine_parameter = unreformed }
			any_sub_realm_county = {
				faith = {
					NOT = { has_doctrine_parameter = unreformed }
				}
			}
		}
		save_scope_as = faith_changer
		random_sub_realm_county = {
			limit = {
				faith = {
					NOT = { has_doctrine_parameter = unreformed }
				}
			}
			weight = {
				base = 1
				modifier = {
					save_temporary_scope_as = county_faith_check
					add = mongol_successor_faith_chance
				}
			}
			scope:faith_changer = {
				set_character_faith = prev.faith
			}
		}
	}
}
	
	
### END Title creation effects
	
grant_suitable_title_to_candidate_effect = {
	save_temporary_scope_as = candidate
	
	# Runs through available titles and grants an available one
	random_list = {
		# Ilkhanate
		1 = {
			trigger = {
				exists = global_var:creatable_ilkhanate
				NOT = { exists = global_var:ilkhanate_handed_out }
				NOT = { exists = title:e_ilkhanate.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_ilkhanate_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_ilkhanate_effect = yes
		}
		# Golden Horde
		1 = {
			trigger = {
				exists = global_var:creatable_golden_horde
				NOT = { exists = global_var:golden_horde_handed_out }
				NOT = { exists = title:e_golden_horde.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_golden_horde_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_golden_horde_effect = yes
		}
		# Chagatai
		1 = {
			trigger = {
				exists = global_var:creatable_chagatai
				NOT = { exists = global_var:chagatai_handed_out }
				NOT = { exists = title:e_chagatai.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_chagatai_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_chagatai_effect = yes
		}
		# Great Yuan
		1 = {
			trigger = {
				exists = global_var:creatable_great_yuan
				NOT = { exists = global_var:great_yuan_handed_out }
				NOT = { exists = scope:great_yuan_title.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_great_yuan_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_great_yuan_effect = yes
		}
		# Red Horde
		1 = {
			trigger = {
				exists = global_var:creatable_red_horde
				NOT = { exists = global_var:red_horde_handed_out }
				NOT = { exists = title:e_red_horde.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_red_horde_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_red_horde_effect = yes
		}
		# White Horde
		1 = {
			trigger = {
				exists = global_var:creatable_white_horde
				NOT = { exists = global_var:white_horde_handed_out }
				NOT = { exists = title:e_white_horde.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_white_horde_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_white_horde_effect = yes
		}
		# Blue Horde
		1 = {
			trigger = {
				exists = global_var:creatable_blue_horde
				NOT = { exists = global_var:blue_horde_handed_out }
				NOT = { exists = title:e_blue_horde.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_blue_horde_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_blue_horde_effect = yes
		}
		# Omnod Dalai Khanate
		1 = {
			trigger = {
				exists = global_var:creatable_omnod_dalai_khanate
				NOT = { exists = global_var:omnod_dalai_khanate_handed_out }
				NOT = { exists = title:e_omnod_dalai_khanate.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_omnod_dalai_khanate_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_omnod_dalai_khanate_effect = yes
		}
		# Aarlud Khanate
		1 = {
			trigger = {
				exists = global_var:creatable_aarlud_khanate
				NOT = { exists = global_var:aarlud_khanate_handed_out }
				NOT = { exists = title:e_aarlud_khanate.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_aarlud_khanate_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_aarlud_khanate_effect = yes
		}
		# Tögsköl Khanate
		1 = {
			trigger = {
				exists = global_var:creatable_togskol_khanate
				NOT = { exists = global_var:togskol_khanate_handed_out }
				NOT = { exists = title:e_togskol_khanate.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_togskol_khanate_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_togskol_khanate_effect = yes
		}
		# Baruun Khanate
		1 = {
			trigger = {
				exists = global_var:creatable_baruun_khanate
				NOT = { exists = global_var:baruun_khanate_handed_out }
				NOT = { exists = title:e_baruun_khanate.holder }
			}
			# Weight the chance by how much territory you hold there
			modifier = {
				add = {
					every_sub_realm_county = {
						limit = {
							title_province = {
								geographical_region = special_mongol_empire_baruun_khanate_region
							}
						}
						add = 50
					}
				}
				always = yes
			}
			grant_baruun_khanate_effect = yes
		}
	}

	# Add to list so we can move related titles around later
	add_to_list = candidate_granted_title
}


break_up_mongol_empire_effect = { # Intended to run in the Mongol Emperor's scope
	save_scope_as = old_mongol_emperor

	every_tributary = {
		add_to_list = mongol_tributaries
	}
	
	every_held_title = { # Clean up excess kingdoms
		limit = {
			is_landless_type_title = no
			OR = {
				tier = tier_kingdom
				tier = tier_duchy
			}
		}
		scope:old_mongol_emperor = {
			destroy_title = prev
		}
	}

	every_character_war = {
		limit = {
			primary_attacker = scope:old_mongol_emperor
			is_white_peace_possible = yes
		}
		end_war = white_peace
	}

	set_global_variable = {
		name = number_of_mongol_heir_candidates
		value = 0
	}
	# Find suitable heir candidates
	dynasty = {
		every_dynasty_member = { # Every potential khandidate
			limit = {
				character_gender_can_inherit_from_trigger = {
					CHARACTER = scope:old_mongol_emperor
				}
				is_alive = yes
			}
			change_global_variable = {
				name = number_of_mongol_heir_candidates
				add = 1
			}
			add_to_list = mongol_heir_candidates
		}
	}

	# Gather Ilkhanate counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_ilkhanate_region
			}
		}
		add_to_temporary_list = ilkhanate_counties
	}
	# Gather Golden Horde counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_golden_horde_region
			}
		}
		add_to_temporary_list = golden_horde_counties
	}
	# Gather Chagatai counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_chagatai_region
			}
		}
		add_to_temporary_list = chagatai_counties
	}
	# Gather Great Yuan counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_great_yuan_region
			}
		}
		add_to_temporary_list = great_yuan_counties
	}
	# Gather Red Horde counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_red_horde_region
			}
		}
		add_to_temporary_list = red_horde_counties
	}
	# Gather White Horde counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_white_horde_region
			}
		}
		add_to_temporary_list = white_horde_counties
	}
	# Gather Blue Horde counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_blue_horde_region
			}
		}
		add_to_temporary_list = blue_horde_counties
	}
	# Gather Omnod Dalai Khanate counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_omnod_dalai_khanate_region
			}
		}
		add_to_temporary_list = omnod_dalai_khanate_counties
	}
	# Gather Aarlud Khanate counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_aarlud_khanate_region
			}
		}
		add_to_temporary_list = aarlud_khanate_counties
	}
	# Gather Tögsköl Khanate counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_togskol_khanate_region
			}
		}
		add_to_temporary_list = togskol_khanate_counties
	}
	# Gather Baruun Khanate counties
	every_sub_realm_county = {
		limit = {
			title_province = {
				geographical_region = special_mongol_empire_baruun_khanate_region
			}
		}
		add_to_temporary_list = baruun_khanate_counties
	}

	# Check which titles are creatable
	set_global_variable = {
		name = creatable_mongol_successor_states_number
		value = 0
	}
	# Ilkhanate
	if = {
		limit = {
			any_in_list = {
				list = ilkhanate_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Ilkhanate is creatable"
		set_global_variable = {
			name = creatable_ilkhanate
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Golden Horde
	if = {
		limit = {
			any_in_list = {
				list = golden_horde_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Golden Horde is creatable"
		set_global_variable = {
			name = creatable_golden_horde
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Chagatai
	if = {
		limit = {
			any_in_list = {
				list = chagatai_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Chagatai is creatable"
		set_global_variable = {
			name = creatable_chagatai
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Great Yuan
	if = {
		limit = {
			any_in_list = {
				list = great_yuan_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Great Yuan is creatable"
		set_global_variable = {
			name = creatable_great_yuan
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Red Horde
	if = {
		limit = {
			any_in_list = {
				list = red_horde_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Red Horde is creatable"
		set_global_variable = {
			name = creatable_red_horde
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# White Horde
	if = {
		limit = {
			any_in_list = {
				list = white_horde_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "White Horde is creatable"
		set_global_variable = {
			name = creatable_white_horde
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Blue Horde
	if = {
		limit = {
			any_in_list = {
				list = blue_horde_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Blue Horde is creatable"
		set_global_variable = {
			name = creatable_blue_horde
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Omnod Dalai Khanate
	if = {
		limit = {
			any_in_list = {
				list = omnod_dalai_khanate_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Omnod Dalai Khanate is creatable"
		set_global_variable = {
			name = creatable_omnod_dalai_khanate
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Aarlud Khanate
	if = {
		limit = {
			any_in_list = {
				list = aarlud_khanate_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Aarlud is creatable"
		set_global_variable = {
			name = creatable_aarlud_khanate
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Tögsköl Khanate
	if = {
		limit = {
			any_in_list = {
				list = togskol_khanate_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Tögsköl is creatable"
		set_global_variable = {
			name = creatable_togskol_khanate
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}
	# Baruun Khanate
	if = {
		limit = {
			any_in_list = {
				list = baruun_khanate_counties
				count >= @creatable_successor_empire_county_threshold
			}
		}
		debug_log = "Baruun is creatable"
		set_global_variable = {
			name = creatable_baruun_khanate
			value = yes
		}
		change_global_variable = {
			name = creatable_mongol_successor_states_number
			add = 1
		}
	}

	ordered_in_list = {
		list = mongol_heir_candidates
		order_by = mongol_breakup_succession_score
		max = 15

		debug_log = "Mongol succession list found:"
		debug_log_scopes = yes

		add_to_list = selected_mongol_heirs
		add_character_flag = {
			flag = mongol_successor_flag
			days = 10
		}
	}

	# Find the "main" heir
	
	if = {
		limit = {
			is_ai = no
			player_heir.dynasty ?= dynasty
		}
		player_heir = {
			debug_log = "Found Mongol main heir"
			debug_log_scopes = yes

			assign_core_mongol_titles_to_heir_effect = yes

			remove_from_list = selected_mongol_heirs
		}
	}
	else = {
		ordered_in_list = {
			list = selected_mongol_heirs
			order_by = mongol_breakup_succession_score
			max = 1

			debug_log = "Found Mongol main heir"
			debug_log_scopes = yes

			assign_core_mongol_titles_to_heir_effect = yes

			remove_from_list = selected_mongol_heirs
		}
	}
	
	if = {
		limit = {
			is_ai = no
			player_heir.dynasty ?= dynasty
			player_heir = { highest_held_title_tier < tier_empire }
		}
		player_heir = {
			grant_suitable_title_to_candidate_effect = yes
		}
	}

	# Assign titles to everyone else
	ordered_in_list = {
		list = selected_mongol_heirs
		order_by = mongol_breakup_succession_score
		max = global_var:creatable_mongol_successor_states_number

		debug_log = "Found another Mongol Heir"
		debug_log_scopes = yes
		grant_suitable_title_to_candidate_effect = yes
		
		debug_log = "Tried granting title to heir"
	}

	pick_up_remaining_counties_effect = yes
	set_correct_mongol_breakup_vassalage_effect = yes
	shift_counties_on_mongol_succession_effect = yes

	# Send notification events
	scope:mongolia_ruler = {
		save_scope_as = successor_1
	}

	ordered_in_list = {
		list = selected_mongol_heirs
		order_by = mongol_breakup_succession_score
		max = 3

		if = {
			limit = {
				NOT = { exists = scope:successor_2 }
			}
			save_scope_as = successor_2
		}
		else_if = {
			limit = {
				NOT = { exists = scope:successor_3 }
				NOT = {
					this = scope:successor_2
				}
			}
			save_scope_as = successor_3
		}
		if = {
			limit = {
				NOT = { exists = scope:successor_4 }
				NOR = {
					this = scope:successor_2
					this = scope:successor_3
				}
			}
			save_scope_as = successor_4
		}
	}

	every_player = {
		trigger_event = {
			id = mongol_invasion.1004
			days = 2 # Delay it a little to let effects settle
		}
	}

	# Cleanup
	remove_global_variable = creatable_mongol_successor_states_number
	remove_global_variable = number_of_mongol_heir_candidates
	remove_global_variable = creatable_ilkhanate
	remove_global_variable = creatable_golden_horde
	remove_global_variable = creatable_chagatai
	remove_global_variable = creatable_great_yuan
	remove_global_variable = creatable_red_horde
	remove_global_variable = creatable_white_horde
	remove_global_variable = creatable_blue_horde
	remove_global_variable = creatable_omnod_dalai_khanate
	remove_global_variable = creatable_aarlud_khanate
	remove_global_variable = creatable_togskol_khanate
	remove_global_variable = creatable_baruun_khanate

	# Make sure the Mongol Empire title is destroyed as appropriate
	set_global_variable = {
		name = mongol_empire_was_broken_up
		value = yes
	}
	scope:successor_1 = {
		trigger_event = {
			id = mongol_invasion.9999
			days = 1
		}
	}
	
	# Assign appropriate De Jure, so that the successors do not switch away from their empires immediately
	if = {
		limit = {
			exists = scope:chagatai_ruler
		}
		scope:chagatai_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = chagatai_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:great_yuan_ruler
		}
		scope:great_yuan_ruler = {
			#Should not have dejure reassignment if they got an already existing title
			if = {
				limit = {
					scope:great_yuan_ruler.primary_title = title:e_great_yuan
				}
				add_realm_law_skip_effects = high_partition_succession_law
				save_scope_as = title_assignment
				every_sub_realm_county = {
					limit = {
						title_province = {
							geographical_region = great_yuan_de_jure_region
						}
						exists = kingdom
						OR = {
							NOT = { exists = kingdom.holder }
							kingdom.holder = {
								OR = {
									this = scope:title_assignment
									is_vassal_of = scope:title_assignment
								}
							}
						}
						holder.top_liege = scope:title_assignment
					}
					if = {
						limit = {
							NOT = {
								kingdom = {
									is_in_list = assigned_kingdoms
								}
							}
						}
						kingdom = {
							set_de_jure_liege_title = scope:title_assignment.primary_title
							add_to_list = assigned_kingdoms
						}
					}
				}
			}
			if = {
				limit = {
					has_dlc_feature = admin_gov
				}
				convert_great_yuan_to_admin_effect = yes
			}
			else = {
				change_mongol_successor_illegal_government = yes
			}
		}
	}
	if = {
		limit = {
			exists = scope:golden_horde_ruler
		}
		scope:golden_horde_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = golden_horde_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:ilkhanate_ruler
		}
		scope:ilkhanate_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = ilkhanate_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:red_horde_ruler
		}
		scope:red_horde_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = red_horde_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:white_horde_ruler
		}
		scope:white_horde_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = white_horde_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:blue_horde_ruler
		}
		scope:blue_horde_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = blue_horde_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:omnod_dalai_khanate_ruler
		}
		scope:omnod_dalai_khanate_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = omnod_dalai_khanate_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:aarlud_khanate_ruler
		}
		scope:aarlud_khanate_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = aarlud_khanate_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:togskol_khanate_ruler
		}
		scope:togskol_khanate_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = togskol_khanatede_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	if = {
		limit = {
			exists = scope:baruun_khanate_ruler
		}
		scope:baruun_khanate_ruler = {
			add_realm_law_skip_effects = high_partition_succession_law
			save_scope_as = title_assignment
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = baruun_khanate_de_jure_region
					}
					exists = kingdom
					OR = {
						NOT = { exists = kingdom.holder }
						AND = {
							exists = kingdom.holder
							OR = {
								kingdom.holder = scope:title_assignment
								kingdom.holder = {
									is_vassal_of = scope:title_assignment
								}
							}
						}
					}
					holder.top_liege = scope:title_assignment
				}
				if = {
					limit = {
						NOT = {
							kingdom = {
								is_in_list = assigned_kingdoms
							}
						}
					}
					kingdom = {
						set_de_jure_liege_title = scope:title_assignment.primary_title
						add_to_list = assigned_kingdoms
					}
				}
			}
			change_mongol_successor_illegal_government = yes
		}
	}
	scope:mongolia_ruler = {
		#Allocate tributaries of mongol empire or give them independence
		trigger_event = {
			id = mongol_invasion.3000
			days = 1
		}
		#Break off exclaves
		trigger_event = {
			id = mongol_invasion.3200
			days = 1
		}
	}
	every_in_list = {
		list = selected_mongol_heirs
		limit = {
			highest_held_title_tier >= tier_empire
			NOT = {
				this = scope:mongolia_ruler
			}
		}
		#Break off exclaves
		trigger_event = {
			id = mongol_invasion.3200
			days = 1
		}
	}
}

# Special stuff for player Temüjin, disbursed in event conqueror.0001
temujin_conqueror_bonuses_effect = {
	add_gold = 100
	add_dread = medium_dread
	add_prestige = 500
	if = {
		limit = {
			prestige_level < 2
		}
		add_prestige_level = 2
	}
	else_if = {
		limit = {
			prestige_level < 3
		}
		add_prestige_level = 1
	}
	if = {
		limit = {
			government_has_flag = government_is_nomadic
		}
		if = {
			limit = {
				OR = {
					has_realm_law = nomadic_authority_4
					has_realm_law = nomadic_authority_5
				}
			}
			domicile = {
				change_herd = {
					add = nomadic_authority_level_2_requirement
				}
			}
		}
		else = {
			domicile = {
				change_herd = {
					value = nomadic_authority_level_4_requirement
				}
			}
		}
		
		if = {
			limit = {
				NOR = {
					has_realm_law = nomadic_authority_5
					has_realm_law = nomadic_authority_4
				}
			}
			hidden_effect = {
				if = {
					limit = { has_realm_law = nomadic_authority_1 }
					remove_realm_law = nomadic_authority_1
				}
				if = {
					limit = { has_realm_law = nomadic_authority_2 }
					remove_realm_law = nomadic_authority_2
				}
				if = {
					limit = { has_realm_law = nomadic_authority_3 }
					remove_realm_law = nomadic_authority_3
				}
			}
			add_realm_law_skip_effects = nomadic_authority_4
		}
	}
	if = {
		limit = {
			is_decision_on_cooldown = nomad_higher_tier_title_decision
		}
		remove_decision_cooldown = nomad_higher_tier_title_decision
	}
	custom_tooltip = temujin_horde_gathers_tt
	trigger_event = {
		id = mpo_greatest_of_khans.1010
		months = { 3 9 }
	}
}

convert_great_yuan_to_admin_effect = {
	save_scope_as = administrative_liege

	#Create cadet branch to ensure you have a domicile
	if = {
		limit = {
			exists = house.house_head
			NOT = {
				this = house.house_head
			}
		}
		#Create cadet branch
		found_cadet_house_decision_effect = {
			CHARACTER = scope:administrative_liege
			PRESTIGE = 0
		}
		house = {
			set_coa = scope:administrative_liege.capital_province.barony
		}
	}
	change_to_administrative_effect = yes

	#Direct Vassals who fulfill the tgp_mongol_vassal_will_become_admin criteria are converted. Vassals above 25 opinion always accept
	#Vassals are converted as a hierarchy. If a king is converted we convert all who are valid below that king (so his dukes, their counts, and their barons) are all converted.
	#If a vassal does not convert (because of not accepting or because they are outside of the de jure empire, etc) then the vassals below them are _not_ converted either.

	#Human vassals are given a choice to convert or not in the ping event, even if powerful or having very good relation.

	hidden_effect = { 
		save_scope_as = actor
		every_vassal = {
			limit = {
				tgp_mongol_vassal_will_become_admin = yes
			}
			save_scope_as = recipient
			change_to_administrative_effect = yes
			every_vassal = { #Everyone below also converts (could be Counts, could be Dukes)
				limit = {
					tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
					is_ai = yes
				}
				save_scope_as = recipient	
				change_to_administrative_effect = yes
				every_vassal = { #Everyone below also converts (Could be Counts, could be Barons)
					limit = {
						tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
						is_ai = yes
					}
					save_scope_as = recipient	
					change_to_administrative_effect = yes
					every_vassal = { #Everyone below also converts (could be Barons)
						limit = {
							tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
							is_ai = yes
						}
						save_scope_as = recipient
						change_to_administrative_effect = yes
					}
				}
			}
		}
	}

	if = {
		limit = {
			NOT = {
				has_character_flag = latin_emp_force_admin_flag
			}
			top_liege = this
		}
		add_character_modifier = {
			modifier = first_admin_emperor
		}
	}
	
	change_influence = 1500
	add_treasury = 2500

	every_vassal_or_below = {
		limit = {
			is_ai = no
			tgp_mongol_vassal_will_become_admin = yes
		}
		trigger_event = ep3_decisions_event.4065
	}
	if = {
		limit = {
			exists = capital_county
			NOT = {
				domicile.domicile_location.county ?= capital_county
			}
		}
		domicile = {
			move_domicile = scope:administrative_liege.capital_province
		}
	}
	if = {
		limit = {
			government_has_flag = government_is_celestial
			highest_held_title_tier >= tier_empire
			primary_title = {
				has_custom_title_name = no
			}
		}
		trigger_event = {
			id = tgp_dynastic_cycle.9000
			days = 1
		}
	}
}

change_mongol_successor_illegal_government = {
	trigger_event = {
		id = mongol_invasion.3100
		days = 1
	}
}

mongol_breakup_purge_mongolia_exclaves_effect = {
	save_scope_as = mongol_exclaves_target

	capital_province.county = {
		every_connected_county = { # Start off by making a list of all disconnected Counties
			invert = yes
			max_naval_distance = 2000
			allow_one_county_land_gap = yes
			add_to_list = disconnected_counties
		}
	}
	
	every_in_list = {
		list = disconnected_counties
		
		limit = {
			any_connected_county = {
				NOT = { is_in_list = disconnected_counties }
				max_naval_distance = 2000
			}
		}
		add_to_list = cull_naval_connection_counties
	}
	
	while = {
		limit = {
			any_in_list = {
				list = cull_naval_connection_counties
			}
		}
		random_in_list = {
			list = cull_naval_connection_counties
			
			save_scope_as = cull_origin_county
			
			every_connected_county = {
				remove_from_list = cull_naval_connection_counties
				remove_from_list = disconnected_counties
			}
			remove_from_list = cull_naval_connection_counties
			remove_from_list = disconnected_counties
		}
	}
	
	every_in_list = {
		list = disconnected_counties
		
		limit = {
			target_is_de_jure_liege_or_above = scope:mongol_exclaves_target.primary_title
		}
		add_to_list = cull_de_jure_connection_counties
	}
	
	while = {
		limit = {
			any_in_list = {
				list = cull_de_jure_connection_counties
			}
		}
		random_in_list = {
			list = cull_de_jure_connection_counties
			
			save_scope_as = cull_origin_county
			
			every_connected_county = {
				remove_from_list = cull_de_jure_connection_counties
				remove_from_list = disconnected_counties
			}
			remove_from_list = cull_de_jure_connection_counties
			remove_from_list = disconnected_counties
		}
	}
	#Make them vassals if they are de jure vassals of another successor
	every_in_list = { # Transfer Kings first
		list = disconnected_counties
		
		limit = {
			holder.primary_title = {
				tier = tier_kingdom
				empire.holder ?= {
					OR = {
						is_in_list = selected_mongol_heirs
						primary_title = title:e_mongolia
					}
					NOT = {
						this = scope:mongol_exclaves_target
					}
				}
			}
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
				add_claim_on_loss = no
			}
			change_liege = {
				liege = primary_title.empire.holder
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
			every_realm_county = {
				limit = {
					is_in_list = disconnected_counties
				}
				remove_from_list = disconnected_counties
			}
		}
	}
	every_in_list = { # Transfer Dukes second
		list = disconnected_counties
		
		limit = {
			holder.primary_title = {
				tier = tier_duchy
				empire.holder ?= {
					OR = {
						is_in_list = selected_mongol_heirs
						primary_title = title:e_mongolia
					}
					NOT = {
						this = scope:mongol_exclaves_target
					}
				}
			}
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
				add_claim_on_loss = no
			}
			change_liege = {
				liege = primary_title.empire.holder
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
			every_realm_county = {
				limit = {
					is_in_list = disconnected_counties
				}
				remove_from_list = disconnected_counties
			}
		}
	}

	every_in_list = { # transfer Counts last
		list = disconnected_counties
		
		limit = {
			holder.primary_title = {
				tier = tier_county
				empire.holder ?= {
					OR = {
						is_in_list = selected_mongol_heirs
						primary_title = title:e_mongolia
					}
					NOT = {
						this = scope:mongol_exclaves_target
					}
				}
			}
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
				add_claim_on_loss = no
			}
			change_liege = {
				liege = primary_title.empire.holder
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
			every_realm_county = {
				limit = {
					is_in_list = disconnected_counties
				}
				remove_from_list = disconnected_counties
			}
		}
	}
	every_in_list = { # Finally, transfer contiguous areas under someone from the pool
		list = disconnected_counties
		
		limit = {
			empire.holder ?= {
				OR = {
					is_in_list = selected_mongol_heirs
					primary_title = title:e_mongolia
				}
				NOT = {
					this = scope:mongol_exclaves_target
				}
			}
			OR = {
				holder.top_liege = scope:mongol_exclaves_target
				holder = scope:mongol_exclaves_target
			}
		}
		
		save_scope_as = county_of_origin
		
		every_pool_character = {
			province = scope:county_of_origin.title_province
			limit = {
				is_available_adult = yes
			}
			add_to_list = potential_holders
		}
		
		every_pool_character = {
			province = scope:county_of_origin.holder.capital_province
			limit = {
				is_available_adult = yes
			}
			add_to_list = potential_holders
		}
		
		if = {
			limit = {
				NOT = {
					any_in_list = {
						list = potential_holders
						is_available_adult = yes
					}
				}
			}
			create_character = {
				location = scope:county_of_origin.title_province
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
				gender_female_chance = 50
				age = 32
				save_scope_as = backup_character
			}
			scope:backup_character = {
				add_to_list = potential_holders
			}
		}
		
		random_in_list = {
			list = potential_holders
			limit = {
				is_available_adult = yes
				has_claim_on = scope:county_of_origin
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				faith = scope:county_of_origin.faith
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				has_claim_on = scope:county_of_origin
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
			}
			alternative_limit = {
				is_available_adult = yes
				faith = scope:county_of_origin.faith
			}
			alternative_limit = {
				is_available_adult = yes
			}
			
			save_scope_as = new_county_holder
			add_character_flag = {
				flag = domicile_culture_and_faith_check
				days = 1
			}
			
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_in_list = {
				list = disconnected_counties
				limit = {
					OR = {
						holder.top_liege = scope:mongol_exclaves_target
						holder = scope:mongol_exclaves_target
					}
					is_connected_to = {
						target = scope:county_of_origin
					}
					NOT ={
						is_connected_to = {
							target = scope:mongol_exclaves_target.capital_province.county
						}
					}
				}
				change_title_holder = {
					holder = scope:new_county_holder
					change = scope:change
				}
				#scope:new_county_holder = { get_title = prev }
			}
			resolve_title_and_vassal_change = scope:change

			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
				add_claim_on_loss = no
			}
			change_liege = {
				liege = primary_title.empire.holder
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
			# This system should not generate strange-culture nomads
			if = {
				limit = {
					government_has_flag = government_is_nomadic
					domicile.domicile_culture != scope:new_county_holder.capital_county.culture
				}
				domicile = {
					set_domicile_culture = scope:new_county_holder.capital_county.culture
				}
			}
			if = {
				limit = {
					government_has_flag = government_is_nomadic
					domicile.domicile_faith != scope:new_county_holder.capital_county.faith
				}
				domicile = {
					set_domicile_faith = scope:new_county_holder.capital_county.faith
				}
			}
			if = { # Just in case they need to create a duchy
				limit = {
					gold < 500
				}
				add_gold = 500
			}
		}
		remove_from_list = disconnected_counties
	}
	
	#Make the rest independent
	every_in_list = { # Release Kings first
		list = disconnected_counties
		
		limit = {
			holder.primary_title.tier = tier_kingdom
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}
			becomes_independent = {
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
		}
	}
	
	every_in_list = { # Release Dukes second
		list = disconnected_counties
		
		limit = {
			holder.primary_title.tier = tier_duchy
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}
			becomes_independent = {
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
		}
	}
	
	every_in_list = { # Release Counts last
		list = disconnected_counties
		
		limit = {
			holder.primary_title.tier = tier_county
			NOR = {
				holder = scope:mongol_exclaves_target
				holder = {
					any_sub_realm_title = {
						tier = tier_county
						NOT = { is_in_list = disconnected_counties }
					}
				}
			}
		}
		holder = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}
			becomes_independent = {
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
		}
	}
	
	every_in_list = { # Finally, release contiguous areas under someone from the pool
		list = disconnected_counties
		
		limit = {
			OR = {
				holder.top_liege = scope:mongol_exclaves_target
				holder = scope:mongol_exclaves_target
			}
		}
		
		save_scope_as = county_of_origin
		
		every_pool_character = {
			province = scope:county_of_origin.title_province
			limit = {
				is_available_adult = yes
			}
			add_to_list = potential_holders
		}
		
		every_pool_character = {
			province = scope:county_of_origin.holder.capital_province
			limit = {
				is_available_adult = yes
			}
			add_to_list = potential_holders
		}
		
		if = {
			limit = {
				NOT = {
					any_in_list = {
						list = potential_holders
						is_available_adult = yes
					}
				}
			}
			create_character = {
				location = scope:county_of_origin.title_province
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
				gender_female_chance = 50
				age = 32
				save_scope_as = backup_character
			}
			scope:backup_character = {
				add_to_list = potential_holders
			}
		}
		
		random_in_list = {
			list = potential_holders
			limit = {
				is_available_adult = yes
				has_claim_on = scope:county_of_origin
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				faith = scope:county_of_origin.faith
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				faith = {
					has_dominant_ruling_gender = prev
				}
			}
			alternative_limit = {
				is_available_adult = yes
				has_claim_on = scope:county_of_origin
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
				faith = scope:county_of_origin.faith
			}
			alternative_limit = {
				is_available_adult = yes
				culture = scope:county_of_origin.culture
			}
			alternative_limit = {
				is_available_adult = yes
				faith = scope:county_of_origin.faith
			}
			alternative_limit = {
				is_available_adult = yes
			}
			
			save_scope_as = new_county_holder
			add_character_flag = {
				flag = domicile_culture_and_faith_check
				days = 1
			}
			#get_title = scope:county_of_origin
			
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_in_list = {
				list = disconnected_counties
				limit = {
					OR = {
						holder.top_liege = scope:mongol_exclaves_target
						holder = scope:mongol_exclaves_target
					}
					is_connected_to = {
						target = scope:county_of_origin
					}
					NOT ={
						is_connected_to = {
							target = scope:mongol_exclaves_target.capital_province.county
						}
					}
				}
				change_title_holder = {
					holder = scope:new_county_holder
					change = scope:change
				}
				#scope:new_county_holder = { get_title = prev }
			}
			becomes_independent = {
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
			# This system should not generate strange-culture nomads
			if = {
				limit = {
					government_has_flag = government_is_nomadic
					domicile.domicile_culture != scope:new_county_holder.capital_county.culture
				}
				domicile = {
					set_domicile_culture = scope:new_county_holder.capital_county.culture
				}
			}
			if = {
				limit = {
					government_has_flag = government_is_nomadic
					domicile.domicile_faith != scope:new_county_holder.capital_county.faith
				}
				domicile = {
					set_domicile_faith = scope:new_county_holder.capital_county.faith
				}
			}
			if = { # Just in case they need to create a duchy
				limit = {
					gold < 500
				}
				add_gold = 500
			}
		}
	}
}
