﻿court_language_ai_score = {
	add = scope:their_language_counties

	# Bit of relative score for percentage too
	add = {
		value = scope:their_language_counties
		multiply = 10
		divide = scope:total_counties
	}
	if = {
		limit = { scope:checking_native_language = no }
		subtract = scope:my_language_counties
	}

	#Adjust for Court Grandeur.
	#World religions primarily cares about other courts that share their faith.
	add = {
		value = 0
		if = {	#Islamic rulers cares about islamic courts
			limit = {
				faith.religion = religion:islam_religion
				scope:target.faith.religion = religion:islam_religion
			}
			add = {
				value = scope:target.court_grandeur_current
				if = { #Reduce further if not same faith
					limit = {
						NOT = { faith = scope:target.faith }
					}
					divide = 2
				}
			}
		}
		else_if = {	#Christian cares about other Christians - especially of the same faith
			limit = {
				faith.religion = religion:christianity_religion
				scope:target.faith.religion = religion:christianity_religion
			}
			add = {
				value = scope:target.court_grandeur_current
				if = { #Reduce further if not same faith
					limit = {
						NOT = { faith = scope:target.faith }
					}
					divide = 3
				}
			}
		}
		else_if = {	#Eastern Faiths
			limit = {
				OR = {
					faith.religion = religion:hinduism_religion
					faith.religion = religion:buddhism_religion
					faith.religion = religion:jainism_religion
				}
				OR = {
					scope:target.faith.religion = religion:hinduism_religion
					scope:target.faith.religion = religion:buddhism_religion
					scope:target.faith.religion = religion:jainism_religion
				}
			}
			add = {
				value = scope:target.court_grandeur_current
				if = { #Reduce further if not same Religion
					limit = {
						NOT = { faith.religion = scope:target.faith.religion }
					}
					divide = 2
				}
			}
		}
		else_if = { #Abrahamic religion matching vs non co-religionist - CGV Ignored
			limit = {
				OR = {
					faith.religion = religion:islam_religion
					faith.religion = religion:christianity_religion
				}
				NOT = { faith.religion = scope:target.faith.religion }
			}
			#Add nothing
		}
		else_if = { #Eastern religion matching vs non Eastern religion - CGV Ignored
			limit = {
				OR = {
					faith.religion = religion:hinduism_religion
					faith.religion = religion:buddhism_religion
					faith.religion = religion:jainism_religion
				}
				NOR = {
					scope:target.faith.religion = religion:hinduism_religion
					scope:target.faith.religion = religion:buddhism_religion
					scope:target.faith.religion = religion:jainism_religion
				}
			}
			#Add nothing
		}
		else = { #Everyone else just cares about the Grandeur directly
			add = scope:target.court_grandeur_current
		}
	}


	#Increase from number of other courts using the Language (1.5 per court).
	if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		add = {
			value = scope:courts_with_language
			multiply = 0.5
		}
	}

 
	#Arbitrary Geographical Bias - if our courts are not in the same region the score is divided by 2.
	divide = {
		value = 1
		if = {
			limit = {
				OR = {
					#Europe:
					AND = {
						capital_province = { geographical_region = world_europe_west_britannia }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_west_britannia } }
					}
					AND = {
						capital_province = { geographical_region = world_europe_west_germania }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_west_germania } }
					}
					AND = {
						capital_province = { geographical_region = world_europe_west_francia }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_west_francia } }
					}
					AND = {
						capital_province = { geographical_region = world_europe_west_iberia }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_west_iberia } }
					}
					AND = {
						capital_province = { geographical_region = world_europe_north }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_north } }
					}
					#Added Caucasus region so Georgia doesn't go Greek as easily
					AND = {
						capital_province = { geographical_region = ghw_region_caucasus }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_caucasus } }
					}
					#Replace Southeast Europe region with the separate Balkans and Greece regions. That way the Balkans don't find turning Greek as appealing
					AND = {
						capital_province = { geographical_region = ghw_region_mainland_greece }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_mainland_greece } }
					}
					AND = {
						capital_province = { geographical_region = ghw_region_balkans }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_balkans } }
					}
					AND = {
						capital_province = { geographical_region = world_europe_south_italy }
						NOT = { scope:target.capital_province = { geographical_region = world_europe_south_italy } }
					}
					#Added East Europe since this region wasn't covered by any of the vanilla regions and that keeps Kiev Rus from thinking a Greek court language is a great idea. Used the GHW regions so they don't instead decide to become Volga Finnic
					AND = {
						capital_province = { geographical_region = ghw_region_russia }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_russia } }
					}
					AND = {
						capital_province = { geographical_region = ghw_region_baltic }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_baltic } }
					}
					AND = {
						capital_province = { geographical_region = ghw_region_wendish_lands }
						NOT = { scope:target.capital_province = { geographical_region = ghw_region_wendish_lands } }
					}
					#South Asia:
					AND = {
						capital_province = { geographical_region = world_india_rajastan }
						scope:target.capital_province = { geographical_region = world_india_rajastan }
					}
					AND = {
						capital_province = { geographical_region = world_india_bengal }
						NOT = { scope:target.capital_province = { geographical_region = world_india_bengal } }
					}
					AND = {
						capital_province = { geographical_region = world_india_deccan }
						NOT = { scope:target.capital_province = { geographical_region = world_india_deccan } }
					}
					AND = {
						capital_province = { geographical_region = world_burma }
						NOT = { scope:target.capital_province = { geographical_region = world_burma } }
					}
					AND = {
						capital_province = { geographical_region = world_himalaya }
						NOT = { scope:target.capital_province = { geographical_region = world_himalaya } }
					}
					#Replace the overall Middle East region with the seperate Jerusalem and Arabia
					AND = {
						capital_province = { geographical_region = world_middle_east_jerusalem }
						NOT = { scope:target.capital_province = { geographical_region = world_middle_east_jerusalem } }
					}
					AND = {
						capital_province = { geographical_region = world_middle_east_arabia }
						NOT = { scope:target.capital_province = { geographical_region = world_middle_east_arabia } }
					}
					AND = {
						capital_province = { geographical_region = world_middle_east_persia }
						NOT = { scope:target.capital_province = { geographical_region = world_middle_east_persia } }
					}
					#Africa
					#Broke up North Africa into its west and east parts.
					AND = {
						capital_province = { geographical_region = world_africa_north_west }
						NOT = { scope:target.capital_province = { geographical_region = world_africa_north_west } }
					}
					AND = {
						capital_province = { geographical_region = world_africa_north_east }
						NOT = { scope:target.capital_province = { geographical_region = world_africa_north_east } }
					}
					AND = {
						capital_province = { geographical_region = world_africa_west }
						NOT = { scope:target.capital_province = { geographical_region = world_africa_west } }
					}
					AND = {
						capital_province = { geographical_region = world_africa_east }
						NOT = { scope:target.capital_province = { geographical_region = world_africa_east } }
					}
					#Added Sahara
					AND = {
						capital_province = { geographical_region = world_africa_sahara }
						NOT = { scope:target.capital_province = { geographical_region = world_africa_sahara } }
					}
					#Central Asia
					AND = {
						capital_province = { geographical_region = world_steppe_west }
						NOT = { scope:target.capital_province = { geographical_region = world_steppe_west } }
					}
					AND = {
						capital_province = { geographical_region = world_steppe_east }
						NOT = { scope:target.capital_province = { geographical_region = world_steppe_east } }
					}
					AND = {
						capital_province = { geographical_region = world_tibet }
						NOT = { scope:target.capital_province = { geographical_region = world_tibet } }
					}
					#Added Transoxiana
					AND = {
						capital_province = { geographical_region = world_transoxiana }
						NOT = { scope:target.capital_province = { geographical_region = world_transoxiana } }
					}
					#Added Tarim Basin
					AND = {
						capital_province = { geographical_region = world_steppe_tarim }
						NOT = { scope:target.capital_province = { geographical_region = world_steppe_tarim } }
					}
				}
			}
			add = 1
		}
	}

	# Prefer the status quo slightly. Needs to be last
	if = {
		limit = {
			scope:checking_native_language = yes
			has_court_language_of_culture = culture
		}
		multiply = 3.0
	 #	add = 1000 # Add a large constant to the score of the current court language
	}
	else_if = {
		limit = {
			scope:checking_native_language = no
			scope:target = { has_royal_court = yes }
			has_same_court_language = scope:target
		}
		multiply = 3.0
	 #	add = 1000 # Add a large constant to the score of the current court language
	}
}
