kereite_naiman_missions_1 = {
	slot = 1
	generic = no
	ai = yes
	potential = {
		OR = {
			tag = KRE	#Kereites
			tag = NAI	#Naimans
		}
		NOT = { map_setup = map_setup_random }
	}
	has_country_shield = yes
	
	kre_outer_faction_chiefs_mission = {
		icon = mission_central_asian_steppes
		required_missions = { kre_swearing_the_anda_bond_mission }
		position = 2
		trigger = {
			legitimacy_equivalent = 90
			if = {
				limit = {
					has_estate = estate_nomadic_tribes
				}
				OR = {
					estate_loyalty = {
						estate = estate_nomadic_tribes
						loyalty = 60
					}
					num_of_estate_agendas_completed = {
						estate = estate_nomadic_tribes
						value = 2
					}
					crown_land_share = 60
				}
			}
			else_if = {
				limit = {
					has_estate = estate_nobles
				}
				OR = {
					estate_loyalty = {
						estate = estate_nobles
						loyalty = 60
					}
					num_of_estate_agendas_completed = {
						estate = estate_nobles
						value = 2
					}
					crown_land_share = 60
				}
			}
			else = {
				stability = 3
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_loyal_outer_faction"
				duration = 10950
			}
		}
	}
	kre_ong_khan_mission = {
		icon = mission_claim_khanate
		required_missions = { kre_outer_faction_chiefs_mission }
		position = 4
		trigger = {
			num_of_battles = { amount = 50 }
			is_at_war = no
			has_regency = no
		}
		effect = {
			add_mil_power = 100
			add_country_modifier = {
				name = "me_kre_ong_khan"
				duration = -1
			}
		}
	}
	kre_war_with_the_kyrgyz_mission = {
		icon = mission_non-western_cavalry_raid
		required_missions = { kre_levy_the_central_faction_mission }
		position = 5
		provinces_to_highlight = {
			area = tannu_uriankhai_area
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			is_empty = no
			has_discovered = ROOT
		}
		trigger = {
			tannu_uriankhai_area = {
				type = all
				OR = {
					country_or_non_sovereign_subject_holds = ROOT
					is_empty = yes
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_agricultural_colonies"
				duration = 10950
			}
		}
	}
	kre_hegemonize_the_uyghurs_mission = {
		icon = mission_strengthen_basqaqs
		required_missions = {  }
		position = 6
		provinces_to_highlight = {
			OR = {
				area = turpan_kumul_area
				area = tarim_basin_area		#North Altishahr
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			turpan_kumul_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			tarim_basin_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		effect = {
			country_event = {
				id = mmetr_KHA_mission_events.7
			}
			tooltip = {
				add_prestige = 10
				define_advisor = {
					type = statesman
					name = "Tata-tunga"
					skill = 2
					culture = uyghur
					religion = tengri_pagan_reformed
					discount = yes
				}
				if = {
					limit = {
						capital_scope = {
							NOT = { writing = 100 }
						}
					}
					capital_scope = {
						add_institution_embracement = {
							which = writing
							value = 100
						}
					}
				}
			}
		}
	}
	kre_seize_sogdian_markets_mission = {
		icon = mission_chinese_market
		required_missions = { kre_hegemonize_the_uyghurs_mission }
		position = 7
		provinces_to_highlight = {
			province_id = 454
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_or_non_sovereign_subject_of = 454	#Samarkand
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_samarkand_artisans"
				duration = 10950
			}
			define_advisor = {
				type = artist
				skill = 2
				culture = sogdian
				religion = sunni
				discount = yes
			}
		}
	}
	kre_nestorians_of_central_asia_mission = {	#Merv
		icon = per_reform_our_defenses
		required_missions = { kre_seize_sogdian_markets_mission }
		position = 8
		provinces_to_highlight = {
			province_id = 445
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_or_non_sovereign_subject_of = 445	#Merv
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_archbishop_of_merv"
				duration = 10950
			}
			define_advisor = {
				type = theologian
				skill = 3
				culture = khorasani
				religion = nestorian
				discount = yes
			}
		}
	}
	kre_tribute_from_the_west_mission = {
		icon = mission_tribute_tax
		required_missions = { kre_persian_ambitions_mission }
		position = 9
		trigger = {
			calc_true_if = {
				all_subject_country = {
					capital_scope = {
						OR = {
							superregion = near_east_superregion
							continent = africa
							continent = europe
						}
					}
				}
				amount = 5
			}
		}
		effect = {
			add_dip_power = 100
			add_country_modifier = {
				name = "me_kre_universal_khagan"
				duration = -1
			}
		}
	}
	kre_the_exile_of_nestorius_mission = {
		icon = mission_arius_arianism
		required_missions = { kre_great_mongol_ulus_mission }
		position = 12
		provinces_to_highlight = {
			province_id = 1233
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			OR = {
				religion = nestorian
				secondary_religion = nestorian
			}
			owns_or_non_sovereign_subject_of = 1233		#Kharga
			num_of_owned_provinces_with = {
				value = 5
				region = egypt_region
				OR = {
					religion = nestorian
					has_owner_religion = yes
				}
			}
		}
		effect = {
			add_army_tradition = 10
			add_prestige = 20
			add_country_modifier = {
				name = "me_kre_great_pilgrimage"
				duration = 10950
			}
		}
	}
}

kereite_naiman_missions_2 = {
	slot = 2
	generic = no
	ai = yes
	potential = {
		OR = {
			tag = KRE	#Kereites
			tag = NAI	#Naimans
		}
		NOT = { map_setup = map_setup_random }
	}
	has_country_shield = yes
	
	kre_swearing_the_anda_bond_mission = {
		icon = mission_diplomatic_relation
		required_missions = {  }
		position = 1
		trigger = {
			custom_trigger_tooltip = {
				tooltip = building_alliances.tooltip
				num_of_allies = 2
				calc_true_if = {
					all_ally = {
						has_opinion = {
							who = ROOT
							value = 150
						}
					}
					amount = 2
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_sworn_brotherhood"
				duration = 10950
			}
			custom_tooltip = genchinese_borrow_a_distant_knife_mission.tt
			every_ally = {
				limit = {
					has_opinion = {
						who = ROOT
						value = 150
					}
				}
				add_trust = {
					who = ROOT
					value = 5
					mutual = yes
				}
			}
		}
	}
	kre_obeisance_to_the_khan_mission = {
		icon = mission_noble_tribes
		required_missions = { kre_swearing_the_anda_bond_mission }
		position = 2
		trigger = {
			num_of_subjects = 3
			num_of_provinces_owned_or_owned_by_subjects_with = {
				value = 20
				owner = {
					is_subject_of = ROOT
				}
			}
			num_of_war_reparations = 2
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_sphere_of_influence"
				duration = 10950
			}
		}
	}
	kre_sedentary_subjects_mission = {
		icon = per_qizilbash_loyalty
		required_missions = { kre_obeisance_to_the_khan_mission }
		position = 3
		trigger = {
			calc_true_if = {
				all_subject_country = {
					is_tribal = no
					has_opinion = {
						who = ROOT
						value = 150
					}
					num_of_cities = 10
				}
				amount = 2
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_intellectual_tribute"
				duration = 10950
			}
		}
	}
	kre_subjugate_the_merkits_mission = {
		icon = mission_hunting
		required_missions = { kre_levy_the_central_faction_mission }
		position = 5
		provinces_to_highlight = {
			area = irkutsk_area
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			is_empty = no
			has_discovered = ROOT
		}
		trigger = {
			irkutsk_area = {
				type = all
				OR = {
					country_or_non_sovereign_subject_holds = ROOT
					is_empty = yes
				}
			}
		}
		effect = {
			add_yearly_manpower = 1
			add_country_modifier = {
				name = "me_kre_three_merkits"
				duration = 10950
			}
		}
	}
	kre_the_house_of_afrasiab_mission = {
		icon = mission_persianate_empire
		required_missions = { kre_hegemonize_the_uyghurs_mission }
		position = 7
		provinces_to_highlight = {
			OR = {
				area = jetysuu_area
				area = shanshan_area
				area = kashgaria_area
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			jetysuu_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			shanshan_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			kashgaria_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_khagan_of_turan"
				duration = 10950
			}
		}
	}
	kre_persian_ambitions_mission = {
		icon = per_convert_persia
		required_missions = { kre_mongol_unification_mission kre_the_house_of_afrasiab_mission }
		position = 8
		provinces_to_highlight = {
			OR = {
				region = persia_region
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_subjects_with = {
				value = 20
				region = persia_region
			}
		}
		effect = {
			add_army_tradition = 10
			country_event = {
				id = mmetr_KHA_mission_events.3
			}
			tooltip = {
				capital_scope = {
					add_base_tax = 1
					add_base_production = 1
				}
				define_advisor = {
					type = artist
					skill = 2
					culture = persian
					religion = sunni
					discount = yes
				}
			}
		}
	}
	kre_long_ride_to_baghdad_mission = {
		icon = mission_crush_delhi
		required_missions = { kre_persian_ambitions_mission }
		position = 10
		provinces_to_highlight = {
			province_id = 410		#Baghdad
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_or_non_sovereign_subject_of = 410
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_patriarch_of_baghdad"
				duration = -1
			}
		}
	}
	kre_great_mongol_ulus_mission = {
		icon = mission_beijing
		required_missions = { kre_long_ride_to_baghdad_mission }
		position = 11
		trigger = {
			development = 1200
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_divine_khagan"
				duration = -1
			}
		}
	}
	kre_protector_of_the_shunned_mission = {
		icon = mission_nestorian_cross
		required_missions = { kre_great_mongol_ulus_mission }
		position = 13
		trigger = {
			religion = nestorian
			is_defender_of_faith = yes
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_protector_of_the_church"
				duration = -1
			}
		}
	}
}

kereite_naiman_missions_3 = {
	slot = 3
	generic = no
	ai = yes
	potential = {
		OR = {
			tag = KRE	#Kereites
			tag = NAI	#Naimans
		}
		NOT = { map_setup = map_setup_random }
	}
	has_country_shield = yes
	
	kre_westward_caravans_mission = {
		icon = mission_horde_caravans
		required_missions = {  }
		position = 2
		trigger = {
			home_trade_node = {
				is_strongest_trade_power = ROOT
			}
		}
		effect = {
			add_mercantilism_or_monarch_power = { amount = 3 }
			add_country_modifier = {
				name = "me_kre_mongol_caravans"
				duration = -1
			}
			define_advisor = {
				type = trader
				skill = 2
				discount = yes
			}
			if = {
				limit = {
					NOT = { has_estate = estate_burghers }
				}
				custom_tooltip = kre_westward_caravans_mission.tt
				hidden_effect = {
					set_country_flag = mmetr_enable_burghers_estate_flag
				}
			}
		}
	}
	kre_levy_the_central_faction_mission = {
		icon = mission_mongol_charge
		required_missions = {  }
		position = 4
		trigger = {
			army_size_percentage = 1.0
			num_of_generals = 1
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_loyal_army_of_the_khan"
				duration = 10950
			}
			uliastai_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT	}
				}
				add_permanent_claim = ROOT
			}
			central_mongolia_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT	}
				}
				add_permanent_claim = ROOT
			}
			outer_mongolia_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT	}
				}
				add_permanent_claim = ROOT
			}
		}
	}
	kre_supplant_khamag_mongol_mission = {
		icon = mission_mongol_throne
		required_missions = { kre_levy_the_central_faction_mission }
		position = 5
		provinces_to_highlight = {
			OR = {
				province_id = 717
				province_id = 2116
				area = buryatia_area
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_or_non_sovereign_subject_of = 717
			owns_or_non_sovereign_subject_of = 2116
			buryatia_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			OR = {
				NOT = { exists = KMO }
				overlord_of = KMO
			}
		}
		effect = {
			country_event = {
				id = mmetr_KRE_mission_events.1
			}
			tooltip = {
				add_horde_unity = 15
				add_country_modifier = {
					name = "me_kre_khamag_mongol_khan"
					duration = 10950
				}	
			}
		}
	}
	kre_new_zubu_confederation_mission = {
		icon = mission_mongol_allies_banner
		required_missions = { kre_supplant_khamag_mongol_mission kre_christian_rivals_mission  }
		position = 6
		provinces_to_highlight = {
			OR = {
				province_id = 717
				province_id = 2116
				province_id = 2190
				province_id = 2189
				province_id = 719
			}
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
			}
			has_discovered = ROOT
		}
		allow = {
			is_subject = no
			is_at_war = no
			owns_core_province = 717
			owns_core_province = 2116
			owns_core_province = 2190
			owns_core_province = 2189
			owns_core_province = 719
		}
		effect = {
			country_event = {
				id = mmetr_KRE_mission_events.2
			}
			tooltip = {
				add_horde_unity = 20
				add_country_modifier = {
					name = "me_kre_zubu_khagan"
					duration = -1
				}	
			}
		}
	}
	kre_mongol_unification_mission = {
		icon = mission_genghis_khan_2
		required_missions = { kre_new_zubu_confederation_mission  }
		position = 7
		provinces_to_highlight = {
			OR = {
				area = uliastai_area
				area = central_mongolia_area
				area = outer_mongolia_area
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			uliastai_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			central_mongolia_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			outer_mongolia_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		effect = {
			add_horde_unity = 30
			add_country_modifier = {
				name = "me_kre_united_mongolia"
				duration = 10950
			}
			custom_tooltip = kre_mongol_unification_mission.tt
			country_event = {
				id = mmetr_KRE_mission_events.3
			}
		}
	}
	kre_church_of_iran_mission = {
		icon = per_the_persian_influence
		required_missions = { kre_persian_ambitions_mission  }
		position = 9
		provinces_to_highlight = {
			country_or_non_sovereign_subject_holds = ROOT
			NOT = {
				OR = {
					religion = nestorian
				}
			}
		}
		trigger = {
			OR = {
				religion = nestorian
				secondary_religion = nestorian
			}
			if = {
				limit = {
					religion = nestorian
				}
				num_of_provinces_owned_or_owned_by_subjects_with = {
					value = 15
					religion = nestorian
					OR = {
						region = persia_region
						region = khorasan_region
					}
				}
			}
			else = {
				num_of_provinces_owned_or_owned_by_subjects_with = {
					value = 15
					OR = {
						religion = nestorian
						religion = tengri_pagan_reformed
					}
					OR = {
						region = persia_region
						region = khorasan_region
					}
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_church_of_the_east_in_persia"
				duration = 10950
			}
		}
	}
	kre_custodian_of_holy_cities_mission = {
		icon = jerusalem
		required_missions = { kre_church_of_iran_mission kre_long_ride_to_baghdad_mission }
		position = 11
		provinces_to_highlight = {
			OR = {
				province_id = 379
				province_id = 410
				province_id = 2308
				province_id = 445
				province_id = 739
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_or_non_sovereign_subject_of = 379
			owns_or_non_sovereign_subject_of = 410
			owns_or_non_sovereign_subject_of = 2308
			owns_or_non_sovereign_subject_of = 445
			owns_or_non_sovereign_subject_of = 739
		}
		effect = {
			add_prestige = 30
			add_horde_unity = 30
			add_legitimacy = 50
			add_country_modifier = {
				name = "me_kre_mongol_crusade"
				duration = -1
			}
		}
	}
	kre_mend_eastern_schisms_mission = {
		icon = mission_pf_cross
		required_missions = { kre_great_mongol_ulus_mission }
		position = 12
		provinces_to_highlight = {
			province_id = 1233
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			OR = {
				religion = nestorian
				secondary_religion = nestorian
			}
			owns_or_non_sovereign_subject_of = 151		#Constantinople
			151 = {
				OR = {
					religion = nestorian
					has_owner_religion = yes
				}
			}
			num_of_owned_provinces_with = {
				value = 20
				OR = {
					religion = nestorian
					has_owner_religion = yes
				}
				OR = {
					region = caucasia_region
					region = mashriq_region
					region = arabia_region
					region = egypt_region
					region = anatolia_region
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_reunification_of_eastern_churches"
				duration = -1
			}
		}
	}
}

kereite_naiman_missions_4 = {
	slot = 4
	generic = no
	ai = yes
	potential = {
		OR = {
			tag = KRE	#Kereites
			tag = NAI	#Naimans
		}
		NOT = { map_setup = map_setup_random }
	}
	has_country_shield = yes
	
	kre_descendants_of_three_magi_mission = {
		icon = mission_nestorian_cross
		required_missions = {  }
		position = 1
		trigger = {
			stability = 2
			capital_scope = {
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
			any_owned_province = {
				NOT = { is_capital = yes }
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
			if = {
				limit = {
					OR = {
						AND = {
							started_in = 1007.1.1	#Nestorian is adopted as secondary in history files
							tag = KRE
						}
						AND = {
							started_in = 1120.1.1
							tag = NAI
						}
					}
				}
				OR = {
					religion = nestorian
					secondary_religion = nestorian
				}
			}
		}
		effect = {
			custom_tooltip = kre_descendants_of_three_magi_mission.tt3
			
			custom_tooltip = SEPERATOR_TOOLTIP
			
			if = {		#Nestorian secondary religion
				limit = {
					OR = {
						AND = {
							started_in = 1007.1.1	#Nestorian is adopted as secondary in history files
							tag = KRE
						}
						AND = {
							started_in = 1120.1.1
							tag = NAI
						}
					}
					secondary_religion = nestorian
				}
				custom_tooltip = kre_descendants_of_three_magi_mission.tt1
				country_event = {
					id = mmetr_KRE_mission_events.4
				}
				tooltip = {
					add_country_modifier = {
						name = "me_kre_religious_fervor"
						duration = 9125
					}
				}
			}
			else_if = {		#Nestorian primary religion
				custom_tooltip = kre_descendants_of_three_magi_mission.tt3
				hidden_effect = {
					capital_scope = {
						change_religion = nestorian
					}
					random_owned_province = {
						limit = {
							NOT = { is_capital = yes }
							OR = {
								has_building = temple
								has_building = cathedral
							}
						}
						change_religion = nestorian
					}
				}
				
				custom_tooltip = SEPERATOR_TOOLTIP
				
				limit = {
					OR = {
						AND = {
							started_in = 1007.1.1	#Nestorian is adopted as secondary in history files
							tag = KRE
						}
						AND = {
							started_in = 1120.1.1
							tag = NAI
						}
					}
					religion = nestorian
				}
				add_country_modifier = {
					name = "me_kre_religious_fervor"
					duration = 9125
				}
			}
			else = {	#Not yet Nestorian
				custom_tooltip = kre_descendants_of_three_magi_mission.tt3
				
				custom_tooltip = SEPERATOR_TOOLTIP
			
				custom_tooltip = kre_descendants_of_three_magi_mission.tt2
				country_event = {
					id = mmetr_KRE_mission_events.5
				}
				tooltip = {
					add_country_modifier = {
						name = "me_kre_religious_fervor"
						duration = 9125
					}
				}
			}
		}
	}
	kre_baptize_the_mongols_mission = {
		icon = mission_mass_baptism
		required_missions = { kre_descendants_of_three_magi_mission }
		position = 2
		trigger = {
			OR = {
				AND = {
					religion = nestorian
					num_of_owned_provinces_with = {
						value = 15
						culture_group = mongolic
						religion = nestorian
					}
				}
				AND = {
					secondary_religion = nestorian
					num_of_owned_provinces_with = {
						value = 15
						culture_group = mongolic
						OR  ={
							religion = nestorian
							has_owner_religion = yes
						}
					}
					religious_unity = 1.0	#all owned provinces are primary or secondary religion
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_doctrine_of_nestorius"
				duration = 10950
			}
		}
	}
	kre_merchant_missionaries_mission = {
		icon = mission_silk_road
		required_missions = { kre_baptize_the_mongols_mission kre_westward_caravans_mission kre_nestorian_churches_mission }
		position = 3
		trigger = {
			religion = nestorian
			OR = {
				trader = 3
				AND = {
					religious_unity = 0.95
					trader = 2
				}
			}
		}
		effect = {
			custom_tooltip = kre_merchant_missionaries_mission.tt
			set_country_flag = can_use_propagate_religion
			add_country_modifier = {
				name = "me_kre_mongol_mission"
				duration = 10950
			}
		}
	}
	kre_christian_rivals_mission = {
		icon = mission_tribe_management
		required_missions = { kre_levy_the_central_faction_mission }
		position = 5
		provinces_to_highlight = {
			area = uliastai_area
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			if = {
				limit = {
					tag = NAI
				}
				OR = {
					alliance_with = KRE
					overlord_of = KRE
					uliastai_area = {
						type = all
						country_or_non_sovereign_subject_holds = ROOT
					}
				}
			}
			else_if = {
				limit = {
					tag = KRE
				}
				OR = {
					alliance_with = NAI
					overlord_of = NAI
					uliastai_area = {
						type = all
						country_or_non_sovereign_subject_holds = ROOT
					}
				}
			}
		}
		effect = {
			add_horde_unity = 10
			add_country_modifier = {
				name = "me_kre_christian_horde"
				duration = 10950
			}
			ordos_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT	}
				}
				add_permanent_claim = ROOT
			}
			inner_mongolia_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT	}
				}
				add_permanent_claim = ROOT
			}
		}
	}
	kre_invade_the_western_xia_mission = {
		icon = mission_ancient_chinese_army_in_siege
		required_missions = { kre_christian_rivals_mission }
		position = 7
		provinces_to_highlight = {
			OR = {
				area = ordos_area
				owned_by = XIA
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			ordos_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			OR = {
				NOT = { exists = XIA }
				overlord_of = XIA
			}
		}
		effect = {
			add_horde_unity = 15
			add_country_modifier = {
				name = "me_kre_newly_acquired_siegecraft"
				duration = 10950
			}
		}
	}
	kre_chinese_campaign_mission = {
		icon = mng_thirteen_provinces
		required_missions = { kre_invade_the_western_xia_mission }
		position = 9
		provinces_to_highlight = {
			province_id = 688	#Kaifeng
			NOT = {
				owned_by = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns = 688
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_chinese_subjects"
				duration = 10950
			}
			
			custom_tooltip = kre_chinese_campaign_mission.tt
			set_country_flag = mmetr_can_claim_mandate_of_heaven_cb_flag
			
			custom_tooltip = SEPERATOR_TOOLTIP
			
			custom_tooltip = kre_beyond_the_great_wall_mission.tt
			hidden_effect = {
				every_owned_province = {
					every_neighbor_province = {
						limit = {
							superregion = china_superregion
							NOT = { owned_by = ROOT }
							NOT = { is_permanent_claim = ROOT	}
							NOT = { is_core = ROOT	}
						}
						add_claim = ROOT
					}
				}
			}
			country_event = {
				id = mmetr_KHA_mission_events.10
			}
			tooltip = {
				add_years_of_income = 0.75
			}
		}
	}
	kre_claim_gods_mandate_mission = {
		icon = ark_of_the_covenant
		required_missions = { kre_chinese_campaign_mission kre_burn_down_zhongdu_mission }
		position = 11
		provinces_to_highlight = {
			superregion = china_superregion
			NOT = {
				owned_by = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			OR = {
				is_emperor_of_china = yes
				num_of_owned_provinces_with = {
					value = 40
					superregion = china_superregion
				}
			}
			custom_trigger_tooltip = {		#fixed script since did not work properly in vanilla
				tooltip = chi_strongest_warlord_tt
				NOT = {
					any_country = { 
						capital_scope = { superregion = china_superregion }
						army_size = ROOT
						total_development = ROOT
					}	
				}
			}
		}
		effect = {
			add_horde_unity = 25
			add_legitimacy = 50
			add_prestige = 50
			add_country_modifier = {
				name = "me_kre_khagan_of_the_middle_kingdom"
				duration = -1
			}
			if = {
				limit = {
					NOT = { government_rank = 3 }
				}
				set_government_rank = 3
			}
		}
	}
	kre_heavenly_kingdom_mission = {
		icon = shield_of_christendom
		required_missions = { kre_claim_gods_mandate_mission }
		position = 13
		provinces_to_highlight = {
			superregion = china_superregion
			NOT = {
				country_or_subject_holds = ROOT
			}
			is_empty = no
			has_discovered = ROOT
		}
		trigger = {
			china_superregion = {
				type = all
				OR = {
					country_or_subject_holds = ROOT
					is_empty = yes
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_empire_of_heaven"
				duration = -1
			}
		}
	}
}

kereite_naiman_missions_5 = {
	slot = 5
	generic = no
	ai = yes
	potential = {
		OR = {
			tag = KRE	#Kereites
			tag = NAI	#Naimans
		}
		NOT = { map_setup = map_setup_random }
	}
	has_country_shield = yes
	
	kre_nestorian_churches_mission = {
		icon = fund_the_monasteries
		required_missions = { kre_descendants_of_three_magi_mission }
		position = 2
		provinces_to_highlight = {
			is_capital_of = ROOT
			NOT = {
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
		}
		trigger = {
			num_of_owned_provinces_with = {
				value = 10
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
			capital_scope = {
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_mongol_building_projects"
				duration = 10950
			}
		}
	}
	kre_church_of_prestor_john_mission = {
		icon = mission_tribal_allegiance
		required_missions = { kre_nestorian_churches_mission }
		position = 4
		trigger = {
			religion = nestorian
			capital_scope = {
				OR = {
					has_building = temple
					has_building = cathedral
				}
			}
			religious_unity = 0.9
			num_of_provinces_owned_or_owned_by_subjects_with = {
				value = 50
				religion = nestorian
				continent = asia
			}
		}
		effect = {
			add_country_modifier = {
				name = "me_kre_prester_john"
				duration = -1
			}
			if = {
				limit = {
					NOT = { has_estate = estate_church }
				}
				custom_tooltip = kre_church_of_prestor_john_mission.tt
				hidden_effect = {
					set_country_flag = mmetr_enable_church_estate_flag
				}
			}
			if = {
				limit = {
					capital_scope = {
						has_building = temple
					}
				}
				capital_scope = {
					remove_building = temple
					add_building = cathedral
				}
			}
		}
	}
	kre_decimate_the_tatars_mission = {
		icon = mission_ulug_ulus
		required_missions = { kre_levy_the_central_faction_mission }
		position = 5
		provinces_to_highlight = {
			OR = {
				area = xilin_gol_area
				owned_by = TAT
			}
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			xilin_gol_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			OR = {
				NOT = { exists = TAT }
				overlord_of = TAT
			}
		}
		effect = {
			add_horde_unity = 10
			add_country_modifier = {
				name = "me_kre_tatar_mercenaries"
				duration = 10950
			}
		}
	}
	kre_quell_the_jurchens_mission = {
		icon = mission_jurchen_iron_pagoda
		required_missions = { kre_decimate_the_tatars_mission }
		position = 6
		provinces_to_highlight = {
			region = manchuria_region
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			is_empty = no
			has_discovered = ROOT
		}
		trigger = {
			manchuria_region = {
				type = all
				OR = {
					country_or_non_sovereign_subject_holds = ROOT
					is_empty = yes
				}
			}
		}
		effect = {
			add_horde_unity = 10
			add_country_modifier = {
				name = "me_kre_jurchen_iron_pagoda_cavalry"
				duration = 10950
			}
		}
	}
	kre_quash_the_korean_kings_mission = {
		icon = mission_korean_castle_assault
		required_missions = { kre_quell_the_jurchens_mission }
		position = 7
		provinces_to_highlight = {
			region = korea_region
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			korea_region = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		effect = {
			add_yearly_manpower = 1
			country_event = {
				id = mmetr_KHA_mission_events.13
			}
			tooltip = {
				add_country_modifier = {
					name = "me_kha_et_korean_warships"
					duration = 10950
				}
			}
		}
	}
	kre_beyond_the_great_wall_mission = {
		icon = mch_bypass_great_wall
		required_missions = { kre_invade_the_western_xia_mission }
		position = 8
		provinces_to_highlight = {
			region = north_china_region
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_subjects_with = {
				value = 10
				region = north_china_region
			}
		}
		effect = {
			custom_tooltip = kre_beyond_the_great_wall_mission.tt
			hidden_effect = {
				every_owned_province = {
					every_neighbor_province = {
						limit = {
							superregion = china_superregion
							NOT = { owned_by = ROOT }
							NOT = { is_permanent_claim = ROOT	}
							NOT = { is_core = ROOT	}
						}
						add_claim = ROOT
					}
				}
			}
		}
	}
	kre_burn_down_zhongdu_mission = {
		icon = mission_chinese_fortress_siege
		required_missions = { kre_beyond_the_great_wall_mission }
		position = 10
		provinces_to_highlight = {
			province_id = 1816	#Beijing
			NOT = {
				owned_by = ROOT
				is_core = ROOT
			}
			has_discovered = ROOT
		}
		trigger = {
			owns_core_province = 1816
		}
		effect = {
			country_event = {
				id = mmetr_KHA_mission_events.8
			}
			tooltip = {
				add_country_modifier = {
					name = "me_kha_et_taxation_policy"
					duration = 7300
				}
				define_advisor = {
					type = statesman
					name = "Yelü Chucai"
					skill = 3
					culture = khitan
					religion = confucianism		#Was a Confucian scholar
					discount = yes
				}
			}
		}
	}
	kre_restore_beth_sinaye_mission = {
		icon = mission_to_china
		required_missions = { kre_burn_down_zhongdu_mission }
		position = 12
		provinces_to_highlight = {
			OR = {
				province_id = 1816	#Beijing
				province_id = 688	#Kaifeng
				province_id = 700	#Xi'an
			}
			NOT = {
				OR = {
					religion = nestorian
					owned_by = ROOT
				}
			}
			has_discovered = ROOT
		}
		trigger = {
			num_of_owned_provinces_with = {
				value = 10
				religion = nestorian
				superregion = china_superregion
			}
			owns = 1816
			1816 = {
				religion = nestorian
			}
			owns = 688
			688 = {
				religion = nestorian
			}
			owns = 700
			700 = {
				religion = nestorian
			}
		}
		effect = {
			add_adm_power = 100
			add_country_modifier = {
				name = "me_kha_beth_sinaye"
				duration = -1
			}
			define_advisor = {
				type = inquisitor
				skill = 3
				culture = zhongyuan
				religion = nestorian
				discount = yes
			}
		}
	}
}