hsn_first_branch = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_political_security = {
		icon = mission_reliable_allies
		required_missions = {  }
		position = 1
		trigger = {
			OR = {
				num_of_allies = 2
				OR = {
					advisor = diplomat
					advisor = statesman
				}
			}
		}
		effect = {
			if = {
				limit = {
					has_dlc = "The Cossacks"
				}
				custom_tooltip = hsn_trust_allies_tt
			}
			add_country_modifier = {
				name = hsn_political_security
				duration = 7300 
			}
			if = {
				limit = {
					alliance_with = QOM
				}
				custom_tooltip = hsn_alliance_ajam_yes
				tooltip = {
					add_country_modifier = {
						name = hsn_persian_support
						duration = 3650
					}
				}
			}
			else = {
				custom_tooltip = hsn_alliance_ajam_no
				tooltip = {
					add_country_modifier = {
						name = hsn_persian_support
						duration = 3650
					}
				}
			}
			if = {
				limit = {
					alliance_with = TUR
				}
				custom_tooltip = hsn_alliance_ottoman_yes
				tooltip = {
					add_country_modifier = {
						name = hsn_ottoman_janissaries
						duration = 3650
					}
				}
			}
			else = {
				custom_tooltip = hsn_alliance_ottoman_no
				tooltip = {
					add_country_modifier = {
						name = hsn_ottoman_janissaries
						duration = 3650
					}
				}
			}
			if = {
				limit = {
					alliance_with = MAM
				}
				custom_tooltip = hsn_alliance_mamluks_yes
				tooltip = {
					add_country_modifier = {
						name = hsn_mamluk_reinforcements
						duration = 3650
					}
				}
			}
			else = {
				custom_tooltip = hsn_alliance_mamluks_no
				tooltip = {
					add_country_modifier = {
						name = hsn_mamluk_reinforcements
						duration = 3650
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						has_dlc = "The Cossacks"
					}
					every_ally = {
						add_trust = {
							who = ROOT
							value = 10
							mutual = yes
						}
					}
				}
				if = {
					limit = {
						alliance_with = QOM
					}
					add_country_modifier = {
						name = hsn_persian_support
						duration = 3650
					}
				}
				if = {
					limit = {
						alliance_with = TUR
					}
					add_country_modifier = {
						name = hsn_ottoman_janissaries
						duration = 3650
					}
				}
				if = {
					limit = {
						alliance_with = MAM
					}
					add_country_modifier = {
						name = hsn_mamluk_reinforcements
						duration = 3650
					}
				}
			}
		}

		ai_weight = {
			factor = 250
		}
	}
	
	hsn_last_bastion = {
		icon = mission_tear_down_spanish_strongholds
		required_missions = {  }
		position = 2
		
		provinces_to_highlight = {
			province_id = 4295
		}
		
		trigger = {
			OR = {
				4295 = {
					base_manpower = 4
				}
				4295 = {
					fort_level = 4
				}
				advisor = fortification_expert
			}
		}
		
		effect = {
			add_yearly_manpower = 1.5
			4295 = {
				add_province_modifier = {
					name = "hsn_rock_fortress"
					duration = 3650
				}
			}
		}
	}
	
	hsn_saladins_legacy = {
		icon = mission_saladins_legacy
		required_missions = { hsn_last_bastion }
		position = 3
		
		provinces_to_highlight = {
			owned_by = ROOT
			NOT = {
				has_manpower_building_trigger = yes
			}
		}

		trigger = {
			army_size = 20 # modified
			army_tradition = 70
			num_of_owned_provinces_with = {
				has_manpower_building_trigger = yes
				value = 10
			}
		}
		
		effect = {
			country_event = { id = flavor_hsn.5 }
			custom_tooltip = hsn_saladins_legacy_event_insight_tt
		}
	}
	
	hsn_eagle_flies_alone = {
		icon = encroach_on_the_germans
		required_missions = { hsn_saladins_legacy }
		position = 4
		
		provinces_to_highlight = {
			owner = {
				is_rival = ROOT
				army_size = ROOT
			}
		}
		
		trigger = {
			army_size = 35 # modified
			OR = {
				army_tradition = 80
				army_professionalism = 0.6
			}
			has_global_modifier_value = {
				which = discipline
				value = 0.15
			}
			OR = {
				NOT = {
					all_rival_country = {
						army_size = ROOT
					}
				}
				NOT = {
					any_country = {
						army_size = ROOT
					}
				}
			}
		}
		
		effect = {
			create_general = { tradition = 100 }
			add_country_modifier = {
				name = "hsn_sword_of_islam"
				duration = 7300
			}
			if = {
				limit = {
					NOT = {
						any_country = {
							religion_group = muslim
							army_size = ROOT
						}
					}
				}
				custom_tooltip = hsn_largest_army_tt_yes
			}
			else = {
				custom_tooltip = hsn_largest_army_tt_no
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							any_country = {
								religion_group = muslim
								army_size = ROOT
							}
						}
					}
					if = {
						limit = {
							has_country_modifier = hsn_sword_of_islam
						}
						remove_country_modifier = hsn_sword_of_islam
						add_country_modifier = {
							name = "hsn_sword_of_islam"
							duration = 14600
						}
					}
				}
			}
		}
	}
	
	hsn_fate_of_anatolia = {
		icon = anatolian_frontier
		required_missions = { hsn_slay_white_sheep }
		position = 5
		
		provinces_to_highlight = {
			region = anatolia_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			OR = {
				num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
					region = anatolia_region
					value = 25
				}
				custom_trigger_tooltip = {
					tooltip = hsn_anatolian_ally_tt
					any_ally = {
						OR = {
							capital_scope = {
								region = anatolia_region
							}
							primary_culture = turkish
							religion_group = muslim
						}
						custom_trigger_tooltip = {
							tooltip = hsn_ally_anatolia
							num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
								region = anatolia_region
								value = 25
							}
						}
					}
				}
			}
		}
		
		effect = {
			hidden_effect = {
				if = {
					limit = { ai = yes }
					country_event = {
						id = flavor_hsn.0
					}
				}
			}
			clr_country_flag = hsn_unlock_anatolian_alliance
			clr_country_flag = hsn_unlock_anatolian_conquest
			if = {
				limit = {
					num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
						region = anatolia_region
						value = 25
					}
				}
				custom_tooltip = hsn_anatolia_conquest_tt_yes
				tooltip = {
					custom_tooltip = hsn_unlock_branching1
					add_country_modifier = {
						name = hsn_overthrow_the_ottomans
						duration = 7300
					}
					anatolia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
			}
			else = {
				custom_tooltip = hsn_anatolia_conquest_tt_no
				tooltip = {
					custom_tooltip = hsn_unlock_branching1
					add_country_modifier = {
						name = hsn_overthrow_the_ottomans
						duration = 7300
					}
					anatolia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
			}
			if = {
				limit = {
					any_ally = {
						OR = {
							capital_scope = {
								region = anatolia_region
							}
							primary_culture = turkish
							religion_group = muslim
						}
						custom_trigger_tooltip = {
							tooltip = hsn_ally_anatolia
							num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
								region = anatolia_region
								value = 25
							}
						}
					}
				}
				custom_tooltip = hsn_anatolia_alliance_tt_yes
				tooltip = {
					custom_tooltip = hsn_unlock_branching2
					if = {
						limit = {
							has_dlc = "The Cossacks"
						}
						add_country_modifier = {
							name = hsn_anatolian_alliance
							duration = 7300
						}
					}
					else = {
						add_country_modifier = {
							name = hsn_anatolian_alliance2
							duration = 7300
						}
					}
				}
			}
			else = {
				custom_tooltip = hsn_anatolia_alliance_tt_no
				tooltip = {
					custom_tooltip = hsn_unlock_branching2
					if = {
						limit = {
							has_dlc = "The Cossacks"
						}
						add_country_modifier = {
							name = hsn_anatolian_alliance
							duration = 7300
						}
					}
					else = {
						add_country_modifier = {
							name = hsn_anatolian_alliance2
							duration = 7300
						}
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
							region = anatolia_region
							value = 25
						}
					}
					set_country_flag = hsn_unlock_anatolian_conquest
					swap_non_generic_missions = yes
					select_current_missions = {
						key = HSN
					}
					add_country_modifier = {
						name = hsn_overthrow_the_ottomans
						duration = 7300
					}
					anatolia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
				else_if = {
					limit = {
						any_ally = {
							OR = {
								capital_scope = {
									region = anatolia_region
								}
								primary_culture = turkish
								religion_group = muslim
							}
							custom_trigger_tooltip = {
								tooltip = hsn_ally_anatolia
								num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
									region = anatolia_region
									value = 25
								}
							}
						}
					}
					set_country_flag = hsn_unlock_anatolian_alliance
					swap_non_generic_missions = yes
					select_current_missions = {
						key = HSN
					}
					if = {
						limit = {
							has_dlc = "The Cossacks"
						}
						add_country_modifier = {
							name = hsn_anatolian_alliance
							duration = 7300
						}
					}
					else = {
						add_country_modifier = {
							name = hsn_anatolian_alliance
							duration = 7300
						}
					}
				}
			}
		}
	}
	
}

hsn_first_branch_branching_locked = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		NOT = {
			OR = {
				has_country_flag = hsn_unlock_anatolian_alliance
				has_country_flag = hsn_unlock_anatolian_conquest
			}
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_branching_first = {
		icon = mission_unknown_mission
		required_missions = { hsn_fate_of_anatolia }
		position = 6

		trigger = { custom_trigger_tooltip = { tooltip = hsn_this_is_a_branching_mission always = no } }
		
		effect = {
			custom_tooltip = hsn_this_is_a_branching_mission
		}
	}
	
}

hsn_first_branch_branching_unlocked_alliance = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_country_flag = hsn_unlock_anatolian_alliance
		NOT = {
			has_country_flag = hsn_unlock_anatolian_conquest
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_a_sublime_alliance = {
		icon = mission_ottoman_diplomacy
		required_missions = { hsn_fate_of_anatolia }
		position = 6
		
		provinces_to_highlight = {
			owner = {
				alliance_with = ROOT
				OR = {
					capital_scope = {
						region = anatolia_region
					}
					primary_culture = turkish
					religion_group = muslim
				}
			}
		}
		
		trigger = {
			not_in_mission_preview_mode = { key = HSN }
			any_ally = {
				OR = {
					capital_scope = {
						region = anatolia_region
					}
					primary_culture = turkish
					religion_group = muslim
				}
				has_opinion = {
					who = ROOT
					value = 190
				}
				if = {
					limit = {
						has_dlc = "The Cossacks"
					}
					trust = { who = ROOT value = 80 }
				}
			}
		}
		
		effect = {
			random_ally = {
				limit = {
					OR = {
						capital_scope = {
							region = anatolia_region
						}
						primary_culture = turkish
						religion_group = muslim
					}
					has_opinion = {
						who = ROOT
						value = 190
					}
					if = {
						limit = {
							has_dlc = "The Cossacks"
						}
						trust = { who = ROOT value = 80 }
					}
				}
				add_historical_friend = ROOT
				ROOT = {
					add_historical_friend = PREV
				}
			}
			capital_scope = {
				custom_tooltip = hsn_spawn_10_janissaries
			}
			custom_tooltip = hsn_anatolian_alliance_tt_historical_friend
			add_country_modifier = {
				name = hsn_a_sublime_alliance
				duration = -1
			}
			custom_tooltip = hsn_drop_all_claims
			hidden_effect = {
				every_claimed_province = {
					limit = {
						owner = {
							OR = {
								capital_scope = {
									region = anatolia_region
								}
								primary_culture = turkish
								religion_group = muslim
							}
							has_opinion = {
								who = ROOT
								value = 190
							}
							if = {
								limit = {
									has_dlc = "The Cossacks"
								}
								trust = { who = ROOT value = 80 }
							}
						}
					}
					remove_claim = ROOT
				}
				every_core_province = {
					limit = {
						owner = {
							OR = {
								capital_scope = {
									region = anatolia_region
								}
								primary_culture = turkish
								religion_group = muslim
							}
							has_opinion = {
								who = ROOT
								value = 190
							}
							if = {
								limit = {
									has_dlc = "The Cossacks"
								}
								trust = { who = ROOT value = 80 }
							}
						}
					}
					remove_core = ROOT
				}
				every_ally = {
					limit = {
						OR = {
							capital_scope = {
								region = anatolia_region
							}
							primary_culture = turkish
							religion_group = muslim
						}
						has_opinion = {
							who = ROOT
							value = 190
						}
						if = {
							limit = {
								has_dlc = "The Cossacks"
							}
							trust = { who = ROOT value = 80 }
						}
					}
					every_claimed_province = {
						limit = { owned_by = ROOT }
						remove_claim = PREV
					}
					every_core_province = {
						limit = { owned_by = ROOT }
						remove_core = PREV
					}
				}
				capital_scope = {
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
					janissary_infantry = ROOT
				}
			}
		}
	}
	
}

hsn_first_branch_branching_unlocked_conquest = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_country_flag = hsn_unlock_anatolian_conquest
		NOT = {
			has_country_flag = hsn_unlock_anatolian_alliance
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_overthrow_the_ottomans = {
		icon = geo_break_the_crescent_2
		required_missions = { hsn_fate_of_anatolia }
		position = 6
		
		provinces_to_highlight = {
			region = anatolia_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			not_in_mission_preview_mode = { key = HSN }
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				region = anatolia_region
				value = 40
			}
		}
		
		effect = {
			add_power_projection = {
				type = mission_rewards_power_projection
				amount = 30
			}
			change_ruler_stat = {
				type = mil
				amount = 2
			}
			thrace_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
}

hsn_first_branch_2 = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_recover_egypt = {
		icon = mission_egyptian_mamluk_soldier
		required_missions = { hsn_ayyubid_restoration }
		position = 8
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				region = egypt_region 
				value = 15
			}
		}
		
		provinces_to_highlight = {
			region = egypt_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		effect = {
			country_event = { id = flavor_hsn.2 }
			custom_tooltip = hsn_fate_mamluks_insight_tt
		}
	}
	
	hsn_ayyubid_caliphate = {
		icon = mission_fatimid_caliphate
		required_missions = { hsn_recover_egypt }
		position = 10
		
		provinces_to_highlight = {
			OR = {
				province_id = 361
				province_id = 379
				province_id = 384
				province_id = 385
				province_id = 410
				province_id = 382
			}
			NOT = {
				owned_by = ROOT
			}
		}
		
		trigger = {
			prestige = 90
			legitimacy = 90
			OR = {
				piety = 0.75
				NOT = { piety = -0.75 }
			}
			stability = 3
			is_defender_of_faith = yes
			owns = 361
			owns = 379
			owns = 384
			owns = 385
			owns = 410
			owns = 382
		}
		
		effect = {
			set_government_rank = 3
			custom_tooltip = hsn_empty
			country_event = { id = flavor_hsn.3 }
			custom_tooltip = hsn_caliphate_insight_tt
			sicily_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT }
				}
				add_permanent_claim = ROOT
			}
			western_sicily_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT }
				}
				add_permanent_claim = ROOT
			}
			upper_andalucia_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT }
				}
				add_permanent_claim = ROOT
			}
			lower_andalucia_area = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT }
				}
				add_permanent_claim = ROOT
			}
			maghreb_region = {
				limit = {
					NOT = { owned_by = ROOT }
					NOT = { is_core = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_dar_al_islam = {
		icon = per_unify_islam
		required_missions = { hsn_ayyubid_caliphate }
		position = 11
		
		provinces_to_highlight = {
			religion_group = muslim
			NOT = {
				owned_by = ROOT
			}
		}
		
		trigger = {
			development_in_provinces = {
				value = 1000
				religion_group = muslim
			}
		}
		
		effect = {
			custom_tooltip = hsn_manpower_islam_tt
			add_country_modifier = {
				name = "hsn_black_banner"
				duration = -1
			}
			hidden_effect = {
				for = {
					amount = 20
					effect = "
						random_owned_province = {
							limit = {
								religion_group = muslim
							}
							add_base_manpower = 1
						}
					"
				}
			}
		}
	}
}

hsn_second_branch = {
	slot = 2
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes

	hsn_expand_the_domain = {
		icon = mission_levantine_restoration
		required_missions = { hsn_buildforces hsn_political_security }
		position = 2
		trigger = {
			grown_by_development = 25
		}
		effect = {
			custom_tooltip = hsn_lose_ae_neighnour_tt
			add_country_modifier = {
				name = "hsn_resurgent_ayyubids"
				duration = 7300
			}
			add_permanent_claim_province = { province = 4302 }
			add_permanent_claim_province = { province = 331 }
			add_permanent_claim_province = { province = 2305 }
			add_permanent_claim_province = { province = 2308 }
			north_kurdistan_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			al_jazira_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			shahrizor_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			iraq_arabi_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			hidden_effect = {
				every_neighbor_country = {
					add_aggressive_expansion = {
						who = ROOT
						value = -10
						apply_calc = no
					}
				}
			}
		}
	}
	
	hsn_slay_white_sheep = {
		icon = qara_qoyunlu_dismantle_ak_qoyunlu
		required_missions = { hsn_expand_the_domain }
		position = 4
		
		provinces_to_highlight = {
			OR = {
				province_id = 407
				province_id = 4292
				province_id = 2308
				province_id = 418
				province_id = 2306
				province_id = 2305
				province_id = 331
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					province_id = 407
					province_id = 4292
					province_id = 2308
					province_id = 418
					province_id = 2306
					province_id = 2305
					province_id = 331
				}
				value = 4
			}
		}
		
		effect = {
			add_war_exhaustion = -3
			define_advisor = {
				type = army_reformer
				skill = 2
				culture = ROOT
				religion = ROOT
				cost_multiplier = 0.25
			}
			custom_tooltip = hsn_empty
			dulkadir_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			aleppo_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			syria_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			syrian_desert_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			samtskhe_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			armenia_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			tabriz_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_turn_against_mamluks = {
		icon = mission_break_the_mamluks
		required_missions = { hsn_slay_white_sheep }
		position = 6
		
		provinces_to_highlight = {
			OR = {
				area = aleppo_area
				area = syria_area
				area = syrian_desert_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = aleppo_area
					area = syria_area
					area = syrian_desert_area
				}
				value = 8
			}
		}
		effect = {
			custom_tooltip = hsn_damascus_capital_tt
			add_country_modifier = {
				name = "hsn_vengeful"
				duration = 7300
			}
			palestine_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			trans_jordan_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			hidden_effect = {
				set_country_flag = hsn_turn_against_mamluks_flag
			}
		}
	}
	
	hsn_ayyubid_restoration = {
		icon = mission_ayyubid_restoration
		required_missions = { hsn_turn_against_mamluks }
		position = 7
		
		provinces_to_highlight = {
			OR = {
				area = palestine_area
				area = trans_jordan_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			palestine_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			trans_jordan_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		
		effect = {
			country_event = { id = flavor_hsn.1 }
			custom_tooltip = hsn_empty
			add_permanent_claim_province = { province = 321 }
			tabuk_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			mecca_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			medina_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			egypt_region = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			custom_tooltip = hsn_ayyubid_restoration_insight
			tooltip = {
				add_country_modifier = {
					name = "hsn_rise_of_the_eagle"
					duration = 7300
				}
			}
		}
	}
	
	hsn_crusaders = {
		icon = kingdom_of_cyprus
		required_missions = { hsn_ayyubid_restoration }
		position = 8
		
		provinces_to_highlight = {
			province_id = 321
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			321 = {
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		effect = {
			add_sailors = 1000
			add_country_modifier = {
				name = "hsn_east_mediterranean"
				duration = 3650
			}
			320 = {
				if = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
			}
			163 = {
				if = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
			}
			if = {
				limit = {
					NOT = {
						any_province = {
							OR = {
								region = anatolia_region
								region = mashriq_region
							}
							owner = {
								religion_group = christian
							}
						}
					}
				}
				custom_tooltip = hsn_banished_crusaders_tt_yes
			}
			else = {
				custom_tooltip = hsn_banished_crusaders_tt_no
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							any_province = {
								OR = {
									region = anatolia_region
									region = mashriq_region
								}
								owner = {
									religion_group = christian
								}
							}
						}
					}
					if = {
						limit = {
							has_country_modifier = hsn_east_mediterranean
						}
						remove_country_modifier = hsn_east_mediterranean
						add_country_modifier = {
							name = "hsn_east_mediterranean"
							duration = 7300
						}
					}
				}
			}
		}
	}
	
	hsn_alexandria = {
		icon = mission_conquer_alexandria
		required_missions = { hsn_recover_egypt }
		position = 9
		provinces_to_highlight = {
			province_id = 358
		}
		trigger = {
			owns = 358
			358 = {
				development = 30
			}
			358 = {
				has_trade_building_trigger = yes
			}
			358 = {
				has_production_building_trigger = yes
			}
		}
		effect = {
			358 = {
				add_province_modifier = {
					name = hsn_center_of_commerce
					duration = -1
				}
			}
			if = {
				limit = {
					any_ally = {
						culture_group = latin
						government = republic
					}
				}
				custom_tooltip = hsn_western_alliance_tt_yes
				tooltip = {
					358 = {
						add_province_modifier = {
							name = hsn_latin_quarters
							duration = -1
						}
					}
				}
			}
			else = {
				custom_tooltip = hsn_western_alliance_tt_no
				tooltip = {
					358 = {
						add_province_modifier = {
							name = hsn_latin_quarters
							duration = -1
						}
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						any_ally = {
							culture_group = latin
							government = republic
						}
					}
					358 = {
						add_province_modifier = {
							name = hsn_latin_quarters
							duration = -1
						}
					}
				}
			}
		}
	}
	
	hsn_granary = {
		icon = mission_consume_the_baghels
		required_missions = { hsn_alexandria }
		position = 10
		
		provinces_to_highlight = {
			region = egypt_region
			owned_by = ROOT
			OR = {
				trade_goods = grain
				trade_goods = cotton
				trade_goods = sugar
			}
			OR = {
				NOT = {
					has_production_building_trigger = yes
				}
				NOT = {
					base_production = 8
				}
			}
		}
		
		trigger = {
			calc_true_if = {
				all_owned_province = {
					region = egypt_region
					OR = {
						trade_goods = grain
						trade_goods = cotton
						trade_goods = sugar
					}
					has_production_building_trigger = yes
					base_production = 8
				}
				amount = 6
			}
		}
		
		effect = {
			custom_tooltip = hsn_granary_mediterranean
			tooltip = {
				add_province_modifier = {
					name = hsn_granary
					duration = -1
				}
			}
			if = {
				limit = {
					trading_bonus = {
						trade_goods = grain
						value = yes
					}
				}
				custom_tooltip = hsn_grain_bonus_tt_yes
				tooltip = {
					change_price = {
						trade_goods = grain
						key = granary_of_the_mediterranean_key
						value = 0.1
						duration = -1
					}
				}
			}
			else = {
				custom_tooltip = hsn_grain_bonus_tt_no
				tooltip = {
					change_price = {
						trade_goods = grain
						key = granary_of_the_mediterranean_key
						value = 0.1
						duration = -1
					}
				}
			}
			hidden_effect = {
				every_owned_province = {
					limit = {
						region = egypt_region
						OR = {
							trade_goods = grain
							trade_goods = cotton
							trade_goods = sugar
						}
						has_production_building_trigger = yes
						base_production = 8
					}
					add_base_production = 1
					add_base_manpower = 1
					add_province_modifier = {
						name = hsn_granary
						duration = -1
					}
				}
				if = {
					limit = {
						trading_bonus = {
							trade_goods = grain
							value = yes
						}
					}
					change_price = {
						trade_goods = grain
						key = granary_of_the_mediterranean_key
						value = 0.1
						duration = -1
					}
				}
			}
		}
	}
	
}

hsn_third_branch = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_buildforces = {
		icon = mission_reconquer_ceuta
		required_missions = { }
		position = 1
		
		trigger = {
			army_size_percentage = 1
			manpower_percentage = 0.8
		}
		
		effect = {
			create_general = { tradition = 40 }
			add_country_modifier = {
				name = "oma_buildforces_mod"
				duration = 5475
			}
			custom_tooltip = hsn_neighbour_claim_tt
			hidden_effect = {
				every_owned_province = {
					every_neighbor_province = {
						limit = {
							NOT = { owned_by = ROOT }
							NOT = { is_permanent_claim = ROOT	}
							NOT = { is_core = ROOT	}
						}
						add_permanent_claim = ROOT
					}
				}
			}
		}
		ai_weight = {
			factor = 500
		}
	}
	
	hsn_fertile_crescent = {
		icon = mission_coromandel_trade
		required_missions = { hsn_recover_baghdad }
		position = 4
		
		provinces_to_highlight = {
			owned_by = ROOT
			OR = {
				area = basra_area
				area = iraq_arabi_area
			}
			OR = {
				NOT = {
					has_production_building_trigger = yes
				}
				NOT = {
					base_production = 4
				}
			}
		}
		
		trigger = {
			num_of_owned_provinces_with = {
				has_production_building_trigger = yes
				base_production = 4
				OR = {
					area = basra_area
					area = iraq_arabi_area
				}
				value = 5
			}
		}
		
		effect = {
			iraq_arabi_area = {
				limit = { owned_by = ROOT }
				add_base_production = 1
				if = {
					limit = {
						has_dlc = "Mandate of Heaven"
					}
					add_province_modifier = {
						name = "hsn_fertile_crescent"
						duration = 9125
					}
				}
				else = {
					add_province_modifier = {
						name = "hsn_fertile_crescent_no_moh"
						duration = 9125
					}
				}
			}
			basra_area = {
				limit = { owned_by = ROOT }
				add_base_production = 1
				if = {
					limit = {
						has_dlc = "Mandate of Heaven"
					}
					add_province_modifier = {
						name = "hsn_fertile_crescent"
						duration = 9125
					}
				}
				else = {
					add_province_modifier = {
						name = "hsn_fertile_crescent_no_moh"
						duration = 9125
					}
				}
			}
		}
	}
	
	hsn_eastern_frontier = {
		icon = mission_the_caucasus_rus
		required_missions = { hsn_slay_white_sheep }
		position = 5
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				region = caucasia_region
				value = 6
			}
		}
		
		provinces_to_highlight = {
			region = caucasia_region
			NOT = {
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		
		effect = {
			add_mil_power = 100
			caucasia_region = {
				limit = {
					country_or_non_sovereign_subject_holds = ROOT
				}
				add_nationalism = -10
			}
			imereti_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			kartli_kakheti_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			shirvan_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_sultan_shah = {
		icon = mam_persia
		required_missions = { hsn_conquer_basra }
		position = 6
		provinces_to_highlight = {
			region = persia_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			OR = {
				num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
					region = persia_region
					value = 30
				}
				custom_trigger_tooltip = {
					tooltip = hsn_persian_ally_tt
					any_ally = {
						capital_scope = {
							region = persia_region
						}
						religion_group = muslim
						custom_trigger_tooltip = {
							tooltip = hsn_ally_persia
							num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
								region = persia_region
								value = 30
							}
						}
					}
				}
			}
		}
		effect = {
			hidden_effect = {
				if = {
					limit = { ai = yes }
					country_event = {
						id = flavor_hsn.4
					}
				}
			}
			clr_country_flag = hsn_unlock_persian_alliance
			clr_country_flag = hsn_unlock_persian_conquest
			if = {
				limit = {
					num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
						region = persia_region
						value = 30
					}
				}
				custom_tooltip = hsn_persia_conquest_tt_yes
				tooltip = {
					custom_tooltip = hsn_unlock_branching3
					add_country_modifier = {
						name = hsn_subjugate_eranshahr
						duration = 7300
					}
					persia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
			}
			else = {
				custom_tooltip = hsn_persia_conquest_tt_no
				tooltip = {
					custom_tooltip = hsn_unlock_branching3
					add_country_modifier = {
						name = hsn_subjugate_eranshahr
						duration = 7300
					}
					persia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
			}
			if = {
				limit = {
					any_ally = {
						capital_scope = {
							OR = {
								region = persia_region 
								region = khorasan_region
							}
						}
						religion_group = muslim
						custom_trigger_tooltip = {
							tooltip = hsn_ally_persia
							num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
								region = persia_region
								value = 30
							}
						}
					}
				}
				custom_tooltip = hsn_persia_alliance_tt_yes
				tooltip = {
					custom_tooltip = hsn_unlock_branching4
					add_country_modifier = {
						name = hsn_pact_with_shah
						duration = 7300
					}
				}
			}
			else = {
				custom_tooltip = hsn_persia_alliance_tt_no
				tooltip = {
					custom_tooltip = hsn_unlock_branching4
					add_country_modifier = {
						name = hsn_pact_with_shah
						duration = 7300
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
							region = persia_region
							value = 30
						}
					}
					set_country_flag = hsn_unlock_persian_conquest
					swap_non_generic_missions = yes
					select_current_missions = {
						key = HSN2
					}
					add_country_modifier = {
						name = hsn_subjugate_eranshahr
						duration = 7300
					}
					persia_region = {
						limit = {
							NOT = { is_core = ROOT }
							NOT = { is_permanent_claim = ROOT }
						}
						add_permanent_claim = ROOT
					}
				}
				else_if = {
					limit = {
						any_ally = {
							capital_scope = {
								region = persia_region
							}
							religion_group = muslim
							custom_trigger_tooltip = {
								tooltip = hsn_ally_persia
								num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
									region = persia_region
									value = 30
								}
							}
						}
					}
					set_country_flag = hsn_unlock_persian_alliance
					swap_non_generic_missions = yes
					select_current_missions = {
						key = HSN2
					}
					add_country_modifier = {
						name = hsn_pact_with_shah
						duration = 7300
					}
				}
			}
		}
	}
}
	
hsn_third_branch_branching_locked = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		NOT = {
			OR = {
				has_country_flag = hsn_unlock_persian_alliance
				has_country_flag = hsn_unlock_persian_conquest
			}
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_branching_second = {
		icon = mission_unknown_mission
		required_missions = { hsn_sultan_shah }
		position = 7
		provinces_to_highlight = {
		}
		trigger = {
			custom_trigger_tooltip = { tooltip = hsn_this_is_a_branching_mission2 always = no } 
		}
		effect = {
			custom_tooltip = hsn_this_is_a_branching_mission2
		}
	}
	
}

hsn_third_branch_branching_unlocked_alliance = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_country_flag = hsn_unlock_persian_alliance
		NOT = {
			has_country_flag = hsn_unlock_persian_conquest
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_befriend_the_shah = {
		icon = per_enlightened_rule
		required_missions = { hsn_sultan_shah }
		position = 7
		
		provinces_to_highlight = {
			owner = {
				alliance_with = ROOT
				capital_scope = {
					region = persia_region
				}
			}
		}
		
		trigger = {
			not_in_mission_preview_mode = { key = HSN2 }
			any_ally = {
				capital_scope = {
					region = persia_region
				}
				religion_group = muslim
				has_opinion = {
					who = ROOT
					value = 190
				}
				if = {
					limit = {
						has_dlc = "The Cossacks"
					}
					trust = { who = ROOT value = 80 }
				}
			}
		}
		
		effect = {
			unlock_decision = {
				type = grand_vizier_selection
				effect_tooltip = "
					custom_tooltip = grand_vizier_selection_tt
				"
			}
			custom_tooltip = hsn_empty
			custom_tooltip = hsn_drop_all_claims
			hidden_effect = {
				every_claimed_province = {
					limit = {
						owner = {
							capital_scope = {
								region = persia_region
							}
							religion_group = muslim
							has_opinion = {
								who = ROOT
								value = 190
							}
							if = {
								limit = {
									has_dlc = "The Cossacks"
								}
								trust = { who = ROOT value = 80 }
							}
						}
					}
					remove_claim = ROOT
				}
				every_core_province = {
					limit = {
						owner = {
							capital_scope = {
								region = persia_region
							}
							religion_group = muslim
							has_opinion = {
								who = ROOT
								value = 190
							}
							if = {
								limit = {
									has_dlc = "The Cossacks"
								}
								trust = { who = ROOT value = 80 }
							}
						}
					}
					remove_core = ROOT
				}
				every_ally = {
					limit = {
						capital_scope = {
							region = persia_region
						}
						religion_group = muslim
						has_opinion = {
							who = ROOT
							value = 190
						}
						if = {
							limit = {
								has_dlc = "The Cossacks"
							}
							trust = { who = ROOT value = 80 }
						}
					}
					every_claimed_province = {
						limit = { owned_by = ROOT }
						remove_claim = PREV
					}
					every_core_province = {
						limit = { owned_by = ROOT }
						remove_core = PREV
					}
				}
			}
		}
	}
}

hsn_third_branch_branching_unlocked_conquest = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_country_flag = hsn_unlock_persian_conquest
		NOT = {
			has_country_flag = hsn_unlock_persian_alliance
		}
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_subjugate_eranshahr = {
		icon = per_tab_ziyarids_successor
		required_missions = { hsn_sultan_shah }
		position = 7
		
		provinces_to_highlight = {
			region = persia_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			not_in_mission_preview_mode = { key = HSN2 }
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				region = persia_region
				value = 45
			}
		}
		
		effect = {
			add_years_of_owned_provinces_production_income = {
				years = 5
				trigger = {
					trade_goods = silk
				}
				custom_tooltip = hsn_5_years_silk
			}
			persia_region = {
				limit = {
					country_or_non_sovereign_subject_holds = ROOT
				}
				add_province_modifier = {
					name = "hsn_riches_of_persia"
					duration = 7300
				}
			}
			khorasan_region = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
}


hsn_third_branch_2 = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_custodian = {
		icon = mission_into_arabia
		required_missions = { hsn_ayyubid_restoration }
		position = 8
		
		provinces_to_highlight = {
			OR = {
				area = tabuk_area
				area = medina_area
				area = mecca_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			tabuk_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			medina_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
			mecca_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		
		effect = {
			if = {
				limit = {
					has_dlc = "Leviathan"
				}
				custom_tooltip = hsn_upgrade_kaaba_tt
			}
			else = {
				add_country_modifier = { 
					name = hsn_protector_of_pilgrims
					duration = -1
				}
			}
			asir_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			tihama_al_yemen_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			yemen_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			upper_yemen_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			if = {
				limit = {
					NOT = {
						any_country = {
							religion = sunni
							is_defender_of_faith = yes
						}
					}
				}
				custom_tooltip = hsn_dotf_tt_yes
			}
			else = {
				custom_tooltip = hsn_dotf_tt_no
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							any_country = {
								religion = sunni
								is_defender_of_faith = yes
							}
						}
					}
					set_defender_of_the_faith = { who = ROOT religion = ROOT }
				}
			}
		}
	}
	
	hsn_red_sea = {
		icon = mission_arabian_ports
		required_missions = { hsn_alexandria hsn_aden }
		position = 10
		
		provinces_to_highlight = {
			OR = {
				province_id = 4346
				province_id = 358
			}
		}
		
		trigger = {
			4346 = {
				trade_share = {
					country = ROOT
					share = 50
				}
			}
			358 = {
				trade_share = {
					country = ROOT
					share = 50
				}
			}
		}
		
		effect = {
			if = {
				limit = {
					has_dlc = "Cradle of Civilization"
				}
				custom_tooltip = hsn_upgrade_propagate_religion
				set_country_flag = 40_trade_power_for_propogate_religion
			}	
			else = {
				add_country_modifier = {
					name = "hsn_trading_network"
					duration = -1
				}
			}
			if = {
				limit = {
					4346 = {
						trade_share = {
							country = ROOT
							share = 75
						}
					}
					358 = {
						trade_share = {
							country = ROOT
							share = 75
						}
					}
				}
				custom_tooltip = hsn_control_bab_el_mandeb_tt_yes
				tooltip = {
					1330 = {
						add_trade_modifier = {
							who = ROOT
							duration = 9125
							power = 50
							key = hsn_bab_el_mandeb
						}
					}
					add_country_modifier = {
						name = hsn_red_sea_trade_hegemony
						duration = -1
					}
				}
			}
			else = {
				custom_tooltip = hsn_control_bab_el_mandeb_tt_no
				tooltip = {
					1330 = {
						add_trade_modifier = {
							who = ROOT
							duration = 9125
							power = 50
							key = hsn_bab_el_mandeb
						}
					}
					add_country_modifier = {
						name = hsn_red_sea_trade_hegemony
						duration = -1
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						4346 = {
							trade_share = {
								country = ROOT
								share = 75
							}
						}
						358 = {
							trade_share = {
								country = ROOT
								share = 75
							}
						}
					}
					1330 = {
						add_trade_modifier = {
							who = ROOT
							duration = 9125
							power = 50
							key = hsn_bab_el_mandeb
						}
					}
					add_country_modifier = {
						name = hsn_red_sea_trade_hegemony
						duration = -1
					}
				}
			}
		}
	}
	
	hsn_suez_canal = {
		icon = mam_highway_empire
		required_missions = { hsn_red_sea hsn_granary }
		position = 10
		
		provinces_to_highlight = {
			OR = {
				province_id = 4316 
				province_id = 2315
			}
		}
		
		trigger = {
			4316 = {
				owned_by = ROOT
				OR = {
					num_of_times_improved = 10
					has_great_project = { 
						type = suez_canal 
						tier = 3 
					}
				}
			}
			2315 = { owned_by = ROOT }		
		}
		effect = {
			if = {
				limit = { 
					4316 = {
						NOT = {
							has_great_project = { 
								type = suez_canal 
								tier = 3 
							}
						}
					}
					NOT = { adm_tech = 22 }
				}
				custom_tooltip = hsn_suez_canal_tt
				if = {
					limit = {
						has_dlc = "Mandate of Heaven"
					}
					4316 = {
						add_province_modifier = {
							name = hsn_suez_canal
							duration = -1
						}
					}
				}
				else = {
					add_province_modifier = {
						name = hsn_suez_canal_dlcless
						duration = -1
					}
				}
			}
			else = {
				4316 = { add_base_production = 3 }
				4316 = {
					add_province_modifier = {
						name = hsn_suez_canal_dlcless
						duration = -1
					}
				}
			}
		}
	}
	
}

hsn_fourth_branch = {
	slot = 4
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_recover_baghdad = {
	    icon = mission_into_persia_1
		required_missions = { hsn_expand_the_domain }
		position = 3
		
		provinces_to_highlight = {
			area = iraq_arabi_area
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			iraq_arabi_area = {
				type = all
				country_or_non_sovereign_subject_holds = ROOT
			}
		}
		
		effect = {
			add_adm_power = 100
			410 = {
				add_province_modifier = {
					name = "hsn_restoration_baghdad"
					duration = 5475
				}
			}
			basra_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			khuzestan_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			tabriz_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_conquer_basra = {
		icon = mission_dominate_trade_in_bengal
		required_missions = { hsn_recover_baghdad }
		position = 5
		
		provinces_to_highlight = {
			OR = {
				area = basra_area
				area = khuzestan_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			408 = {
				country_or_non_sovereign_subject_holds = ROOT
			}
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = basra_area
					area = khuzestan_area
				}
				value = 4
			}
		}
		effect = {
			custom_tooltip = hsn_money_for_trade_building_tt
			hidden_effect = {
				every_owned_province = {
					limit = {
						has_trade_building_trigger = yes
					}
					owner = {
						add_treasury = 10
					}
				}
			}
			bahrain_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			persian_gulf_coast = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_consolidate_coastline = {
		icon = mission_dharma_mission_arabian_trade
		required_missions = { hsn_conquer_basra }
		position = 7
		
		provinces_to_highlight = {
			OR = {
				area = bahrain_area
				area = persian_gulf_coast
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = persian_gulf_coast
					area = bahrain_area
				}
				value = 6
			}
		}
		effect = {
			custom_tooltip = hsn_coast_autonomy_tt
			408 = {
				add_trade_modifier = {
					who = ROOT
					duration = 9125
					power = 25
					key = hsn_grip_over_gulf
				}
			}
			custom_tooltip = hsn_empty
			hidden_effect = {
				every_owned_province = {
					limit = {
						OR = {
							area = persian_gulf_coast
							area = bahrain_area
						}
					}
					add_local_autonomy = -50
				}
			}
			pirate_coast_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			mogostan_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			oman_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			mascat_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	hsn_monopolize_gulf_trade = {
		icon = qara_qoyunlu_dominate_the_gulf
		required_missions = { hsn_consolidate_coastline }
		position = 8
		
		provinces_to_highlight = {
			OR = {
				AND = {
					province_id = 1334
					NOT = {
						trade_share = {
							country = ROOT
							share = 50
						}
					}
				}
				AND = {
					province_id = 408
					NOT = {
						trade_share = {
							country = ROOT
							share = 50
						}
					}
				}
				AND = {
					province_id = 1335
					NOT = {
						trade_share = {
							country = ROOT
							share = 50
						}
					}
				}
				if = {
					limit = {
						has_dlc = "Leviathan"
					}
					OR = {
						AND = {
							province_id = 2999
							NOT = { country_or_non_sovereign_subject_holds = ROOT }
						}
						AND = {
							province_id = 403
							OR = {
								NOT = {
									has_great_project = {
										type = nizwa_fort
										tier = 1
									}
								}
								NOT = { country_or_non_sovereign_subject_holds = ROOT }
							}
						}
					}
				}
				else = {
					AND = {
						province_id = 2999
						NOT = { country_or_non_sovereign_subject_holds = ROOT }
						NOT = { has_trade_building_trigger = yes }
					}
				}
			}
		}
		
		trigger = {
			owns = 2999
			OR = {
				mercantilism = 20
				advisor = trader
				trade_income_percentage = 0.3
			}
			408 = {
				trade_share = {
					country = ROOT
					share = 50
				}
			}
			2999 = {
				trade_share = {
					country = ROOT
					share = 50
				}
			}
			if = {
				limit = {
					has_dlc = "Leviathan"
				}
				owns = 403
				403 = {
					has_great_project = {
						type = nizwa_fort
						tier = 1
					}
				}
			}
			else = {
				num_of_owned_provinces_with = {
					value = 20
					has_trade_building_trigger = yes 
				}
			}
		}
		effect = {
			add_years_of_trade_income = {
				years = 4
				custom_tooltip = zan_settle_trade_posts_ct
			}
			custom_tooltip = hsn_empty
			if = {
				limit = {
					has_dlc = "Leviathan"
				}
				2999 = {
					upgrade_trade_building = yes
				}
				custom_tooltip = hsn_empty
				custom_tooltip = hsn_upgrade_nizwa_tt
			}
			else = {
				2999 = {
					upgrade_trade_building = yes
				}
				custom_tooltip = hsn_empty
				2999 = {
					add_province_modifier = {
						name = hsn_safeguard_gulf_entrance
						duration = -1
					}
				}
			}
		}
	}
	
	hsn_aden = {
		icon = mission_african_trade_post
		required_missions = { hsn_custodian }
		position = 9
		
		provinces_to_highlight = {
			OR = {
				area = tihama_al_yemen_area
				area = yemen_area
				area = upper_yemen_area
				area = asir_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = tihama_al_yemen_area
					area = yemen_area
					area = upper_yemen_area
					area = asir_area
				}
				value = 10
			}
		}
		
		effect = {
			add_years_of_owned_provinces_production_income = {
				years = 10
				trigger = {
					trade_goods = coffee
				}
				custom_tooltip = hsn_10_years_coffee
			}
			define_advisor = {
				type = trader
				skill = 3
				culture = ROOT
				religion = ROOT
				cost_multiplier = 0.25
			}
		}
	}
	
}

hsn_fifth_branch = {
	slot = 5
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Winds of Change"
	}
	potential = {
		tag = HSN
		NOT = { map_setup = map_setup_random }
		has_dlc = "Winds of Change"
	}
	has_country_shield = yes
	
	hsn_appease_ulema = {
		icon = mission_restore_caliphate_of_cordoba
		required_missions = { }
		position = 1
		
		trigger = {
			if = {
				limit = {
					has_estate = estate_church
				}
				num_of_estate_privileges = {
					estate = estate_church
					value = 3
				}
			}
			if = {
				limit = {
					has_estate = estate_church
				}
				estate_loyalty = {
					estate = estate_church
					loyalty = 60
				}
			}
			else = {
				stability = 1
				OR = {
					advisor = theologian
					advisor = inquisitor
				}
			}
			num_of_owned_provinces_with = {
				religion = ROOT
				value = 5
			}
		}
		
		effect = {
			if = {
				limit = { 
					has_dlc = "Cradle of Civilization"
				}
				if = {
					limit = {
						piety = 0
					}
					add_piety = 0.25
				}
				else_if = {
					limit = {
						NOT = { piety = 0 }
					}
					add_piety = -0.25
				}
			}
			else = {
				add_dip_power = 50
			}
			custom_tooltip = hsn_clerical_council_tt
			hidden_effect = {
				set_country_flag = hsn_appease_ulema_reward_flag
			}
		}
		ai_weight = {
			factor = 500
		}
	}
	
	hsn_build_mosques = {
		icon = mission_conquer_gujarat_bah
		required_missions = { hsn_appease_ulema }
		position = 2
		
		provinces_to_highlight = {
			owned_by = ROOT
			NOT = { has_tax_building_trigger = yes }
		}
		
		trigger = {
			num_of_owned_provinces_with = {
				has_tax_building_trigger = yes
				value = 5
			}
		}
		
		effect = {
			add_country_modifier = {
				name = "hsn_ayyubid_architecture"
				duration = 3650
			}
			if = {
				limit = {
					num_of_owned_provinces_with = {
						has_tax_building_trigger = yes
						NOT = {
							religion_group = muslim
						}
						value = 3
					}
				}
				custom_tooltip = hsn_jizya_tt_yes
				tooltip = {
					add_country_modifier = {
						name = "hsn_jizya"
						duration = 3650
					}
				}
			}
			else = {
				custom_tooltip = hsn_jizya_tt_no
				tooltip = {
					add_country_modifier = {
						name = "hsn_jizya"
						duration = 3650
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						num_of_owned_provinces_with = {
							has_tax_building_trigger = yes
							NOT = {
								religion_group = muslim
							}
							value = 3
						}
					}
					add_country_modifier = {
						name = "hsn_jizya"
						duration = 3650
					}
				}
			}
		}
	}
	
	hsn_city_of_peace = {
	    icon = mission_mustansiriya_madrasah
		required_missions = { hsn_recover_baghdad hsn_build_mosques }
		position = 4
		
		provinces_to_highlight = {
			province_id = 410
		}
		
		trigger = {
			owns = 410
			410 = {
				development = 25
			}
			410 = {
				has_tax_building_trigger = yes
			}
			410 = {
				has_trade_building_trigger = yes
			}
			410 = {
				has_production_building_trigger = yes
			}
			410 = { 
				is_state = yes
			}
		}
		
		effect = {
			410 = {
				upgrade_tax_building = yes
			}
			410 = {
				add_province_modifier = {
					name = "hsn_city_of_peace"
					duration = -1
				}
			}
			if = {
				limit = {
					has_institution = renaissance
				}
				custom_tooltip = hsn_renaissance_yes
				tooltip = {
					if = {
						limit = {
							has_dlc = "Mandate of Heaven"
						}
						410 = {
							add_prosperity = 100
						}
					}
					else = {
						410 = {
							add_base_tax = 1
							add_base_production = 1
							add_base_manpower = 1
						}
					}
				}
			}
			else = {
				custom_tooltip = hsn_renaissance_no
				tooltip = {
					if = {
						limit = {
							has_dlc = "Mandate of Heaven"
						}
						410 = {
							add_prosperity = 100
						}
					}
					else = {
						410 = {
							add_base_tax = 1
							add_base_production = 1
							add_base_manpower = 1
						}
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						has_institution = renaissance
					}
					if = {
						limit = {
							has_dlc = "Mandate of Heaven"
						}
						410 = {
							add_prosperity = 100
						}
					}
					else = {
						410 = {
							add_base_tax = 1
							add_base_production = 1
							add_base_manpower = 1
						}
					}
				}
			}
		}
	}
	
	hsn_house_wisdom = {
	    icon = mission_quran
		required_missions = { hsn_city_of_peace }
		position = 5
		
		provinces_to_highlight = {
			province_id = 410
		}
		
		trigger = {
			410 = {
				development = 40
			}
			OR = {
				DIP = 5
				monthly_dip = 10
				innovativeness = 20
			}
			has_adm_advisor_3 = yes
			has_dip_advisor_3 = yes
			has_mil_advisor_3 = yes
		}
		
		effect = {
			if = {
				limit = {
					has_dlc = "Mandate of Heaven"
				}
				add_splendor = 100
			}
			else = {
				add_dip_power = 100
			}
			add_ruler_modifier = {
				name = hsn_patron_science
				duration = -1
			}
			if = {
				limit = {
					410 = {
						NOT = {
							any_province = {
								religion_group = muslim
								higher_development_than = PREV
							}
						}
					}
				}
				custom_tooltip = hsn_paradise_garden_tt_yes
				tooltip = {
					410 = {
						add_province_modifier = {
							name = hsn_paradise_gardens
							duration = -1
						}
					}
				}
			}
			else = {
				custom_tooltip = hsn_paradise_garden_tt_no
				tooltip = {
					410 = {
						add_province_modifier = {
							name = hsn_paradise_gardens
							duration = -1
						}
					}
				}
			}
			hidden_effect = {
				if = {
					limit = {
						410 = {
							NOT = {
								any_province = {
									religion_group = muslim
									higher_development_than = PREV
								}
							}
						}
					}
					410 = {
						add_province_modifier = {
							name = hsn_paradise_gardens
							duration = -1
						}
					}
				}
			}
		}
	}
	
	hsn_madrasas = {
		icon = mission_gawans_madrasar
		required_missions = { hsn_house_wisdom }
		position = 6
		
		provinces_to_highlight = {
			owned_by = ROOT
			NOT = { has_building = university }
		}
		
		trigger = {
			num_of_owned_provinces_with = {
				has_building = university
				value = 10
			}
		}
		
		effect = {
			if = {
				limit = {
					has_dlc = "Rights of Man"
				}
				custom_tooltip = hsn_scholar_trait_tt
				set_country_flag = hsn_scholar_trait
			}
			else = {
				change_government_reform_progress = 100
			}
			add_country_modifier = {
				name = hsn_madrasas
				duration = 7300
			}
		}
	}
	
	hsn_golden_age = {
		icon = mission_islamic_golden_age
		required_missions = { hsn_madrasas }
		position = 8
		
		provinces_to_highlight = {
			if = {
				limit = {
					NOT = {
						has_dlc = "Mandate of Heaven"
					}
				}
				owned_by = ROOT
				NOT = { has_building = university }
			}
			owner = {
				tech_difference = 1
				technology_group = western
				NOT = { tag = ROOT }
			}
		}
		
		trigger = {
			if = {
				limit = {
					has_dlc = "Mandate of Heaven"
				}
				OR = {
					in_golden_age = yes
					has_had_golden_age = yes
				}
			}
			else = {
				num_of_owned_provinces_with = {
					has_building = university
					value = 20
				}
			}
			if = {
				limit = {
					has_dlc = "Rule Britannia"
				}
				innovativeness = 20
			}
			else = {
				OR = {
					prestige = 90
					stability = 3
				}
			}
			OR = {
				has_better_tech_than_westerns = yes
				full_idea_group = innovativeness_ideas
			}
		}
		
		effect = {
			if = {
				limit = {
					has_dlc = "Mandate of Heaven"
				}
				if = {
					limit = {
						in_golden_age = yes
					}
					custom_tooltip = hsn_golden_age_extend_tt_yes
				}
				else = {
					custom_tooltip = hsn_golden_age_extend_tt_no
				}
				if = {
					limit = {
						has_had_golden_age = yes
					}
					custom_tooltip = hsn_golden_age_reset_tt_yes
				}
				else = {
					custom_tooltip = hsn_golden_age_reset_tt_no
				}
				hidden_effect = {
					if = {
						limit = {
							in_golden_age = yes
						}
						extend_golden_age = 600
					}
					if = {
						limit = {
							has_had_golden_age = yes
						}
						reset_golden_age = yes
					}
				}
			}
			else = {
				add_country_modifier = {
					name = "hsn_ayyubid_golden_age"
					duration = 18250
				}
			}
		}
	}
	
	hsn_sands_of_arabia = {
		icon = mission_conquer_air
		required_missions = { hsn_aden }
		position = 10
		
		provinces_to_highlight = {
			region = arabia_region
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				region = arabia_region
				value = 25
			}
		}
		effect = {
			custom_tooltip = ARB_unlock_oasis_development
			set_country_flag = ARB_unlock_oasis_development_flag
			custom_tooltip = hsn_empty
			arabia_region = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}
	
	
}