﻿
convert_county_and_holder_if_in_region_effect = {
	if = {
		# If this county is of the old culture and is in the designated region, flip it to the new culture.
		limit = {
			culture = $OLD_CULTURE$
			title_province = {
				geographical_region = $REGION$
			}
		}
		set_county_culture = $NEW_CULTURE$

		# If the holder is also of the old culture, and their capital is in the designated region, we flip them along with the county.
		holder = {
			if = {
				limit = {
					culture = $OLD_CULTURE$
					capital_province = {
						geographical_region = $REGION$
					}
				}
				set_culture = $NEW_CULTURE$
			}
		}
	}
}

merge_cultures_in_region_effect = {
	hidden_effect = {
		convert_county_and_holder_if_in_region_effect = {
			OLD_CULTURE = $OLD_CULTURE_1$
			NEW_CULTURE = $NEW_CULTURE$
			REGION = $REGION$
		}
		convert_county_and_holder_if_in_region_effect = {
			OLD_CULTURE = $OLD_CULTURE_2$
			NEW_CULTURE = $NEW_CULTURE$
			REGION = $REGION$
		}
	}
}

convert_player_realm_from_old_culture_to_new_effect = {
	# For localization
	$OLD_CULTURE$ = { save_scope_as = old_culture }
	$NEW_CULTURE$ = { save_scope_as = new_culture }

	custom_tooltip = global_culture.custom.change_culture
	hidden_effect = {
		# Compile a list of everyone who will flip to the new culture.
		every_vassal_or_below = {
			limit = {
				culture = $OLD_CULTURE$
			}
			add_to_list = characters_to_convert
			every_courtier = {
				limit = {
					culture = $OLD_CULTURE$
				}
				add_to_list = characters_to_convert
			}
		}
		every_courtier = {
			limit = {
				culture = $OLD_CULTURE$
			}
			add_to_list = characters_to_convert
		}

		# Flip the player to the new culture.
		set_culture = $NEW_CULTURE$
		add_character_flag = converted_culture_this_lifetime

		# Flip their courtiers/vassals with a custom description.
		every_in_list = {
			list = characters_to_convert
			set_culture = $NEW_CULTURE$
		}

		# Then flip all their counties.
		every_sub_realm_county = {
			limit = {
				culture = $OLD_CULTURE$
			}
			set_county_culture = $NEW_CULTURE$
		}
	}
}

merge_cultures_in_player_realm_effect = {
	$OLD_CULTURE_1$ = { save_scope_as = old_culture_1 }
	$OLD_CULTURE_2$ = { save_scope_as = old_culture_2 }
	$NEW_CULTURE$ = { save_scope_as = new_culture }

	custom_tooltip = global_culture.custom_merge_culture

	hidden_effect = {
		convert_player_realm_from_old_culture_to_new_effect = {
			OLD_CULTURE = scope:old_culture_1
			NEW_CULTURE = scope:new_culture
		}
		convert_player_realm_from_old_culture_to_new_effect = {
			OLD_CULTURE = scope:old_culture_2
			NEW_CULTURE = scope:new_culture
		}
	}
}

convert_family_culture_and_notify_vassals_effect = {
	# Save the root character as a reference
	save_scope_as = converting_character
	# Save the old culture as a scope
	$OLD_CULTURE$ = {
		save_scope_as = old_culture
	}
	$NEW_CULTURE$ = {
		save_scope_as = new_culture
	}
	$CONVERTER$ = {
		save_scope_as = converter
	}
	# Convert root character and AI close family members
	set_culture = scope:new_culture
	if = {
		limit = {
			is_ai = yes
		}
		add_character_flag = converted_culture_this_lifetime_ai
	}
	else = {
		add_character_flag = converted_culture_this_lifetime
	}

	every_close_family_member = {
		custom = every_close_family_member_sharing_your_culture
		limit = {
			OR = {
				is_courtier_of = scope:converter
				is_vassal_of = scope:converter
			}
			# Exclude previous generations
			NOT = { is_parent_of = root }
			NOT = { is_grandparent_of = root }
			# Only non-ruler same-culture characters
			is_ruler = no
			has_culture = scope:old_culture
		}
		set_culture = scope:new_culture
		add_to_temporary_list = notified_of_culture_change
	}
	every_consort = {
		#custom = every_consort_sharing_your_culture
		limit = {
			is_ruler = no
			has_culture = scope:old_culture
			NOT = { is_in_list = notified_of_culture_change }
		}
		set_culture = scope:new_culture
		add_to_temporary_list = notified_of_culture_change
	}
	every_consort = {
		limit = {
			is_ruler = yes
			has_culture = scope:old_culture
			NOT = { is_in_list = notified_of_culture_change }
		}
		custom_description = {
			text = decide_on_local_culture_conversion
			trigger_event = {
				id = culture_conversion.0001
				days = 1
			}
		}
	}

	# Offer every same-culture vassal a chance to convert
	every_vassal = {
		custom = every_old_culture_vassal_holding_new_culture_land
		limit = {
			culture = scope:old_culture
			NOT = { is_in_list = notified_of_culture_change }
		}
		custom_description = {
			text = decide_on_local_culture_conversion
			trigger_event = {
				id = culture_conversion.0001
				days = 1
			}
		}
		add_to_temporary_list = notified_of_culture_change
	}

	# Notifications
	hidden_effect = {
		every_player = {
			limit = {
				OR = {
					is_consort_of = scope:converting_character
					liege ?= scope:converting_character

					AND = {
						exists = scope:converting_character.liege
						this = scope:converting_character.liege
					}
				}
				NOT = { is_in_list = notified_of_culture_change }
			}
			send_interface_message = {
				type = msg_culture_conversion
				title = converted_culture_msg_title
				custom_tooltip = converted_from_old_culture_to_new_culture_tt
				right_icon = scope:converting_character
			}
		}
	}
}

norse_assimilate_local_traditions_effect = {
	# Save the root character as a reference
	save_scope_as = converting_character
	# Save the old culture as a scope
	$OLD_CULTURE$ = {
		save_scope_as = old_culture
	}
	$NEW_CULTURE$ = {
		save_scope_as = new_culture
	}
	$OLD_FAITH$ = {
		save_scope_as = old_faith
	}
	$NEW_FAITH$ = {
		save_scope_as = new_faith
	}
	$CONVERTER$ = {
		save_scope_as = converter
	}
	add_character_modifier = {
		modifier = embraced_local_traditions_modifier
	}
	if = {
		limit = {
			dynasty ?= {
				NOT = {
					has_dynasty_modifier = settled_norse_dynasty_modifier
				}
			}
		}
		dynasty = {
			add_dynasty_modifier = { modifier = settled_norse_dynasty_modifier years = 80 }
		}
	}
	# Convert root character and AI close family members
	set_culture = scope:new_culture
	if = {
		limit = {
			NOR = {
				scope:old_faith = scope:new_faith
				has_trait = zealous
			}
		}
		hidden_effect = {
			bastard_to_wild_oat_conversion_assimilation_effect = yes
		}
		set_character_faith = scope:new_faith
	}
	if = {
		limit = {
			is_ai = yes
		}
		add_character_flag = converted_culture_this_lifetime_ai
	}
	else = {
		add_character_flag = converted_culture_this_lifetime
	}

	every_close_family_member = {
		custom = every_close_family_member_sharing_your_culture
		limit = {
			is_courtier_of = scope:converter
			# Only non-ruler same-culture characters
			has_culture = scope:old_culture
		}
		set_culture = scope:new_culture
		if = {
			limit = {
				NOR = {
					scope:old_faith = scope:new_faith
					has_trait = zealous
				}
			}
			hidden_effect = {
				bastard_to_wild_oat_conversion_assimilation_effect = yes
			}
			set_character_faith = scope:new_faith
		}
		hidden_effect = {
			add_character_modifier = {
				modifier = embraced_local_traditions_modifier
			}
		}
		add_to_temporary_list = notified_of_culture_change
	}
	every_consort = {
		#custom = every_consort_sharing_your_culture
		limit = {
			is_ruler = no
			has_culture = scope:old_culture
			NOT = { is_in_list = notified_of_culture_change }
		}
		set_culture = scope:new_culture
		if = {
			limit = {
				NOR = {
					scope:old_faith = scope:new_faith
					has_trait = zealous
				}
			}
			hidden_effect = {
				bastard_to_wild_oat_conversion_assimilation_effect = yes
			}
			set_character_faith = scope:new_faith
		}
		hidden_effect = {
			add_character_modifier = {
				modifier = embraced_local_traditions_modifier
			}
		}
		add_to_temporary_list = notified_of_culture_change
	}

	# All Norse vassals convert
	every_vassal = {
		custom = every_norse_vassal
		limit = {
			culture = scope:old_culture
			NOT = { is_in_list = notified_of_culture_change }
		}
		add_character_modifier = {
			modifier = embraced_local_traditions_modifier
		}
		hidden_effect = {
			if = {
				limit = {
					dynasty ?= {
						NOT = {
							has_dynasty_modifier = settled_norse_dynasty_modifier
						}
					}
				}
				dynasty = {
					add_dynasty_modifier = { modifier = settled_norse_dynasty_modifier years = 80 }
				}
			}
		}
		set_culture = scope:new_culture
		if = {
			limit = {
				NOR = {
					scope:old_faith = scope:new_faith
					has_trait = zealous
				}
			}
			hidden_effect = {
				bastard_to_wild_oat_conversion_assimilation_effect = yes
			}
			set_character_faith = scope:new_faith
		}

		hidden_effect = {
			every_close_family_member = {
				limit = {
					is_courtier_of = scope:converter
					# Only non-ruler same-culture characters
					has_culture = scope:old_culture
				}
				set_culture = scope:new_culture
				if = {
					limit = {
						NOR = {
							scope:old_faith = scope:new_faith
							has_trait = zealous
						}
					}
					hidden_effect = {
						bastard_to_wild_oat_conversion_assimilation_effect = yes
					}
					set_character_faith = scope:new_faith
				}
				hidden_effect = {
					add_character_modifier = {
						modifier = embraced_local_traditions_modifier
					}
				}
				add_to_temporary_list = notified_of_culture_change
			}
			every_consort = {
				limit = {
					is_ruler = no
					has_culture = scope:old_culture
					NOT = { is_in_list = notified_of_culture_change }
				}
				set_culture = scope:new_culture
				if = {
					limit = {
						NOR = {
							scope:old_faith = scope:new_faith
							has_trait = zealous
						}
					}
					hidden_effect = {
						bastard_to_wild_oat_conversion_assimilation_effect = yes
					}
					set_character_faith = scope:new_faith
				}
				hidden_effect = {
					add_character_modifier = {
						modifier = embraced_local_traditions_modifier
					}
				}
				add_to_temporary_list = notified_of_culture_change
			}
		}

		add_to_temporary_list = notified_of_culture_change
	}

	# Notifications
	hidden_effect = {
		every_player = {
			limit = {
				OR = {
					is_consort_of = scope:converting_character
					liege ?= scope:converting_character

					AND = {
						exists = scope:converting_character.liege
						this = scope:converting_character.liege
					}
				}
				NOT = { is_in_list = notified_of_culture_change }
			}
			send_interface_message = {
				type = msg_culture_conversion
				title = converted_culture_msg_title
				custom_tooltip = converted_from_old_culture_to_new_culture_tt
				right_icon = scope:converting_character
			}
		}
	}
}

expand_hybrid_culture_from_origin_point = {
	every_title_to_title_neighboring_and_across_water_county = {
		limit = {
			holder.top_liege = $CONVERTEE$.top_liege
			save_temporary_scope_as = county_check
			$CULTURE$ = {
				any_parent_culture = {
					this = scope:county_check.culture
				}
			}
		}

		random = {
			chance = {
				value = 30
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 45 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 50 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 55 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 60 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 65 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 70 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 75 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 80 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 85 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 90 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 95 }
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						$CULTURE$ = {
							any_parent_culture = {
								save_temporary_scope_as = first_parent
							}
							any_parent_culture = {
								this != scope:first_parent
								cultural_acceptance = { target = scope:first_parent value >= 100 }
							}
						}
					}
					add = 5
				}
			}
			set_county_culture = $CULTURE$
			every_title_to_title_neighboring_and_across_water_county = {
				limit = {
					holder.top_liege = $CONVERTEE$.top_liege
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
				random = {
					chance = {
						value = 30
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 45 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 50 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 55 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 60 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 65 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 70 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 75 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 80 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 85 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 90 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 95 }
									}
								}
							}
							add = 5
						}
						if = {
							limit = {
								$CULTURE$ = {
									any_parent_culture = {
										save_temporary_scope_as = first_parent
									}
									any_parent_culture = {
										this != scope:first_parent
										cultural_acceptance = { target = scope:first_parent value >= 100 }
									}
								}
							}
							add = 5
						}
					}
					set_county_culture = $CULTURE$
				}
			}
		}
	}
}

new_culture_created_conversion_effect = {

	# Save the hybrid culture for use with ai_will_do down the line
	if = {
		limit = {
			$CULTURE$ = { is_hybrid_culture = yes }
		}
		add_to_global_variable_list = { name = hybrid_cultures target = $CULTURE$ }
	}

	# Convert Counties (if of same culture as recipient's old culture)
	$CONVERTEE$ = {
		if = {
			limit = {
				capital_county = {
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
			}
			capital_county = {
				set_county_culture = $CULTURE$
				expand_hybrid_culture_from_origin_point = {
					CONVERTEE = $CONVERTEE$
					CULTURE = $CULTURE$
				}
			}
		}
		else_if = {
			limit = {
				any_held_title = {
					title_tier = county
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
			}
			random_held_title = {
				title_tier = county
				limit = {
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
				set_county_culture = $CULTURE$
				expand_hybrid_culture_from_origin_point = {
					CONVERTEE = $CONVERTEE$
					CULTURE = $CULTURE$
				}
			}
		}
		else_if = {
			limit = {
				any_sub_realm_county = {
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
			}
			random_sub_realm_county = {
				limit = {
					save_temporary_scope_as = county_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:county_check.culture
						}
					}
				}
				set_county_culture = $CULTURE$
				expand_hybrid_culture_from_origin_point = {
					CONVERTEE = $CONVERTEE$
					CULTURE = $CULTURE$
				}
			}
		}
	}
	# Spouses convert
	$CONVERTEE$ = {
		every_spouse = {
			limit = {
				OR = {
					is_courtier_of = $CONVERTER$
					is_courtier_of = $CONVERTEE$
					is_vassal_of = $CONVERTER$
					is_vassal_of = $CONVERTEE$
				}
				save_temporary_scope_as = spouse_check
				$CULTURE$ = {
					any_parent_culture = {
						this = scope:spouse_check.culture
					}
				}
			}
			if = {
				limit = {
					exists = domicile.domicile_culture
					culture = domicile.domicile_culture
				}
				domicile = { set_domicile_culture = $CULTURE$ }
			}
			set_culture = $CULTURE$
			hidden_effect = {
				add_character_flag = converted_culture_this_lifetime
			}
		}
	}
	# Family in recipient's court also convert
	if = {
		limit = {
			$CONVERTEE$ = {
				is_ruler = yes
				any_close_or_extended_family_member = {
					court_owner ?= $CONVERTEE$
					NOT = { culture = $CULTURE$ }
					is_ai = yes
				}
			}
		}
		$CONVERTEE$ = {
			every_close_or_extended_family_member = {
				custom = all_family_members_at_court
				limit = {
					court_owner ?= $CONVERTEE$
					NOT = { culture = $CULTURE$ }
					is_ai = yes
					save_temporary_scope_as = family_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:family_check.culture
						}
					}
				}
				if = {
					limit = {
						exists = domicile.domicile_culture
						culture = domicile.domicile_culture
					}
					domicile = { set_domicile_culture = $CULTURE$ }
				}
				set_culture = $CULTURE$
				hidden_effect = {
					add_character_flag = converted_culture_this_lifetime
				}
			}
		}
	}
	# Make sure relevant non-significant characters convert
	$CONVERTEE$ = {
		hidden_effect = {
			every_courtier_or_guest = {
				limit = {
					NOT = { culture = $CULTURE$ }
					is_ai = yes
					has_no_particular_noble_roots_trigger = yes
					save_temporary_scope_as = family_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:family_check.culture
						}
					}
				}
				if = {
					limit = {
						exists = domicile.domicile_culture
						culture = domicile.domicile_culture
					}
					domicile = { set_domicile_culture = $CULTURE$ }
				}
				set_culture = $CULTURE$
				hidden_effect = {
					add_character_flag = converted_culture_this_lifetime
				}
			}
			if = {
				limit = {
					exists = $CONVERTEE$.capital_province
				}
				every_pool_character = {
					province = $CONVERTEE$.capital_province
					limit = {
						NOT = { culture = $CULTURE$ }
						is_ai = yes
						has_no_particular_noble_roots_trigger = yes
						save_temporary_scope_as = family_check
						$CULTURE$ = {
							any_parent_culture = {
								this = scope:family_check.culture
							}
						}
					}
					if = {
						limit = {
							exists = domicile.domicile_culture
							culture = domicile.domicile_culture
						}
						domicile = { set_domicile_culture = $CULTURE$ }
					}
					set_culture = $CULTURE$
					hidden_effect = {
						add_character_flag = converted_culture_this_lifetime
					}
				}
			}
		}
	}
	$CONVERTEE$ = { # Clean up culture in the realm for subvassals with a liege of the wrong culture
		hidden_effect = {
			every_vassal_or_below = {
				limit = {
					is_playable_character = yes
					save_temporary_scope_as = vassal_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:vassal_check.culture
						}
					}
					NOT = {
						$CULTURE$ = {
							any_parent_culture = {
								this = scope:vassal_check.liege.culture
							}
						}
					}
				}
				save_scope_as = vassal_converting
				new_culture_created_vassal_conversion_effect = {
					CONVERTEE = scope:vassal_converting
					CONVERTER = $CONVERTER$
					CULTURE = $CULTURE$
				}
			}
			#every_sub_realm_county = {
			#	limit = {
			#		save_temporary_scope_as = county_check
			#		$CULTURE$ = {
			#			any_parent_culture = {
			#				this = scope:county_check.culture
			#			}
			#		}
			#		NOT = {
			#			$CULTURE$ = {
			#				any_parent_culture = {
			#					this = scope:county_check.holder.culture
			#				}
			#			}
			#		}
			#	}
			#	set_county_culture = $CULTURE$
			#}
		}
	}
	$CONVERTEE$ = {
		if = {
			limit = {
				exists = domicile.domicile_culture
				culture = domicile.domicile_culture
			}
			domicile = { set_domicile_culture = $CULTURE$ }
		}
		set_culture = $CULTURE$
		hidden_effect = {
			add_character_flag = converted_culture_this_lifetime
		}
	}
}

new_culture_created_vassal_conversion_effect = {

	# Save the hybrid culture for use with ai_will_do down the line
	if = {
		limit = {
			$CULTURE$ = { is_hybrid_culture = yes }
			NOT = {
				any_in_global_list = {
					variable = hybrid_cultures
					this = $CULTURE$
				}
			}
		}
		add_to_global_variable_list = { name = hybrid_cultures target = $CULTURE$ }
	}

	# Convert Counties (if of same culture as recipient's old culture)
	$CONVERTEE$ = {
		#every_held_title = {
		#	title_tier = county
		#	limit = {
		#		save_temporary_scope_as = county_check
		#		$CULTURE$ = {
		#			any_parent_culture = {
		#				this = scope:county_check.culture
		#			}
		#		}
		#	}
		#	set_county_culture = $CULTURE$
		#}
	}
	# Spouses convert
	$CONVERTEE$ = {
		every_spouse = {
			limit = {
				OR = {
					is_courtier_of = $CONVERTER$
					is_courtier_of = $CONVERTEE$
					is_vassal_of = $CONVERTER$
					is_vassal_of = $CONVERTEE$
				}
				save_temporary_scope_as = spouse_check
				$CULTURE$ = {
					any_parent_culture = {
						this = scope:spouse_check.culture
					}
				}
			}
			if = {
				limit = {
					exists = domicile.domicile_culture
					culture = domicile.domicile_culture
				}
				domicile = { set_domicile_culture = $CULTURE$ }
			}
			set_culture = $CULTURE$
			hidden_effect = {
				add_character_flag = converted_culture_this_lifetime
			}
		}
	}
	# Family in recipient's court also convert
	if = {
		limit = {
			$CONVERTEE$ = {
				is_ruler = yes
				any_close_or_extended_family_member = {
					court_owner ?= $CONVERTEE$
					NOT = { culture = $CULTURE$ }
					is_ai = yes
				}
			}
		}
		$CONVERTEE$ = {
			every_close_or_extended_family_member = {
				custom = all_family_members_at_court
				limit = {
					court_owner ?= $CONVERTEE$
					NOT = { culture = $CULTURE$ }
					is_ai = yes
					save_temporary_scope_as = family_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:family_check.culture
						}
					}
				}
				if = {
					limit = {
						exists = domicile.domicile_culture
						culture = domicile.domicile_culture
					}
					domicile = { set_domicile_culture = $CULTURE$ }
				}
				set_culture = $CULTURE$
				hidden_effect = {
					add_character_flag = converted_culture_this_lifetime
				}
			}
		}
	}

	# Make sure relevant non-significant characters convert
	$CONVERTEE$ = {
		hidden_effect = {
			every_courtier_or_guest = {
				limit = {
					NOT = { culture = $CULTURE$ }
					is_ai = yes
					has_no_particular_noble_roots_trigger = yes
					save_temporary_scope_as = family_check
					$CULTURE$ = {
						any_parent_culture = {
							this = scope:family_check.culture
						}
					}
				}
				if = {
					limit = {
						exists = domicile.domicile_culture
						culture = domicile.domicile_culture
					}
					domicile = { set_domicile_culture = $CULTURE$ }
				}
				set_culture = $CULTURE$
				hidden_effect = {
					add_character_flag = converted_culture_this_lifetime
				}
			}
			if = {
				limit = {
					exists = $CONVERTEE$.capital_province
				}
				every_pool_character = {
					province = $CONVERTEE$.capital_province
					limit = {
						NOT = { culture = $CULTURE$ }
						is_ai = yes
						has_no_particular_noble_roots_trigger = yes
						save_temporary_scope_as = family_check
						$CULTURE$ = {
							any_parent_culture = {
								this = scope:family_check.culture
							}
						}
					}
					if = {
						limit = {
							exists = domicile.domicile_culture
							culture = domicile.domicile_culture
						}
						domicile = { set_domicile_culture = $CULTURE$ }
					}
					set_culture = $CULTURE$
					hidden_effect = {
						add_character_flag = converted_culture_this_lifetime
					}
				}
			}
		}
	}
	$CONVERTEE$ = {
		if = {
			limit = {
				exists = domicile.domicile_culture
				culture = domicile.domicile_culture
			}
			domicile = { set_domicile_culture = $CULTURE$ }
		}
		set_culture = $CULTURE$
		hidden_effect = {
			add_character_flag = converted_culture_this_lifetime
		}
	}

	$CONVERTEE$ = {
		every_vassal = {
			limit = {
				is_playable_character = yes
				is_ai = yes
				save_temporary_scope_as = vassal_check
				$CULTURE$ = {
					any_parent_culture = {
						this = scope:vassal_check.culture
					}
				}
			}

			run_interaction = {
				interaction = request_culture_conversion_interaction
				actor = $CONVERTEE$
				recipient = this
				execute_threshold = accept
			}
		}
	}
}

inspired_by_tradition_effect = {
	save_scope_as = tradition_scope
	custom_tooltip = inspire_by_culture_tt
	$CHARACTER$ = {
		add_to_variable_list = {
			name = culture_tradition_reduction
			target = prev
		}
	}
}
