###################################
#
# Mongol Horde Events
#
# Id 60000 - 61000 is reserved
# Events revamped by Rylock
#
###################################

# Genghis Khan dies with a large enough empire to split up among sons
narrative_event = {
	id = 60002
	title = EVTNAME60002
	picture = GFX_evt_mongols
	
	desc = {
		text = EVTDESC60002A
		trigger = { 
			ROOT = { has_character_flag = has_third_son }
		}
	}
	desc = {
		text = EVTDESC60002B
		trigger = { 
			ROOT = { NOT = { has_character_flag = has_third_son } } 
		}
	}
	
	is_triggered_only = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	major = yes
	
	trigger = {
		always = no
		has_landed_title = e_mongol_empire
		culture = mongol
		any_realm_title = {
			tier = COUNT
			location = {
				OR = {
					region = custom_cuman
					duchy = { title = d_khwarizmian }
				}
			}
		}
		any_realm_title = {
			tier = COUNT
			location = { 
				OR = {
					region = custom_persia 					
					duchy = { title = d_dihistan }
				}
			}
		}
		any_realm_title = {
			tier = COUNT
			location = { 
				region = custom_khwarizm 
				NOR = {
					duchy = { title = d_khwarizmian }
					duchy = { title = d_dihistan }
				}
			}
		}
		any_child = {
			is_female = no
			NOT = { trait = bastard }
			count = 2
		}
	}

	immediate = {
		hidden_tooltip = {
			#attempt to give titles to historical people
			random_child = {
				limit = {
					is_alive = yes
					has_character_flag = is_jochi_khan
				}
				save_event_target_as = first_mongol_son
				ROOT = { set_character_flag = jochi_exists }
			}
			if = {
				limit = {
					has_character_flag = is_genghis_khan
					NOT = { has_character_flag = jochi_exists }
				}
				random_realm_character = {
					limit = {
						has_character_flag = son_of_jochi_khan
						NOT = {
							trait = bastard
							any_sibling = {
								NOT = { trait = bastard }
								is_older_than = PREV
							}
						}
					}
					save_event_target_as = first_mongol_son
					ROOT = { set_character_flag = jochi_exists }
				}
			}
			random_child = {
				limit = {
					is_alive = yes
					has_character_flag = is_tolui_khan
				}
				save_event_target_as = second_mongol_son
				ROOT = { set_character_flag = tolui_exists }
			}
			random_child = {
				limit = {
					is_alive = yes
					has_character_flag = is_chagatai_khan
					ROOT = {
						any_child = {
							is_female = no
							NOT = { trait = bastard }
							NOT = { has_character_flag = is_chagatai_khan }
							count = 2
						}
					}
				}
				save_event_target_as = third_mongol_son
				ROOT = { set_character_flag = has_third_son }
			}

			#otherwise assign areas to children
			if = {
				limit = { NOT = { has_character_flag = jochi_exists } }	
				#give GH to a son/grandson who's already a king in cuman
				random_vassal = {
					limit = {
						tier = KING
						capital_scope = { region = custom_cuman }
						NOR = {
							trait = bastard
							character = event_target:second_mongol_son
							character = event_target:third_mongol_son
						}
						OR = {
							is_child_of = ROOT
							father_even_if_dead = {
								is_alive = no
								is_child_of = ROOT
							}
						}
					}
					save_event_target_as = first_mongol_son
					ROOT = { set_character_flag = jochi_exists }
				}
			}
			if = {
				limit = { NOT = { has_character_flag = jochi_exists } }	
				#give GH to a son who's already a duke in cuman
				random_realm_character = {
					limit = {
						is_ruler = yes
						is_female = no
						tier = DUKE
						capital_scope = { region = custom_cuman }
						NOR = {
							trait = bastard
							character = event_target:second_mongol_son
							character = event_target:third_mongol_son
						}
						is_child_of = ROOT
					}
					save_event_target_as = first_mongol_son
					ROOT = { set_character_flag = jochi_exists }
				}
			}
			if = {
				limit = { NOT = { has_character_flag = jochi_exists } }	
				#otherwise give GH to eldest available son
				random_child = {
					limit = {
						is_alive = yes
						is_female = no
						NOR = {
							trait = bastard
							character = event_target:second_mongol_son
							character = event_target:third_mongol_son
							any_sibling = {
								NOR = {
									trait = bastard
									character = event_target:second_mongol_son
									character = event_target:third_mongol_son
								}
								is_older_than = PREV
							}
						}
					}
					save_event_target_as = first_mongol_son
				}
			}
			if = {
				limit = { NOT = { has_character_flag = tolui_exists } }	
				#give ilkhanate to a son/grandson who's already a king in persia
				random_vassal = {
					limit = {
						tier = KING
						capital_scope = { region = custom_persia }
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:third_mongol_son
						}
						OR = {
							is_child_of = ROOT
							father_even_if_dead = {
								is_alive = no
								is_child_of = ROOT
							}
						}
					}
					save_event_target_as = second_mongol_son
					ROOT = { set_character_flag = tolui_exists }
				}
			}
			if = {
				limit = { NOT = { has_character_flag = tolui_exists } }
				#give ilkhanate to a son who's already a duke in persia
				random_realm_character = {
					limit = {
						is_ruler = yes
						is_female = no
						tier = DUKE
						capital_scope = { region = custom_persia }
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:third_mongol_son
						}
						is_child_of = ROOT
					}
					save_event_target_as = second_mongol_son
					ROOT = { set_character_flag = tolui_exists }
				}
			}
			if = {
				limit = { NOT = { has_character_flag = tolui_exists } }
				#otherwise give ilkhanate to eldest available son
				random_child = {
					limit = {
						is_alive = yes
						is_female = no
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:third_mongol_son
							any_sibling = {
								NOT = { trait = bastard }
								NOT = { character = event_target:first_mongol_son }
								NOT = { character = event_target:third_mongol_son }
								is_older_than = PREV
							}
						}
					}
					save_event_target_as = second_mongol_son
				}
			}
			if = {
				limit = {
					NOT = { has_character_flag = has_third_son }
					any_child = {
						is_alive = yes
						is_female = no
						NOT = { trait = bastard }
						NOT = { character = event_target:first_mongol_son }
						NOT = { character = event_target:second_mongol_son }
					}
				}
				#give Chagatai to son/grandson who's already a king in khwarizm
				random_vassal = {
					limit = {
						tier = KING
						capital_scope = { region = custom_khwarizm }
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:second_mongol_son
						}
						OR = {
							is_child_of = ROOT
							father_even_if_dead = {
								is_alive = no
								is_child_of = ROOT
							}
						}
					}
					save_event_target_as = third_mongol_son
					ROOT = { set_character_flag = has_third_son }
				}
			}
			if = {
				limit = {
					NOT = { has_character_flag = has_third_son }
					any_child = {
						is_alive = yes
						is_female = no
						NOT = { trait = bastard }
						NOT = { character = event_target:first_mongol_son }
						NOT = { character = event_target:second_mongol_son }
					}
				}
				#give Chagatai to son who's already a duke in khwarizm
				random_realm_character = {
					limit = {
						is_ruler = yes
						is_female = no
						tier = DUKE
						capital_scope = { region = custom_khwarizm }
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:second_mongol_son
						}
						is_child_of = ROOT
					}
					save_event_target_as = third_mongol_son
					ROOT = { set_character_flag = has_third_son }
				}
			}
			if = {
				limit = {
					NOT = { has_character_flag = has_third_son }
					any_child = {
						is_alive = yes
						is_female = no
						NOT = { trait = bastard }
						NOT = { character = event_target:first_mongol_son }
						NOT = { character = event_target:second_mongol_son }
					}
				}
				#otherwise give Chagatai to eldest available son				
				random_child = {
					limit = {
						is_alive = yes
						is_female = no
						NOR = {
							trait = bastard
							character = event_target:first_mongol_son
							character = event_target:second_mongol_son
							any_sibling = {
								NOT = { trait = bastard }
								NOT = { character = event_target:first_mongol_son }
								NOT = { character = event_target:second_mongol_son }
								is_older_than = PREV
							}
						}
					}
					save_event_target_as = third_mongol_son
					ROOT = { set_character_flag = has_third_son }
				}
			}

			clr_character_flag = jochi_exists
			clr_character_flag = tolui_exists
		
			#stop any wars and disband the initial mongol forces
			any_war = {
				limit = {
					OR = {
						attacker = { character = ROOT }
						defender = { character = ROOT }
					}
				}
				end_war = invalid
			}
			disband_event_forces = first_mongol_horde
			
			if = {
				limit = { has_character_flag = has_third_son }
				current_heir = { set_character_flag = has_third_son }
			}
			current_heir = { character_event = { id = 60005 days = 1 } }
		}
	}
	
	option = {
		name = EVTOPTA60002
		trigger = { character = ROOT }
	}
	option = {
		name = EVTOPTB60002
		trigger = {
			NOT = { character = ROOT }
			OR = {
				culture = mongol
				same_realm = ROOT
			}
		}
	}
	option = {
		name = EVTOPTC60002
		trigger = {
			NOR = {
				character = ROOT
				culture = mongol
				same_realm = ROOT
			}
		}
	}
}

# Vassals are given the option to serve one of the sons
character_event = {
	id = 60003
	picture = GFX_evt_tengri_throneroom_oldgods
	
	desc = {
		text = EVTDESC60003A
		trigger = { FROM = { has_character_flag = has_third_son } }
	}
	desc = {
		text = EVTDESC60003B
		trigger = { FROM = { NOT = { has_character_flag = has_third_son } } }
	}
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA60003 #Join Golden Horde
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				is_ruler = yes			
				NOT = {
					any_realm_province = {
						any_neighbor_province = {
							owner = { top_liege = { has_landed_title = e_golden_horde } }
						}
					}
				}
			}
			modifier = {
				factor = 3
				opinion_diff = {
					first = event_target:first_mongol_son
					second = event_target:second_mongol_son
					value = 10
					as_if_liege = yes
				}
				OR = {
					FROM = { NOT = { has_character_flag = has_third_son } }
					opinion_diff = {
						first = event_target:first_mongol_son
						second = event_target:third_mongol_son
						value = 10
						as_if_liege = yes
					}
				}
			}
			modifier = {
				factor = 2
				is_ruler = yes
				event_target:first_mongol_son = {
					any_realm_province = {
						ROOT = {
							capital_scope = {
								distance = { where = PREVPREV value = 200 }
							}
						}
					}
				}
			}
		}
		if = {
			limit = { is_ruler = no }
			any_spouse = {
				limit = {
					prisoner = no
					is_ruler = no
				}
				move_character = event_target:first_mongol_son
			}
			any_child = {
				limit = {
					prisoner = no
					is_adult = no
					is_ruler = no
				}
				move_character = event_target:first_mongol_son
			}
			move_character = event_target:first_mongol_son
		}
		if = {
			limit = { is_ruler = yes }
			set_defacto_liege = event_target:first_mongol_son
		}
		opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
	}
	option = {
		name = EVTOPTB60003 #Join Ilkhanate
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				is_ruler = yes
				NOT = {
					any_realm_province = {
						any_neighbor_province = {
							owner = { top_liege = { has_landed_title = e_il-khanate } }
						}
					}
				}
			}
			modifier = {
				factor = 3
				opinion_diff = {
					first = event_target:second_mongol_son
					second = event_target:first_mongol_son
					value = 10
					as_if_liege = yes
				}
				OR = {
					FROM = { NOT = { has_character_flag = has_third_son } }
					opinion_diff = {
						first = event_target:second_mongol_son
						second = event_target:third_mongol_son
						value = 10
						as_if_liege = yes
					}
				}
			}
			modifier = {
				factor = 2
				is_ruler = yes
				event_target:second_mongol_son = {
					any_realm_province = {
						ROOT = {
							capital_scope = {
								distance = { where = PREVPREV value = 200 }
							}
						}
					}
				}
			}
		}
		if = {
			limit = { is_ruler = no }
			any_spouse = {
				limit = {
					prisoner = no
					is_ruler = no
				}
				move_character = event_target:second_mongol_son
			}
			any_child = {
				limit = {
					prisoner = no
					is_adult = no
					is_ruler = no
				}
				move_character = event_target:second_mongol_son
			}
			move_character = event_target:second_mongol_son
		}
		if = {
			limit = { is_ruler = yes }
			set_defacto_liege = event_target:second_mongol_son
		}
		opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
	}
	option = {
		name = EVTOPTC60003 #Join Chagatai
		trigger = {
			FROM = { has_character_flag = has_third_son }
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				is_ruler = yes
				NOT = {
					any_realm_province = {
						any_neighbor_province = {
							owner = { top_liege = { has_landed_title = e_chagatai } }
						}
					}
				}
			}
			modifier = {
				factor = 3
				opinion_diff = {
					first = event_target:third_mongol_son
					second = event_target:first_mongol_son
					value = 10
					as_if_liege = yes
				}
				opinion_diff = {
					first = event_target:third_mongol_son
					second = event_target:second_mongol_son
					value = 10
					as_if_liege = yes
				}
			}
			modifier = {
				factor = 2
				is_ruler = yes
				event_target:third_mongol_son = {
					any_realm_province = {
						ROOT = {
							capital_scope = {
								distance = { where = PREVPREV value = 200 }
							}
						}
					}
				}
			}
		}
		if = {
			limit = { is_ruler = no }
			any_spouse = {
				limit = {
					prisoner = no
					is_ruler = no
				}
				move_character = event_target:third_mongol_son
			}
			any_child = {
				limit = {
					prisoner = no
					is_adult = no
					is_ruler = no
				}
				move_character = event_target:third_mongol_son
			}
			move_character = event_target:third_mongol_son
		}
		if = {
			limit = { is_ruler = yes }
			set_defacto_liege = event_target:third_mongol_son
		}
		opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
	}
}

# Sons are informed of the Mongol Empire division
character_event = {
	id = 60004
	desc = EVTDESC60004
	picture = GFX_evt_tengri_throneroom_oldgods
	
	is_triggered_only = yes
	
	immediate = {
		#son will immediately form a cadet dynasty
		FROMFROM = { save_event_target_as = old_dynasty_head }
		any_dynasty_member = {
			limit = {
				OR = {
					is_child_of = ROOT
					mother_even_if_dead = { is_child_of = ROOT }
					father_even_if_dead = { is_child_of = ROOT }
				}
			}
			character_event = { id = Plus.142 days = 1 }
		}
		dynasty = father_bastard
		if = {
			limit = {
				OR = {
					has_character_flag = is_jochi_khan
					AND = {
						has_character_flag = son_of_jochi_khan
						NOT = {
							any_independent_ruler = {
								NOT = { character = ROOT }
								has_character_flag = son_of_jochi_khan
							}
						}
					}
				}
			}
			dynasty = 7379
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_chagatai_khan
					AND = {
						has_character_flag = son_of_chagatai_khan
						NOT = {
							any_independent_ruler = {
								NOT = { character = ROOT }
								has_character_flag = son_of_chagatai_khan
							}
						}
					}
				}
			}
			dynasty = 7380
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_tolui_khan
					AND = {
						has_character_flag = son_of_tolui_khan
						NOT = {
							any_independent_ruler = {
								NOT = { character = ROOT }
								has_character_flag = son_of_tolui_khan
							}
						}
					}
				}
			}
			dynasty = 101916
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_ogodei_khan
					AND = {
						has_character_flag = son_of_ogodei_khan
						NOT = {
							any_independent_ruler = {
								NOT = { character = ROOT }
								has_character_flag = son_of_ogodei_khan
							}
						}
					}
				}
			}
			dynasty = 1000124389
		}
		if = {
			limit = { ai = no }
			chronicle = {
				entry = CHRONICLE_CADET_BRANCH
				portrait = [Root.GetID]
				picture = GFX_evt_coronation
			}
		}
		
		#move capital to primary capital, if possible
		if = {
			limit = {
				primary_title = {
					capital_scope = {
						owner = { character = ROOT }
						county = { is_feudal = yes }
						is_capital = no
					}
				}
			}
			primary_title = {
				capital_scope = {
					county = {
						ROOT = { capital = PREV }
					}
				}
			}
		}
		#move tribal capital to feudal one, if primary capital not held
		if = {
			limit = {
				is_feudal = no
				NOT = {
					primary_title = {
						capital_scope = {
							owner = { character = ROOT }
							county = { is_feudal = yes }
							is_capital = yes
						}
					}
				}
				any_demesne_title = {
					tier = COUNT
					is_feudal = yes
				}
			}
			random_demesne_title = {
				limit = {
					tier = COUNT
					is_feudal = yes
				}
				ROOT = { capital = PREV }
			}
		}
		#change succession to gavelkind if still tribal
		if = {
			limit = { is_tribal = yes }
			primary_title = { add_law = succ_gavelkind }
		}
	}
	
	option = {
		name = EVTOPTA60004
		trigger = { has_landed_title = e_golden_horde }
		set_global_flag = golden_horde_arrival
		custom_tooltip = { text = ESTABLISH_CADET_BRANCH }
		
		#lose all claims held by the other hordes
		any_claim = {
			limit = {
				holder_scope = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_chagatai
						top_liege = { has_landed_title = e_il-khanate }
						top_liege = { has_landed_title = e_chagatai }
					}
				}
			}
			remove_claim = ROOT
		}
		capital_scope = {
			ROOT = {
				spawn_unit = {
					owner = THIS
					province = PREV
					home = PREV
					troops = {
						horse_archers = { 6750 6750 }
						light_cavalry = { 4000 4000 }
						light_infantry = { 1350 1350 }
						heavy_infantry = { 525 525 }
						knights = { 118 118 }
					}
					attrition = 0.35
					maintenance_multiplier = 0
					earmark = second_mongol_horde
				}
			}
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		hidden_tooltip = {
			#turn over any remaining vassals
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_persia
							region = custom_afghanistan
							region = custom_baluchistan
							region = custom_byzantium
							region = custom_arabia
							region = custom_jerusalem
							region = custom_mesopotamia
							region = custom_syria
							region = custom_armenia
							region = custom_azerbaijan
							region = custom_nikaea
							region = custom_trebizond
							region = world_india_bengal
							region = world_india_deccan
							region = world_india_rajastan
							duchy = { title = d_merv }
							duchy = { title = d_dihistan }
						}
					}
				}
				set_defacto_liege = event_target:second_mongol_son
				opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			any_vassal = {
				any_vassal = {
					limit = {
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
					}
					set_defacto_liege = event_target:second_mongol_son
					opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
			}
			if = {
				limit = { FROM = { has_character_flag = has_third_son } }
				any_vassal = {
					limit = {
						capital_scope = {
							region = custom_khwarizm
							NOT = { duchy = { title = d_khwarizmian } }
						}
					}
					set_defacto_liege = event_target:third_mongol_son
					opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
				any_vassal = {
					any_vassal = {
						limit = {
							capital_scope = {
								region = custom_khwarizm
								NOT = { duchy = { title = d_khwarizmian } }
							}
						}
						set_defacto_liege = event_target:third_mongol_son
						opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
					}
				}
			}		
		}
	}
	option = {
		name = EVTOPTA60004
		trigger = { has_landed_title = e_il-khanate }
		set_global_flag = il_khanate_arrival
		custom_tooltip = { text = ESTABLISH_CADET_BRANCH }
		#lose all claims held by the other hordes
		any_claim = {
			limit = {
				holder_scope = {
					OR = {
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						top_liege = { has_landed_title = e_golden_horde }
						top_liege = { has_landed_title = e_chagatai }
					}
				}
			}
			remove_claim = ROOT
		}
		capital_scope = {
			ROOT = {
				spawn_unit = {
					owner = THIS
					province = PREV
					home = PREV
					troops = {
						horse_archers = { 6750 6750 }
						light_cavalry = { 4000 4000 }
						light_infantry = { 1350 1350 }
						heavy_infantry = { 525 525 }
						knights = { 118 118 }
					}
					attrition = 0.35
					maintenance_multiplier = 0
					earmark = second_mongol_horde
				}
			}
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		hidden_tooltip = {
			#turn over any remaining vassals
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_cuman
							region = custom_perm
							region = custom_volga
							region = custom_alania
							region = custom_crimea
							region = custom_lithuania
							region = custom_livonia
							region = custom_muscovy
							region = custom_novgorod
							region = custom_rus
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							region = custom_wallachia
							duchy = { title = d_khwarizmian }
						}
					}
				}
				set_defacto_liege = event_target:first_mongol_son
				opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			any_vassal = {
				any_vassal = {
					limit = {
						capital_scope = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia
								duchy = { title = d_khwarizmian }
							}
						}
					}
					set_defacto_liege = event_target:first_mongol_son
					opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
			}
			if = {
				limit = { FROM = { has_character_flag = has_third_son } }
				any_vassal = {
					limit = {
						capital_scope = {
							region = custom_khwarizm
							NOT = { duchy = { title = d_merv } }
							NOT = { duchy = { title = d_dihistan } }
						}
					}
					set_defacto_liege = event_target:third_mongol_son
					opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
				any_vassal = {
					any_vassal = {
						limit = {
							capital_scope = {
								region = custom_khwarizm
								NOT = { duchy = { title = d_merv } }
								NOT = { duchy = { title = d_dihistan } }
							}
						}
						set_defacto_liege = event_target:third_mongol_son
						opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTA60004
		trigger = { has_landed_title = e_chagatai }
		set_global_flag = chagatai_arrival
		if = {
			limit = { NOT = { dynasty = 7380 } }
			e_chagatai = {
				set_name= MOGHUL
				adjective= MOGHUL_ADJ
			}
		}
		custom_tooltip = { text = ESTABLISH_CADET_BRANCH }
		#lose all claims held by the other hordes
		any_claim = {
			limit = {
				holder_scope = {
					OR = {
						has_landed_title = e_golden_horde
						has_landed_title = e_il-khanate
						top_liege = { has_landed_title = e_golden_horde }
						top_liege = { has_landed_title = e_il-khanate }
					}
				}
			}
			remove_claim = ROOT
		}
		capital_scope = {
			ROOT = {
				spawn_unit = {
					owner = THIS
					province = PREV
					home = PREV
					troops = {
						horse_archers = { 6750 6750 }
						light_cavalry = { 4000 4000 }
						light_infantry = { 1350 1350 }
						heavy_infantry = { 525 525 }
						knights = { 118 118 }
					}
					attrition = 0.35
					maintenance_multiplier = 0
					earmark = second_mongol_horde
				}
			}
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		hidden_tooltip = {
			#turn over any remaining vassals
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_cuman
							region = custom_perm
							region = custom_volga
							region = custom_alania
							region = custom_crimea
							region = custom_lithuania
							region = custom_livonia
							region = custom_muscovy
							region = custom_novgorod
							region = custom_rus
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							region = custom_wallachia
							duchy = { title = d_khwarizmian }
						}
					}
				}
				set_defacto_liege = event_target:first_mongol_son
				opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			any_vassal = {
				any_vassal = {
					limit = {
						capital_scope = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia
								duchy = { title = d_khwarizmian }
							}
						}
					}
					set_defacto_liege = event_target:first_mongol_son
					opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
			}
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_persia
							region = custom_afghanistan
							region = custom_baluchistan
							region = custom_byzantium
							region = custom_arabia
							region = custom_jerusalem
							region = custom_mesopotamia
							region = custom_syria
							region = custom_armenia
							region = custom_azerbaijan
							region = custom_nikaea
							region = custom_trebizond
							region = world_india_bengal
							region = world_india_deccan
							region = world_india_rajastan
							duchy = { title = d_merv }
							duchy = { title = d_dihistan }
						}
					}
				}
				set_defacto_liege = event_target:second_mongol_son
				opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			any_vassal = {
				any_vassal = {
					limit = {
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
					}
					set_defacto_liege = event_target:second_mongol_son
					opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
			}
		}
	}
}

# Bounce event to assign territories
character_event = {
	id = 60005
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		#make sure the first son gets a county in cuman/khwarizmia
		if = {
			limit = {
				NOT = {
					any_realm_title = {
						tier = COUNT
						location = { region = custom_cuman }
					}
				}
			}
			if = {
				limit = { has_landed_title = c_khwarizm }
				c_khwarizm = {
					grant_title = event_target:first_mongol_son
				}
			}
			if = {
				limit = {
					c_khwarizm = {
						holder_scope = {
							is_liege_or_above = ROOT
							NOR = {
								character = event_target:first_mongol_son
								character = event_target:second_mongol_son
								character = event_target:third_mongol_son
							}
						}
					}
				}
				c_khwarizm = {
					event_target:first_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
				}
			}
			if = {
				limit = {
					event_target:first_mongol_son = {
						NOT = {
							any_demesne_title = {
								tier = COUNT
								location = { duchy = { title = d_khwarizmian } }
							}
						}
					}
				}
				random_realm_title = {
					limit = {						
						tier = COUNT
						is_feudal = yes
						location = { duchy = { title = d_khwarizmian } }
					}
					event_target:first_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
				}
			}
		}
		if = {
			limit = {
				has_landed_title = c_saray
				event_target:first_mongol_son = { NOT = { has_landed_title = c_saray } }
			}
			c_saray = {
				grant_title = event_target:first_mongol_son
			}
		}
		if = {
			limit = {
				c_saray = {
					holder_scope = {
						is_liege_or_above = ROOT
						NOR = {
							character = event_target:first_mongol_son
							character = event_target:second_mongol_son
							character = event_target:third_mongol_son
						}
					}
				}
			}
			c_saray = {
				event_target:first_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
			}
		}
		if = {
			limit = {
				event_target:first_mongol_son = {
					NOT = {
						any_demesne_title = {
							tier = COUNT
							location = { region = custom_cuman }
						}
					}
				}
			}
			random_realm_title = {
				limit = {
					tier = COUNT					
					is_feudal = yes
					location = { region = custom_cuman }
				}
				event_target:first_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
			}
		}

		#make sure the second son gets a county in persia
		if = {
			limit = {
				has_landed_title = c_esfahan
				event_target:second_mongol_son = { NOT = { has_landed_title = c_esfahan } }
			}
			c_esfahan = {
				grant_title = event_target:second_mongol_son
			}
		}
		if = {
			limit = {
				c_esfahan = {
					holder_scope = {
						is_liege_or_above = ROOT
						NOR = {
							character = event_target:first_mongol_son
							character = event_target:second_mongol_son
							character = event_target:third_mongol_son
						}
					}
				}
			}
			c_esfahan = {
				event_target:second_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
			}
		}
		if = {
			limit = {
				event_target:second_mongol_son = {
					NOT = {
						any_demesne_title = {
							tier = COUNT
							location = { region = custom_persia }
						}
					}
				}
			}
			random_realm_title = {
				limit = {
					tier = COUNT					
					is_feudal = yes
					OR = {
						location = { region = custom_persia }
						duchy = { title = d_dihistan }
					}
				}
				event_target:second_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
			}
		}

		#make sure the third son gets a county in khwarizm
		if = {
			limit = { has_character_flag = has_third_son }
			if = {
				limit = {
					has_landed_title = c_ili
					event_target:third_mongol_son = { NOT = { has_landed_title = c_ili } }
				}
				c_ili = {
					grant_title = event_target:third_mongol_son
				}
			}
			if = {
				limit = {
					c_ili = {
						holder_scope = {
							is_liege_or_above = ROOT
							NOR = {
								character = event_target:first_mongol_son
								character = event_target:second_mongol_son
								character = event_target:third_mongol_son
							}
						}
					}
				}
				c_ili = {
					event_target:third_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
				}
			}
			if = {
				limit = {
					event_target:third_mongol_son = {
						NOT = {
							any_demesne_title = {
								tier = COUNT
								location = { region = custom_khwarizm }
							}
						}
					}
				}
				random_realm_title = {
					limit = {
						tier = COUNT						
						is_feudal = yes
						location = { region = custom_khwarizm }
					}
					event_target:third_mongol_son = { usurp_title_plus_barony_if_unlanded = PREV }
				}
			}
		}

		#sons that have lands in another's territory should give them up
		event_target:first_mongol_son = {
			any_demesne_title = {
				limit = {
					OR = {
						location = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
						title = d_merv
						title = d_dihistan
					}
					NOT = { tier = EMPEROR }
				}
				grant_title = event_target:second_mongol_son
			}
			if = {
				limit = { ROOT = { has_character_flag = has_third_son } }
				any_demesne_title = {
					limit = {
						OR = {
							location = { region = custom_khwarizm }
							capital_scope = { region = custom_khwarizm }
						}
						NOR = {
							duchy = { title = d_khwarizmian }
							title = d_khwarizmian
							tier = EMPEROR
						}
					}
					grant_title = event_target:third_mongol_son
				}
			}
		}
		event_target:second_mongol_son = {
			any_demesne_title = {
				limit = {
					OR = {
						location = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia								
								duchy = { title = d_khwarizmian }
							}
						}
						capital_scope = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia
								duchy = { title = d_khwarizmian }
							}
						}
						title = d_khwarizmian
					}
					NOT = { tier = EMPEROR }
				}
				grant_title = event_target:first_mongol_son
			}
			if = {
				limit = { ROOT = { has_character_flag = has_third_son } }
				any_demesne_title = {
					limit = {
						OR = {
							location = { region = custom_khwarizm }
							capital_scope = { region = custom_khwarizm }
						}
						NOR = {
							duchy = { title = d_merv }
							duchy = { title = d_dihistan }
							title = d_merv
							title = d_dihistan
							tier = EMPEROR
						}
					}
					grant_title = event_target:third_mongol_son
				}
			}
		}
		if = {
			limit = { has_character_flag = has_third_son }
			event_target:third_mongol_son = {
				any_demesne_title = {
					limit = {
						OR = {
							location = {
								OR = {
									region = custom_cuman
									region = custom_perm
									region = custom_volga
									region = custom_alania
									region = custom_crimea
									region = custom_lithuania
									region = custom_livonia
									region = custom_muscovy
									region = custom_novgorod
									region = custom_rus
									region = custom_bulgaria
									region = custom_croatia
									region = custom_serbia
									region = custom_wallachia
									duchy = { title = d_khwarizmian }
								}
							}
							capital_scope = {
								OR = {
									region = custom_cuman
									region = custom_perm
									region = custom_volga
									region = custom_alania
									region = custom_crimea
									region = custom_lithuania
									region = custom_livonia
									region = custom_muscovy
									region = custom_novgorod
									region = custom_rus
									region = custom_bulgaria
									region = custom_croatia
									region = custom_serbia
									region = custom_wallachia
									duchy = { title = d_khwarizmian }
								}
							}
							title = d_khwarizmian
						}
						NOT = { tier = EMPEROR }
					}
					grant_title = event_target:first_mongol_son
				}
				any_demesne_title = {
					limit = {
						OR = {
							location = {
								OR = {
									region = custom_persia
									region = custom_afghanistan
									region = custom_baluchistan
									region = custom_byzantium
									region = custom_arabia
									region = custom_jerusalem
									region = custom_mesopotamia
									region = custom_syria
									region = custom_armenia
									region = custom_azerbaijan
									region = custom_nikaea
									region = custom_trebizond
									region = world_india_bengal
									region = world_india_deccan
									region = world_india_rajastan
									duchy = { title = d_merv }
									duchy = { title = d_dihistan }
								}
							}
							capital_scope = {
								OR = {
									region = custom_persia
									region = custom_afghanistan
									region = custom_baluchistan
									region = custom_byzantium
									region = custom_arabia
									region = custom_jerusalem
									region = custom_mesopotamia
									region = custom_syria
									region = custom_armenia
									region = custom_azerbaijan
									region = custom_nikaea
									region = custom_trebizond
									region = world_india_bengal
									region = world_india_deccan
									region = world_india_rajastan
									duchy = { title = d_merv }
									duchy = { title = d_dihistan }
								}
							}
							title = d_merv
							title = d_dihistan
						}
						NOT = { tier = EMPEROR }
					}
					grant_title = event_target:second_mongol_son
				}
			}
		}

		#split up lands
		if = {
			limit = {
				NOR = {
					character = event_target:first_mongol_son
					character = event_target:second_mongol_son
					character = event_target:third_mongol_son
				}
			}
			any_demesne_title = {
				limit = {
					OR = {
						location = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia
								duchy = { title = d_khwarizmian }
							}
						}
						capital_scope = {
							OR = {
								region = custom_cuman
								region = custom_perm
								region = custom_volga
								region = custom_alania
								region = custom_crimea
								region = custom_lithuania
								region = custom_livonia
								region = custom_muscovy
								region = custom_novgorod
								region = custom_rus
								region = custom_bulgaria
								region = custom_croatia
								region = custom_serbia
								region = custom_wallachia
								duchy = { title = d_khwarizmian }
							}
						}
						duchy = { title = d_khwarizmian }
						title = d_khwarizmian
					}
					NOT = { tier = EMPEROR }
				}
				grant_title = event_target:first_mongol_son
			}
			any_demesne_title = {
				limit = {
					OR = {
						location = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_afghanistan
								region = custom_baluchistan
								region = custom_byzantium
								region = custom_arabia
								region = custom_jerusalem
								region = custom_mesopotamia
								region = custom_syria
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_nikaea
								region = custom_trebizond
								region = world_india_bengal
								region = world_india_deccan
								region = world_india_rajastan
								duchy = { title = d_merv }
								duchy = { title = d_dihistan }
							}
						}
						title = d_merv
						title = d_dihistan
					}
					NOT = { tier = EMPEROR }
				}
				grant_title = event_target:second_mongol_son
			}
			if = {
				limit = { has_character_flag = has_third_son }
				any_demesne_title = {
					limit = {
						OR = {
							location = { region = custom_khwarizm }
							capital_scope = { region = custom_khwarizm }
						}
						NOT = { tier = EMPEROR }
					}
					grant_title = event_target:third_mongol_son
				}
			}
		}
	
		#create new horde titles
		activate_title = { title = e_golden_horde status = yes }
		e_golden_horde = {
			copy_title_laws = e_mongol_empire
			add_law = succ_ultimogeniture
			grant_title = event_target:first_mongol_son
			make_primary_title = yes
		}
		activate_title = { title = e_il-khanate status = yes }
		e_il-khanate = {
			copy_title_laws = e_mongol_empire
			add_law = succ_ultimogeniture
			grant_title = event_target:second_mongol_son
			make_primary_title = yes
		}
		if = {
			limit = { has_character_flag = has_third_son }
			activate_title = { title = e_chagatai status = yes }
			e_chagatai = {
				copy_title_laws = e_mongol_empire
				add_law = succ_ultimogeniture
				grant_title = event_target:third_mongol_son
				make_primary_title = yes
			}
		}

		hidden_tooltip = {
			#seperate vassals
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_cuman
							region = custom_perm
							region = custom_volga
							region = custom_alania
							region = custom_crimea
							region = custom_lithuania
							region = custom_livonia
							region = custom_muscovy
							region = custom_novgorod
							region = custom_rus
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							region = custom_wallachia
							duchy = { title = d_khwarizmian }
						}
					}
				}
				set_defacto_liege = event_target:first_mongol_son
				opinion = { who = event_target:first_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			any_vassal = {
				limit = {
					capital_scope = {
						OR = {
							region = custom_persia
							region = custom_afghanistan
							region = custom_baluchistan
							region = custom_byzantium
							region = custom_arabia
							region = custom_jerusalem
							region = custom_mesopotamia
							region = custom_syria
							region = custom_armenia
							region = custom_azerbaijan
							region = custom_nikaea
							region = custom_trebizond
							region = world_india_bengal
							region = world_india_deccan
							region = world_india_rajastan
							duchy = { title = d_merv }
							duchy = { title = d_dihistan }
						}
					}
				}
				set_defacto_liege = event_target:second_mongol_son
				opinion = { who = event_target:second_mongol_son modifier = opinion_loyal_vassal years = 5 }
			}
			if = {
				limit = { has_character_flag = has_third_son }
				any_vassal = {
					limit = {
						capital_scope = { region = custom_khwarizm }
					}
					set_defacto_liege = event_target:third_mongol_son
					opinion = { who = event_target:third_mongol_son modifier = opinion_loyal_vassal years = 5 }
				}
			}

			#any remaining children will be asked to swear to a son
			FROM = {
				any_child = {
					limit = {
						is_ruler = no
						is_adult = yes
						NOT = { character = event_target:first_mongol_son }
						NOT = { character = event_target:second_mongol_son }
						NOT = { character = event_target:third_mongol_son }
					}
					character_event = { id = 60003 days = 1 }
				}
			}
			
			#any mongol generals will be asked to serve a son
			any_courtier = {
				limit = {
					culture = FROM
					is_ruler = no
					is_female = no
					NOT = { character = event_target:first_mongol_son }
					NOT = { character = event_target:second_mongol_son }
					NOT = { character = event_target:third_mongol_son }
					NOT = { is_child_of = FROM }
					trait = brilliant_strategist
				}
				character_event = { id = 60003 days = 1 }
			}
					
			#send event to inheriting sons
			event_target:first_mongol_son = { character_event = { id = 60004 } }
			event_target:second_mongol_son = { character_event = { id = 60004 } }
			event_target:third_mongol_son = { character_event = { id = 60004 } }

			if = {
				limit = {
					NOR = {
						character = event_target:first_mongol_son
						character = event_target:second_mongol_son
						character = event_target:third_mongol_son
					}
				}
				set_defacto_liege = event_target:first_mongol_son
			}
			
			clr_character_flag = has_third_son
			
			e_mongol_empire = {
				unsafe_destroy_landed_title = THIS
				activate_title = { title = THIS status = no }
			}
		}
	}

}

# Assigning flags to the mongol sons
character_event = {
	id = 60006
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		always = no
		is_title_active = e_mongol_empire
		culture = mongol
		OR = {
			has_character_flag = is_jochi_khan
			has_character_flag = son_of_jochi_khan
			has_character_flag = is_tolui_khan
			has_character_flag = son_of_tolui_khan
			has_character_flag = is_chagatai_khan
			has_character_flag = son_of_chagatai_khan
			has_character_flag = is_ogodei_khan
			has_character_flag = son_of_ogodei_khan
		}
	}
	
	immediate = {
		if = {
			limit = {
				OR = {
					has_character_flag = is_jochi_khan
					has_character_flag = son_of_jochi_khan
				}
			}
			any_child = {
				limit = {
					is_female = no
					NOT = { trait = bastard }
				}
				set_character_flag = son_of_jochi_khan
			}
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_tolui_khan
					has_character_flag = son_of_tolui_khan
				}
			}
			any_child = {
				limit = {
					is_female = no
					NOT = { trait = bastard }
				}
				set_character_flag = son_of_tolui_khan
			}
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_chagatai_khan
					has_character_flag = son_of_chagatai_khan
				}
			}
			any_child = {
				limit = {
					is_female = no
					NOT = { trait = bastard }
				}
				set_character_flag = son_of_chagatai_khan
			}
		}
		if = {
			limit = {
				OR = {
					has_character_flag = is_ogodei_khan
					has_character_flag = son_of_ogodei_khan
				}
			}
			any_child = {
				limit = {
					is_female = no
					NOT = { trait = bastard }
				}
				set_character_flag = son_of_ogodei_khan
			}
		}
	}
}


### The Hordes Convert ###

# Horde converts to Catholic
character_event = {
	id = 60010
	title = "EVTNAME60010"
	desc = "EVTDESC60010"
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_war"
	major = yes
	
	only_playable = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	trigger = {
		primary_title = {
			OR = {
				title = e_il-khanate
				title = e_golden_horde
				title = e_chagatai
			}
			holder_scope = {
				religion = tengri_pagan
				NOT = { trait = zealous }
			}
		}
		any_realm_province = { religion = catholic }
		OR = {
			AND = {
				primary_title = { title = e_il-khanate }
				had_global_flag = { flag = il_khanate_arrival days = 14600 }
				NOT = { had_global_flag = { flag = il_khanate_arrival days = 29200 } }
				NOT = { has_global_flag = il_khanate_converts }
			}
			AND = {
				primary_title = { title = e_golden_horde }
				had_global_flag = { flag = golden_horde_arrival days = 14600 }
				NOT = { had_global_flag = { flag = golden_horde_arrival days = 29200 } }
				NOT = { has_global_flag = golden_horde_converts }
			}
			AND = {
				primary_title = { title = e_chagatai }
				had_global_flag = { flag = chagatai_arrival days = 14600 }
				NOT = { had_global_flag = { flag = chagatai_arrival days = 29200 } }
				NOT = { has_global_flag = chagatai_converts }
			}
		}
	}

	mean_time_to_happen = {
		months = 1440
		modifier = {
			factor = 0.75
			any_demesne_province = {
				is_capital = yes
				religion = catholic
			}
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { title = e_il-khanate } }
			set_global_flag = il_khanate_converts
		}
		if = {
			limit = { primary_title = { title = e_golden_horde } }
			set_global_flag = golden_horde_converts
		}
		if = {
			limit = { primary_title = { title = e_chagatai } }
			set_global_flag = chagatai_converts
		}
	}
	
	option = {	# Catholic
		name = "EVTOPTA60010"
		trigger = {
			character = ROOT
		}
		religion = catholic
		capital_scope = {
			religion = catholic
		}
		
		any_realm_character = {
			limit = { religion = tengri_pagan }
			religion = catholic
			if = {
				limit = {
					is_playable = yes
					capital_scope = {
						religion = tengri_pagan
					}
				}
				capital_scope = {
					religion = catholic
				}
			}
		}
	}
	# Other rulers are informed
	option = {
		name = "EVTOPTB60010"
		trigger = {
			religion_group = muslim
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EXCELLENT"
		trigger = {
			religion_group = christian
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTD60010"
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			NOT = { character = ROOT }
		}
	}
}

# Horde converts to Orthodox
character_event = {
	id = 60011
	title = "EVTNAME60010"
	desc = "EVTDESC60011"
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_religion"
	major = yes
	
	only_playable = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	trigger = {
		primary_title = {
			OR = {
				title = e_il-khanate
				title = e_golden_horde
				title = e_chagatai
			}
			holder_scope = {
				religion = tengri_pagan
				NOT = { trait = zealous }
			}
		}
		any_realm_province = { religion = orthodox }
		OR = {
			AND = {
				primary_title = { title = e_il-khanate }
				had_global_flag = { flag = il_khanate_arrival days = 14600 }
				NOT = { had_global_flag = { flag = il_khanate_arrival days = 29200 } }
				NOT = { has_global_flag = il_khanate_converts }
			}
			AND = {
				primary_title = { title = e_golden_horde }
				had_global_flag = { flag = golden_horde_arrival days = 14600 }
				NOT = { had_global_flag = { flag = golden_horde_arrival days = 29200 } }
				NOT = { has_global_flag = golden_horde_converts }
			}
			AND = {
				primary_title = { title = e_chagatai }
				had_global_flag = { flag = chagatai_arrival days = 14600 }
				NOT = { had_global_flag = { flag = chagatai_arrival days = 29200 } }
				NOT = { has_global_flag = chagatai_converts }
			}
		}
	}

	mean_time_to_happen = {
		months = 960
		modifier = {
			factor = 0.75
			any_demesne_province = {
				is_capital = yes
				religion = orthodox
			}
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { title = e_il-khanate } }
			set_global_flag = il_khanate_converts
		}
		if = {
			limit = { primary_title = { title = e_golden_horde } }
			set_global_flag = golden_horde_converts
		}
		if = {
			limit = { primary_title = { title = e_chagatai } }
			set_global_flag = chagatai_converts
		}
	}
	
	option = {	# Orthodox
		name = "EVTOPTA60010"
		trigger = {
			character = ROOT
		}
		religion = orthodox
		any_realm_character = {
			limit = { religion = tengri_pagan }
			religion = orthodox
			if = {
				limit = {
					is_playable = yes
					capital_scope = {
						religion = tengri_pagan
					}
				}
				capital_scope = {
					religion = orthodox
				}
			}
		}
	}
	# Other rulers are informed
	option = {
		name = "EVTOPTB60010"
		trigger = {
			religion_group = muslim
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EXCELLENT"
		trigger = {
			religion_group = christian
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTD60010"
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			NOT = { character = ROOT }
		}
	}
}

# Horde converts to Sunni
character_event = {
	id = 60012
	title = "EVTNAME60010"
	desc = "EVTDESC60012"
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_religion"
	major = yes
	
	only_playable = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	trigger = {
		primary_title = {
			OR = {
				title = e_il-khanate
				title = e_golden_horde
				title = e_chagatai
			}
			holder_scope = {
				religion = tengri_pagan
				NOT = { trait = zealous }
			}
		}
		any_realm_province = { religion = sunni }
		OR = {
			AND = {
				primary_title = { title = e_il-khanate }
				had_global_flag = { flag = il_khanate_arrival days = 14600 }
				NOT = { had_global_flag = { flag = il_khanate_arrival days = 29200 } }
				NOT = { has_global_flag = il_khanate_converts }
			}
			AND = {
				primary_title = { title = e_golden_horde }
				had_global_flag = { flag = golden_horde_arrival days = 14600 }
				NOT = { had_global_flag = { flag = golden_horde_arrival days = 29200 } }
				NOT = { has_global_flag = golden_horde_converts }
			}
			AND = {
				primary_title = { title = e_chagatai }
				had_global_flag = { flag = chagatai_arrival days = 14600 }
				NOT = { had_global_flag = { flag = chagatai_arrival days = 29200 } }
				NOT = { has_global_flag = chagatai_converts }
			}
		}
	}

	mean_time_to_happen = {
		months = 420
		modifier = {
			factor = 0.75
			any_demesne_province = {
				is_capital = yes
				religion = sunni
			}
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { title = e_il-khanate } }
			set_global_flag = il_khanate_converts
		}
		if = {
			limit = { primary_title = { title = e_golden_horde } }
			set_global_flag = golden_horde_converts
		}
		if = {
			limit = { primary_title = { title = e_chagatai } }
			set_global_flag = chagatai_converts
		}
	}
	
	option = {	# Sunni
		name = "EVTOPTA60010"
		trigger = {
			character = ROOT
		}
		religion = sunni
		any_realm_character = {
			limit = { religion = tengri_pagan }
			religion = sunni
			if = {
				limit = {
					is_playable = yes
					capital_scope = {
						religion = tengri_pagan
					}
				}
				capital_scope = {
					religion = sunni
				}
			}
		}
	}
	# Other rulers are informed
	option = {
		name = "EXCELLENT"
		trigger = {
			religion_group = muslim
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTC60010"
		trigger = {
			religion_group = christian
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTD60010"
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			NOT = { character = ROOT }
		}
	}
}

# Horde converts to Shiite
character_event = {
	id = 60013
	title = "EVTNAME60010"
	desc = "EVTDESC60013"
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_religion"
	
	major = yes
	
	only_playable = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	trigger = {
		primary_title = {
			OR = {
				title = e_il-khanate
				title = e_golden_horde
				title = e_chagatai
			}
			holder_scope = {
				religion = tengri_pagan
				NOT = { trait = zealous }
			}
		}
		any_realm_province = { religion = shiite }
		OR = {
			AND = {
				primary_title = { title = e_il-khanate }
				had_global_flag = { flag = il_khanate_arrival days = 14600 }
				NOT = { had_global_flag = { flag = il_khanate_arrival days = 29200 } }
				NOT = { has_global_flag = il_khanate_converts }
			}
			AND = {
				primary_title = { title = e_golden_horde }
				had_global_flag = { flag = golden_horde_arrival days = 14600 }
				NOT = { had_global_flag = { flag = golden_horde_arrival days = 29200 } }
				NOT = { has_global_flag = golden_horde_converts }
			}
			AND = {
				primary_title = { title = e_chagatai }
				had_global_flag = { flag = chagatai_arrival days = 14600 }
				NOT = { had_global_flag = { flag = chagatai_arrival days = 29200 } }
				NOT = { has_global_flag = chagatai_converts }
			}
		}
	}

	mean_time_to_happen = {
		months = 420
		modifier = {
			factor = 0.75
			any_demesne_province = {
				is_capital = yes
				religion = shiite
			}
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { title = e_il-khanate } }
			set_global_flag = il_khanate_converts
		}
		if = {
			limit = { primary_title = { title = e_golden_horde } }
			set_global_flag = golden_horde_converts
		}
		if = {
			limit = { primary_title = { title = e_chagatai } }
			set_global_flag = chagatai_converts
		}
	}
	
	option = {	# Shiite
		name = "EVTOPTA60010"
		trigger = {
			character = ROOT
		}
		religion = shiite
		any_realm_character = {
			limit = { religion = tengri_pagan }
			religion = shiite
			if = {
				limit = {
					is_playable = yes
					capital_scope = {
						religion = tengri_pagan
					}
				}
				capital_scope = {
					religion = shiite
				}
			}
		}
	}
	# Other rulers are informed
	option = {
		name = "EXCELLENT"
		trigger = {
			religion_group = muslim
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTC60010"
		trigger = {
			religion_group = christian
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTD60010"
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			NOT = { character = ROOT }
		}
	}
}

# Horde converts to Nestorian
character_event = {
	id = 60014
	title = "EVTNAME60010"
	desc = "EVTDESC60014"
	picture = "GFX_evt_mongols"
	border = "GFX_event_normal_frame_war"
	major = yes
	
	only_playable = yes
	only_independent = yes
	only_capable = yes
	min_age = 16
	prisoner = no
	
	trigger = {
		primary_title = {
			OR = {
				title = e_il-khanate
				title = e_golden_horde
				title = e_chagatai
			}
			holder_scope = {
				religion = tengri_pagan
				NOT = { trait = zealous }
			}
		}
		any_realm_title = {
			tier = COUNT
			count = 1
		}
		OR = {
			AND = {
				primary_title = { title = e_il-khanate }
				had_global_flag = { flag = il_khanate_arrival days = 14600 }
				NOT = { had_global_flag = { flag = il_khanate_arrival days = 29200 } }
				NOT = { has_global_flag = il_khanate_converts }
			}
			AND = {
				primary_title = { title = e_golden_horde }
				had_global_flag = { flag = golden_horde_arrival days = 14600 }
				NOT = { had_global_flag = { flag = golden_horde_arrival days = 29200 } }
				NOT = { has_global_flag = golden_horde_converts }
			}
			AND = {
				primary_title = { title = e_chagatai }
				had_global_flag = { flag = chagatai_arrival days = 14600 }
				NOT = { had_global_flag = { flag = chagatai_arrival days = 29200 } }
				NOT = { has_global_flag = chagatai_converts }
			}
		}
	}

	mean_time_to_happen = {
		months = 420
		modifier = {
			factor = 0.75
			any_demesne_province = {
				is_capital = yes
				religion = nestorian
			}
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { title = e_il-khanate } }
			set_global_flag = il_khanate_converts
		}
		if = {
			limit = { primary_title = { title = e_golden_horde } }
			set_global_flag = golden_horde_converts
		}
		if = {
			limit = { primary_title = { title = e_chagatai } }
			set_global_flag = chagatai_converts
		}
	}
	
	option = {	# Nestorian
		name = "EVTOPTA60010"
		trigger = {
			character = ROOT
		}
		religion = nestorian		
		capital_scope = { religion = nestorian }
		any_realm_character = {
			limit = { religion = tengri_pagan }
			religion = nestorian
			if = {
				limit = {
					is_playable = yes
					capital_scope = {
						religion = tengri_pagan
					}
				}
				capital_scope = {
					religion = nestorian
				}
			}
		}
	}
	# Other rulers are informed
	option = {
		name = "EVTOPTB60010"
		trigger = {
			religion_group = muslim
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EXCELLENT"
		trigger = {
			religion_group = christian
			NOT = { character = ROOT }
		}
	}
	option = {
		name = "EVTOPTD60010"
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			NOT = { character = ROOT }
		}
	}
}

### Mongols sack European cities ###

# Mongols sack Kiev
narrative_event = {
	id = 60100
	title = "EVTNAME60100"
	desc = "EVTDESC60100"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_kiev }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_kiev }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_kiev
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.1 }
		}
	}
	
	option = {
		name = "EVTOPTA60100"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60100"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Novgorod
narrative_event = {
	id = 60101
	title = "EVTNAME60101"
	desc = "EVTDESC60101"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_novgorod }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_novgorod }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_novgorod
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.2 }
		}
	}
	
	option = {
		name = EVTOPTA60101 # Perhaps their bloodlust has been sated now
		trigger = { NOT = { culture = mongol } }
	}
	option = {
		name = EVTOPTB60101 # May the snows of the frozen north claim them
		trigger = {
			culture = mongol
		}
	}
}

# Mongols sack Krakow
narrative_event = {
	id = 60102
	title = "EVTNAME60102"
	desc = "EVTDESC60102"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_krakow }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_krakow }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_krakow
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.3 }
		}
	}
	
	option = {
		name = "EVTOPTA60102"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60102"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Aachen
narrative_event = {
	id = 60103
	title = "EVTNAME60103"
	desc = "EVTDESC60103"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_aachen }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_aachen }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_aachen
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.4 }
		}
	}
	
	option = {
		name = "EVTOPTA60103"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60103"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Paris
narrative_event = {
	id = 60104
	title = "EVTNAME60104"
	desc = "EVTDESC60104"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_paris }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_paris }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_paris
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.5 }
		}
	}
	
	option = {
		name = "EVTOPTA60104"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60104"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack London
narrative_event = {
	id = 60105
	title = "EVTNAME60105"
	desc = "EVTDESC60105"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_london }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_london }

		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_london
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.6 }
		}
	}
	
	option = {
		name = "EVTOPTA60105"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60105"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Rome
narrative_event = {
	id = 60106
	title = "EVTNAME60106"
	desc = "EVTDESC60106"
	major = yes
	
	picture = "GFX_evt_rome_falls"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_rome }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_roma }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_rome
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.7 }
		}
	}
	
	option = {
		name = "EVTOPTA60106"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60106"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Venice
narrative_event = {
	id = 60107
	title = "EVTNAME60107"
	desc = "EVTDESC60107"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_venice }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_venezia }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_venice
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.8 }
		}
	}
	
	option = {
		name = "EVTOPTA60107"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60107"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Constantinople
narrative_event = {
	id = 60108
	title = "EVTNAME60108"
	desc = "EVTDESC60108"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_constantinople }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_constantinople }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_constantinople
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.9 }
		}
	}
	
	option = {
		name = "EVTOPTA60108"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60108"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Lisbon
narrative_event = {
	id = 60109
	title = "EVTNAME60109"
	desc = "EVTDESC60109"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_lisbon }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_lisboa }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_lisbon
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.10 }
		}
	}
	
	option = {
		name = "EVTOPTA60109"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60109"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Smolensk
narrative_event = {
	id = 60110
	title = "EVTNAME60110"
	desc = "EVTDESC60110"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_smolensk }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_smolensk }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_smolensk
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.11 }
		}
	}
	
	option = {
		name = "EVTOPTA60110"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60110"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Prague
narrative_event = {
	id = 60111
	title = "EVTNAME60111"
	desc = "EVTDESC60111"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_prague }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_praha }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_prague
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.12 }
		}
	}
	
	option = {
		name = "EVTOPTA60111"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60111"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Vienna
narrative_event = {
	id = 60112
	title = "EVTNAME60112"
	desc = "EVTDESC60112"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_vienna }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_wien }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_vienna
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.13 }
		}
	}
	
	option = {
		name = "EVTOPTA60112"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60112"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Esztergom
narrative_event = {
	id = 60113
	title = "EVTNAME60113"
	desc = "EVTDESC60113"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_esztergom }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_esztergom }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_esztergom
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.14 }
		}
	}
	
	option = {
		name = "EVTOPTA60113"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60113"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Athens
narrative_event = {
	id = 60114
	title = "EVTNAME60114"
	desc = "EVTDESC60114"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_athens }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_athens }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_athens
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.15 }
		}
	}
	
	option = {
		name = "EVTOPTA60114"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60114"
		trigger = { religion_group = muslim }
	}
}

# Mongols sack Belgrade
narrative_event = {
	id = 60115
	title = "EVTNAME60115"
	desc = "EVTDESC60115"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_belgrade }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_belgrade }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_belgrade
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.16 }
		}
	}
	
	option = {
		name = "EVTOPTA60115"
		trigger = { NOT = { religion_group = muslim } }
	}
	option = {
		name = "EVTOPTB60115"
		trigger = { religion_group = muslim }
	}
}

### Mongols sack Middle Eastern cities ###

# Mongols sack Baghdad
narrative_event = {
	id = 60116
	title = "EVTNAME60116"
	desc = "EVTDESC60116"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		FROM = { title = b_bagdad }
		NOT = { has_global_flag = mongols_sack_baghdad }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_baghdad
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.17 }
		}
	}
	
	option = {
		name = "EVTOPTA60116"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60116"
		trigger = { NOT = { religion_group = muslim } }
	}
}

# Mongols sack Damascus
narrative_event = {
	id = 60117
	title = "EVTNAME60117"
	desc = "EVTDESC60117"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_damascus }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_damascus }

		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_damascus
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.18 }
		}
	}
	
	option = {
		name = "EVTOPTA60117"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60117"
		trigger = { NOT = { religion_group = muslim } }
	}
}

# Mongols sack Jerusalem
narrative_event = {
	id = 60118
	title = "EVTNAME60118"
	desc = "EVTDESC60118"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_jerusalem }
		NOT = {
			OR = {
				religion_group = muslim 
				religion_group = christian 
			}
		}
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_jerusalem }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_jerusalem
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.19 }
		}
	}
	
	option = {
		name = "EVTOPTA60118"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60118"
		trigger = { NOT = { religion_group = muslim } }
	}
}

# Mongols sack Alexandria
narrative_event = {
	id = 60119
	title = "EVTNAME60119"
	desc = "EVTDESC60119"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_alexandria }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_alexandria }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_alexandria
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.20 }
		}
	}
	
	option = {
		name = "EVTOPTA60119"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60119"
		trigger = { NOT = { religion_group = muslim } }
	}
}

# Mongols sack Cairo
narrative_event = {
	id = 60120
	title = "EVTNAME60120"
	desc = "EVTDESC60120"
	major = yes
	
	picture = "GFX_evt_mongols"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_cairo }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_cairo }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_cairo
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.21 }
		}
	}
	
	option = {
		name = "EVTOPTA60120"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60120"
		trigger = { NOT = { religion_group = muslim } }
	}
}

# Mongols sack Mecca
narrative_event = {
	id = 60121
	title = "EVTNAME60121"
	desc = "EVTDESC60121"
	major = yes
	
	picture = "GFX_evt_mecca_falls_soa"
	border = "GFX_event_narrative_frame_war"
	
	is_triggered_only = yes
	
	culture = mongol
	
	trigger = {
		NOT = { has_global_flag = mongols_sack_mecca }
		NOT = { religion_group = muslim }
		OR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
		FROM = { title = b_mecca }
		NOT = {
			FROM = {
				owner = {
					OR = {
						has_landed_title = e_il-khanate
						has_landed_title = e_golden_horde
						has_landed_title = e_chagatai
						has_landed_title = e_mongol_empire
						any_liege = { has_landed_title = e_il-khanate }
						any_liege = { has_landed_title = e_golden_horde }
						any_liege = { has_landed_title = e_chagatai }
						any_liege = { has_landed_title = e_mongol_empire }
					}
				}
			}
		}		
	}
	
	major_trigger = {
		NOR = {
			has_landed_title = e_il-khanate
			has_landed_title = e_golden_horde
			has_landed_title = e_chagatai
			has_landed_title = e_mongol_empire
			any_liege = { has_landed_title = e_il-khanate }
			any_liege = { has_landed_title = e_golden_horde }
			any_liege = { has_landed_title = e_chagatai }
			any_liege = { has_landed_title = e_mongol_empire }
		}
	}
	
	immediate = {
		set_global_flag = mongols_sack_mecca
		any_playable_ruler = {
			limit = {
				ai = no
				OR = {
					has_landed_title = e_il-khanate
					has_landed_title = e_golden_horde
					has_landed_title = e_chagatai
					has_landed_title = e_mongol_empire
					any_liege = { has_landed_title = e_il-khanate }
					any_liege = { has_landed_title = e_golden_horde }
					any_liege = { has_landed_title = e_chagatai }
					any_liege = { has_landed_title = e_mongol_empire }
				}
			}
			narrative_event = { id = TOG.22 }
		}
	}
	
	option = {
		name = "EVTOPTA60121"
		trigger = { religion_group = muslim }
	}
	option = {
		name = "EVTOPTB60121"
		trigger = { NOT = { religion_group = muslim } }
	}
}


##################################
# Rise of the Seljuks
##################################

# Seljuk distinguishes himself in a Turkish court
character_event = {
	id = 60200
	desc = EVTDESC60200
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	only_playable = yes
	
	trigger = {
		is_landed = yes
		war = no
		OR = {
			is_nomadic = yes
			AND = {
				is_tribal = yes
				NOT = { has_dlc = "Horse Lords" }
			}
		}
		OR = {
			culture = turkish
			culture = cuman
			culture = uyghur
			culture = karluk
		}
		NOT = {
			has_game_rule = {
				name = turkic_invasions
				value = off
			}
		}
		OR = {
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = historical
				}
				year = 980
				NOT = { year = 1000 }
			}
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = random
				}
				year = 809
				NOT = { year = 1200 }
			}
		}
		NOT = { has_global_flag = seljuk_spawned }
	}
	
	mean_time_to_happen = {
		years = 2
	}
	
	option = { # A most capable young man
		name = EVTOPTA60200
		set_global_flag = seljuk_spawned
		create_random_soldier = {
			random_traits = no
			historical = yes
			dynasty = 613 # Seljuk
			name = Seljuk
			culture = turkish
			religion = ROOT
			age = 20
			attributes = {
				martial = 12
				diplomacy = 8
				stewardship = 5
				intrigue = 4
				learning = 3
			}
			health = 7
			fertility = 0.8
			trait = brilliant_strategist
			trait = wroth
			trait = cruel
			trait = proud
			trait = ambitious
		}
		new_character = {
			set_character_flag = seljuk_himself
			if = {
				limit = { religion = sunni }
				add_trait = zealous
			}
		}
	}
}

# Seljuk and his men consider starting an adventure
character_event = {
	id = 60201
	desc = EVTDESC60201
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	prisoner = no
	only_capable = yes
	has_character_flag = seljuk_himself
	
	trigger = {
		war = no
		OR = {
			is_ruler = no
			lower_tier_than = KING
			AND = {
				is_nomadic = yes
				NOT = { tier = EMPEROR }
			}
		}
		
		any_independent_ruler = {
			war = no
			NOT = { same_realm = ROOT }
			is_nomadic = no
			is_tributary = no
			OR = {
				630 = { owner = { same_realm = PREVPREV } } #Merv
				631 = { owner = { same_realm = PREVPREV } } #Dihistan
				632 = { owner = { same_realm = PREVPREV } } #Khorasan
			}
		}

		NOR = {
			trait = blinded
			trait = eunuch
			trait = infirm
			trait = content
			trait = craven
			trait = depressed
			trait = imbecile
			liege = { war = yes }
			has_character_flag = seljuk_started_adventure
		}
	}
	
	mean_time_to_happen = {
		years = 5
		modifier = {
			factor = 0.5
			age = 25
		}
		modifier = {
			factor = 0.5
			age = 30
		}
		modifier = {
			factor = 0.5
			age = 35
		}
	}

	immediate = {
		add_trait = adventurer
		set_character_flag = seljuk_started_adventure
	}
	
	option = { # Merv it is!
		name = EVTOPTA60201
		trigger = {
			630 = { # Merv
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 1000
		}
		630 = {
			province_event = {
				id = 60202
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Khorasan
		name = EVTOPTB60201
		trigger = {
			632 = { # Tus
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 10000
		}
		632 = {
			province_event = {
				id = 60202
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Dihistan
		name = EVTOPTC60201
		trigger = {
			631 = { # Dihistan
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		631 = {
			province_event = {
				id = 60202
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = {
		name = EVTOPTD60201 #I am fine where I am
		trigger = { ai = no }
	}
}

# Ping the target province
province_event = {
	id = 60202
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				FROM = { is_ruler = yes }
			}
			FROM = {
				character_event = {
					id = 60204
				}
			}
		}
		if = {
			limit = {
				FROM = { is_ruler = no }
			}
			FROM = {
				character_event = {
					id = 60203
				}
			}
		}
	}
}

# The landless Seljuk and his men start an adventure
character_event = {
	id = 60203
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60205
				days = 1
			}
		}
		
		liege = {
			if = {
				limit = { is_nomadic = yes }
				ROOT = { set_character_flag = will_be_nomadic }
			}
			capital_scope = {
				FROM = {
					owner = {
						top_liege = {
							ROOT = {
								set_defacto_liege = ROOT
								create_title = {
									tier = DUKE
									landless = yes
									temporary = yes
									culture = ROOT
									name = "CLAIMANT_ADVENTURE"
									holder = ROOT
								}
								if = {
									limit = { NOT = { has_character_flag = will_be_nomadic } }
									set_government_type = tribal_government
								}
								if = {
									limit = { has_character_flag = will_be_nomadic }
									clr_character_flag = will_be_nomadic
									set_government_type = nomadic_government
									population = 5000
								}
								set_character_flag = duchy_adventurer
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								war = {
									target = PREV
									casus_belli = duchy_adventure
									thirdparty_title = PREVPREVPREV
									tier = DUKE
									infamy = 0
								}
							}
						}
					}
				}
			}
		}
		
		if = {
			limit = { NOT = { religion_group = muslim } }
			add_trait = zealous
			religion = sunni
		}
		
		# Create some characters
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 22
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60203: Seljuk starts his first war as a landless character!"
	}
}

# The landed Seljuk and his men start an adventure
character_event = {
	id = 60204
	desc = EVTDESC60204
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				tier = BARON
			}
			abdicate = yes
			character_event = { id = 60203 }
			break = yes
		}
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60205
				days = 1
			}
		}
		
		FROM = {
			owner = {
				top_liege = {
					ROOT = {
						capital_scope = {
							ROOT = {
								if = {
									limit = { lower_tier_than = COUNT }
									create_title = {
										tier = DUKE
										landless = yes
										temporary = yes
										culture = ROOT
										name = "CLAIMANT_ADVENTURE"
										holder = ROOT
									}
								}
								if = {
									limit = { is_nomadic = yes }
									population = 5000
								}
								set_character_flag = duchy_adventurer
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = seljuk_event_troops
								}
							}
						}
						war = {
							target = PREV
							casus_belli = duchy_adventure
							thirdparty_title = PREVPREVPREV
							tier = DUKE
							infamy = 0
						}
					}
				}
			}
		}
		
		if = {
			limit = { NOT = { religion_group = muslim } }
			add_trait = zealous
			religion = sunni
		}
		
		# Create some characters
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 22
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60204: Seljuk starts his first war as a landed character!"
	}
	
	option = {
		name = EVTOPTA60204
	}
}

# Notify Seljuk's old liege
character_event = {
	id = 60205
	desc = EVTDESC60205
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_ruler = yes } # The DoW worked and the adventurer has a temporary title
	}
	
	option = {
		name = EVTOPTA60205
	}
}

# Seljuk is successful!
# Fired from the duchy_adventure CB
narrative_event = {
	id = 60206
	title = EVTNAME60206
	desc = EVTDESC60206
	picture = GFX_evt_mongols
	border = GFX_event_narrative_frame_war
	
	is_triggered_only = yes
	
	major = yes
	
	immediate = {
		set_character_flag = seljuk_reinforcements
		set_defacto_liege = ROOT
		
		if = {
			limit = { religion_group = muslim }
			piety = 100
		}
		
		prestige = 500
		
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						horse_archers = { 2700 2700 }
						light_cavalry = { 1600 1600 }
						light_infantry = { 541 541 }
						heavy_infantry = { 210 210 }
						knights = { 47 47 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
			}
		}
		
		log = "60206: Seljuk wins his first war!"
	}
	
	option = {
		name = EVTOPTA60206
		trigger = {
			has_character_flag = seljuk_himself
		}
	}
	option = {
		name = EVTOPTB60206
		trigger = {
			NOT = { has_character_flag = seljuk_himself }
			OR = {
				culture = turkish
				culture = karluk
				culture = cuman
				culture = pecheneg
			}
		}
	}
	option = {
		name = EVTOPTC60206
		trigger = {
			NOT = { has_character_flag = seljuk_himself }
			NOT = {
				OR = {
					culture = turkish
					culture = karluk
					culture = cuman
					culture = pecheneg
				}
			}
		}
	}
}

# Seljuk's successor revitalizes the new state
character_event = {
	id = 60207
	desc = EVTDESC60207
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	only_playable = yes
	only_independent = yes
	religion_group = muslim
	has_global_flag = seljuk_spawned
	war = no
	
	trigger = {
		dynasty = 613 # Seljuk
		year = 980
		higher_tier_than = duke
		NOT = { higher_tier_than = king }
		martial = 7
		NOT = { has_earmarked_regiments = seljuk_event_troops }
		primary_title = { NOT = { has_title_flag = seljuk_state_revitalised } }
		NOR = {
			year = 1100
			realm_size = 150
			trait = blinded
			trait = eunuch
			trait = infirm
			trait = content
			trait = craven
			trait = depressed
			trait = imbecile
			trait = slow
			has_character_flag = seljuk_himself
			has_character_flag = seljuk_reinforcements
		}
		OR = {
			father = { has_character_flag = seljuk_himself }
			father = { father = { has_character_flag = seljuk_himself } }
		}
	}
	
	mean_time_to_happen = {
		months = 360
		modifier = {
			factor = 0.5
			martial = 9
		}
		modifier = {
			factor = 0.5
			martial = 11
		}
		modifier = {
			factor = 0.5
			martial = 13
		}
	}
	
	immediate = {
		set_character_flag = seljuk_reinforcements
		primary_title = { set_global_flag = seljuk_state_revitalised }
		
		piety = 250
		
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
					cannot_inherit = yes
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
					cannot_inherit = yes
				}
				if = {
					limit = {
						martial = 12
					}
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
						cannot_inherit = yes
					}
				}
				if = {
					limit = {
						martial = 15
					}
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
						cannot_inherit = yes
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA60207
	}
}

# Event troops no longer needed
character_event = {
	id = 60208
	desc = EVTDESC60208
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war

	only_playable = yes
	has_character_flag = seljuk_reinforcements
	
	trigger = {
		war = no
		has_earmarked_regiments = seljuk_event_troops
		tier = EMPEROR
		realm_size = 150
	}
	
	mean_time_to_happen = {
		years = 5
	}
	
	option = {
		name = EVTOPTA60208
		disband_event_forces = seljuk_event_troops
	}
}	

# Prompt AI to use the manifest destiny CB
character_event = {
	id = 60209
	
	hide_window = yes
	
	only_playable = yes
	only_independent = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		ai = yes
		OR = {
			dynasty = 613 # Seljuks
			dynasty = 800 #Timurids
		}
		war = no
		wealth = 0
		mercenary = no
		is_tributary = no
		is_ill = no
		has_regent = no
		NOR = {
			realm_size = 150
			trait = content
			trait = humble
			trait = craven
			is_maimed_trigger = yes
			trait = depressed
			trait = infirm
			is_inaccessible_trigger = yes
		}
		is_not_busy_trigger = yes
		any_independent_ruler = {
			reverse_realm_levy_diff = { who = ROOT value = 10000 }
			any_realm_title = {
				count = 3
				tier = COUNT
				kingdom = {
					capital_scope = {
						OR = {
							region = custom_persia
							region = custom_baluchistan
							region = custom_afghanistan
							region = custom_khwarizm
							region = custom_mesopotamia
							region = custom_azerbaijan
							region = custom_georgia
							region = custom_alania
							region = custom_armenia
							region = custom_trebizond
							region = custom_nikaea
							region = custom_syria
							region = custom_arabia
							region = custom_jerusalem
							region = custom_egypt
							region = custom_africa
						}
					}
					ROOT = {
						any_realm_province = {
							OR = {
								county = { de_jure_liege_or_above  = PREVPREVPREV }
								any_neighbor_province = {
									county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
								}
							}
						}
					}
				}
			}
			any_realm_province = {
				any_neighbor_province = {
					owner = { same_realm = ROOT }
				}
			}
			NOR = {
				same_realm = ROOT
				reverse_has_truce = ROOT
				is_married = ROOT
				is_allied_with = ROOT
				has_non_aggression_pact_with = ROOT
				reverse_opinion = { who = ROOT value = 0 }
				pays_tribute_to = ROOT
				ROOT = { rightful_religious_head = PREV }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 12
	}
	
	immediate = {
		#first priority
		random_independent_ruler = {
			limit = {
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				any_realm_title = {
					count = 3
					tier = COUNT
					kingdom = {
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_baluchistan
								region = custom_afghanistan
								region = custom_mesopotamia
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				any_realm_province = {
					any_neighbor_province = {
						owner = { same_realm = ROOT }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					is_married = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					reverse_opinion = { who = ROOT value = 0 }
					pays_tribute_to = ROOT
					ROOT = { rightful_religious_head = PREV }
				}
			}
			save_event_target_as = target_ruler
			random_realm_title = {
				limit = {
					tier = COUNT
					kingdom = {
						event_target:target_ruler = {
							num_of_realm_counties = {
								value = 3
								title = PREV
							}
						}
						capital_scope = {
							OR = {
								region = custom_persia
								region = custom_baluchistan
								region = custom_afghanistan
								region = custom_mesopotamia
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				kingdom = {
					ROOT = {
						war = {
							casus_belli = manifest_destiny_invasion
							target = PREVPREVPREV
							thirdparty_title = PREV
						}
					}
				}
				break = yes
			}
		}
		#second priority
		random_independent_ruler = {
			limit = {
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				any_realm_title = {
					count = 3
					tier = COUNT
					kingdom = {
						capital_scope = {
							OR = {
								region = custom_armenia
								region = custom_nikaea
								region = custom_syria
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				any_realm_province = {
					any_neighbor_province = {
						owner = { same_realm = ROOT }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					is_married = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					reverse_opinion = { who = ROOT value = 0 }
					pays_tribute_to = ROOT
					ROOT = { rightful_religious_head = PREV }
				}
			}
			save_event_target_as = target_ruler
			random_realm_title = {
				limit = {
					tier = COUNT
					kingdom = {
						event_target:target_ruler = {
							num_of_realm_counties = {
								value = 3
								title = PREV
							}
						}
						capital_scope = {
							OR = {
								region = custom_armenia
								region = custom_nikaea
								region = custom_syria
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				kingdom = {
					ROOT = {
						war = {
							casus_belli = manifest_destiny_invasion
							target = PREVPREVPREV
							thirdparty_title = PREV
						}
					}
				}
				break = yes
			}
		}
		#third priority
		random_independent_ruler = {
			limit = {
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				any_realm_title = {
					count = 3
					tier = COUNT
					kingdom = {
						capital_scope = {
							OR = {
								region = custom_azerbaijan
								region = custom_trebizond
								region = custom_arabia
								region = custom_jerusalem
								region = custom_egypt
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				any_realm_province = {
					any_neighbor_province = {
						owner = { same_realm = ROOT }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					is_married = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					reverse_opinion = { who = ROOT value = 0 }
					pays_tribute_to = ROOT
					ROOT = { rightful_religious_head = PREV }
				}
			}
			save_event_target_as = target_ruler
			random_realm_title = {
				limit = {
					tier = COUNT
					kingdom = {
						event_target:target_ruler = {
							num_of_realm_counties = {
								value = 3
								title = PREV
							}
						}
						capital_scope = {
							OR = {
								region = custom_azerbaijan
								region = custom_trebizond
								region = custom_arabia
								region = custom_jerusalem
								region = custom_egypt
							}
						}
						ROOT = {
							any_realm_province = {
								OR = {
									county = { de_jure_liege_or_above  = PREVPREVPREV }
									any_neighbor_province = {
										county = { de_jure_liege_or_above  = PREVPREVPREVPREV }
									}
								}
							}
						}
					}
				}
				kingdom = {
					ROOT = {
						war = {
							casus_belli = manifest_destiny_invasion
							target = PREVPREVPREV
							thirdparty_title = PREV
						}
					}
				}
			}
		}
	}
}

##################################
# Rise of the Timurids
##################################

# Timur distinguishes himself at a Mongol court
character_event = {
	id = 60300
	desc = EVTDESC60300
	
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	only_playable = yes
	culture = mongol
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = turkic_invasions
				value = off
			}
		}
		OR = {
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = historical
				}
				has_global_flag = mongol_empire_arrival
				year = 1350
				NOT = { year = 1370 }
			}
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = random
				}
				year = 1200
			}
		}
		
		higher_tier_than = count
		
		NOT = { has_global_flag = timur_spawned }
		
		any_realm_province = {
			OR = {
				region = custom_persia
				region = custom_baluchistan
				region = custom_afghanistan
				region = custom_khwarizm
				region = custom_mesopotamia
			}
		}
	}
	
	mean_time_to_happen = {
		months = 24
	}

	option = { # A most capable young man
		name = EVTOPTA60300
		
		set_global_flag = timur_spawned
		
		create_character = {
			random_traits = no
			historical = yes
			name = "Timur"
			dynasty = 800
			religion = ROOT
			culture = ROOT
			female = no
			age = 18
			attributes = {
				martial = 12
				diplomacy = 8
				stewardship = 9
				intrigue = 9
				learning = 6
			}
			health = 6
			fertility = 0.8
			trait = brilliant_strategist
			trait = diligent
			trait = ambitious
			trait = proud
			trait = quick
			trait = clubfooted
		}
		
		new_character = {
			set_character_flag = timurid_himself
		}
	}
}

# Timur and his men consider starting an adventure
character_event = {
	id = 60301
	desc = EVTDESC60201
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	prisoner = no
	only_capable = yes
	has_character_flag = timurid_himself
	
	trigger = {
		war = no
		OR = {
			is_ruler = no
			lower_tier_than = KING
			AND = {
				is_nomadic = yes
				NOT = { tier = EMPEROR }
			}
		}
		
		any_independent_ruler = {
			war = no
			NOT = { same_realm = ROOT }
			is_nomadic = no
			is_tributary = no
			OR = {
				630 = { owner = { same_realm = PREVPREV } } #Merv
				631 = { owner = { same_realm = PREVPREV } } #Dihistan
				632 = { owner = { same_realm = PREVPREV } } #Khorasan
				903 = { owner = { same_realm = PREVPREV } } #Samarkand
				904 = { owner = { same_realm = PREVPREV } } #Balkh
			}
		}
		
		NOR = {
			trait = blinded
			trait = eunuch
			trait = infirm
			trait = content
			trait = craven
			trait = depressed
			trait = imbecile
			liege = { war = yes }
			has_character_flag = timur_started_adventure
		}
	}
	
	mean_time_to_happen = {
		years = 5
		modifier = {
			factor = 0.5
			age = 25
		}
		modifier = {
			factor = 0.5
			age = 30
		}
		modifier = {
			factor = 0.5
			age = 35
		}
	}	
	
	immediate = {
		add_trait = adventurer
		set_character_flag = timur_started_adventure
	}
	
	option = { # Merv it is!
		name = EVTOPTA60201
		trigger = {
			630 = { # Merv
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		
		ai_chance = {
			factor = 10000
		}
		
		630 = {
			province_event = {
				id = 60302
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Khorasan
		name = EVTOPTB60201
		trigger = {
			632 = { # Tus
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 1000
		}
		632 = {
			province_event = {
				id = 60302
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Dihistan
		name = EVTOPTC60201
		trigger = {
			631 = { # Dihistan
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		631 = {
			province_event = {
				id = 60302
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Samarkand
		name = EVTOPTD60201
		trigger = {
			903 = { # Samarkand
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		903 = {
			province_event = {
				id = 60302
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Balkh
		name = EVTOPTE60201
		trigger = {
			904 = { # Balkh
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		904 = {
			province_event = {
				id = 60302
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
}

# Ping the target province
province_event = {
	id = 60302
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				FROM = { is_ruler = yes }
			}
			FROM = {
				character_event = {
					id = 60304
				}
			}
		}
		if = {
			limit = {
				FROM = { is_ruler = no }
			}
			FROM = {
				character_event = {
					id = 60303
				}
			}
		}
	}
}

# The landless Timur and his men start an adventure
character_event = {
	id = 60303
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60305
				days = 1
			}
		}
		
		liege = {
			if = {
				limit = { is_nomadic = yes }
				ROOT = { set_character_flag = will_be_nomadic }
			}
			capital_scope = {
				FROM = {
					owner = {
						top_liege = {
							ROOT = {
								set_defacto_liege = ROOT
								create_title = {
									tier = DUKE
									landless = yes
									temporary = yes
									culture = ROOT
									name = "CLAIMANT_ADVENTURE"
									holder = ROOT
								}
								if = {
									limit = { has_character_flag = will_be_nomadic }
									clr_character_flag = will_be_nomadic
									set_government_type = nomadic_government
									population = 5000
								}								
								set_character_flag = duchy_adventurer

								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}								
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								war = {
									target = PREV
									casus_belli = duchy_adventure
									thirdparty_title = PREVPREVPREV
									tier = DUKE
									infamy = 0
								}
							}
						}
					}
				}
			}
		}
		
		# Create some characters
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 28
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 24
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 23
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60303: Timur starts his first war (landless)!"
	}
}

# The landed Timur and his men start an adventure
character_event = {
	id = 60304
	desc = EVTDESC60304
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				tier = BARON
			}
			abdicate = yes
			character_event = { id = 60303 }
			break = yes
		}
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60305
				days = 1
			}
		}
		
		FROM = {
			owner = {
				top_liege = {
					ROOT = {
						capital_scope = {
							ROOT = {
								set_character_flag = duchy_adventurer
								if = {
									limit = { is_nomadic = yes }
									population = 5000
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = timur_event_troops
								}
							}
						}
						
						war = {
							target = PREV
							casus_belli = duchy_adventure
							thirdparty_title = PREVPREVPREV
							tier = DUKE
							infamy = 0
						}
					}
				}
			}
		}
		
		# Create some characters
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 28
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 24
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 23
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60303: Timur starts his first war (landed)!"
	}
	
	option = {
		name = EVTOPTA60204
	}
}

# Notify Timur's old liege
character_event = {
	id = 60305
	desc = EVTDESC60205
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_ruler = yes } # The DoW worked and the adventurer has a temporary title
	}
	
	option = {
		name = EVTOPTA60305
	}
}

# Timur is successful!
# Fired from the duchy_adventure CB
narrative_event = {
	id = 60306
	title = EVTNAME60306
	desc = EVTDESC60306
	picture = GFX_evt_mongols
	border = GFX_event_narrative_frame_war
	
	is_triggered_only = yes
	
	major = yes
	
	immediate = {
		set_character_flag = timur_reinforcements
		set_defacto_liege = ROOT
		
		prestige = 500
		
		if = {
			limit = { religion_group = muslim }
			piety = 100
		}
		
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = seljuk_event_troops
				}
				
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = seljuk_event_troops
					}
				}
			}
		}
		
		log = "60306: Timur wins his first war!"
	}
	
	option = {
		name = EVTOPTA60306
		trigger = {
			has_character_flag = timurid_himself
		}
	}
	option = {
		name = EVTOPTB60306
		trigger = {
			NOT = { has_character_flag = timurid_himself }
			culture = mongol
		}
	}
	option = {
		name = EVTOPTC60306
		trigger = {
			NOT = { has_character_flag = timurid_himself }
			NOT = { culture = mongol }
		}
	}
}

# Timur's successors revitalize the state
character_event = {
	id = 60307
	desc = EVTDESC60307
	
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	only_playable = yes
	only_independent = yes
	has_global_flag = timur_spawned
	
	trigger = {
		dynasty = 800 # Timurid
		year = 1370
		higher_tier_than = duke
		NOT = { higher_tier_than = king }
		martial = 7
		NOT = { has_earmarked_regiments = timur_event_troops }
		primary_title = { NOT = { has_title_flag = timurid_state_revitalised } }
		NOR = {
			year = 1500
			realm_size = 150
			trait = blinded
			trait = eunuch
			trait = infirm
			trait = content
			trait = craven
			trait = depressed
			trait = imbecile
			has_character_flag = timurid_himself
			has_character_flag = timur_reinforcements
		}
		OR = {
			father = { has_character_flag = timurid_himself }
			father = { father = { has_character_flag = timurid_himself } }
		}
	}
	
	mean_time_to_happen = {
		months = 360
		modifier = {
			factor = 0.5
			martial = 9
		}
		modifier = {
			factor = 0.5
			martial = 11
		}
		modifier = {
			factor = 0.5
			martial = 13
		}
	}
	
	immediate = {
		set_character_flag = timur_reinforcements
		primary_title = { set_global_flag = timurid_state_revitalised }
		
		if = {
			limit = { religion_group = muslim }
			piety = 250
		}
		
		capital_scope = { 
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = timur_event_troops
					cannot_inherit = yes
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = timur_event_troops
					cannot_inherit = yes
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = timur_event_troops
					cannot_inherit = yes
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = timur_event_troops
					cannot_inherit = yes
				}
				if = {
					limit = {
						martial = 12
					}
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = timur_event_troops
						cannot_inherit = yes
					}
				}
				if = {
					limit = {
						martial = 15
					}
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = timur_event_troops
						cannot_inherit = yes
					}
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA60307
	}
}

# Event troops no longer needed
character_event = {
	id = 60308
	desc = EVTDESC60208
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war

	only_playable = yes
	has_character_flag = timur_reinforcements
	
	trigger = {
		war = no
		has_earmarked_regiments = timur_event_troops
		tier = EMPEROR
		realm_size = 150
	}
	
	mean_time_to_happen = {
		years = 5
	}
	
	option = {
		name = EVTOPTA60208
		disband_event_forces = timur_event_troops
	}
}


##########################################
# Rise of the Ghaznavids under Sabuktigin
##########################################

# Sabuktigin distinguishes himself at a Muslim court
character_event = {
	id = 60400
	desc = EVTDESC60400
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	only_independent = yes
	religion_group = muslim
	
	trigger = {
		NOT = {
			has_game_rule = {
				name = turkic_invasions
				value = off
			}
		}
		OR = {
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = historical
				}
				year = 965
				NOT = { year = 1010 }
			}
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = random
				}
				year = 809
				NOT = { year = 1200 }
			}
		}
		
		higher_tier_than = count
		
		NOT = { has_global_flag = sabuktigin_spawned }
		
		OR = {
			1182 = { # Ghazna
				owner = {
					same_realm = ROOT
				}
			}
			1183 = { # Bost
				owner = {
					same_realm = ROOT
				}
			}
			907 = { # Mandesh
				owner = {
					same_realm = ROOT
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 24
	}
	
	option = { # A most capable young man
		name = EVTOPTA60300
		
		set_global_flag = sabuktigin_spawned
		
		create_character = {
			random_traits = no
			historical = yes
			name = "Sabuktigin"
			dynasty = 790
			religion = ROOT
			culture = ROOT
			female = no
			age = 18
			attributes = {
				martial = 12
				diplomacy = 8
				stewardship = 9
				intrigue = 9
				learning = 6
			}
			health = 6
			fertility = 0.8
			trait = brilliant_strategist
			trait = diligent
			trait = ambitious
			trait = proud
			trait = quick
		}
		
		new_character = {
			set_character_flag = sabuktigin_himself
		}
	}
}

# Sabuktigin and his men consider starting an adventure
character_event = {
	id = 60401
	desc = EVTDESC60201
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	prisoner = no
	only_capable = yes
	has_character_flag = sabuktigin_himself
	
	trigger = {
		war = no
		OR = {
			is_ruler = no
			lower_tier_than = KING
			AND = {
				is_nomadic = yes
				NOT = { tier = EMPEROR }
			}
		}
		
		any_independent_ruler = {
			war = no
			NOT = { same_realm = ROOT }
			is_nomadic = no
			is_tributary = no
			OR = {
				1341 = { owner = { same_realm = PREVPREV } } #Nandana
				1338 = { owner = { same_realm = PREVPREV } } #Multan
				1362 = { owner = { same_realm = PREVPREV } } #Lahore
				1138 = { owner = { same_realm = PREVPREV } } #Bhakkar
			}
		}
		
		NOR = {
			trait = blinded
			trait = eunuch
			trait = infirm
			trait = content
			trait = craven
			trait = depressed
			trait = imbecile
			liege = { war = yes }
			has_character_flag = sabuktigin_started_adventure
		}
	}
	
	mean_time_to_happen = {
		years = 5
		modifier = {
			factor = 0.5
			age = 25
		}
		modifier = {
			factor = 0.5
			age = 30
		}
		modifier = {
			factor = 0.5
			age = 35
		}
	}	
	
	immediate = {
		add_trait = adventurer
		set_character_flag = sabuktigin_started_adventure
	}
	
	option = { # Gandhara it is!
		name = EVTOPTA60401
		trigger = {
			1341 = { # Nandana
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 10000
		}
		1341 = {
			province_event = {
				id = 60402
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Multan
		name = EVTOPTB60401
		trigger = {
			1338 = { # Multan
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 1000
		}
		1338 = {
			province_event = {
				id = 60402
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Lahore
		name = EVTOPTC60401
		trigger = {
			1362 = { # Lahore
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		1362 = {
			province_event = {
				id = 60402
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = { # Bhakkar
		name = EVTOPTD60401
		trigger = {
			1138 = { # Bhakkar
				owner = {
					NOT = { same_realm = ROOT }
					top_liege = {
						war = no
						is_nomadic = no
						is_tributary = no
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		1138 = {
			province_event = {
				id = 60402
				tooltip = BEGIN_ADVENTURE
			}
		}
	}
	option = {
		name = EVTOPTD60201 #I am fine where I am
		trigger = { ai = no }
	}
}

# Ping the target province
province_event = {
	id = 60402
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				FROM = { is_ruler = yes }
			}
			FROM = {
				character_event = {
					id = 60404
				}
			}
		}
		if = {
			limit = {
				FROM = { is_ruler = no }
			}
			FROM = {
				character_event = {
					id = 60403
				}
			}
		}
	}
}

# The landless Sabuktigin and his men start an adventure
character_event = {
	id = 60403
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60405
				days = 1
			}
		}
		
		liege = {
			if = {
				limit = { is_nomadic = yes }
				ROOT = { set_character_flag = will_be_nomadic }
			}
			capital_scope = {
				FROM = {
					owner = {
						top_liege = {
							ROOT = {
								set_defacto_liege = ROOT
								create_title = {
									tier = DUKE
									landless = yes
									temporary = yes
									culture = ROOT
									name = "CLAIMANT_ADVENTURE"
									holder = ROOT
								}
								if = {
									limit = { has_character_flag = will_be_nomadic }
									clr_character_flag = will_be_nomadic
									set_government_type = nomadic_government
									population = 5000
								}								
								set_character_flag = duchy_adventurer

								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREVPREVPREVPREV
									home = PREVPREVPREVPREV
									owner = THIS
									match_character = PREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								war = {
									target = PREV
									casus_belli = duchy_adventure
									thirdparty_title = PREVPREVPREV
									tier = DUKE
									infamy = 0
								}
							}
						}
					}
				}
			}
		}
		
		# Create some characters
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 28
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 24
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 23
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60403: Sabuktigin starts his first war (landless)!"
	}
}

# The landed Sabuktigin and his men start an adventure
character_event = {
	id = 60404
	desc = EVTDESC60304
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				tier = BARON
			}
			abdicate = yes
			character_event = { id = 60403 }
			break = yes
		}
		wealth = 500
		prestige = 500
		
		any_liege = {
			character_event = {
				id = 60405
				days = 1
			}
		}
		
		FROM = {
			owner = {
				top_liege = {
					ROOT = {
						capital_scope = {
							ROOT = {
								set_character_flag = duchy_adventurer
								if = {
									limit = { is_nomadic = yes }
									population = 5000
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									troops = {
										horse_archers = { 2700 2700 }
										light_cavalry = { 1600 1600 }
										light_infantry = { 541 541 }
										heavy_infantry = { 210 210 }
										knights = { 47 47 }
									}
									attrition = 0.25
									cannot_inherit = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREV
									match_mult = 0.33
									match_min = 500
									match_max = 10000
									attrition = 0.25
									disband_on_peace = yes
									maintenance_multiplier = 0
									earmark = sabuktigin_event_troops
								}
							}
						}
						
						war = {
							target = PREV
							casus_belli = duchy_adventure
							thirdparty_title = PREVPREVPREV
							tier = DUKE
							infamy = 0
						}
					}
				}
			}
		}
		
		# Create some characters
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 28
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 24
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 23
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		
		log = "60404: Sabuktigin starts his first war (landed)!"
	}
	
	option = {
		name = EVTOPTA60204
	}
}

# Notify Sabuktigin's old liege
character_event = {
	id = 60405
	desc = EVTDESC60205
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_ruler = yes } # The DoW worked and the adventurer has a temporary title
	}
	
	option = {
		name = EVTOPTA60305
	}
}

# Sabuktigin is successful!
# Fired from the duchy_adventure CB
narrative_event = {
	id = 60406
	title = EVTNAME60406
	desc = EVTDESC60406
	picture = GFX_evt_mongols
	border = GFX_event_narrative_frame_war
	
	is_triggered_only = yes
	
	major = yes
	
	immediate = {
		set_defacto_liege = ROOT
		
		prestige = 500
		
		if = {
			limit = { religion_group = muslim }
			piety = 100
		}
		
		capital_scope = {
			religion = ROOT
			culture = ROOT
			
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = sabuktigin_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = sabuktigin_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = sabuktigin_event_troops
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 2250 2250 }
						light_cavalry = { 2000 2000 }
						horse_archers = { 1500 1500 }
						knights = { 50 50 }
					}
					attrition = 0.25
					maintenance_multiplier = 0
					earmark = sabuktigin_event_troops
				}
				
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = sabuktigin_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = sabuktigin_event_troops
					}
				}
				random = {
					chance = 50
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						troops = {
							light_infantry = { 2250 2250 }
							light_cavalry = { 2000 2000 }
							horse_archers = { 1500 1500 }
							knights = { 50 50 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = sabuktigin_event_troops
					}
				}
			}
		}
		
		random_realm_province = {
			limit = {
				OR = {
					NOT = { culture = ROOT }
					NOT = { religion = ROOT }
				}
			}
			religion = ROOT
			culture = ROOT
		}
		
		log = "60406: Sabuktigin wins his first war!"
	}
	
	option = {
		name = EVTOPTA60406
		trigger = {
			has_character_flag = sabuktigin_himself
		}
	}
	option = {
		name = EVTOPTB60406
		trigger = {
			NOT = { has_character_flag = sabuktigin_himself }
		}
	}
}

# Event troops no longer needed
character_event = {
	id = 60407
	desc = EVTDESC60208
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war

	only_playable = yes
	has_character_flag = sabuktigin_himself
	
	trigger = {
		war = no
		has_earmarked_regiments = sabuktigin_event_troops
		tier = EMPEROR
		realm_size = 150
	}
	
	mean_time_to_happen = {
		years = 5
	}
	
	option = {
		name = EVTOPTA60208
		disband_event_forces = sabuktigin_event_troops
	}
}


##########################################
# New Mongol Events
##########################################

# Mongol horde starts forming
narrative_event = {
	id = 60500
	title = EVTNAME60500
	desc = EVTDESC60500
	picture = GFX_evt_mongols
	border = GFX_event_narrative_frame_war
	
	major = yes
	hide_new = yes
	hide_from = yes
	
	only_playable = yes
	religion = miaphysite
	
	trigger = {
		OR = {
			AND = {
				has_game_rule = {
					name = mongol_invasion
					value = random
				}
				total_years_played = 50
			}
			AND = {
				has_game_rule = {
					name = mongol_invasion
					value = delayed_random
				}
				year = 1000
				total_years_played = 50
			}
			AND = {
				has_game_rule = {
					name = mongol_invasion
					value = historical
				}
				year = 1210
			}
		}
		NOR = { 
			year = 1218
			has_game_rule = {
				name = mongol_invasion
				value = off
			}
		}
		controls_religion = yes # Let it happen for the Coptic Pope. He's always around.
		NOR = {
			has_global_flag = il_khanate_arrival # Backwards compatibility
			has_global_flag = golden_horde_arrival # Backwards compatibility
			has_global_flag = mongol_empire_arrival
		}
	}
	
	mean_time_to_happen = {
		months = 36
		modifier = {
			factor = 0.5
			year = 1212
		}
		modifier = {
			factor = 0.5
			year = 1214
		}
		modifier = {
			factor = 0.5
			year = 1216
		}
		modifier = {
			factor = 66
			has_game_rule = {
				name = mongol_invasion
				value = random
			}
		}
		modifier = {
			factor = 44
			has_game_rule = {
				name = mongol_invasion
				value = delayed_random
			}
		}
	}
	
	immediate = {
		set_global_flag = mongol_empire_arrival
		activate_title = { title = e_mongol_empire status = yes }
		
		#check to see if Temujin has already been born
		if = {
			limit = { e_mongol_empire = { has_title_flag = temujin_born } }
			#first find him
			any_independent_ruler = {
				if = {
					limit = { has_character_flag = is_temujin }
					save_event_target_as = temujin
				}
				any_realm_character = {
					limit = { has_character_flag = is_temujin }
					save_event_target_as = temujin
				}
			}

			#Temujin still exists and is tengri pagan and capable
			if = {
				limit = {
					event_target:temujin = {
						is_alive = yes
						prisoner = no
						health = 5
						religion = tengri_pagan
						NOR = {
							trait = incapable
							is_maimed_trigger = yes
						}
					}
				}
				event_target:temujin = {
					add_trait = bloodlust
					set_character_flag = has_bloodlust_trait
					#he's already a count or higher
					if = {
						limit = { higher_tier_than = BARON }
						log = "MONGOL ARRIVAL: Temujin already exists as a ruler"
						set_defacto_liege = THIS
						pf_liege_change_effect = yes
						#become a nomad/tribal if not already
						if = {
							limit = { 
								has_dlc = "Horse Lords"
								is_nomadic = no
							}
							set_government_type = nomadic_government
						}
						if = {
							limit = {
								NOT = { has_dlc = "Horse Lords" }
								is_tribal = no
							}
							set_government_type = tribal_government
						}
						#destroy any current emperor titles and grant Mongol Empire
						any_demesne_title = {
							limit = { tier = EMPEROR }
							set_title_flag = to_be_destroyed
						}
						e_mongol_empire = {
							set_title_flag = temporary_landless_title
							grant_title = PREV
						}
						any_demesne_title = {
							limit = { has_title_flag = to_be_destroyed }
							clr_title_flag = to_be_destroyed
							unsafe_destroy_landed_title = THIS
						}
						#give wealth and spawn wealth/population/troops
						wealth = 5000
						prestige = 5000
						set_character_flag = horde_invader
						character_event = { id = 60510 } # Spawn troops
						character_event = { id = 60515 days = 1 } # Spawn population
						save_event_target_as = mongol_china_invader
						break = yes
					}
					
					#he's a baron or a courtier
					log = "MONGOL ARRIVAL: Temujin already exists as a courtier"
					if = {
						limit = { tier = BARON }
						abdicate = yes
					}
					e_mongol_empire = {
						set_title_flag = temporary_landless_title
						grant_title = PREV
					}
					set_defacto_liege = THIS
					pf_liege_change_effect = yes
					if = {
						limit = { has_dlc = "Horse Lords" }
						set_government_type = nomadic_government
					}
					if = {
						limit = { NOT = { has_dlc = "Horse Lords" } }
						set_government_type = tribal_government
					}
					#give wealth and spawn wealth/population/troops
					wealth = 5000
					prestige = 5000
					set_character_flag = horde_invader
					character_event = { id = 60509 } # Spawn courtiers
					character_event = { id = 60510 } # Spawn troops
					character_event = { id = 60515 days = 1 } # Spawn population
					save_event_target_as = mongol_china_invader
					break = yes
				}
			}

			#Temujin is either dead, converted, or incapable
			create_character = {
				random_traits = yes
				dynasty = random
				religion = tengri_pagan
				culture = mongol
				female = no
				age = 24
				attributes = {
					martial = 12
					diplomacy = 8
				}
				trait = bloodlust
				trait = brilliant_strategist
				trait = ambitious
				trait = diligent
				trait = brave
			}
			new_character = {
				set_character_flag = has_bloodlust_trait
				e_mongol_empire = {
					set_title_flag = temporary_landless_title
					grant_title = PREV
				}
				set_defacto_liege = THIS
				if = {
					limit = { has_dlc = "Horse Lords" }
					set_government_type = nomadic_government
				}
				if = {
					limit = { NOT = { has_dlc = "Horse Lords" } }
					set_government_type = tribal_government
				}
				#give wealth and spawn wealth/population/troops
				wealth = 5000
				set_character_flag = horde_invader
				prestige = 5000
				character_event = { id = 60509 } # Spawn courtiers
				character_event = { id = 60510 } # Spawn troops
				character_event = { id = 60515 days = 1 } # Spawn population
			}
			break = yes
		}
		
		#Temujin was not already born and must be spawned
		log = "MONGOL ARRIVAL: Temujin was not born and must be spawned"
		create_character = {
			name = "Temujin"
			dynasty = 1051210
			dna = "bfimkolbecc"
			properties = "ge0af0000000"
			culture = mongol
			religion = tengri_pagan
			age = 43
			attributes = {
				martial = 12
				diplomacy = 8
				intrigue = 8
				stewardship = 9
				learning = 3
			}
			health = 6
			fertility = 0.7
			trait = bloodlust
			trait = brave
			trait = ambitious
			trait = diligent
			trait = cruel
			trait = strong
			trait = hunter
			trait = cavalry_leader
			trait = brilliant_strategist
		}
		new_character = {
			set_character_flag = is_temujin
			set_character_flag = has_bloodlust_trait
			e_mongol_empire = {
				set_title_flag = temporary_landless_title
				grant_title = PREV
			}
			set_defacto_liege = THIS
			if = {
				limit = { has_dlc = "Horse Lords" }
				set_government_type = nomadic_government
			}
			if = {
				limit = { NOT = { has_dlc = "Horse Lords" } }
				set_government_type = tribal_government
			}
			#give wealth and spawn wealth/population/troops
			wealth = 5000
			set_character_flag = horde_invader
			prestige = 5000
			character_event = { id = 60505 } # Spawn Temujin's leaders
			character_event = { id = 60509 } # Spawn courtiers
			character_event = { id = 60510 } # Spawn troops
			character_event = { id = 60515 days = 1 } # Spawn population
			save_event_target_as = mongol_china_invader
		}

		#remove landless status if Temujin already owns land
		if = {
			limit = {
				e_mongol_empire = {
					holder_scope = { num_of_count_titles_in_realm = 1 }
				}
			}
			e_mongol_empire = {
				clr_title_flag = temporary_landless_title
				set_title_landless = { title = THIS status = no }
			}
		}		
		#start the first war, if Temujin does not already own land
		if = {
			limit = {
				e_mongol_empire = {
					holder_scope = {
						NOT = { num_of_count_titles_in_realm = 1 }
					}
				}
			}
			if = {
				limit = { has_dlc = "Horse Lords" }				
				1457 = { # Ordu Baliq
					kingdom = {
						e_mongol_empire = {
							holder_scope = {
								war = {
									casus_belli = nomad_invasion
									target = PREVPREVPREV # The top liege of the owner of the province
									thirdparty_title = PREVPREV # The de jure kingdom
								}
							}
						}
					}
				}
			}
			if = {
				limit = { NOT = { has_dlc = "Horse Lords" } }				
				1457 = { # Ordu Baliq
					kingdom = {
						e_mongol_empire = {
							holder_scope = {
								war = {
									casus_belli = tribal_invasion
									target = PREVPREVPREV # The top liege of the owner of the province
									thirdparty_title = PREVPREV # The de jure kingdom
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					has_dlc = "Jade Dragon"
					offmap_china = {
						OR = {
							NOT = { has_offmap_flag = china_invaded_player_dynasty }
							had_offmap_tmp_flag = {
								flag = china_invaded_player_dynasty
								years = 200
							}
						}
					}
				}
				event_target:mongol_china_invader = {
					character_event = { id = 60531 days = 100 random = 100 }
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_power_omen_modifier_trigger = yes
					has_battle_omen_modifier_trigger = yes
				}
			}
			set_character_flag = negative_event_flag # For the scrying outcome calculation...
		}
	}
	
	option = {
		name = EVTOPTA60500
		trigger = {
			OR = {
				religion_group = christian
				religion_group = muslim
				is_pagan_religion = yes
			}
			NOT = { government = nomadic_government }
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}
	
	option = {
		name = EVTOPTB60500
		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			is_pagan_religion = no
			NOT = { government = nomadic_government }
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}
	
	option = {
		name = EVTOPTC60500
		trigger = {
			government = nomadic_government
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}

	option = { # scrying omen included
		name = "EVTOPTA60500"

		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			OR = {
				religion_group = christian
				religion_group = muslim
				is_pagan_religion = yes
			}
			NOT = { government = nomadic_government }
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
	
	option = { # scrying omen included
		name = "EVTOPTB60500"
		
		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			NOT = { religion_group = christian }
			NOT = { religion_group = muslim }
			is_pagan_religion = no
			NOT = { government = nomadic_government }
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
	
	option = { # scrying omen included
		name = "EVTOPTC60500"

		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			government = nomadic_government
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
}

# Remove landless status for Mongol Empire once a province is gained
# fired from on_action
character_event = {
	id = 60504
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			tier = COUNT
		}
		any_demesne_title = { 
			has_title_flag = temporary_landless_title
			is_landless_type_title = yes
		}
	}
	
	immediate = {
		any_demesne_title = {
			limit = { has_title_flag = temporary_landless_title }
			clr_title_flag = temporary_landless_title
			set_title_landless = { title = THIS status = no }
		}
	}
}

# Spawn Mongol leaders for Temujin
character_event = {
	id = 60505
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		#Borte, Temujin's wife
		create_character = {
			name = "Borte"
			age = 44
			dynasty = 1041000
			religion = ROOT
			culture = ROOT
			female = yes
			random_traits = yes
		}
		new_character = {
			save_event_target_as = borte
			add_spouse = ROOT
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		
		#Subutai, Temujin's primary general
		create_character = {
			name = "Subutai"
			age = 35
			dynasty = 7315
			religion = ROOT
			culture = ROOT
			attributes = {
				martial = 10
				diplomacy = 4
				intrigue = 6
				stewardship = 6
			}
			trait = brave
			trait = strong
			trait = quick
			trait = diligent
			trait = brilliant_strategist
			trait = trickster
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		
		#Chepe, Temujin's secondary general
		create_character = {
			name = "Jebe"
			age = 50
			dynasty = 7317
			religion = ROOT
			culture = ROOT
			attributes = {
				martial = 10
				diplomacy = 5
				intrigue = 5
				stewardship = 4
			}
			trait = skilled_tactician
			trait = brave
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		
		#Jochi
		create_character = {
			random_traits = no
			dynasty = ROOT
			name = "Jochi"
			culture = ROOT
			religion = ROOT
			age = 24
			attributes = {
				martial = 8
			}
			trait = skilled_tactician
			trait = hunter
			trait = kind
			trait = patient
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
			set_character_flag = is_jochi_khan
			ROOT = {
				create_character = {
					name = "Sarkan"
					random_traits = yes
					dynasty = 1041002
					religion = ROOT
					culture = ROOT
					female = yes
					age = 19
				}
				new_character = {
					add_spouse = PREVPREV
					ROOT = {
						create_character = {
							name = "Batu"
							random_traits = yes
							dynasty = ROOT
							religion = ROOT
							culture = ROOT
							female = no
							age = 2
							attributes = {
								martial = 4
							}
						}
						new_character = {
							set_father = PREVPREVPREVPREV
							set_mother = PREVPREV
							character_event = { id = Plus.324 } #genetics check
						}
					}
				}
			}
		}

		#Chagatai
		create_character = {
			random_traits = no
			dynasty = ROOT
			name = "Chagatai"
			culture = ROOT
			religion = ROOT
			age = 22
			trait = skilled_tactician
			trait = wroth
			trait = just
			trait = drunkard
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			set_character_flag = is_chagatai_khan
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
			ROOT = {
				create_character = {
					name = "Ebuskun"
					random_traits = yes
					dynasty = 1041001
					religion = ROOT
					culture = ROOT
					female = yes
					age = 21
					trait = quick
				}
				new_character = {
					add_spouse = PREVPREV
					ROOT = {
						create_character = {
							name = "Mö'etüken"
							random_traits = yes
							dynasty = ROOT
							religion = ROOT
							culture = ROOT
							female = no
							trait = ambitious
							trait = just
							attributes = {
								martial = 6
								intrigue = 3
							}
							age = 5
						}
						new_character = {
							set_mother = PREVPREV
							set_father = PREVPREVPREVPREV
							character_event = { id = Plus.324 } #genetics check
						}
						create_character = {
							name = "Yesü Mongke" 
							random_traits = yes
							dynasty = ROOT
							religion = ROOT
							culture = ROOT
							female = no
							age = 3
							trait = wroth
							trait = quick
							attributes = {
								martial = 4
								diplomacy = 3
							}
						}
						new_character = {
							set_mother = PREVPREV
							set_father = PREVPREVPREVPREV
							character_event = { id = Plus.324 } #genetics check
						}
					}
				}
			}
		}
		
		#Ogodei
		create_character = {
			random_traits = no
			dynasty = ROOT
			name = "Ã–gedei"
			culture = ROOT
			religion = ROOT
			age = 19
			attributes = {
				diplomacy = 8
			}
			trait = skilled_tactician
			trait = gregarious
			trait = just
			trait = hunter
			trait = ambitious
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			set_character_flag = is_ogodei_khan
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
			ROOT = {
				create_character = {
					name = "Töregene"
					random_traits = yes
					dynasty = 1041001
					religion = ROOT
					culture = ROOT
					female = yes
					age = 17
				}
				new_character = {
					add_spouse = PREVPREV
					ROOT = {
						create_character = {
							name = "Guyug"
							random_traits = yes
							dynasty = ROOT
							religion = ROOT
							culture = ROOT
							female = no
							age = 1
							trait = gregarious
							trait = just
						}
						new_character = {
							set_mother = PREVPREV
							set_father = PREVPREVPREVPREV
							character_event = { id = Plus.324 } #genetics check
						}
					}
				}
			}
		}

		#Tolui
		create_character = {
			dynasty = ROOT
			name = "Tolui"
			random_traits = yes
			culture = ROOT
			religion = ROOT
			attributes = {
				martial = 4
				stewardship = 8
			}
			age = 13
			trait = diligent
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			set_character_flag = is_tolui_khan
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
		}
	
		#daughters
		create_character = {
			random_traits = yes
			female = yes
			dynasty = ROOT
			name = "Khochen"
			culture = ROOT
			religion = ROOT
			age = 20
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
		}
		create_character = {
			random_traits = yes
			female = yes
			dynasty = ROOT
			name = "Alakhai"
			culture = ROOT
			religion = ROOT
			age = 14
			trait = strong
			trait = fair
			attributes = {
				martial = 4
				diplomacy = 6
				stewardship = 6
			}
		}
		new_character = {
			set_father = ROOT
			set_mother = event_target:borte
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
			character_event = { id = Plus.324 } #genetics check
		}
	
		recalc_succession = yes
	}
}

# Spawn extra courtiers
character_event = {
	id = 60509
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		create_random_diplomat = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 18
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_random_diplomat = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 20
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_random_steward = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_random_steward = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 26
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_random_intriguer = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 28
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 16
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 17
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 18
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = yes
			age = 20
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 27
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 51
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 44
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 24
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		new_character = {
			opinion = { who = ROOT modifier = opinion_exalted multiplier = 2 years = 100 }
		}
	}
}

# Spawn mongol troops
character_event = {
	id = 60510
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1457 # Ordu-Baliq
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		spawn_unit = {
			province = 1460 # Baygal
			troops = {
				light_cavalry = { 2750 2750 }
				horse_archers = { 2250 2250 }
				knights = { 500 500 }
			}
			earmark = first_mongol_horde
			maintenance_multiplier = 0
			attrition = 0.25
		}
		random = {
			chance = 50
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
		}
		random = {
			chance = 50
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
			spawn_unit = {
				province = 1408 # Gobi
				troops = {
					light_cavalry = { 2750 2750 }
					horse_archers = { 2250 2250 }
					knights = { 500 500 }
				}
				earmark = first_mongol_horde
				maintenance_multiplier = 0
				attrition = 0.25
			}
		}
	}
}

# Spawn population
character_event = {
	id = 60515
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = { is_nomadic = yes }
	
	immediate = {
		population = 120000
		add_character_modifier = {
			modifier = invading_population_halt
			duration = 10950
			hidden = yes
		}
		character_event = {
			id = 60516
			days = 365
		}
	}
}

# Check population factor
character_event = {
	id = 60516
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		#remove modifier if no longer nomadic
		if = {
			limit = {
				NOT = { government = nomadic_government }
				NOT = { has_character_modifier = invading_population_halt }
			}
			remove_character_modifier = invading_population_halt
			break = yes
		}
		#add some population if it's dropped
		if = {
			limit = {
				NOT = { population_factor = 1 }
			}
			population = 80000
			#population has become very high, check for removal in a year
			if = {
				limit = {
					population = 350000
				}
				character_event = {
					id = 60517
					days = 365
				}
				break = yes
			}
		}
		#check again next year
		repeat_event = { 
			id = 60516
			days = 365
		}
	}
}

# Check population factor if population has become very high
character_event = {
	id = 60517
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		#remove modifier if no longer nomadic
		if = {
			limit = {
				NOT = { government = nomadic_government }
				NOT = { has_character_modifier = invading_population_halt }
			}
			remove_character_modifier = invading_population_halt
			break = yes
		}
		#remove modifier if population factor is still high
		if = {
			limit = {
				NOT = { population_factor = 1 }
			}
			remove_character_modifier = invading_population_halt
			break = yes
		}
		repeat_event = {
			id = 60517
			days = 365
		}
	}
}

# Notify world about the greatest of Khans (fired from decision)
narrative_event = {
	id = 60520
	title = EVTNAME60520
	desc = EVTDESC60520
	is_triggered_only = yes
	
	picture = GFX_evt_mongols
	border = GFX_event_narrative_frame_war


	immediate = {
		if = {
			limit = {
				OR = {
					has_power_omen_modifier_trigger = yes
					has_battle_omen_modifier_trigger = yes
				}
			}
			set_character_flag = negative_event_flag # For the scrying outcome calculation...
		}
	}
	
	option = {
		name = EVTOPTA_60520
		trigger = {
			primary_title = {
				title = e_mongol_empire
			}
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}
	
	option = {
		name = EVTOPTB_60520
		trigger = {
			NOT = {
				primary_title = {
					title = e_mongol_empire
				}
			}
			NOT = {
				any_liege = {
					primary_title = {
						title = e_mongol_empire
					}
				}
			}
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}
	
	option = {
		name = EVTOPTC_60520
		trigger = {
			any_liege = {
				primary_title = {
					title = e_mongol_empire
				}
			}
			has_power_omen_modifier_trigger = no
			has_battle_omen_modifier_trigger = no
		}
	}

	option = { # scrying omen included
		name = EVTOPTA_60520

		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			primary_title = {
				title = e_mongol_empire
			}
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
	
	option = { # scrying omen included
		name = EVTOPTB_60520

		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			NOT = {
				primary_title = {
					title = e_mongol_empire
				}
			}
			NOT = {
				any_liege = {
					primary_title = {
						title = e_mongol_empire
					}
				}
			}
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
	
	option = { # scrying omen included
		name = EVTOPTC_60520

		calculate_scrying_outcome_effect = yes
		remove_scrying_omen_modifiers_effect = yes
		tooltip_info = yes

		trigger = {
			any_liege = {
				primary_title = {
					title = e_mongol_empire
				}
			}
			OR = {
				has_power_omen_modifier_trigger = yes
				has_battle_omen_modifier_trigger = yes
			}
		}
	}
}

# AI - reinforcement event for Genghis decision
character_event = {
	id = 60530
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					troops = {
						light_cavalry = { 2750 2750 }
						horse_archers = { 2250 2250 }
						knights = { 500 500 }
					}
					earmark = first_mongol_horde
					maintenance_multiplier = 0
					attrition = 0.25
				}
				spawn_unit = {
					province = PREV
					troops = {
						light_cavalry = { 2750 2750 }
						horse_archers = { 2250 2250 }
						knights = { 500 500 }
					}
					earmark = first_mongol_horde
					maintenance_multiplier = 0
					attrition = 0.25
				}
				spawn_unit = {
					province = PREV
					troops = {
						light_cavalry = { 2750 2750 }
						horse_archers = { 2250 2250 }
						knights = { 500 500 }
					}
					earmark = first_mongol_horde
					maintenance_multiplier = 0
					attrition = 0.25
				}
				spawn_unit = {
					province = PREV
					troops = {
						light_cavalry = { 2750 2750 }
						horse_archers = { 2250 2250 }
						knights = { 500 500 }
					}
					earmark = first_mongol_horde
					maintenance_multiplier = 0
					attrition = 0.25
				}
			}
		}
	}
}

### MONGOL WAR EVENTS

# Use nomad invasion
character_event = {
	id = 60535
	
	hide_window = yes
	
	only_playable = yes
	culture = mongol
	only_independent = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	ai = yes
	war = no
	
	trigger = {
		OR = {
			has_landed_title = e_mongol_empire
			has_landed_title = e_golden_horde
			has_landed_title = e_il-khanate
		}
		is_nomadic = yes
		is_tributary = no
		prestige = 500
		population_factor = 0.9
		ai_not_busy_trigger = yes
		OR = {
			NOT = { num_of_count_titles_in_realm = 50 }
			has_landed_title = e_mongol_empire
		}
		any_independent_ruler = {
			num_of_count_titles_in_realm = 10
			reverse_realm_levy_diff = { who = ROOT value = 10000 }
			NOT = { relative_power = { who = ROOT power = 3.0 } }
			any_realm_province = {
				any_neighbor_province = { owner = { same_realm = ROOT } }
				NOT = { region = world_india }
				OR = {
					AND = {
						OR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_il-khanate }
					}
					AND = {
						NOR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_golden_horde }
					}
					ROOT = { has_landed_title = e_mongol_empire }
				}
			}
			NOR = {
				same_realm = ROOT
				reverse_has_truce = ROOT
				dynasty = ROOT
				is_allied_with = ROOT
				has_non_aggression_pact_with = ROOT
				is_married = ROOT
				reverse_opinion = { who = ROOT value = 25 }
				pays_tribute_to = ROOT
			}
		}
	}
	
	mean_time_to_happen = {
		months = 12
		modifier = {
			factor = 0.5
			NOT = { num_of_count_titles_in_realm = 20 }
		}
		modifier = {
			factor = 2
			num_of_count_titles_in_realm = 35
		}
	}
	
	immediate = {
		random_independent_ruler = {
			limit = {
				num_of_count_titles_in_realm = 10
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				NOT = { relative_power = { who = ROOT power = 3.0 } }
				any_realm_province = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					dynasty = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					is_married = ROOT
					reverse_opinion = { who = ROOT value = 25 }
					pays_tribute_to = ROOT
				}
			}
			random_realm_province = {
				limit = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				kingdom = {
					ROOT = {
						war = {
							casus_belli = nomad_invasion
							target = PREVPREVPREV # The top liege of the owner
							thirdparty_title = PREV # The de jure kingdom
						}
					}
				}
			}
		}
	}
}

# Use nomad expansion
character_event = {
	id = 60536
	
	hide_window = yes
	
	only_playable = yes
	culture = mongol
	only_independent = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	ai = yes
	war = no
	
	trigger = {
		OR = {
			has_landed_title = e_mongol_empire
			has_landed_title = e_golden_horde
			has_landed_title = e_il-khanate
		}
		is_nomadic = yes
		is_tributary = no
		prestige = 200
		population_factor = 0.9
		ai_not_busy_trigger = yes
		OR = {
			NOT = { num_of_count_titles_in_realm = 50 }
			has_landed_title = e_mongol_empire
		}
		any_independent_ruler = {
			reverse_realm_levy_diff = { who = ROOT value = 10000 }
			NOT = { relative_power = { who = ROOT power = 3.0 } }
			any_realm_province = {
				any_neighbor_province = { owner = { same_realm = ROOT } }
				NOT = { region = world_india }
				OR = {
					AND = {
						OR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_il-khanate }
					}
					AND = {
						NOR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_golden_horde }
					}
					ROOT = { has_landed_title = e_mongol_empire }
				}
			}
			NOR = {
				same_realm = ROOT
				reverse_has_truce = ROOT
				dynasty = ROOT
				is_allied_with = ROOT
				has_non_aggression_pact_with = ROOT
				is_married = ROOT
				reverse_opinion = { who = ROOT value = 25 }
				pays_tribute_to = ROOT
			}
		}
	}
	
	mean_time_to_happen = {
		months = 24
		modifier = {
			factor = 0.5
			NOT = { num_of_count_titles_in_realm = 20 }
		}
		modifier = {
			factor = 2
			num_of_count_titles_in_realm = 35
		}
	}
	
	immediate = {
		random_independent_ruler = {
			limit = {
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				NOT = { relative_power = { who = ROOT power = 3.0 } }
				any_realm_province = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					dynasty = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					is_married = ROOT
					reverse_opinion = { who = ROOT value = 25 }
					pays_tribute_to = ROOT
				}
			}
			random_realm_province = {
				limit = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				duchy = {
					ROOT = {
						war = {
							casus_belli = nomad_expansion
							target = PREVPREVPREV # The top liege of the owner
							thirdparty_title = PREV # The de jure duchy
						}
					}
				}
			}
		}
	}
}

# Use tribal invasion
character_event = {
	id = 60537
	
	hide_window = yes
	
	only_playable = yes
	culture = mongol
	only_independent = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	ai = yes
	war = no
	
	trigger = {
		OR = {
			has_landed_title = e_mongol_empire
			has_landed_title = e_golden_horde
			has_landed_title = e_il-khanate
		}
		is_nomadic = no
		is_tributary = no
		prestige = 500
		ai_not_busy_trigger = yes
		OR = {
			NOT = { num_of_count_titles_in_realm = 50 }
			has_landed_title = e_mongol_empire
		}
		NOT = { has_dlc = "Horse Lords" }
		NOT = { religion_group = christian }
		any_independent_ruler = {
			reverse_realm_levy_diff = { who = ROOT value = 10000 }
			NOT = { relative_power = { who = ROOT power = 3.0 } }
			any_realm_province = {
				any_neighbor_province = { owner = { same_realm = ROOT } }
				NOT = { region = world_india }
				OR = {
					AND = {
						OR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_il-khanate }
					}
					AND = {
						NOR = {
							region = world_europe_south_east
							region = world_asia_minor
							region = world_middle_east
							region = world_persia
						}
						ROOT = { has_landed_title = e_golden_horde }
					}
					ROOT = { has_landed_title = e_mongol_empire }
				}
			}
			NOR = {
				same_realm = ROOT
				reverse_has_truce = ROOT
				dynasty = ROOT
				is_allied_with = ROOT
				has_non_aggression_pact_with = ROOT
				is_married = ROOT
				reverse_opinion = { who = ROOT value = 25 }
				pays_tribute_to = ROOT
			}
		}
	}
	
	mean_time_to_happen = {
		months = 12
		modifier = {
			factor = 0.5
			NOT = { num_of_count_titles_in_realm = 20 }
		}
		modifier = {
			factor = 2
			num_of_count_titles_in_realm = 35
		}
	}
	
	immediate = {
		random_independent_ruler = {
			limit = {
				reverse_realm_levy_diff = { who = ROOT value = 10000 }
				NOT = { relative_power = { who = ROOT power = 3.0 } }
				any_realm_province = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				NOR = {
					same_realm = ROOT
					reverse_has_truce = ROOT
					dynasty = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					is_married = ROOT
					reverse_opinion = { who = ROOT value = 25 }
					pays_tribute_to = ROOT
				}
			}
			random_realm_province = {
				limit = {
					any_neighbor_province = { owner = { same_realm = ROOT } }
					NOT = { region = world_india }
					OR = {
						AND = {
							OR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_il-khanate }
						}
						AND = {
							NOR = {
								region = world_europe_south_east
								region = world_asia_minor
								region = world_middle_east
								region = world_persia
							}
							ROOT = { has_landed_title = e_golden_horde }
						}
						ROOT = { has_landed_title = e_mongol_empire }
					}
				}
				kingdom = {
					ROOT = {
						war = {
							casus_belli = tribal_invasion
							target = PREVPREVPREV # The top liege of the owner
							thirdparty_title = PREV # The de jure kingdom
						}
					}
				}
			}
		}
	}
}

character_event = {
	id = 60531
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		if = { # If China exists - Invade it!
			limit = {
				offmap_china = {
					NOT = {
						has_status = china_mongol_invasion
					}
					offmap_ruler = {
						NOT = {
							dynasty = event_target:mongol_china_invader
						}
					}
				}
			}
			offmap_china = {
				if = {
					limit = { # Mongols take presedence over Jurchens/Civil War
						OR = {
							has_status = china_jurchen_invasion
							has_status = china_civil_war
						}
					}
					set_offmap_flag = no_status_news
					set_status = china_unrest
					set_offmap_flag = china_had_unrest
					clr_offmap_flag = no_status_news
				}
				governor = {
					offmap_china = {
						set_offmap_flag = no_status_news
						set_status = china_mongol_invasion
						set_offmap_flag = china_mongol_invasion
						clr_offmap_flag = no_status_news
					}
					any_player = {
						limit = {
							has_offmap_news_enabled = offmap_china
							is_within_diplo_range = PREV
						}
						narrative_event = { id = JD.50141 }
					}
				}
			}
		}
	}
}

##################################
# Rise of the Sultanate of Rum
##################################

# A Turkic character wants a foothold in Armenia
character_event = {
	id = 60600
	
	hide_window = yes # Only fires for unplayable landless characters
	
	min_age = 16
	max_age = 50
	only_men = yes
	capable_only = yes
	prisoner = no
	
	culture_group = altaic
	religion_group = muslim
	
	trigger = {
		OR = { # Pacing mechanic, we don't want too many adventurers to spawn at once
			had_global_flag = { flag = rum_invader_spawned years = 10 }
			NOT = {
				has_global_flag = rum_invader_spawned
			}
		}
	
		OR = {
			AND = {
				diplomacy = 5
				martial = 9
				health = 4
			}
			has_character_flag = demon_child_non_pagan
		}
		
		father_even_if_dead = { # Is of a noble house
			always = yes
		}
		
		NOT = { trait = content }
		NOT = { trait = craven }
		
		NOT = {
			has_game_rule = {
				name = turkic_invasions
				value = off
			}
		}
		OR = {
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = historical
				}
				year = 1000
				NOT = { year = 1200 }
			}
			AND = {
				has_game_rule = {
					name = turkic_invasions
					value = random
				}
				year = 809
				NOT = { year = 1200 }
			}
		}
		
		NOT = { has_global_flag = rum_spawned }
		OR = {
			NOT = { has_global_flag = rum_spawning }
			had_global_flag = { flag = rum_spawning days = 1460 }
		}
		
		is_ruler = no
		NOT = { any_spouse = { is_ruler = yes } }
		
		NOT = { # Somewhat clunky way of checking that the character does not stand to inherit any titles
			any_heir_title = {
				always = yes
			}
		}
		
		liege = {
			culture_group = altaic
			capital_scope = {
				kingdom = {
					OR ={
						title = k_mesopotamia
						title = k_persia
						title = k_syria
						title = k_armenia
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 120
		modifier = {
			factor = 20
			NOT = { dynasty = 613 } # Seljuk 
		}
		modifier = {
			factor = 0.5
			culture = turkish
		}
		modifier = {
			factor = 0.5
			has_character_flag = flag_denied_title
		}
		modifier = {
			factor = 0.01
			has_character_flag = demon_child_non_pagan
		}
		modifier = {
			factor = 3.0
			trait = slothful
		}
		modifier = {
			factor = 3.0
			trait = humble
		}
		modifier = {
			factor = 3.0
			trait = kind
		}
	}
	
	immediate = {
		set_global_flag = rum_invader_spawned
		random_independent_ruler = {
			limit = {
				is_landed = yes
				independent = yes
				in_revolt = no
				ROOT = {
					liege = {
						NOT = {
							war_with = PREVPREV
						}
					}
				}
				NOT = { same_realm = ROOT }
				NOT = { religion_group = muslim }
				any_realm_province = {
					OR = {
						kingdom = {
							title = k_armenia
						}
						duchy = {
							title = d_azerbaijan
						}
					}
				}
			}
			
			random_realm_province = {
				limit = {
					OR = {
						kingdom = {
							title = k_armenia
						}
						duchy = {
							title = d_azerbaijan
						}
					}
				}
				
				save_event_target_as = target_province
				
				ROOT = {
					opinion = {
						who = PREVPREV
						years = 3
						modifier = opinion_duchy_adventure_target
					}
					add_character_modifier = {
						name = planning_duchy_adventure
						hidden = yes
						days = 730
					}
					character_event = {
						id = 60603 # Fire the attack
						days = 730
					}
					
					end_inaccessibility_effect = yes #removes in hiding or in_seclusion
					set_character_flag = do_not_disturb
					character_event = { id = 60602 days = 730 } # Safety clear of DND
					set_global_flag = rum_spawning
				}
				PREV = {
					character_event = {
						id = 60601 # Warn the target
					}
				}
			}
		}
	}
}

# Warn the target
character_event = {
	id = 60601
	desc = EVTDESC_TOG_1211
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		opinion = {
			who = FROM
			modifier = opinion_targeted_by_adventurer
			months = 24
		}
	}
	
	option = {
		name = EVTOPTA_TOG_1211
	}
}

# Safety clear of DND
character_event = {
	id = 60602
	
	is_triggered_only = yes
	
	hide_window = yes
	
	immediate = {
		remove_do_not_disturb_effect = yes
	}
}

# Launch the attack!
character_event = {
	id = 60603
	
	hide_window = yes 
	
	is_triggered_only = yes

	prisoner = no
	only_capable = yes
	
	trigger = {
		is_ruler = no
		NOT = { any_spouse = { is_ruler = yes } }
		
		NOT = {
			any_heir_title = {
				always = yes
			}
		}
		
		event_target:target_province = {
			owner = {
				top_liege = {
					is_landed = yes
					independent = yes
					NOT = { same_realm = ROOT }
					NOT = { religion_group = muslim }
				}
			}
		}
	}
	
	immediate = {
		wealth = 500
		remove_do_not_disturb_effect = yes
		
		set_character_flag = rum_creator
		
		liege = {
			character_event = {
				id = 60604
				days = 1
			}
		}
		
		liege = {
			capital_scope = {
				event_target:target_province = {
					top_liege = {
						ROOT = {
							set_defacto_liege = ROOT
							create_title = {
								tier = DUKE
								landless = yes
								temporary = yes
								adventurer = yes
								culture = ROOT
								name = "CLAIMANT_ADVENTURE"
								holder = ROOT
							}
							
							set_character_flag = duchy_adventurer
						
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
								cannot_inherit = yes
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
								cannot_inherit = yes
							}
							spawn_unit = {
								province = PREVPREVPREV
								home = PREVPREVPREV
								owner = THIS
								match_character = PREV
								match_mult = 0.25
								match_min = 2000
								match_max = 10000
								attrition = 0.25
								cannot_inherit = yes
							}
							war = {
								target = PREV
								casus_belli = duchy_adventure
								thirdparty_title = PREVPREV
								tier = DUKE
							}
							remove_opinion = {
								who = PREV
								modifier = opinion_duchy_adventure_target
							}
						}
					}
				}
			}
		}
		
		# Create some decent commander characters
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 30
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 19
		}
		create_random_soldier = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 23
		}
		
		clr_global_flag = rum_spawning
		set_global_flag = rum_spawned
	}
}


character_event = {
	id = 60604
	desc = EVTDESC_TOG_1213
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		FROM = { is_ruler = yes } # The DoW worked and the adventurer has a temporary title
	}
	
	immediate = {
		FROM = {
			add_trait = adventurer
		}
		any_liege = {
			character_event = {
				id = 60605
			}
		}
	}
	
	option = {
		name = EVTOPTA_TOG_1203
	}
}

character_event = {
	id = 60605
	desc = EVTDESC_TOG_1214
	picture = GFX_evt_mongols
	border = GFX_event_normal_frame_war
	
	show_from_from = yes
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1203
	}
}

#######################################
# Stage 2 (Armenia) and 3 (Anatolia)
# Fired from CB 'duchy_adventure' or 'kingdom_adventure'
#######################################
character_event = {
	id = 60610
	
	is_triggered_only = yes
	hide_window = yes
	ai = yes
	
	immediate = {
		if = {
			limit = {
				war = no
				independent = yes
			}
			random_independent_ruler = {
				limit = {
					is_landed = yes
					independent = yes
					in_revolt = no
					NOT = { reverse_has_truce = ROOT }
					NOT = { religion_group = muslim }
					any_realm_province = {
						kingdom = {
							title = k_armenia
						}
					}
				}
				random_realm_province = {
					limit = {
						kingdom = {
							title = k_armenia
						}
					}
					ROOT = {
						capital_scope = {
							ROOT = {
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREVPREV
									match_mult = 0.25
									match_min = 2000
									match_max = 10000
									attrition = 0.25
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREVPREV
									match_mult = 0.25
									match_min = 2000
									match_max = 10000
									attrition = 0.25
								}
								spawn_unit = {
									province = PREV
									home = PREV
									owner = THIS
									match_character = PREVPREVPREVPREV
									match_mult = 0.25
									match_min = 2000
									match_max = 10000
									attrition = 0.25
								}
							}
						}
						war = {
							target = PREVPREV
							casus_belli = kingdom_adventure
							thirdparty_title = PREV
							tier = KING
						}
						break = yes
					}
				}
			}
		}
		
		repeat_event = { 
			id = 60610
			days = 30
		}
	}
}
