﻿##############################################
#
# CULTURE
#
##############################################
	

##############################################
#
# EAST IRAN - CHANGES
#
##############################################

ce_east_iranian_867_setup_effect = {
	
	# Scopes
	culture:saka = { save_scope_as = saka }
	
	# Innovations
	culture:tocharian = {
		get_all_innovations_from = scope:saka
	}
	culture:khotanese = {
		get_all_innovations_from = scope:saka
	}
	culture:pamiri = {
		get_all_innovations_from = scope:saka
	}

	# Move to Khotan/Sogdian/Tarim Basin/Dunhuang/Tocharian Flavor Pack in the future
	culture:saka = {
		set_culture_pillar = ethos_bureaucratic
		add_culture_tradition = tradition_language_scholars # Translators
		remove_variable = tradition_cooldown
	}
	culture:khotanese = {
		add_culture_tradition = tradition_language_scholars # Translators
		remove_variable = tradition_cooldown
	}
	culture:tocharian = {
		add_culture_tradition = tradition_music_theory # Kuchean music is famous
		remove_variable = tradition_cooldown
	}
	
	# Below is based on Encyclopedia Iranica, citing Mahmud Kashgari who lived in the 11th century during the 1066 start date, so should be considered accurate enough for game purposes
	title:c_khotan = {
		set_county_culture = culture:khotanese
	}
	title:c_karghalik = {
		set_county_culture = culture:khotanese
	}
	title:c_cherchen = {
		set_county_culture = culture:khotanese
	}
	title:c_keriya = {
		set_county_culture = culture:khotanese
	}
	title:c_yarkand = {
		set_county_culture = culture:khotanese
	}
	title:c_kashgar = {
		set_county_culture = culture:khotanese
	}
	title:c_terek_pass = {
		set_county_culture = culture:khotanese
	}

	#Language Fixes
	culture:pamiri = {
		set_culture_pillar = language_pamiri
	}
	culture:khwarezmian = {
		set_culture_pillar = language_khwarezmian
	}
	culture:afghan = {
		set_culture_pillar = language_pashto
	}

	#Cultural Fixes
	culture:saka = {
		set_culture_pillar = heritage_sakan
	}

	character:191923 = {
		set_culture = culture:huna
	}
	character:188242 = {
		set_culture = culture:huna
	}
	character:191922 = {
		set_culture = culture:huna
	}
	character:191920 = {
		set_culture = culture:huna
	}

	if = {
		limit = {
			title:k_khotan.holder = {
				highest_held_title_tier = tier_kingdom
				culture = { has_cultural_pillar = heritage_sakan }
			}
		}
		title:k_khotan.holder = {
			make_khotanese_culture_effect = yes
		}
	}
	if = {
		limit = {
			title:d_khotan.holder = {
				highest_held_title_tier = tier_duchy
				culture = { has_cultural_pillar = heritage_sakan }
			}
		}
		title:d_khotan.holder = {
			make_khotanese_culture_effect = yes
		}
	}
	if = {
		limit = {
			title:d_kashgar.holder = {
				highest_held_title_tier = tier_duchy
				culture = { has_cultural_pillar = heritage_sakan }
			}
		}
		title:d_kashgar.holder = {
			make_khotanese_culture_effect = yes
		}
	}
	if = {
		limit = {
			title:c_kiz.holder = {
				highest_held_title_tier = tier_county
				culture = { has_cultural_pillar = heritage_indo_aryan }
			}
		}
		title:c_kiz.holder = {
			make_jat_culture_effect = yes
		}
	}
	if = {
		limit = {
			title:c_khawr.holder = {
				highest_held_title_tier = tier_county
				culture = { has_cultural_pillar = heritage_iranian }
			}
		}
		title:c_khawr.holder= {
			make_jat_culture_effect = yes
		}
	}
	if = {
		limit = {
			title:c_kalat.holder = {
				highest_held_title_tier = tier_county
				culture = { has_cultural_pillar = heritage_iranian }
			}
		}
		title:c_kalat.holder= {
			make_jat_culture_effect = yes
		}
	}
	title:c_debul.holder= {
		make_jat_culture_effect = yes
	}
	title:c_kutch.holder= {
		make_jat_culture_effect = yes
	}
}

ce_east_iranian_1066_setup_effect = {
	
	# Scopes
	culture:saka = { save_scope_as = saka }
	
	# Innovations
	culture:tocharian = {
		get_all_innovations_from = scope:saka
	}
	culture:khotanese = {
		get_all_innovations_from = scope:saka
	}
	culture:pamiri = {
		get_all_innovations_from = scope:saka
	}


	# Move to Khotan/Sogdian/Tarim Basin/Dunhuang/Tocharian Flavor Pack in the future
	culture:saka = {
		set_culture_pillar = ethos_bureaucratic
		add_culture_tradition = tradition_language_scholars # Translators
		remove_variable = tradition_cooldown
	}
	culture:khotanese = {
		add_culture_tradition = tradition_language_scholars # Translators
		remove_variable = tradition_cooldown
	}
	culture:tocharian = {
		add_culture_tradition = tradition_music_theory # Kuchean music is famous
		remove_variable = tradition_cooldown
	}
	
	#Language Fixes
	culture:sogdian = {
		set_culture_pillar = language_sogdian
	}
	culture:pamiri = {
		set_culture_pillar = language_pamiri
	}
	culture:khwarezmian = {
		set_culture_pillar = language_khwarezmian
	}
	culture:afghan = {
		set_culture_pillar = language_pashto
	}

	#Cultural Fixes
	culture:saka = {
		set_culture_pillar = heritage_sakan
	}
	
	# Below is based on Encyclopedia Iranica, citing Mahmud Kashgari who lived in the 11th century during the 1066 start date, so should be considered accurate enough for game purposes
	if = {
		limit = {
			current_date > 1000.1.1
			current_date < 1100.1.1
		}
		title:c_khotan = {
			set_county_culture = culture:khotanese
		}
		title:c_keriya = {
			set_county_culture = culture:khotanese
		}
		title:c_kashgar = {
			set_county_culture = culture:khotanese
		}
		# See https://iranicaonline.org/articles/sogdiana-iii-history-and-archeology and https://iranicaonline.org/articles/yaghnobi
		# Latest Sogdian texts come from Talas, Kashgari mentions people there are bilingual in Sogdian and Turkic
		title:c_taraz = {
			set_county_culture = culture:sogdian
		}
		# Per Encyclopedia Iranica, much of the area between Samarkand and Bukhara was still Sogdian until 15th century, even if elites abandoned language
		title:c_dabusiya = {
			set_county_culture = culture:sogdian
		}

		# Roughly areas where Yagnobi, a descendant of Sogdian, is spoken nowadays
		# Actual Yagnobi valley is in mountainous terrain, Encyclopedia Iranica suggests it was once spoken in a wider area, however
		title:c_zarafshan = {
			set_county_culture = culture:sogdian
		}
		title:c_rasht = {
			set_county_culture = culture:sogdian
		}
		# Area of origin for Yagnobi dialect
		title:c_oshrusana = {
			set_county_culture = culture:sogdian
		}
	}

	#Culture effects
	title:c_debul.holder= {
		make_jat_culture_effect = yes
	}
	title:d_makran.holder= {
		make_jat_culture_effect = yes
	}

	# Historical Character Culture Shifts - Huna
	character:cedi_daughter_1 = {
		set_culture = culture:huna
	}
	character:hunas_4 = {
		set_culture = culture:huna
	}
	character:hunas_5 = {
		set_culture = culture:huna
	}
	character:hunas_6 = {
		set_culture = culture:huna
	}
	character:hunas_3 = {
		set_culture = culture:huna
	}
	character:hunas_2 = {
		set_culture = culture:huna
	}
	character:hunas_1 = {
		set_culture = culture:huna
	}
	character:191923 = {
		set_culture = culture:huna
	}
	character:188242 = {
		set_culture = culture:huna
	}
	character:191922 = {
		set_culture = culture:huna
	}
	character:191920 = {
		set_culture = culture:huna
	}
	
	#Character Cultures Jat
	character:188544 = {
		set_culture = culture:jat
	}
	character:188295 = {
		set_culture = culture:jat
	}
	character:188294 = {
		set_culture = culture:jat
	}
	character:188293 = {
		set_culture = culture:jat
	}
	character:188292 = {
		set_culture = culture:jat
	}
	character:188291 = {
		set_culture = culture:jat
	}
	character:188290 = {
		set_culture = culture:jat
	}
	character:188289 = {
		set_culture = culture:jat
	}
	character:188288 = {
		set_culture = culture:jat
	}
	character:188304 = {
		set_culture = culture:jat
	}
	character:188303 = {
		set_culture = culture:jat
	}
	character:188287 = {
		set_culture = culture:jat
	}
}

make_khotanese_culture_effect = {
	#Convert your, and your whole family's, culture
	set_culture = culture:khotanese
	if = {
		limit = {
			knows_language = language_scythian
		}
	}
	if = {
		limit = {
			is_married = yes
			any_spouse = { is_landed = no }
		}
		every_spouse = {
			set_culture = culture:khotanese
			if = {
				limit = {
					knows_language = language_scythian
				}
			}
		}
	}
	if = {
		limit = {
			any_close_family_member = {
				is_landed = no
			}
		}
		every_close_family_member = {
			custom = all_family_members
			limit = {
				is_landed = no
			}
			set_culture = culture:khotanese
			if = {
				limit = {
					knows_language = language_scythian
				}
			}
		}
	}

	#Convert appropriate vassals, and their family
	if = {
		limit = {
			OR = {
				any_vassal = {
					is_ai = yes
				}
				any_courtier = {
					is_ai = yes
				}			
			}
		}
		every_vassal = {
			limit = {
				is_ai = yes
			}
			set_culture = culture:khotanese
			hidden_effect = {
				if = {
					limit = { any_spouse = { is_landed = no } }
					every_spouse = {
						set_culture = culture:khotanese
						if = {
							limit = {
								knows_language = language_scythian
							}
						}
					}
				}
				if = {
					limit = {
						any_close_family_member = {
							is_landed = no
						}
					}
					every_close_family_member = {
						limit = {
							is_landed = no
						}
						set_culture = culture:khotanese
						if = {
							limit = {
								knows_language = language_scythian
							}
						}
					}
				}
			}
		}
		every_courtier_or_guest = {
			limit = {
				is_ai = yes
			}
			set_culture = culture:khotanese
			if = {
				limit = {
					knows_language = language_scythian
				}
			}
			hidden_effect = {
				if = {
					limit = { any_spouse = { is_landed = no } }
					every_spouse = {
						set_culture = culture:khotanese
						if = {
							limit = {
								knows_language = language_scythian
							}
						}
					}
				}
				if = {
					limit = {
						any_close_family_member = {
							is_landed = no
						}
					}
					every_close_family_member = {
						limit = {
							is_landed = no
						}
						set_culture = culture:khotanese
						if = {
							limit = {
								knows_language = language_scythian
							}
						}
					}
				}
			}
		}
	}
}

make_jat_culture_effect = {
	#Convert your, and your whole family's, culture
	set_culture = culture:jat
	if = {
		limit = {
			OR = {
				knows_language = language_brahui
				knows_language = language_balochi
			}
		}
	}
	if = {
		limit = {
			is_married = yes
			any_spouse = { is_landed = no }
		}
		every_spouse = {
			set_culture = culture:jat
			if = {
				limit = {
					OR = {
						knows_language = language_brahui
						knows_language = language_balochi
					}
				}
			}
		}
	}
	if = {
		limit = {
			any_close_family_member = {
				is_landed = no
			}
		}
		every_close_family_member = {
			custom = all_family_members
			limit = {
				is_landed = no
			}
			set_culture = culture:jat
			if = {
				limit = {
					OR = {
						knows_language = language_brahui
						knows_language = language_balochi
					}
				}
			}
		}
	}

	#Convert appropriate vassals, and their family
	if = {
		limit = {
			OR = {
				any_vassal = {
					is_ai = yes
				}
				any_courtier = {
					is_ai = yes
				}			
			}
		}
		every_vassal = {
			limit = {
				is_ai = yes
			}
			set_culture = culture:jat
			hidden_effect = {
				if = {
					limit = { any_spouse = { is_landed = no } }
					every_spouse = {
						set_culture = culture:jat
						if = {
							limit = {
								OR = {
									knows_language = language_brahui
									knows_language = language_balochi
								}
							}
						}
					}
				}
				if = {
					limit = {
						any_close_family_member = {
							is_landed = no
						}
					}
					every_close_family_member = {
						limit = {
							is_landed = no
						}
						set_culture = culture:jat
						if = {
							limit = {
								OR = {
									knows_language = language_brahui
									knows_language = language_balochi
								}
							}
						}
					}
				}
			}
		}
		every_courtier_or_guest = {
			limit = {
				is_ai = yes
			}
			set_culture = culture:jat
			if = {
				limit = {
					knows_language = language_brahui
				}
			}
			hidden_effect = {
				if = {
					limit = { any_spouse = { is_landed = no } }
					every_spouse = {
						set_culture = culture:jat
						if = {
							limit = {
								OR = {
									knows_language = language_brahui
									knows_language = language_balochi
								}
							}
						}
					}
				}
				if = {
					limit = {
						any_close_family_member = {
							is_landed = no
						}
					}
					every_close_family_member = {
						limit = {
							is_landed = no
						}
						set_culture = culture:jat
						if = {
							limit = {
								OR = {
									knows_language = language_brahui
									knows_language = language_balochi
								}
							}
						}
					}
				}
			}
		}
	}
}

