﻿namespace = global_religion


#When a pagan (ai) domain is ready to feudalize, a reformed neighbor they're on good terms with should attempt to convert them, or they should have a chance to spontaneously convert


#########################################################################
# Pagan reformed by neighbor or spontaneously 							#
# by Linnéa Thimrén														#
# global_religion.0001-0009												#
#########################################################################


#global_religion.0001 = {
#	hidden = yes
#	
#	immediate = {
#		random_list = {
#			7 = {
#				trigger = {
#					any_neighboring_top_liege_realm_owner = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				modifier = {
#					add = 1
#					any_neighboring_top_liege_realm_owner = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						OR = {
#							government_has_flag = government_is_clan
#							government_has_flag = government_is_feudal
#						}
#					}
#				}
#				modifier = { #Give Muslim faiths a boost in Africa
#					add = 4
#					capital_province = {
#						geographical_region = world_africa
#					}
#					any_neighboring_top_liege_realm_owner = {
#						faith.religion = religion:islam_religion
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				random_neighboring_top_liege_realm_owner = {
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						OR = {
#							government_has_flag = government_is_clan
#							government_has_flag = government_is_feudal
#						}
#					}
#					alternative_limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
#			5 = {
#				trigger = {
#					any_consort = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						NOR = {
#							has_relation_potential_rival = root
#							has_relation_rival = root
#						}
#					}
#				}
#				random_consort = {
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						NOR = {
#							has_relation_potential_rival = root
#							has_relation_rival = root
#						}
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
#			5 = {
#				trigger = {
#					any_relation = {
#						type = soulmate
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				random_relation = {
#					type = soulmate
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
#			2 = {
#				trigger = {
#					any_relation = {
#						type = friend
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				modifier = {
#					add = 2
#					any_relation = {
#						type = friend
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#				}
#				random_relation = {
#					type = friend
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#					alternative_limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
#			2 = {
#				trigger = {
#					any_relation = {
#						type = lover
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				modifier = {
#					add = 2
#					any_relation = {
#						type = lover
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#				}
#				random_relation = {
#					type = lover
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#					alternative_limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
#			2 = {
#				trigger = {
#					any_councillor = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#				}
#				modifier = {
#					add = 2
#					any_councillor = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#				}
#				random_councillor = {
#					limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#						has_relation_best_friend = root
#					}
#					alternative_limit = {
#						faith = { NOT = { has_doctrine_parameter = unreformed } }
#					}
#					save_scope_as = actor #for the effect to work properly
#				}
#			}
##			#Geographical regions to also push extra for
##			2 = {
##				trigger = { #Russia - orthodox
##					capital_province = {
##						geographical_region = ghw_region_russia
##					}
##					exists = faith:orthodox
##					faith:orthodox = {
##						exists = religious_head
##					}
##				}
##				faith:orthodox = {
##					religious_head = {
##						save_scope_as = actor #for the effect to work properly
##					}
##				}
##			}
##			2 = {
##				trigger = { #Scandinavia - catholic
##					capital_province = {
##						geographical_region = ghw_region_scandinavia
##					}
##					exists = faith:catholic
##					faith:catholic = {
##						exists = religious_head
##					}
##				}
##				faith:catholic = {
##					religious_head = {
##						save_scope_as = actor #for the effect to work properly
##					}
##				}
##			}
#			100 = {
#				modifier = { # A parallel system for africans lowers the need for this
#					add = 50
#					faith = {
#						has_doctrine = west_african_unreformed_faith_doctrine
#					}
#				}
#				modifier = { # Historically held out for a long time
#					add = 150
#					OR = {
#						faith.religion = religion:baltic_religion
#						faith.religion = religion:adonist_religion
#					}
#				}
#				modifier = { # Less susceptible
#					add = 50
#					faith.religion = faith:finnish_pagan.religion
#				}
#				modifier = { # The mongols are (mostly) busy
#					add = 150
#					mpo_has_gok_mongol_empire_trigger = yes
#				}
#				modifier = {
#					add = -40
#					current_date >= 2600.1.1
#				}
#				modifier = {
#					add = -15
#					current_date >= 2650.1.1
#				}
#				modifier = {
#					add = -25
#					current_date >= 2700.1.1
#				}
#				modifier = {
#					add = -10
#					current_date >= 2750.1.1
#				}
#				modifier = { #100 % that something happens if it can
#					add = -10
#					current_date >= 2850.1.1
#				}
#			}
#		}
#
#		if = {
#			limit = {
#				exists = scope:actor
#			}
#			save_scope_as = recipient #for the effect to work properly
#			
#			every_vassal = {
#				limit = {
#					faith = root.faith
#				}
#
#				demand_conversion_interaction_effect = yes
#
#				if = { #If you converted to a neighboring faith your government and capital county also converts
#					limit = {
#						root = {
#							any_neighboring_top_liege_realm_owner = {
#								this = scope:recipient
#							}
#						}
#						NAND = { # The Steppes convert, but stay tribal
#							capital_province ?= { geographical_region = world_steppe }
#						}
#					}
#					if = {
#						limit = {
#							faith = { religion_tag = islam_religion }
#						}
#						change_government = clan_government
#					}
#					else = { change_government = feudal_government }
#					capital_county = {
#						set_county_faith = prev.faith
#					}
#				}
#			}
#
#			demand_conversion_interaction_effect = yes
#
#			if = { #If you converted to a neighboring faith your government and capital county also converts
#				limit = {
#					any_neighboring_top_liege_realm_owner = {
#						this = scope:recipient
#					}
#					NAND = { # The Steppes convert, but stay tribal
#						capital_province ?= { geographical_region = world_steppe }
#					}
#				}
#				if = {
#					limit = {
#						faith = { religion_tag = islam_religion }
#					}
#					change_government = clan_government
#				}
#				else = { change_government = feudal_government }
#				capital_county = {
#					set_county_faith = root.faith
#				}
#			}
#		}
#	}
#}

# Events for expelled faith development to relocate
global_religion.1000 = {
	type = character_event
	title = global_religion.1000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:seeking_same_faith_counties
					scope:target_faith_associated_county_faith != scope:target_faith
				}
				desc = global_religion.1000.desc_same_faith_counties_alt
			}
			triggered_desc = {
				trigger = {
					exists = scope:seeking_same_faith_counties
				}
				desc = global_religion.1000.desc_same_faith_counties
			}
			triggered_desc = {
				trigger = {
					scope:target_faith_associated_county_faith = scope:target_faith
				}
				desc = global_religion.1000.desc_any_counties_alt
			}
			desc = global_religion.1000.desc_any_counties
		}
	}
	theme = faith
	
	left_portrait = {
		character = root
		animation = wedding_priest
		camera = camera_event_very_left
	}
	
	right_portrait = {
		character = scope:local_character
		animation = holding_staff
		camera = camera_event_very_right_far
	}

	immediate = {
		hidden_effect_new_object = {
			scope:target_faith = {
				var:associated_culture = {
					save_scope_as = target_faith_associated_culture
				}
				var:associated_county = {
					save_scope_as = target_faith_associated_county
					faith = { save_scope_as = target_faith_associated_county_faith }
				}
			}
			save_scope_value_as = {
				name = initial_available_development
				value = scope:target_faith.var:converted_development
			}
			
			# Save same-faith Counties if that's what we're looking for, they can be all over the place
			if = {
				limit = {
					exists = scope:seeking_same_faith_counties
				}
				random_sub_realm_county = {
					limit = {
						faith = scope:target_faith
					}
					save_scope_as = initial_county_target
					add_to_list = counties_to_move_in_to
					set_variable = {
						name = county_development_to_get
						value = {
							value = development_level
							divide = 10
							floor = yes
							add = 1
							max = scope:initial_available_development
							min = 1
						}
					}
					save_scope_value_as = {
						name = remaining_converted_development
						value = {
							value = scope:initial_available_development
							subtract = var:county_development_to_get
						}
					}
				}
				while = {
					count = {
						add = root.primary_title.tier
						if = {
							limit = {
								root.primary_title.tier <= tier_duchy
							}
							add = -1
							min = 1
						}
					}
					limit = {
						scope:remaining_converted_development > 0
					}
					random_sub_realm_county = {
						limit = {
							faith = scope:target_faith
							NOT = {
								is_in_list = counties_to_move_in_to
							}
						}
						add_to_list = counties_to_move_in_to
						set_variable = {
							name = county_development_to_get
							value = {
								value = development_level
								divide = 10
								floor = yes
								add = 1
								max = scope:remaining_converted_development
								min = 1
							}
						}
						save_scope_value_as = {
							name = remaining_converted_development
							value = {
								value = scope:remaining_converted_development
								subtract = var:county_development_to_get
							}
						}
					}
				}
			}
			
			# Otherwise save a cluster of connected same-faith Counties
			else = {
				random_sub_realm_county = {
					limit = {
						faith = root.faith
						NOT = {
							is_target_in_variable_list = {
								name = faiths_converted_in_the_county
								target = scope:target_faith
							}
						}
						trigger_if = {
							limit = {
								root = {
									is_ai = yes
								}
							}
							holder = {
								is_ai = yes
							}
						}
					}
					weight = {
						base = 1
						modifier = {
							add = 25
							NOT = {
								any_neighboring_county = {
									OR = {
										this = root.capital_county
										any_neighboring_county = {
											this = root.capital_county
										}
									}
								}
							}
						}
					}
					save_scope_as = initial_county_target
					add_to_list = counties_to_move_in_to
					set_variable = {
						name = county_development_to_get
						value = {
							value = development_level
							divide = 10
							floor = yes
							add = 1
							max = scope:initial_available_development
							min = 1
						}
					}
					save_scope_value_as = {
						name = remaining_converted_development
						value = {
							value = scope:initial_available_development
							subtract = var:county_development_to_get
						}
					}
				}
				while = {
					count = root.primary_title.tier
					limit = {
						scope:remaining_converted_development > 0
					}
					random_sub_realm_county = {
						limit = {
							faith = root.faith
							NOT = {
								is_target_in_variable_list = {
									name = faiths_converted_in_the_county
									target = scope:target_faith
								}
							}
							trigger_if = {
								limit = {
									root = {
										is_ai = yes
									}
								}
								holder = {
									is_ai = yes
								}
							}
							any_neighboring_county = {
								is_in_list = counties_to_move_in_to
							}
							NOT = {
								is_in_list = counties_to_move_in_to
							}
						}
						weight = {
							base = 1
							modifier = {
								add = 25
								NOT = {
									any_neighboring_county = {
										OR = {
											this = root.capital_county
											any_neighboring_county = {
												this = root.capital_county
											}
										}
									}
								}
							}
							modifier = {
								add = 0
								add = {
									every_neighboring_county = {
										limit = {
											is_in_list = counties_to_move_in_to
										}
										add = 10
									}
								}
							}
						}
						add_to_list = counties_to_move_in_to
						set_variable = {
							name = county_development_to_get
							value = {
								value = development_level
								divide = 10
								floor = yes
								add = 1
								max = scope:remaining_converted_development
								min = 1
							}
						}
						save_scope_value_as = {
							name = remaining_converted_development
							value = {
								value = scope:remaining_converted_development
								subtract = var:county_development_to_get
							}
						}
					}
				}
			}
			create_character = {
				template = pool_repopulate_learning
				faith = scope:target_faith
				culture = scope:target_faith_associated_culture
				location = root.capital_province
				gender_female_chance = {
					if = {
						limit = { scope:target_faith = { has_doctrine = doctrine_gender_male_dominated } }
						add = 0
					}
					else_if = {
						limit = { scope:target_faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
					}
					else = {
						add = 50
					}
				}
				save_scope_as = local_character
			}
			scope:local_character = {
				add_trait = lifestyle_mystic
				set_variable = {
					name = loc_number
					value = {
						add = {
							every_in_list = {
								list = counties_to_move_in_to
								add = var:county_development_to_get
							}
						}
						multiply = 1000
					}
				}
				if = { # Error suppression
					limit = {
						var:loc_number = var:loc_number
					}
				}
			}
		}
	}

	option = {
		name = global_religion.1000.serenity_aspect
		reason = serenity_aspect
		trigger = {
			house ?= { has_house_aspiration_parameter = aspect_of_serenity }
		}
		add_courtier = scope:local_character
		
		capital_county = {
			if = {
				limit = {
					faith != scope:target_faith
				}
				faith = {
					if = {
						limit = {
							OR = {
								NOT = { has_variable = associated_county }
								AND = {
									has_variable = converted_development
									var:converted_development <= 0
								}
							}
						}
						set_variable = {
							name = associated_county
							value = scope:county
						}
					}
					if = {
						limit = {
							OR = {
								NOT = { has_variable = associated_culture }
								AND = {
									has_variable = converted_development
									var:converted_development <= 0
								}
							}
						}
						set_variable = {
							name = associated_culture
							value = scope:county.culture
						}
					}
					if = {
						limit = {
							NOT = { has_variable = converted_development }
						}
						set_variable = {
							name = converted_development
							value = {
								every_in_list = {
									list = counties_to_move_in_to
									add = {
										add = var:county_development_to_get
										divide = 2
										min = 1
									}
								}
							}
						}
					}
					else = {
						change_variable = {
							name = converted_development
							add = {
								every_in_list = {
									list = counties_to_move_in_to
									add = {
										add = var:county_development_to_get
										divide = 2
										min = 1
									}
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					root.faith != scope:target_faith
					faith != scope:target_faith
				}
				set_county_faith = scope:target_faith
			}
			change_development_level = {
				value = {
					every_in_list = {
						list = counties_to_move_in_to
						add = {
							add = var:county_development_to_get
							divide = 2
							min = 1
						}
					}
				}
			}
			change_county_control = {
				value = {
					every_in_list = {
						list = counties_to_move_in_to
						add = {
							add = var:county_development_to_get
							divide = 2
							min = 1
						}
					}
				}
				multiply = -5
			}
		}
		
		if = {
			limit = {
				culture != scope:target_faith_associated_culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:target_faith_associated_culture
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
					}
					desc = cultural_acceptance_gain_event
				}
			}
		}
		
		scope:target_faith = {
			change_variable = {
				name = converted_development
				subtract = {
					every_in_list = {
						list = counties_to_move_in_to
						add = var:county_development_to_get
						divide = 3
						min = 1
					}
				}
			}
		}
		
		if = {
			limit = {
				is_ai = no
			}
			add_achievement_global_variable_effect = {
				VARIABLE = achieved_ep4_20_promised_land_achievement
				VALUE = yes
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = global_religion.1000.violent
		trigger = {
			NOT = { exists = scope:from_decision }
			NOT = { house = { has_house_aspiration_parameter = aspect_of_serenity } }
			OR = {
				has_trait = callous
				has_trait = sadistic
				has_trait = greedy
				has_trait = arbitrary
			}
		}
		trait = callous
		trait = sadistic
		trait = greedy
		trait = arbitrary
		
		add_gold = {
			value = {
				value = scope:initial_available_development
				multiply = 15
			}
		}
		
		if = {
			limit = {
				culture != scope:target_faith_associated_culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:target_faith_associated_culture
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
						multiply = -0.5
					}
					desc = cultural_acceptance_gain_event
				}
			}
		}
		
		scope:target_faith = {
			change_variable = {
				name = converted_development
				subtract = 1
			}
		}
		
		stress_impact = {
			generous = massive_stress_impact_gain
			compassionate = massive_stress_impact_gain
			humble = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 25
			modifier = {
				OR = {
					has_trait = generous
					has_trait = compassionate
					has_trait = humble
					has_trait = just
				}
				factor = 0
			}
		}
	}

	option = {
		name = global_religion.1000.special
		add_internal_flag = dangerous
		trigger = {
			faith != scope:target_faith
			faith.religious_head != root
		}
		show_as_tooltip = {
			set_character_faith_with_conversion = scope:target_faith
			if = {
				limit = { 
					scope:target_faith = { has_doctrine = doctrine_monotheist }
				}
				custom_description_no_bullet = { text = mandala_monotheist_warning_tt }
			}
		}
		add_courtier = scope:local_character
		if = {
			limit = {
				OR = {
					faith = { has_doctrine_parameter = unreformed }
					government_has_flag = government_is_nomadic
				}
			}
			add_piety = major_piety_gain
		}
		else_if = {
			limit = {
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
				scope:target_faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
			add_piety = minor_piety_gain
		}
		else = {
			add_piety_level = -2
		}
		hidden_effect = {
			set_character_faith_with_conversion = scope:target_faith
		}
		if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			domicile ?= {
				change_herd = {
					value = 0
					every_in_list = {
						list = counties_to_move_in_to
						add = var:county_development_to_get
					}
					multiply = 250
				}
				if = {
					limit = {
						domicile_faith != scope:target_faith
					}
					set_domicile_faith = scope:target_faith
				}
			}
			every_held_title = {
				limit = {
					tier = tier_county
					is_landless_type_title = no
					faith = root.faith
				}
				set_county_faith = scope:target_faith
			}
		}
		else = {
			every_in_list = {
				list = counties_to_move_in_to
				change_development_level = var:county_development_to_get
				set_county_faith = scope:target_faith
				change_county_control = {
					value = var:county_development_to_get
					multiply = -5
				}
			}
		}
		
		if = {
			limit = {
				culture != scope:target_faith_associated_culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:target_faith_associated_culture
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
					}
					desc = cultural_acceptance_gain_event
				}
			}
		}
		
		scope:target_faith = {
			change_variable = {
				name = converted_development
				subtract = {
					every_in_list = {
						list = counties_to_move_in_to
						add = var:county_development_to_get
					}
				}
			}
		}
		
		stress_impact = {
			zealous = massive_stress_impact_gain
		}
		
		if = {
			limit = {
				is_ai = no
			}
			add_achievement_global_variable_effect = {
				VARIABLE = achieved_ep4_20_promised_land_achievement
				VALUE = yes
			}
		}
		
		ai_chance = {
			base = 0
			modifier = {
				current_year >= 1000
				faith = {
					has_doctrine_parameter = unreformed
					NOT = { religion_tag = baltic_religion }
				}
				add = 10
			}
			modifier = {
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
				scope:target_faith = { has_doctrine = doctrine_pluralism_pluralistic }
				
				OR = {
					faith.religion = scope:target_faith.religion
					AND = {
						faith.religion = { is_in_family = rf_eastern }
						scope:target_faith.religion = { is_in_family = rf_eastern }
					}
					AND = {
						faith.religion = { is_in_family = rf_sinitic }
						scope:target_faith.religion = { is_in_family = rf_sinitic }
					}
				}
				
				add = 10
			}
			modifier = {
				has_trait = zealous
				factor = 0
			}
			modifier = {
				has_trait = eccentric
				add = 1
			}
			modifier = {
				faith.religion = { is_in_family = rf_abrahamic }
				NOT = {
					scope:target_faith.religion = { is_in_family = rf_abrahamic }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_shia_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_shia_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_zandaqa_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_zandaqa_doctrine }
				}
				factor = 0
			}
			modifier = {
				exists = scope:from_decision
				factor = 0
			}
		}
	}

	option = {
		name = global_religion.1000.a
		add_courtier = scope:local_character
		if = {
			limit = {
				exists = scope:seeking_same_faith_counties
			}
			if = {
				limit = {
					government_has_flag = government_is_nomadic
				}
				domicile ?= {
					change_herd = {
						value = 0
						every_in_list = {
							list = counties_to_move_in_to
							add = var:county_development_to_get
						}
						multiply = 250
					}
				}
			}
			else = {
				every_in_list = {
					list = counties_to_move_in_to
					change_development_level = var:county_development_to_get
					change_county_control = {
						value = var:county_development_to_get
						multiply = -5
					}
				}
			}
		}
		else = {
			if = {
				limit = {
					government_has_flag = government_is_nomadic
				}
				domicile ?= {
					change_herd = {
						value = 0
						every_in_list = {
							list = counties_to_move_in_to
							add = var:county_development_to_get
						}
						multiply = 250
					}
					if = {
						limit = {
							domicile_faith != scope:target_faith
						}
						set_domicile_faith = scope:target_faith
					}
				}
				every_held_title = {
					limit = {
						tier = tier_county
						is_landless_type_title = no
						faith = root.faith
					}
					set_county_faith = scope:target_faith
				}
			}
			else = {
				every_in_list = {
					list = counties_to_move_in_to
					change_development_level = {
						value = var:county_development_to_get
						if = {
							limit = {
								culture = {
									has_cultural_parameter = development_gain_from_religious_exiles_is_doubled
								}
							}
							multiply = 2
						}
					}
					set_county_faith = scope:target_faith
					change_county_control = {
						value = var:county_development_to_get
						multiply = -5
					}
				}
			}
		}
		
		if = {
			limit = {
				culture != scope:target_faith_associated_culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:target_faith_associated_culture
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
					}
					desc = cultural_acceptance_gain_event
				}
			}
		}
		
		scope:target_faith = {
			change_variable = {
				name = converted_development
				subtract = {
					every_in_list = {
						list = counties_to_move_in_to
						add = var:county_development_to_get
					}
				}
			}
		}
		
		if = {
			limit = {
				is_ai = no
			}
			add_achievement_global_variable_effect = {
				VARIABLE = achieved_ep4_20_promised_land_achievement
				VALUE = yes
			}
		}
		
		ai_chance = {
			base = 0
			modifier = {
				faith = scope:target_faith
				add = 5000
			}
			modifier = {
				current_year >= 1000
				faith = {
					has_doctrine_parameter = unreformed
					NOT = { religion_tag = baltic_religion }
				}
				add = 10
			}
			modifier = {
				faith.religion = { is_in_family = rf_eastern }
				scope:target_faith.religion = { is_in_family = rf_eastern }
				add = 1000
			}
			modifier = {
				faith.religion = { is_in_family = rf_sinitic }
				scope:target_faith.religion = { is_in_family = rf_sinitic }
				add = 1000
			}
			modifier = {
				culture = { has_cultural_pillar = heritage_chinese }
				scope:target_faith.religion = { is_in_family = rf_sinitic }
				add = 1000
			}
			modifier = {
				highest_held_title_tier >= tier_kingdom
				OR = {
					has_perk = open_minded_perk
					has_trait = compassionate
					has_trait = humble
				}
				is_open_to_inviting_other_faiths_trigger = yes
				faith.religion = { is_in_family = rf_eastern }
				scope:target_faith = { num_county_followers < 5 }
				add = 1000
			}
			modifier = {
				is_open_to_inviting_other_faiths_trigger = yes
				scope:target_faith = { faith_is_open_minded_trigger = yes }
				add = 10
			}
			modifier = {
				faith.religion = { is_in_family = rf_abrahamic }
				NOT = {
					scope:target_faith.religion = { is_in_family = rf_abrahamic }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_sunni_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_shia_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_shia_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_muhakkima_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith = { has_doctrine = muhammad_succession_zandaqa_doctrine }
				NOT = {
					scope:target_faith = { has_doctrine = muhammad_succession_zandaqa_doctrine }
				}
				factor = 0
			}
			modifier = {
				faith != scope:target_faith
				any_sub_realm_county = {
					count < {
						value = {
							every_in_list = {
								list = counties_to_move_in_to
								add = 2
							}
						}
					}
					faith = root.faith
				}
				factor = 0
			}
			modifier = {
				has_trait = eccentric
				add = 5
			}
			modifier = {
				exists = scope:from_decision
				add = 5
			}
		}
	}

	option = {
		name = global_religion.1000.b
		if = {
			limit = {
				exists = scope:from_decision
			}
		}
		else = {
			if = {
				limit = {
					faith != scope:target_faith
				}
				add_piety = {
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
						multiply = 100
						divide = 2
					}
				}
			}
			else = {
				add_prestige = {
					value = {
						value = scope:initial_available_development
						subtract = scope:remaining_converted_development
						multiply = 100
						divide = 2
					}
				}
			}
		}
		
		ai_chance = {
			base = 100
			modifier = {
				exists = scope:from_decision
				factor = 0
			}
		}
	}
	
	after = {
		every_in_list = {
			list = counties_to_move_in_to
			remove_variable = county_development_to_get
		}
		scope:local_character = {
			silent_disappearance_ai_effect = yes
		}
	}
}
