#	Example:
#
#	example_effect = {
#		treasury = 100
#		prestige = 50
#	}
#
#
#	In a script file:
#
#	effect = {
#		example_effect = yes
#	}
#
# Naming convention:  xxxx_effect
#

# used in title scope (THIS)
current_inheritance_laws_effect = {
	log = "INFO: law changing for the [This.GetFullName] ([This.GetID]):"

	trigger_switch = {
		on_trigger = has_law

		succ_gavelkind = { log = "---> current succession law for [This.GetID]: Gavelkind" }
		succ_elective_gavelkind = { log = "---> current succession law for [This.GetID]: Elective Gavelkind" }
		succ_seniority = { log = "---> current succession law for [This.GetID]: Seniority" }
		succ_primogeniture = { log = "---> current succession law for [This.GetID]: Primogeniture" }
		succ_feudal_elective = { log = "---> current succession law for [This.GetID]: Feudal Elective" }
		succ_hre_elective = { log = "---> current succession law for [This.GetID]: Princely Elective" }
		succ_byzantine_elective = { log = "---> current succession law for [This.GetID]: Imperial Elective" }
		succ_tanistry = { log = "---> current succession law for [This.GetID]: Tanistry" }
		succ_eldership = { log = "---> current succession law for [This.GetID]: Eldership" }
		succ_ultimogeniture = { log = "---> current succession law for [This.GetID]: Ultimogeniture" }
		succ_turkish_succession = { log = "---> current succession law for [This.GetID]: Turkish Succession" }
		succ_papal_succession = { log = "---> current succession law for [This.GetID]: Papal Succession" }
		succ_appointment = { log = "---> current succession law for [This.GetID]: Appointment" }
		succ_open_elective = { log = "---> current succession law for [This.GetID]: Open Elective" }
		succ_catholic_bishopric = { log = "---> current succession law for [This.GetID]: Bishopric" }
		succ_patrician_elective = { log = "---> current succession law for [This.GetID]: Patrician Elective" }
		succ_nomad_succession = { log = "---> current succession law for [This.GetID]: Nomadic" }
	}

	trigger_switch = {
		on_trigger = has_law

		agnatic_succession = { log = "---> current gender law for [This.GetID]: Agnatic" }
		cognatic_succession = { log = "---> current gender law for [This.GetID]: Agnatic-Cognatic" }
		true_cognatic_succession = { log = "---> current gender law for [This.GetID]: Absolute Cognatic" }
		enatic_cognatic_succession = { log = "---> current gender law for [This.GetID]: Enatic-Cognatic" }
		enatic_succession = { log = "---> current gender law for [This.GetID]: Enatic" }
	}
}

escape_siege_effect = {
	random_list = {
		9 = {
			mult_modifier = {
				factor = 1.5
				trait = genius
			}

			mult_modifier = {
				factor = 1.25

				OR = {
					trait = quick
					trait = shrewd
				}
			}

			mult_modifier = {
				factor = 0.75
				trait = brave
			}

			mult_modifier = {
				factor = 1.25
				trait = craven
			}

			mult_modifier = {
				factor = 0.75
				trait = wounded
			}

			mult_modifier = {
				factor = 0.5
				trait = infirm
			}

			mult_modifier = {
				factor = 0.5
				trait = maimed
			}

			mult_modifier = {
				factor = 0.9

				intrigue < 2
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 0.9

				intrigue < 4
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 0.9

				intrigue < 6
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 0.9

				intrigue < 8
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 1.1

				intrigue >= 10
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 1.1

				intrigue >= 12
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 1.1

				intrigue >= 14
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 1.1

				intrigue >= 16
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 1.1

				intrigue >= 18
				is_adult = yes
				is_incapable = no
			}

			mult_modifier = {
				factor = 0.8
				has_character_flag = in_danger
			}

			custom_tooltip = {
				text = EVTTOOLTIPsiegehide

				add_trait = in_hiding
				set_character_flag = in_hiding_siege
			}
		}

		1 = {
			mult_modifier = {
				factor = 2.5
				has_character_flag = in_danger
			}

			custom_tooltip = {
				text = EVTTOOLTIPsiegeremain

				set_character_flag = has_siege_effect

				add_character_modifier = {
					name = left_at_siege
					months = 6
				}
			}
		}
	}
}

heresy_character_effect = {
	# Search nearby first
	if = {
		limit = {
			location = {
				any_neighbor_province = {
					has_owner = yes

					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}
				}
			}
		}

		location = {
			random_neighbor_province = {
				limit = {
					has_owner = yes

					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}
				}

				# Prefer a neighboring heresy
				preferred_limit = { is_heresy_of = ROOT }

				# Prefer a neighboring member of the same religion group
				preferred_limit = {
					is_heretic = no
					religion_group = ROOT

					NOR = {
						religion = ROOT
						religion_group = pagan_group
					}
				}

				reverse_religion = ROOT
			}
		}
	}
	# Prefer an existing heresy in the realm
	else_if = {
		limit = {
			top_liege = {
				any_realm_province = {
					held_under_PREV = yes

					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}
				}
			}
		}

		# Prefer an existing heresy in the realm
		top_liege = {
			random_realm_province = {
				limit = {
					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					held_under_PREV = yes
				}

				# Prefer a heresy
				preferred_limit = { is_heresy_of = ROOT }

				# Prefer a member of the same religion group
				preferred_limit = {
					is_heretic = no
					religion_group = ROOT

					NOR = {
						religion = ROOT
						religion_group = pagan_group
					}
				}

				reverse_religion = ROOT
			}
		}
	}
	# Or one not far away
	else_if = {
		limit = {
			any_neighbor_independent_ruler = {
				any_realm_province = {
					held_under_PREV = yes

					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					ROOT = {
						location = {
							distance = {
								where = PREVPREV
								value < 300
							}
						}
					}
				}
			}
		}

		random_neighbor_independent_ruler = {
			limit = {
				any_realm_province = {
					held_under_PREV = yes

					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					ROOT = {
						location = {
							distance = {
								where = PREVPREV
								value < 300
							}
						}
					}
				}
			}

			random_realm_province = {
				limit = {
					trigger_if = {
						limit = { is_heretic = yes }
						is_heresy_of = ROOT
					}
					trigger_else = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					held_under_PREV = yes

					ROOT = {
						location = {
							distance = {
								where = PREVPREV
								value < 300
							}
						}
					}
				}

				# Prefer a heresy
				preferred_limit = { is_heresy_of = ROOT }

				# Prefer a member of the same religion group
				preferred_limit = {
					is_heretic = no
					religion_group = ROOT

					NOR = {
						religion = ROOT
						religion_group = pagan_group
					}
				}

				reverse_religion = ROOT
			}
		}
	}

	# ...otherwise, just pick a heresy
	else_if = {
		limit = { religion_group = christian }

		if = {
			limit = { religion = chalcedonian }

			random_list = {
				75 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25

						location = {
							NOR = {
								region = custom_aquitaine
								region = custom_burgundy
							}
						}

						NOT = { culture = occitan }
					}

					mult_modifier = {
						factor = 1.5
						culture = occitan
					}

					religion = cathar
				}

				75 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_france }
							culture = french
						}
					}

					mult_modifier = {
						factor = 1.5
						culture = french
					}

					religion = waldensian
				}

				75 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_british_isles } }
					}

					religion = lollard
				}

				75 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_iberia } }
					}

					mult_modifier = {
						factor = 1.5
						culture_group = iberian
					}

					religion = adoptionist
				}

				75 = {
					trigger = {
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25

						OR = {
							culture_group = south_slavic

							location = {
								OR = {
									region = custom_bulgaria
									region = custom_croatia
									region = custom_serbia
								}
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}

					religion = bogomilist
				}

				75 = {
					trigger = {
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25

						NOT = { culture_group = arabic }

						location = {
							NOR = {
								region = world_middle_east
								region = custom_azerbaijan
								region = custom_persia
							}
						}
					}

					religion = monothelite
				}

				75 = {
					trigger = {
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { location = { region = custom_byzantium } }
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							culture = greek
							culture = pontic_greek
						}
					}

					religion = iconoclast
				}

				25 = {
					trigger = {
						OR = {
							culture = armenian

							location = {
								OR = {
									region = custom_armenia
									region = custom_georgia
								}
							}
						}
					}

					religion = paulician
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						location = {
							NOR = {
								region = world_middle_east
								region = world_africa
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = custom_armenia
								region = custom_georgia
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}

					religion = apostolic
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						location = {
							NOR = {
								region = world_india
								region = world_steppe
								region = world_middle_east
								region = world_middle_east_asia_minor
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5

						location = {
							NOR = {
								region = world_india
								region = world_steppe
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						OR = {
							trait = sympathy_zoroastrianism

							location = {
								OR = {
									region = world_middle_east_persia
									region = world_steppe_east
									region = world_steppe_tarim
									region = world_middle_east_arabia
								}
							}
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					mult_modifier = {
						factor = 0.25

						NOR = {
							location = { region = world_middle_east_levant }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_judaism
					}

					religion = jewish
				}

				10 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = catholic }

			random_list = {
				75 = {
					trigger = {
						OR = {
							location = { region = world_europe_south_italy }
							is_italian_trigger = yes
						}
					}

					religion = fraticelli
				}

				75 = {
					trigger = {
						OR = {
							culture = occitan

							location = {
								OR = {
									region = custom_aquitaine
									region = custom_burgundy
								}
							}
						}
					}

					religion = cathar
				}

				75 = {
					trigger = {
						location = { region = world_europe_west_british_isles }
					}

					mult_modifier = {
						factor = 0.5

						NOR = {
							location = { region = custom_england }
							culture = english
						}
					}

					religion = lollard
				}

				75 = {
					trigger = {
						OR = {
							location = { region = custom_france }
							culture = french
						}
					}

					religion = waldensian
				}

				50 = {
					trigger = {
						location = { region = world_europe_west_iberia }
					}

					religion = adoptionist
				}

				75 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_south_east
								region = world_europe_east
								region = world_middle_east_asia_minor
								region = world_middle_east_levant
							}
						}
					}

					mult_modifier = {
						factor = 0.35

						NOR = {
							location = { region = custom_byzantium }
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}

					religion = orthodox
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_middle_east
								region = world_africa
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = custom_armenia
								region = custom_georgia
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_india
								region = world_steppe
								region = world_middle_east
								region = world_middle_east_asia_minor
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5

						location = {
							NOR = {
								region = world_india
								region = world_steppe
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						OR = {
							trait = sympathy_zoroastrianism

							location = {
								OR = {
									region = world_middle_east_persia
									region = world_steppe_east
									region = world_steppe_tarim
									region = world_middle_east_arabia
								}
							}
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							location = { region = world_middle_east_levant }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_judaism
					}

					religion = jewish
				}

				25 = {
					become_heretic = yes
				}
			}
		}

		else_if = {
			limit = { religion = orthodox }

			random_list = {
				50 = {
					trigger = {
						OR = {
							culture_group = south_slavic

							location = {
								OR = {
									region = custom_bulgaria
									region = custom_croatia
									region = custom_serbia
								}
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}

					religion = bogomilist
				}

				50 = {
					trigger = {
						location = { region = custom_byzantium }
					}

					religion = iconoclast
				}

				25 = {
					trigger = {
						OR = {
							culture = armenian

							location = {
								OR = {
									region = custom_armenia
									region = custom_georgia
								}
							}
						}
					}

					religion = paulician
				}

				50 = {
					trigger = {
						OR = {
							culture_group = arabic

							location = {
								OR = {
									region = world_middle_east
									region = custom_azerbaijan
									region = custom_persia
								}
							}
						}
					}

					religion = monothelite
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_india
								region = world_steppe
								region = world_middle_east
								region = world_middle_east_asia_minor
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5

						location = {
							NOR = {
								region = world_india
								region = world_steppe
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_middle_east
								region = world_africa
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = custom_armenia
								region = custom_georgia
							}
						}
					}

					mult_modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						OR = {
							trait = sympathy_zoroastrianism

							location = {
								OR = {
									region = world_middle_east_persia
									region = world_steppe_east
									region = world_steppe_tarim
									region = world_middle_east_arabia
								}
							}
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
								region = custom_croatia
								region = custom_poland
								region = custom_carpathia
							}
						}
					}

					religion = catholic
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							location = { region = world_middle_east_levant }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_judaism
					}

					religion = jewish
				}

				25 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = nestorian }

			random_list = {
				25 = {
					trigger = {
						OR = {
							trait = sympathy_zoroastrianism

							location = {
								OR = {
									region = world_india
									region = world_middle_east
									region = world_steppe
									region = world_middle_east_persia
								}
							}
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_africa
								region = world_middle_east
							}
						}
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						location = { region = world_middle_east_asia_minor }
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						location = { region = world_europe }
					}

					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					else = {
						religion = chalcedonian
					}
				}

				50 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = miaphysite }

			random_list = {
				25 = {
					trigger = {
						trait = sympathy_zoroastrianism

						location = {
							OR = {
								region = world_india
								region = world_middle_east
								region = world_steppe
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_india
								region = world_africa
								region = world_steppe
								region = world_middle_east
								region = world_middle_east_persia
							}
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						location = { region = world_middle_east_asia_minor }
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						location = {
							OR = {
								region = world_europe
								region = world_middle_east
							}
						}
					}

					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					else = {
						religion = chalcedonian
					}
				}

				25 = {
					religion = monophysite
				}
			}
		}
		else = {
			become_heretic = yes
		}
	}
	else_if = {
		limit = { religion_group = muslim }

		random_list = {
			40 = {
				trigger = {
					NOT = { religion = sunni }
				}

				mult_modifier = {
					factor = 0.25
					religion = shiite
				}

				religion = sunni
			}

			20 = {
				trigger = {
					OR = {
						culture = kurdish
						trait = sympathy_zoroastrianism

						location = {
							OR = {
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_mesopotamia
							}
						}
					}

					NOT = { religion = yazidi }
				}

				mult_modifier = {
					factor = 2
					culture = kurdish
				}

				mult_modifier = {
					factor = 0.25

					location = { region = custom_mesopotamia }
					NOT = { culture = kurdish }
				}

				religion = yazidi
			}

			20 = {
				trigger = {
					NOT = { religion = ibadi }
				}

				mult_modifier = {
					factor = 0.5

					NOT = { culture = bedouin }

					location = {
						NOR = {
							region = world_africa
							region = custom_arabia
						}
					}
				}

				mult_modifier = {
					factor = 2
					culture = bedouin
				}

				religion = ibadi
			}

			20 = {
				trigger = {
					OR = {
						religion = ibadi
						location = { region = world_middle_east_arabia }
					}

					NOT = { religion = kharijite }
				}

				religion = kharijite
			}

			40 = {
				trigger = {
					NOT = { religion = shiite }
				}

				mult_modifier = {
					factor = 1.5
					religion = sunni
				}

				religion = shiite
			}

			20 = {
				trigger = {
					location = { region = world_europe_south_east }
					NOT = { religion = bektashi }
				}

				religion = bektashi
			}

			20 = {
				trigger = {
					OR = {
						location = { region = world_middle_east_levant }
						culture = levantine
					}

					NOT = { religion = druze }
				}

				mult_modifier = {
					factor = 0.25

					culture = levantine
					NOT = { location = { region = world_middle_east_levant } }
				}

				religion = druze
			}

			20 = {
				trigger = {
					NOT = { religion = hurufi }
				}

				religion = hurufi
			}

			10 = {
				trigger = {
					OR = {
						culture = persian
						trait = sympathy_zoroastrianism

						location = {
							OR = {
								region = world_middle_east_persia
								region = custom_mesopotamia
								region = custom_khwarizm
							}
						}
					}
				}

				mult_modifier = {
					factor = 2
					location = { region = custom_persia }
				}

				mult_modifier = {
					factor = 2
					trait = sympathy_zoroastrianism
				}

				mult_modifier = {
					factor = 0.5
					year >= 1200
				}

				religion = zoroastrian
			}

			10 = {
				trigger = {
					location = {
						OR = {
							region = world_india
							region = world_middle_east
							region = custom_azerbaijan
							region = world_middle_east_persia
							region = world_steppe
						}
					}
				}

				mult_modifier = {
					factor = 2
					location = { region = world_steppe }
				}

				mult_modifier = {
					factor = 0.5
					year >= 1100
				}

				mult_modifier = {
					factor = 0.5
					year >= 1200
				}

				religion = manichaean
			}

			10 = {
				trigger = {
					OR = {
						location = { region = custom_jerusalem }
						trait = sympathy_judaism
					}
				}

				religion = jewish
			}

			10 = {
				trigger = {
					location = { region = world_middle_east_asia_minor }
				}

				mult_modifier = {
					factor = 3
					culture = armenian
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				religion = apostolic
			}

			10 = {
				trigger = {
					OR = {
						culture = egyptian
						location = { region = world_africa }
					}
				}

				mult_modifier = {
					factor = 2.5
					culture = egyptian
				}

				mult_modifier = {
					factor = 0.5

					location = {
						NOR = {
							region = custom_egypt
							region = custom_abyssinia
							region = custom_nubia
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				religion = miaphysite
			}

			10 = {
				trigger = {
					location = {
						OR = {
							region = world_europe_south_east
							region = world_europe_east
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				mult_modifier = {
					factor = 2.5

					OR = {
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				mult_modifier = {
					factor = 0.5

					NOR = {
						location = { region = custom_byzantium }
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = orthodox
				}
				else = {
					religion = chalcedonian
				}
			}

			10 = {
				trigger = {
					location = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				else = {
					religion = chalcedonian
				}
			}

			10 = {
				become_heretic = yes
			}
		}
	}
	else_if = {
		limit = { religion_group = jewish_group }

		random_list = {
			75 = {
				trigger = {
					culture_group = altaic
					NOT = { religion = karaite }
				}

				religion = karaite
			}

			25 = {
				trigger = {
					location = {
						OR = {
							region = world_europe_south_east
							region = world_europe_east
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				mult_modifier = {
					factor = 0.5

					NOR = {
						location = { region = custom_byzantium }
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = orthodox
				}
				else = {
					religion = chalcedonian
				}
			}

			25 = {
				trigger = {
					location = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				else = {
					religion = chalcedonian
				}
			}

			25 = {
				trigger = {
					location = { region = world_middle_east_asia_minor }
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}

				religion = apostolic
			}

			25 = {
				trigger = {
					location = { region = world_africa }
				}

				mult_modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				religion = miaphysite
			}

			50 = {
				mult_modifier = {
					factor = 0.25
					culture_group = altaic
				}

				become_heretic = yes
			}
		}
	}
	else_if = {
		limit = { religion_group = zoroastrian_group }

		random_list = {
			50 = {
				trigger  = {
					NOT = { religion = zoroastrian }
				}

				mult_modifier = {
					factor = 0.5
					religion = manichaean
				}

				religion = zoroastrian
			}

			50 = {
				trigger = {
					NOT = { religion = manichaean }
				}

				mult_modifier = {
					factor = 0.5
					religion = zoroastrian
				}

				religion = manichaean
			}

			50 = {
				trigger = {
					OR = {
						culture = kurdish

						location = {
							OR = {
								region = custom_armenia
								region = custom_azerbaijan
								region = custom_mesopotamia
							}
						}
					}

					NOT = { religion = yazidi }
				}

				mult_modifier = {
					factor = 0.25

					location = { region = custom_mesopotamia }
					NOT = { culture = kurdish }
				}

				mult_modifier = {
					factor = 2
					trait = sympathy_islam
				}

				mult_modifier = {
					factor = 2
					culture = kurdish
				}

				religion = yazidi
			}

			50 = {
				mult_modifier = {
					factor = 2
					trait = sympathy_islam
				}

				religion = shiite
			}

			50 = {
				trigger = { religion = manichaean }

				mult_modifier = {
					factor = 2
					trait = sympathy_christendom
				}

				religion = nestorian
			}

			20 = {
				trigger = {
					location = { region = world_middle_east_asia_minor }
				}

				mult_modifier = {
					factor = 2
					trait = sympathy_christendom
				}

				religion = apostolic
			}

			20 = {
				trigger = {
					location = { region = world_africa }
				}

				mult_modifier = {
					factor = 2
					trait = sympathy_christendom
				}

				religion = miaphysite
			}

			50 = {
				become_heretic = yes
			}
		}
	}
	else = {
		become_heretic = yes
	}
}

heresy_province_effect = {
	# Search nearby first
	if = {
		limit = {
			any_neighbor_province = {
				has_owner = yes

				trigger_if = {
					limit = { is_heretic = yes }
					is_heresy_of = ROOT
				}
				trigger_else = {
					is_heretic = no
					religion_group = ROOT

					NOR = {
						religion = ROOT
						religion_group = pagan_group
					}
				}
			}
		}

		random_neighbor_province = {
			limit = {
				has_owner = yes

				trigger_if = {
					limit = { is_heretic = yes }
					is_heresy_of = ROOT
				}
				trigger_else = {
					is_heretic = no
					religion_group = ROOT

					NOR = {
						religion = ROOT
						religion_group = pagan_group
					}
				}
			}

			# Prefer a neighboring heresy
			preferred_limit = { is_heresy_of = ROOT }

			# Prefer a neighboring member of the same religion group
			preferred_limit = {
				is_heretic = no
				religion_group = ROOT

				NOR = {
					religion = ROOT
					religion_group = pagan_group
				}
			}

			reverse_religion = ROOT
		}
	}
	# Prefer an existing heresy in the realm
	else_if = {
		limit = {
			owner = {
				top_liege = {
					any_realm_province = {
						held_under_PREV = yes

						trigger_if = {
							limit = { is_heretic = yes }
							is_heresy_of = ROOT
						}
						trigger_else = {
							is_heretic = no
							religion_group = ROOT

							NOR = {
								religion = ROOT
								religion_group = pagan_group
							}
						}
					}
				}
			}
		}

		# Prefer an existing heresy in the realm
		owner = {
			top_liege = {
				random_realm_province = {
					limit = {
						trigger_if = {
							limit = { is_heretic = yes }
							is_heresy_of = ROOT
						}
						trigger_else = {
							is_heretic = no
							religion_group = ROOT

							NOR = {
								religion = ROOT
								religion_group = pagan_group
							}
						}

						held_under_PREV = yes
					}

					# Prefer a heresy
					preferred_limit = { is_heresy_of = ROOT }

					# Prefer a member of the same religion group
					preferred_limit = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					reverse_religion = ROOT
				}
			}
		}
	}
	# Or one not far away
	else_if = {
		limit = {
			owner = {
				any_neighbor_independent_ruler = {
					any_realm_province = {
						held_under_PREV = yes

						trigger_if = {
							limit = { is_heretic = yes }
							is_heresy_of = ROOT
						}
						trigger_else = {
							is_heretic = no
							religion_group = ROOT

							NOR = {
								religion = ROOT
								religion_group = pagan_group
							}
						}

						ROOT = {
							location = {
								distance = {
									where = PREVPREV
									value < 300
								}
							}
						}
					}
				}
			}
		}

		owner = {
			random_neighbor_independent_ruler = {
				limit = {
					any_realm_province = {
						held_under_PREV = yes

						trigger_if = {
							limit = { is_heretic = yes }
							is_heresy_of = ROOT
						}
						trigger_else = {
							is_heretic = no
							religion_group = ROOT

							NOR = {
								religion = ROOT
								religion_group = pagan_group
							}
						}

						ROOT = {
							location = {
								distance = {
									where = PREVPREV
									value < 300
								}
							}
						}
					}
				}

				random_realm_province = {
					limit = {
						trigger_if = {
							limit = { is_heretic = yes }
							is_heresy_of = ROOT
						}
						trigger_else = {
							is_heretic = no
							religion_group = ROOT

							NOR = {
								religion = ROOT
								religion_group = pagan_group
							}
						}

						held_under_PREV = yes

						ROOT = {
							location = {
								distance = {
									where = PREVPREV
									value < 300
								}
							}
						}
					}

					# Prefer a heresy
					preferred_limit = { is_heresy_of = ROOT }

					# Prefer a member of the same religion group
					preferred_limit = {
						is_heretic = no
						religion_group = ROOT

						NOR = {
							religion = ROOT
							religion_group = pagan_group
						}
					}

					reverse_religion = ROOT
				}
			}
		}
	}

	# ...otherwise, just pick a heresy
	else_if = {
		limit = { religion_group = christian }

		if = {
			limit = { religion = chalcedonian }

			random_list = {
				75 = {
					trigger = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25

						NOR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}

					mult_modifier = {
						factor = 1.5
						culture = occitan
					}

					religion = cathar
				}

				75 = {
					trigger = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25

						NOR = {
							region = custom_france
							culture = french
						}
					}

					mult_modifier = {
						factor = 1.5
						culture = french
					}

					religion = waldensian
				}

				75 = {
					trigger = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_british_isles }
					}

					religion = lollard
				}

				75 = {
					trigger = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_iberia }
					}

					mult_modifier = {
						factor = 1.5
						culture_group = iberian
					}

					religion = adoptionist
				}

				75 = {
					trigger = {
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25

						NOR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}

					mult_modifier = {
						factor = 1.5
						region = custom_bulgaria
					}

					religion = bogomilist
				}

				75 = {
					trigger = {
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25

						NOR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}

					religion = monothelite
				}

				75 = {
					trigger = {
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}

					mult_modifier = {
						factor = 0.25
						NOT = { region = custom_byzantium }
					}

					mult_modifier = {
						factor = 1.5

						OR = {
							culture = greek
							culture = pontic_greek
						}
					}

					religion = iconoclast
				}

				25 = {
					trigger = {
						OR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}

					religion = paulician
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}

					mult_modifier = {
						factor = 1.5
						region = world_africa_east
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						OR = {
							region = custom_armenia
							region = custom_georgia
						}
					}

					mult_modifier = {
						factor = 1.5
						region = custom_armenia
					}

					religion = apostolic
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_middle_east_asia_minor
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5

						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						OR = {
							region = world_middle_east_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					mult_modifier = {
						factor = 0.25

						NOR = {
							region = world_middle_east_levant
							culture_group = israelite
						}
					}

					religion = jewish
				}

				10 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = catholic }

			random_list = {
				75 = {
					trigger = {
						OR = {
							region = world_europe_south_italy
							is_italian_trigger = yes
						}
					}

					religion = fraticelli
				}

				75 = {
					trigger = {
						OR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}

					religion = cathar
				}

				75 = {
					trigger = { region = world_europe_west_british_isles }

					mult_modifier = {
						factor = 0.5

						NOR = {
							region = custom_england
							culture = english
						}
					}

					religion = lollard
				}

				75 = {
					trigger = {
						OR = {
							region = custom_france
							culture = french
						}
					}

					religion = waldensian
				}

				50 = {
					trigger = { region = world_europe_west_iberia }
					religion = adoptionist
				}

				75 = {
					trigger = {
						OR = {
							region = world_europe_south_east
							region = world_europe_east
							region = world_middle_east_asia_minor
							region = world_middle_east_levant
						}
					}

					mult_modifier = {
						factor = 0.35

						NOR = {
							region = custom_byzantium
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}

					religion = orthodox
				}

				25 = {
					trigger = {
						OR = {
							region = world_middle_east
							region = world_africa
						}
					}

					mult_modifier = {
						factor = 1.5
						region = world_africa_east
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						OR = {
							region = custom_armenia
							region = custom_georgia
						}
					}

					mult_modifier = {
						factor = 1.5
						region = custom_armenia
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						OR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_middle_east_asia_minor
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5

						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						OR = {
							region = world_middle_east_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							region = world_middle_east_levant
							culture_group = israelite
						}
					}

					religion = jewish
				}

				25 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = orthodox }

			random_list = {
				50 = {
					trigger = {
						OR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}

					mult_modifier = {
						factor = 1.5
						region = custom_bulgaria
					}

					religion = bogomilist
				}

				50 = {
					trigger = { region = custom_byzantium }
					religion = iconoclast
				}

				25 = {
					trigger = {
						OR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}

					religion = paulician
				}

				50 = {
					trigger = {
						OR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}

					religion = monothelite
				}

				25 = {
					trigger = {
						OR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_middle_east_asia_minor
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5

						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = {
						OR = {
							region = world_middle_east
							region = world_africa
						}
					}

					mult_modifier = {
						factor = 1.5
						region = world_africa_east
					}

					religion = miaphysite
				}

				25 = {
					trigger = {
						OR = {
							region = custom_armenia
							region = custom_georgia
						}
					}

					mult_modifier = {
						factor = 1.5
						region = custom_armenia
					}

					religion = apostolic
				}

				25 = {
					trigger = {
						OR = {
							region = world_middle_east_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
							region = custom_croatia
							region = custom_poland
							region = custom_carpathia
						}
					}

					religion = catholic
				}

				25 = {
					mult_modifier = {
						factor = 0.1

						NOR = {
							region = world_middle_east_levant
							culture_group = israelite
						}
					}

					religion = jewish
				}

				25 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = nestorian }

			random_list = {
				25 = {
					trigger = {
						OR = {
							region = world_india
							region = world_middle_east
							region = world_steppe
							region = world_middle_east_persia
						}
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						OR = {
							region = world_africa
							region = world_middle_east
						}
					}

					religion = miaphysite
				}

				25 = {
					trigger = { region = world_middle_east_asia_minor }
					religion = apostolic
				}

				25 = {
					trigger = { region = world_europe }

					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					else = {
						religion = chalcedonian
					}
				}

				50 = {
					become_heretic = yes
				}
			}
		}
		else_if = {
			limit = { religion = miaphysite }

			random_list = {
				25 = {
					trigger = {
						OR = {
							region = world_india
							region = world_middle_east
							region = world_steppe
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1100
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = manichaean
				}

				25 = {
					trigger = {
						OR = {
							region = world_india
							region = world_africa
							region = world_steppe
							region = world_middle_east
							region = world_middle_east_persia
						}
					}

					mult_modifier = {
						factor = 0.5
						year >= 1200
					}

					religion = nestorian
				}

				25 = {
					trigger = { region = world_middle_east_asia_minor }
					religion = apostolic
				}

				25 = {
					trigger = {
						OR = {
							region = world_europe
							region = world_middle_east
						}
					}

					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					else = {
						religion = chalcedonian
					}
				}

				25 = {
					religion = monophysite
				}
			}
		}
		else = {
			become_heretic = yes
		}
	}
	else_if = {
		limit = { religion_group = muslim }

		random_list = {
			40 = {
				trigger = {
					NOT = { religion = sunni }
				}

				mult_modifier = {
					factor = 0.25
					religion = shiite
				}

				religion = sunni
			}

			20 = {
				trigger = {
					OR = {
						culture = kurdish
						region = custom_armenia
						region = custom_azerbaijan
						region = custom_mesopotamia
					}

					NOT = { religion = yazidi }
				}

				mult_modifier = {
					factor = 2
					culture = kurdish
				}

				mult_modifier = {
					factor = 0.25

					region = custom_mesopotamia
					NOT = { culture = kurdish }
				}

				religion = yazidi
			}

			20 = {
				trigger = {
					NOT = { religion = ibadi }
				}

				mult_modifier = {
					factor = 0.5

					NOR = {
						region = world_africa
						region = custom_arabia
						culture = bedouin
					}
				}

				mult_modifier = {
					factor = 2
					culture = bedouin
				}

				religion = ibadi
			}

			20 = {
				trigger = {
					OR = {
						religion = ibadi
						region = world_middle_east_arabia
					}

					NOT = { religion = kharijite }
				}

				religion = kharijite
			}

			40 = {
				trigger = {
					NOT = { religion = shiite }
				}

				mult_modifier = {
					factor = 1.5
					religion = sunni
				}

				religion = shiite
			}

			20 = {
				trigger = {
					region = world_europe_south_east
					NOT = { religion = bektashi }
				}

				religion = bektashi
			}

			20 = {
				trigger = {
					OR = {
						region = world_middle_east_levant
						culture = levantine
					}

					NOT = { religion = druze }
				}

				mult_modifier = {
					factor = 0.25

					culture = levantine
					NOT = { region = world_middle_east_levant }
				}

				religion = druze
			}

			20 = {
				trigger = {
					NOT = { religion = hurufi }
				}

				religion = hurufi
			}

			10 = {
				trigger = {
					OR = {
						region = world_middle_east_persia
						region = custom_mesopotamia
						region = custom_khwarizm
						culture = persian
					}
				}

				mult_modifier = {
					factor = 2
					region = custom_persia
				}

				mult_modifier = {
					factor = 0.5
					year >= 1200
				}

				religion = zoroastrian
			}

			10 = {
				trigger = {
					OR = {
						region = world_india
						region = world_middle_east
						region = custom_azerbaijan
						region = world_middle_east_persia
						region = world_steppe
					}
				}

				mult_modifier = {
					factor = 2
					region = world_steppe
				}

				mult_modifier = {
					factor = 0.5
					year >= 1100
				}

				mult_modifier = {
					factor = 0.5
					year >= 1200
				}

				religion = manichaean
			}

			10 = {
				trigger = { region = custom_jerusalem }
				religion = jewish
			}
			10 = {
				trigger = { region = world_middle_east_asia_minor }

				mult_modifier = {
					factor = 3
					culture = armenian
				}
				religion = apostolic
			}

			10 = {
				trigger = { region = world_africa }

				mult_modifier = {
					factor = 2.5
					culture = egyptian
				}

				mult_modifier = {
					factor = 0.5

					location = {
						NOR = {
							region = custom_egypt
							region = custom_abyssinia
							region = custom_nubia
						}
					}
				}

				religion = miaphysite
			}

			10 = {
				trigger = {
					OR = {
						region = world_europe_south_east
						region = world_europe_east
					}
				}

				mult_modifier = {
					factor = 2.5

					OR = {
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				mult_modifier = {
					factor = 0.5

					NOR = {
						region = custom_byzantium
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = orthodox
				}
				else = {
					religion = chalcedonian
				}
			}

			10 = {
				trigger = {
					OR = {
						region = world_europe_west
						region = world_europe_north
						region = world_europe_south_italy
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				else = {
					religion = chalcedonian
				}
			}

			10 = {
				become_heretic = yes
			}
		}
	}
	else_if = {
		limit = { religion_group = jewish_group }

		random_list = {
			75 = {
				trigger = {
					culture_group = altaic
					NOT = { religion = karaite }
				}

				religion = karaite
			}

			25 = {
				trigger = {
					OR = {
						region = world_europe_south_east
						region = world_europe_east
					}
				}

				mult_modifier = {
					factor = 0.5

					NOR = {
						region = custom_byzantium
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = orthodox
				}
				else = {
					religion = chalcedonian
				}
			}

			25 = {
				trigger = {
					OR = {
						region = world_europe_west
						region = world_europe_north
						region = world_europe_south_italy
					}
				}

				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				else = {
					religion = chalcedonian
				}
			}

			25 = {
				trigger = { region = world_middle_east_asia_minor }
				religion = apostolic
			}

			25 = {
				trigger = { region = world_africa }
				religion = miaphysite
			}

			50 = {
				mult_modifier = {
					factor = 0.25
					culture_group = altaic
				}

				become_heretic = yes
			}
		}
	}
	else_if = {
		limit = { religion_group = zoroastrian_group }

		random_list = {
			50 = {
				trigger = {
					NOT = { religion = zoroastrian }
				}

				mult_modifier = {
					factor = 0.5
					religion = manichaean
				}

				religion = zoroastrian
			}

			50 = {
				trigger = {
					NOT = { religion = manichaean }
				}

				mult_modifier = {
					factor = 0.5
					religion = zoroastrian
				}

				religion = manichaean
			}

			50 = {
				trigger = {
					OR = {
						culture = kurdish
						region = custom_armenia
						region = custom_azerbaijan
						region = custom_mesopotamia
					}

					NOT = { religion = yazidi }
				}

				mult_modifier = {
					factor = 0.25

					region = custom_mesopotamia
					NOT = { culture = kurdish }
				}

				mult_modifier = {
					factor = 2
					culture = kurdish
				}

				religion = yazidi
			}

			50 = {
				religion = shiite
			}

			50 = {
				trigger = { religion = manichaean }
				religion = nestorian
			}

			25 = {
				trigger = { region = world_middle_east_asia_minor }
				religion = apostolic
			}

			25 = {
				trigger = { region = world_africa }
				religion = miaphysite
			}

			50 = {
				become_heretic = yes
			}
		}
	}
	else = {
		become_heretic = yes
	}
}


# used in scope of revolter who was previously-landed, to verify government type
landless_government_check_effect = {
	if = {
		limit = {
			OR = {
				is_theocracy = yes
				is_republic = yes

				AND = {
					is_feudal = yes
					num_of_demesne_castles == 0
				}

				AND = {
					is_tribal = yes
					num_of_demesne_tribes == 0
				}

				AND = {
					is_nomadic = yes

					NOT = {
						any_demesne_title = {
							real_tier = BARON
							holding_type = nomad
						}
					}
				}
			}
		}

		# First priority: Feudal
		if = {
			limit = {
				any_demesne_title = {
					real_tier = BARON
					holding_type = castle
					location = { culture = ROOT }
				}
			}

			if = {
				limit = { religion_group = muslim }
				log = "----> [Root.GetBestName] has been set to iqta government (Liberation Revolt)"
				set_government_type = muslim_feudal_government
			}
			else = {
				log = "----> [Root.GetBestName] has been set to feudal government (Liberation Revolt)"
				set_government_type = feudal_government
			}
		}

		# Second priority: Nomadic
		else_if = {
			limit = {
				OR = {
					any_demesne_title = {
						real_tier = BARON
						holding_type = nomad
						location = { culture = ROOT }
					}

					any_demesne_province = {
						culture = ROOT
						num_of_settlements < 1
						owned_by = PREV
					}
				}
			}

			log = "----> [Root.GetBestName] has been set to nomadic government (Liberation Revolt)"
			set_government_type = nomadic_government
		}

		# Third priority: Tribal
		else_if = {
			limit = {
				any_demesne_title = {
					real_tier = BARON
					holding_type = tribal
					location = { culture = ROOT }
				}
			}

			log = "----> [Root.GetBestName] has been set to tribal government (Liberation Revolt)"
			set_government_type = tribal_government
		}
	}
}

marry_to_ROOT_effect = {
	if = {
		limit = { ROOT = { father_even_if_dead = { always = yes } } }
		ROOT = { father_even_if_dead = { save_event_target_as = father_rank } }
	}

	if = {
		limit = { ROOT = { mother_even_if_dead = { always = yes } } }
		ROOT = { mother_even_if_dead = { save_event_target_as = mother_rank } }
	}

	if = {
		limit = {
			ROOT = {
				wants_matrilineal_marriage_trigger = yes
				can_marry_matrilineally_trigger = yes
			}

			NOT = { dynasty = ROOT }
			can_marry_matrilineally_trigger = yes

			OR = {
				AND = {
					ROOT = { is_ruler = yes }

					NOR = {
						higher_real_tier_than = ROOT
						higher_real_tier_than = event_target:father_rank
						higher_real_tier_than = event_target:mother_rank

						father_even_if_dead = {
							OR = {
								higher_real_tier_than = ROOT
								higher_real_tier_than = event_target:father_rank
								higher_real_tier_than = event_target:mother_rank
							}
						}

						mother_even_if_dead = {
							OR = {
								higher_real_tier_than = ROOT
								higher_real_tier_than = event_target:father_rank
								higher_real_tier_than = event_target:mother_rank
							}
						}
					}
				}

				AND = {
					ROOT = {
						is_ruler = no
						father_even_if_dead = { is_ruler = yes }
					}

					NOR = {
						higher_real_tier_than = event_target:father_rank
						father_even_if_dead = { higher_real_tier_than = event_target:father_rank }
						mother_even_if_dead = { higher_real_tier_than = event_target:father_rank }
					}
				}

				AND = {
					ROOT = {
						is_ruler = no
						mother_even_if_dead = { is_ruler = yes }
					}

					NOR = {
						higher_real_tier_than = event_target:mother_rank
						father_even_if_dead = { higher_real_tier_than = event_target:mother_rank }
						mother_even_if_dead = { higher_real_tier_than = event_target:mother_rank }
					}
				}
			}
		}

		log = "---> the above marriage is matrilineal"
		add_spouse_matrilineal = ROOT
	}
	else = {
		add_spouse = ROOT
	}
}

pardon_effect = {
	hidden_effect = {
		reverse_remove_opinion = { who = FROM name = opinion_dishonorable }
		reverse_remove_opinion = { who = FROM name = opinion_traitor }
		reverse_remove_opinion = { who = FROM name = opinion_rebel_traitor }
		reverse_remove_opinion = { who = FROM name = opinion_regicide_traitor }
		reverse_remove_opinion = { who = FROM name = opinion_targeted_by_adventurer }
		reverse_remove_opinion = { who = FROM name = slut_seductress }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_spouse }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_child }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_parent }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_sibling }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_vassal }
		reverse_remove_opinion = { who = FROM name = attempted_murder }
		reverse_remove_opinion = { who = FROM name = opinion_spouse_slayer }
		reverse_remove_opinion = { who = FROM name = opinion_murder_attempt }
		reverse_remove_opinion = { who = FROM name = opinion_killed_close_kin }
		reverse_remove_opinion = { who = FROM name = opinion_fatwa_target }
		reverse_remove_opinion = { who = FROM name = opinion_refused_order }
		reverse_remove_opinion = { who = FROM name = opinion_witch }
		reverse_remove_opinion = { who = FROM name = opinion_takfir }
		reverse_remove_opinion = { who = FROM name = opinion_unfaithful_wife }
		reverse_remove_opinion = { who = FROM name = opinion_unfaithful_husband }
		reverse_remove_opinion = { who = FROM name = opinion_cuckolded }
		reverse_remove_opinion = { who = FROM name = opinion_charge_heresiarch }
		reverse_remove_opinion = { who = FROM name = opinion_charge_infidel }
		reverse_remove_opinion = { who = FROM name = opinion_charge_deviant }
		reverse_remove_opinion = { who = FROM name = opinion_charge_illegitimate }
		reverse_remove_opinion = { who = FROM name = opinion_charge_traitor }
		reverse_remove_opinion = { who = FROM name = opinion_charge_slanderer }
		reverse_remove_opinion = { who = FROM name = abuse_of_office }
		reverse_remove_opinion = { who = FROM name = opinion_charge_traitor }
		reverse_remove_opinion = { who = FROM name = attempted_kidnapping }
		reverse_remove_opinion = { who = FROM name = attempted_kidnapping_of_kin }
		reverse_remove_opinion = { who = FROM name = attempted_kidnapping_of_vassal }
		reverse_remove_opinion = { who = FROM name = attempted_murder_of_close_kin }
		reverse_remove_opinion = { who = FROM name = devious_plotter }
		reverse_remove_opinion = { who = FROM name = killed_vassal }
		reverse_remove_opinion = { who = FROM name = mad_heretic }
		reverse_remove_opinion = { who = FROM name = opinion_civil_war_loser }
		reverse_remove_opinion = { who = FROM name = opinion_independent }
		reverse_remove_opinion = { who = FROM name = opinion_kidnapped_kin }
		reverse_remove_opinion = { who = FROM name = opinion_eloped_target }
	}
}

remove_possessed_effect = {
	remove_trait = possessed

	hidden_effect = {
		remove_character_modifier = voice_of_satan
		remove_character_modifier = voice_of_jesus
		remove_character_modifier = speaking_in_tounges
		remove_character_modifier = holy_comet
		remove_character_modifier = lycanthropy
		clr_character_flag = demon_child
		clr_character_flag = demon_child_fake
		clr_character_flag = child_exorcism
		clr_character_flag = changeling_child
		clr_character_flag = changeling_child_fake
		clr_character_flag = changeling_trade
		clr_character_flag = seelie
		clr_character_flag = unseelie
	}
}

# ROOT = liege who originally sent relative away, FROM = relative
return_home_effect = {
	if = {
		limit = { is_ruler = yes }

		FROM = {
			show_scope_change = no
			move_character = ROOT
		}
	}
	else = {
		random_dynasty_member = {
			show_scope_change = no

			limit = { is_ruler = yes }

			FROM = {
				show_scope_change = no
				move_character = PREV
			}
		}
	}
}

save_viceroy_pick_effect = {
	if = {
		limit = {
			NOT = { event_target:council_first_pick = { always = yes } }
		}
		save_event_target_as = council_first_pick
	}
	else_if = {
		limit = {
			NOT = { event_target:council_second_pick = { always = yes } }
		}
		save_event_target_as = council_second_pick
	}
	else_if = {
		limit = {
			NOT = { event_target:council_third_pick = { always = yes } }
		}
		save_event_target_as = council_third_pick
	}
}

sell_estates_effect = {
	if = {
		limit = { has_minor_title = title_lord }
		remove_title = title_lord
	}

	if = {
		limit = { has_character_modifier = estates_1 }
		remove_character_modifier = estates_1
		wealth = 40
	}
}

siege_capture_check_effect = {
	random_list = {
		30 = {
			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = BARON
					father = { higher_real_tier_than = BARON }
					mother = { higher_real_tier_than = BARON }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = COUNT
					father = { higher_real_tier_than = COUNT }
					mother = { higher_real_tier_than = COUNT }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = DUKE
					father = { higher_real_tier_than = DUKE }
					mother = { higher_real_tier_than = DUKE }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = KING
					father = { higher_real_tier_than = KING }
					mother = { higher_real_tier_than = KING }
				}
			}

			mult_modifier = {
				factor = 1.5
				is_adult = no
			}

			mult_modifier = {
				factor = 0.5
				trait = infirm
			}

			mult_modifier = {
				factor = 0.5
				trait = wounded
			}

			mult_modifier = {
				factor = 0.25
				trait = maimed
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 12
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 13
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 14
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 15
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 16
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 17
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 18
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 19
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 20
			}

			mult_modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}

			custom_tooltip = { text = siege_escaped }
		}

		20 = {
			mult_modifier = {
				factor = 2
				trait = brave
			}

			mult_modifier = {
				factor = 0.5
				trait = craven
			}

			character_event = {
				id = Plus.1032
				tooltip = siege_injured
			}
		}

		20 = {
			mult_modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}

			mult_modifier = {
				factor = 3

				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1
				}
			}

			mult_modifier = {
				factor = 3 # if the sieger has a particular Legendary bloodline

				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
						bloodline_is_active_for = PREV
					}
				}
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 12
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 11
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 10
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 9
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 8
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 7
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 6
			}

			character_event = {
				id = Plus.1027
				tooltip = siege_captured
			}
		}
	}
}

siege_kill_check_effect = {
	random_list = {
		30 = {
			mult_modifier = {
				factor = 0.5
				trait = brave
			}

			mult_modifier = {
				factor = 2
				trait = craven
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = BARON
					father = { higher_real_tier_than = BARON }
					mother = { higher_real_tier_than = BARON }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = COUNT
					father = { higher_real_tier_than = COUNT }
					mother = { higher_real_tier_than = COUNT }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = DUKE
					father = { higher_real_tier_than = DUKE }
					mother = { higher_real_tier_than = DUKE }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = KING
					father = { higher_real_tier_than = KING }
					mother = { higher_real_tier_than = KING }
				}
			}

			mult_modifier = {
				factor = 1.5
				is_adult = no
			}

			mult_modifier = {
				factor = 0.5
				trait = infirm
			}

			mult_modifier = {
				factor = 0.5
				trait = wounded
			}

			mult_modifier = {
				factor = 0.25
				trait = maimed
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 11
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 10
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 9
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 8
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 7
			}

			mult_modifier = {
				factor = 0.8
				intrigue < 6
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 12
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 13
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 14
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 15
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 16
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 17
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 18
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 19
			}

			mult_modifier = {
				factor = 1.2
				intrigue >= 20
			}

			mult_modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}

			custom_tooltip = { text = siege_escaped }
		}

		40 = {
			character_event = {
				id = Plus.1032
				tooltip = siege_injured
			}
		}

		20 = {
			mult_modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}

			character_event = {
				id = Plus.1026
				tooltip = siege_killed
			}
		}
	}
}

siege_pagan_capture_check_effect = {
	random_list = {
		40 = {
			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = BARON
					father = { higher_real_tier_than = BARON }
					mother = { higher_real_tier_than = BARON }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = COUNT
					father = { higher_real_tier_than = COUNT }
					mother = { higher_real_tier_than = COUNT }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = DUKE
					father = { higher_real_tier_than = DUKE }
					mother = { higher_real_tier_than = DUKE }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = KING
					father = { higher_real_tier_than = KING }
					mother = { higher_real_tier_than = KING }
				}
			}

			mult_modifier = {
				factor = 0.5
				trait = brave
			}

			mult_modifier = {
				factor = 2.0
				trait = craven
			}

			mult_modifier = {
				factor = 1.5
				is_adult = no
			}

			mult_modifier = {
				factor = 0.5
				trait = infirm
			}

			mult_modifier = {
				factor = 0.5
				trait = wounded
			}

			mult_modifier = {
				factor = 0.25
				trait = maimed
			}

			mult_modifier = {
				factor = 0.8

				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1
				}
			}

			mult_modifier = {
				factor = 0.8

				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
						bloodline_is_active_for = PREV
					}
				}
			}

			mult_modifier = {
				factor = 3
				is_inaccessible_trigger = yes
				intrigue >= 12
			}

			mult_modifier = {
				factor = 2.5

				is_inaccessible_trigger = yes
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 2

				is_inaccessible_trigger = yes
				intrigue < 6
			}

			mult_modifier = {
				factor = 2.5
				is_inaccessible_trigger = no
				intrigue >= 18
			}

			mult_modifier = {
				factor = 2

				is_inaccessible_trigger = no
				intrigue >= 12
				intrigue < 18
			}

			mult_modifier = {
				factor = 1.5

				is_inaccessible_trigger = no
				intrigue >= 6
				intrigue < 12
			}

			custom_tooltip = { text = siege_escaped }
		}

		20 = {
			mult_modifier = {
				factor = 0.1

				is_inaccessible_trigger = yes
				intrigue >= 12
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = yes
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.5

				is_inaccessible_trigger = yes
				intrigue < 6
			}

			mult_modifier = {
				factor = 0.5

				is_inaccessible_trigger = no
				intrigue >= 12
				intrigue < 18
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = no
				intrigue >= 18
			}

			character_event = {
				id = Plus.1032
				tooltip = siege_injured
			}
		}

		20 = {
			mult_modifier = {
				factor = 3

				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1
				}
			}

			mult_modifier = {
				factor = 3 # if the sieger has a particular Legendary bloodline

				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
						bloodline_is_active_for = PREV
					}
				}
			}

			mult_modifier = {
				factor = 0.08

				is_inaccessible_trigger = yes
				intrigue >= 12
			}

			mult_modifier = {
				factor = 0.15

				is_inaccessible_trigger = yes
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = yes
				intrigue < 6
			}

			mult_modifier = {
				factor = 0.5

				is_inaccessible_trigger = no
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = no
				intrigue >= 12
				intrigue < 18
			}

			mult_modifier = {
				factor = 0.1

				is_inaccessible_trigger = no
				intrigue >= 18
			}

			character_event = {
				id = Plus.1027
				tooltip = siege_captured
			}
		}

		20 = {
			trigger = {
				trigger_if = {
					limit = { is_inaccessible_trigger = yes }
					intrigue < 12
				}
				trigger_else = {
					intrigue >= 18
				}
			}

			mult_modifier = {
				factor = 0.1

				is_inaccessible_trigger = yes
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = yes
				intrigue < 6
			}

			mult_modifier = {
				factor = 0.5

				is_inaccessible_trigger = no
				intrigue >= 6
				intrigue < 12
			}

			mult_modifier = {
				factor = 0.25

				is_inaccessible_trigger = no
				intrigue >= 12
				intrigue < 18
			}

			character_event = {
				id = Plus.1026
				tooltip = siege_killed
			}
		}
	}
}

siege_pagan_sacrifice_check_effect = {
	random_list = {
		30 = {
			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = BARON
					father = { higher_real_tier_than = BARON }
					mother = { higher_real_tier_than = BARON }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = COUNT
					father = { higher_real_tier_than = COUNT }
					mother = { higher_real_tier_than = COUNT }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = DUKE
					father = { higher_real_tier_than = DUKE }
					mother = { higher_real_tier_than = DUKE }
				}
			}

			mult_modifier = {
				factor = 1.2

				OR = {
					higher_real_tier_than = KING
					father = { higher_real_tier_than = KING }
					mother = { higher_real_tier_than = KING }
				}
			}

			mult_modifier = {
				factor = 1.5
				is_adult = no
			}

			mult_modifier = {
				factor = 0.5
				trait = infirm
			}

			mult_modifier = {
				factor = 0.5
				trait = wounded
			}

			mult_modifier = {
				factor = 0.25
				trait = maimed
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 12
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 13
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 14
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 15
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 16
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 17
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 18
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 19
			}

			mult_modifier = {
				factor = 1.25
				intrigue >= 20
			}

			mult_modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}

			custom_tooltip = { text = siege_escaped }
		}

		20 = {
			mult_modifier = {
				factor = 2
				trait = brave
			}

			mult_modifier = {
				factor = 0.5
				trait = craven
			}

			character_event = {
				id = Plus.1032
				tooltip = siege_injured
			}
		}

		20 = {
			mult_modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 12
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 11
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 10
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 9
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 8
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 7
			}

			mult_modifier = {
				factor = 1.25
				intrigue < 6
			}

			character_event = {
				id = Plus.1033
				tooltip = siege_sacrificed
			}
		}
	}
}

stop_hiding_effect = {
	if = {
		limit = { is_inaccessible_trigger = yes }
		end_inaccessibility_effect = yes
	}
}

title_reduce_CA_effect = {
	if = {
		limit = {
			higher_real_tier_than = DUKE

			OR = {
				has_law = crown_authority_1
				has_law = crown_authority_2
				has_law = crown_authority_3
				has_law = crown_authority_4
			}
		}

		set_title_flag = non_manual_law_change # No prestige loss

		custom_tooltip = {
			text = CA_LOWERED

			trigger_switch = {
				on_trigger = has_law

				crown_authority_1 = { add_law_w_cooldown = crown_authority_0 }
				crown_authority_2 = { add_law_w_cooldown = crown_authority_1 }
				crown_authority_3 = { add_law_w_cooldown = crown_authority_2 }
				crown_authority_4 = { add_law_w_cooldown = crown_authority_3 }
			}
		}

		clr_title_flag = non_manual_law_change # No prestige loss
	}
}

title_reduce_TO_effect = {
	if = {
		limit = {
			OR = {
				has_law = tribal_organization_1
				has_law = tribal_organization_2
				has_law = tribal_organization_3
				has_law = tribal_organization_4
			}
		}

		set_title_flag = non_manual_law_change # No prestige loss

		custom_tooltip = {
			text = TO_LOWERED

			trigger_switch = {
				on_trigger = has_law

				tribal_organization_1 = { add_law_w_cooldown = tribal_organization_0 }
				tribal_organization_2 = { add_law_w_cooldown = tribal_organization_1 }
				tribal_organization_3 = { add_law_w_cooldown = tribal_organization_2 }
				tribal_organization_4 = { add_law_w_cooldown = tribal_organization_3 }
			}
		}

		clr_title_flag = non_manual_law_change # No prestige loss
	}
}

german_culture_spread_effect_province = {
	if = {
		limit = {
			culture = frankish
			german_culture_region_trigger = yes
		}
		culture = franconian
	}
	else_if = {
		limit = { culture = alemannic }

		if = {
			limit = { region = custom_swiss }
			culture = swiss
		}
		else_if = {
			limit = { german_culture_region_trigger = yes }
			culture = swabian
		}
	}
}

late_german_culture_spread_effect_province = {
	if = {
		limit = {
			region = custom_prussian
			OR = {
				culture = saxon
				culture = prussian
			}
		}
		culture = teutonic
	}
	else_if = {
		limit = {
			region = custom_austrian
			culture = bavarian
		}
		culture = austrian
	}
}

german_culture_spread_from_ROOT_effect = {
	any_courtier = {
		show_scope_change = no

		limit = {
			dynasty = ROOT
			is_ruler = no
			prisoner = no

			OR = {
				culture = alemannic
				culture = frankish
			}
		}

		culture = ROOT
	}

	event_target:melting_pot_province = {
		show_scope_change = no

		culture = ROOT
		set_province_flag = melting_pot

		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
	}
}

austrian_culture_spread_effect = {
	any_courtier = {
		show_scope_change = no

		limit = {
			dynasty = ROOT
			culture = bavarian
			is_ruler = no
			prisoner = no
		}

		culture = austrian
	}

	event_target:melting_pot_province = {
		show_scope_change = no

		culture = austrian
		set_province_flag = melting_pot

		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
	}
}

teutonic_culture_spread_effect = {
	any_courtier = {
		show_scope_change = no

		limit = {
			dynasty = ROOT
			is_ruler = no
			prisoner = no

			OR = {
				culture = saxon
				culture = prussian
			}
		}

		culture = teutonic
	}

	event_target:melting_pot_province = {
		show_scope_change = no

		culture = teutonic
		set_province_flag = melting_pot

		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
	}
}

adjust_gender_law_effect = {
	set_title_flag = non_manual_law_change # No prestige loss

	if = {
		limit = { has_gender_equal_game_rule_trigger = yes }
		add_law = true_cognatic_succession
	}
	else_if = {
		limit = { event_target:liege_primary_title = { has_law = cognatic_succession } }
		add_law = cognatic_succession
	}
	else_if = {
		limit = { event_target:liege_primary_title = { has_law = true_cognatic_succession } }
		add_law = true_cognatic_succession
	}
	else_if = {
		limit = { event_target:liege_primary_title = { has_law = agnatic_succession } }
		add_law = agnatic_succession
	}
	else_if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_succession } }
		add_law = enatic_succession
	}
	else_if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_cognatic_succession } }
		add_law = enatic_cognatic_succession
	}

	clr_title_flag = non_manual_law_change # No prestige loss
}

start_reformed_effect = {
	if = {
		limit = { religion = baltic_pagan }
		religion = baltic_pagan_reformed
	}
	else_if = {
		limit = { religion = finnish_pagan }
		religion = finnish_pagan_reformed
	}
	else_if = {
		limit = { religion = slavic_pagan }
		religion = slavic_pagan_reformed
	}
	else_if = {
		limit = { religion = norse_pagan }
		religion = norse_pagan_reformed
	}
	else_if = {
		limit = { religion = tengri_pagan }
		religion = tengri_pagan_reformed
	}
	else_if = {
		limit = { religion = west_african_pagan }
		religion = west_african_pagan_reformed
	}
	else_if = {
		limit = { religion = zun_pagan }
		religion = zun_pagan_reformed
	}
	else_if = {
		limit = { religion = bon_pagan }
		religion = bon_pagan_reformed
	}
	else_if = {
		limit = { religion = hellenic_pagan }
		religion = hellenic_pagan_oreformed
	}
	else_if = {
		limit = { religion = egyptian_pagan }
		religion = egyptian_pagan_oreformed
	}
	else_if = {
		limit = { religion = celtic_pagan }
		religion = celtic_pagan_reformed
	}
	else_if = {
		limit = { religion = german_pagan }
		religion = german_pagan_reformed
	}
}

select_regnal_name_effect = {
	if = {
		limit = { culture = norse }
		character_event = { id = Plus.3751 }
	}
	else_if = {
		limit = { culture = swedish }
		character_event = { id = Plus.3755 }
	}
	else_if = {
		limit = {
			culture = norwegian
			is_female = no
		}
		character_event = { id = Plus.3758 }
	}
	else_if = {
		limit = {
			culture = norwegian
			is_female = yes
		}
		character_event = { id = Plus.3760 }
	}
	else_if = {
		limit = {
			culture = danish
			is_female = no
		}
		character_event = { id = Plus.3761 }
	}
	else_if = {
		limit = {
			culture = danish
			is_female = yes
		}
		character_event = { id = Plus.3763 }
	}
	else_if = {
		limit = { culture = icelandic }
		character_event = { id = Plus.3764 }
	}
	else_if = {
		limit = { culture = english_norse }
		character_event = { id = Plus.3767 }
	}
	else_if = {
		limit = { german_cultures_trigger = yes }
		character_event = { id = Plus.3770 }
	}
	else_if = {
		limit = { culture = polish }
		character_event = { id = Plus.3774 }
	}
	else_if = {
		limit = {
			OR = {
				culture = scottish
				culture = scots
			}
		}
		character_event = { id = Plus.3777 }
	}
	else_if = {
		limit = { culture = english }
		character_event = { id = Plus.3780 }
	}
	else_if = {
		limit = { culture = anglo_saxon }
		character_event = { id = Plus.3783 }
	}
	else_if = {
		limit = { culture = bohemian }
		character_event = { id = Plus.3785 }
	}
	else_if = {
		limit = { culture = hungarian }
		character_event = { id = Plus.3788 }
	}
	else_if = {
		limit = { culture = croatian }
		character_event = { id = Plus.3791 }
	}
	else_if = {
		limit = { culture = serbian }
		character_event = { id = Plus.3794 }
	}
	else_if = {
		limit = { culture = bulgarian }
		character_event = { id = Plus.3797 }
	}
	else_if = {
		limit = { culture = vlach }
		character_event = { id = Plus.3800 }
	}
	else_if = {
		limit = { culture = french }
		character_event = { id = Plus.3801 }
	}
	else_if = {
		limit = {
			culture = basque
			is_female = no
		}
		character_event = { id = Plus.3804 }
	}
	else_if = {
		limit = {
			culture = basque
			is_female = yes
		}
		character_event = { id = Plus.3831 }
	}
	else_if = {
		limit = {
			culture = castilian
			is_female = no
		}
		character_event = { id = Plus.3805 }
	}
	else_if = {
		limit = {
			culture = castilian
			is_female = yes
		}
		character_event = { id = Plus.3806 }
	}
	else_if = {
		limit = { culture = catalan }
		character_event = { id = Plus.3807 }
	}
	else_if = {
		limit = { culture = frankish }
		character_event = { id = Plus.3809 }
	}
	else_if = {
		limit = {
			OR = {
				culture = greek
				culture = pontic_greek
			}
			is_female = no
		}
		character_event = { id = Plus.3811 }
	}
	else_if = {
		limit = {
			OR = {
				culture = greek
				culture = pontic_greek
			}
			is_female = yes
		}
		character_event = { id = Plus.3813 }
	}
	else_if = {
		limit = { culture = russian }
		character_event = { id = Plus.3814 }
	}
	else_if = {
		limit = { is_italian_trigger = yes }
		character_event = { id = Plus.3818 }
	}
	else_if = {
		limit = {
			culture = portuguese
			is_female = no
		}
		character_event = { id = Plus.3820 }
	}
	else_if = {
		limit = {
			culture = portuguese
			is_female = yes
		}
		character_event = { id = Plus.3822 }
	}
	else_if = {
		limit = { culture = armenian }
		character_event = { id = Plus.3823 }
	}
	else_if = {
		limit = {
			culture = georgian
			is_female = no
		}
		character_event = { id = Plus.3826 }
	}
	else_if = {
		limit = {
			culture = georgian
			is_female = yes
		}
		character_event = { id = Plus.3828 }
	}
	else_if = {
		limit = { culture = lithuanian }
		character_event = { id = Plus.3829 }
	}
	else_if = {
		limit = { culture = welsh }
		character_event = { id = Plus.3832 }
	}
	else_if = {
		limit = { culture = cornish }
		character_event = { id = Plus.3834 }
	}
	else_if = {
		limit = { culture = breton }
		character_event = { id = Plus.3835 }
	}
	else_if = {
		limit = { culture = norman }
		character_event = { id = Plus.3836}
	}
	else_if = {
		limit = {
			culture = persian
			is_female = no
		}
		character_event = { id = Plus.3837}
	}
}

# Roll a random congenital trait. If it succeeds repeat until it fails
generate_potential_congenital_trait = {
	random_list = {
		95 = {}

		5 = {
			random_list = {
				 5 = { add_trait = genius }
				15 = { add_trait = quick }
				15 = { add_trait = slow }
				 5 = { add_trait = imbecile }
				10 = { add_trait = attractive }
				10 = { add_trait = ugly }
				15 = { add_trait = tall }
				 5 = { add_trait = dwarf }
				10 = { add_trait = strong }
				10 = { add_trait = weak }
			}

			generate_potential_congenital_trait = yes
		}
	}
}

out_homosexual_effect = {
	if = {
		limit = {
			trait = homosexual

			NOR = {
				has_character_modifier = known_lesbian
				has_character_modifier = known_lesbian_pagan
				has_character_modifier = known_sodomite
				has_character_modifier = known_sodomite_pagan
			}
		}

		if = {
			limit = { is_female = yes }

			if = {
				limit = { religion_group = pagan_group }

				add_character_modifier = {
					name = known_lesbian_pagan
					duration = -1
				}
			}
			else = {
				add_character_modifier = {
					name = known_lesbian
					duration = -1
				}
			}
		}
		else = {
			if = {
				limit = { religion_group = pagan_group }

				add_character_modifier = {
					name = known_sodomite_pagan
					duration = -1
				}
			}
			else = {
				add_character_modifier = {
					name = known_sodomite
					duration = -1
				}
			}
		}
	}
}

# Convert to ROOT's religion and a culture based on FROM's origin
israel_culture_religion_effect = {
	religion = ROOT

	if = { # Culture depends on Origin
		limit = { # Ashkenazi
			FROM = {
				location = {
					OR = {
						region = world_europe_west_germania
						region = world_europe_east
						region = world_europe_west_british_isles
						region = world_europe_south_east
					}
				}
			}
		}
		culture = ashkenazi
	}
	else_if = { # Sephardi
		limit = {
			FROM = {
				location = {
					OR = {
						region = world_europe_west_iberia
						region = world_africa_north
						region = world_europe_west_gaul
						region = custom_roman_italia
						region = world_africa_west
						region = world_africa_central
					}
				}
			}
		}
		culture = sephardi
	}
	else = { # Mizrahim
		culture = mizrahim
	}
}

israel_culture_effect = { # ROOT's religion to a culture based on THIS region
	if = { # Culture depends on Origin
		limit = { # Ashkenazi
			OR = {
				region = world_europe_west_germania
				region = world_europe_east
				region = world_europe_west_british_isles
				region = world_europe_south_east
			}
		}
		ROOT = { culture = ashkenazi }
	}
	else_if = { # Sephardi
		limit = {
			OR = {
				region = world_europe_west_iberia
				region = world_africa_north
				region = world_europe_west_gaul
				region = custom_roman_italia
				region = world_africa_west
				region = world_africa_central
			}
		}
		ROOT = { culture = sephardi }
	}
	else = { # Mizrahim
		ROOT = { culture = mizrahim }
	}
}

remove_do_not_disturb_effect = {
	hidden_effect = {
		remove_character_modifier = do_not_disturb
		clr_character_flag = do_not_disturb
	}
}

make_court_educator_effect = {
	if = {
		limit = { has_dlc = "Conclave"}
		give_minor_title = title_teacher
	}
	else = {
		give_minor_title = title_court_educator
	}
}

remove_court_educator_effect = {
	if = {
		limit = { has_dlc = "Conclave"}
		remove_title = title_teacher
	}
	else = {
		remove_title = title_court_educator
	}
}

# Used in feast planner's scope (THIS)
clear_jd_feast_flags_effect = {
	clr_character_flag = jd_feast_salmon
	clr_character_flag = jd_feast_cheese_eggs
	clr_character_flag = jd_feast_roasted_milk
	clr_character_flag = jd_feast_balls
	clr_character_flag = jd_feast_poultry
	clr_character_flag = jd_feast_cattle
	clr_character_flag = jd_feast_pig
	clr_character_flag = jd_feast_horse
	clr_character_flag = jd_feast_good
	clr_character_flag = jd_feast_neutral
	clr_character_flag = jd_feast_bad
}

destroy_tradeposts_effect = { # Destroys all de Jure vassal tradeposts. Used in devastating wars
	any_de_jure_vassal_title = {
		limit = { real_tier = COUNT }

		location = {
			FROM = {
				destroy_tradepost = PREV
			}
		}
	}
}

copy_prev_gender_law_effect = {
	set_title_flag = non_manual_law_change # No prestige loss

	if = {
		limit = { has_gender_equal_game_rule_trigger = yes }
		add_law = true_cognatic_succession
	}
	else_if = {
		limit = { PREV = { has_law = cognatic_succession } }
		add_law = cognatic_succession
	}
	else_if = {
		limit = { PREV = { has_law = true_cognatic_succession } }
		add_law = true_cognatic_succession
	}
	else_if = {
		limit = { PREV = { has_law = agnatic_succession } }
		add_law = agnatic_succession
	}
	else_if = {
		limit = { PREV = { has_law = enatic_succession } }
		add_law = enatic_succession
	}
	else_if = {
		limit = { PREV = { has_law = enatic_cognatic_succession } }
		add_law = enatic_cognatic_succession
	}

	clr_title_flag = non_manual_law_change # No prestige loss
}

debutante_cleanup_effect = {
	if = {
		limit = {
			had_character_flag = {
				flag = debutante
				years >= 3
			}
		}
		clr_character_flag = debutante
	}
}

dead_ruler_claim_effect = {
	if = {
		limit = {
			FROMFROM = {
				has_claim = ROOT_FROM
				is_alive = no
			}
		}

		FROM = {
			remove_claim = FROMFROM
		}
	}
}

religion_head_loses_claims_effect = {
	if = {
		limit = {
			FROM = {
				controls_religion = yes
				is_primary_holder_title = yes
			}

			is_theocracy = yes
			num_of_claims >= 1
		}

		any_claim = { remove_claim = ROOT }
	}
}

remove_austerity_modifier_effect = {
	if = {
		limit = {
			ai = no
			has_character_modifier = ai_austerity
		}

		remove_character_modifier = ai_austerity
	}
}

restore_title_secular_name_effect = {
	if = {
		limit = {
			FROMFROM = { is_offmap_trigger = no }
			is_theocracy = no

			FROM = {
				OR = {
					title = k_papacy
					title = d_apostolic
					title = d_egyptian_pagan_reformed
					title = d_fraticelli
					title = d_iconoclast
					title = d_messalian
					title = d_miaphysite
					title = d_monophysite
					title = d_monothelite
					title = d_nestorian
					title = d_paulician
					title = k_orthodox
				}
			}
		}

		set_name = ""
	}
}

ascetic_cleanup_effect = {
	trigger_switch = {
		on_trigger = trait
		desert_father = {
			clr_character_flag = title_desert_father
			remove_special_character_title = DESERT_FATHER_TITLE
			remove_trait = desert_father
		}
		desert_mother = {
			clr_character_flag = title_desert_mother
			remove_special_character_title = DESERT_MOTHER_TITLE
			remove_trait = desert_mother
		}
		monk = {
			clr_character_flag = title_monk
			remove_special_character_title = MONK_BROTHER
			remove_trait = monk
		}
		nun = {
			clr_character_flag = title_nun
			remove_special_character_title = NUN_SISTER
			remove_trait = nun
		}
		perfecti = {
			remove_trait = perfecti
		}
	}
}

reset_name_effect = {
	set_name = ""
	adjective = ""
}

set_byzantium_name = {
	e_byzantium = {
		if = {
			limit = { holder_scope = { culture = roman } }

			set_name = EARLY_ERE
			adjective = EARLY_ERE_ADJ
		}
		else_if = {
			limit = {
				OR = {
					has_global_flag = hre_formed
					has_global_flag = carolingian_empire_formed
				}
			}

			reset_name_effect = yes
		}
	}
}

set_english_coas = {
	k_england = {
		if = {
			limit = { holder_scope = { dynasty = 106 } } # Plantagenet

			set_coa = k_plantagenet
			d_kent = { set_coa = d_kent_norman }
			d_cornwall = { set_coa = d_cornwall_norman }
			d_hwicce = { set_coa = d_hwicce_norman }
			d_mercia = { set_coa = d_mercia_norman }
			d_lancaster = { set_coa = d_lancaster_norman }
			d_east_anglia = { set_coa = d_east_anglia_norman }
			# d_oxford = { set_coa = d_oxford_norman }
			d_wessex = { set_coa = d_wessex_norman }
			d_york = { set_coa = d_york_norman }
		}
		else_if = {
			limit = { has_global_flag = england_is_saxon }

			set_coa = k_england_saxon
			d_kent = { set_coa = d_kent_saxon }
			d_cornwall = { set_coa = d_cornwall_saxon }
			d_hwicce = { set_coa = d_hwicce_saxon }
			d_mercia = { set_coa = d_mercia_saxon }
			d_lancaster = { set_coa = d_lancaster_saxon }
			d_east_anglia = { set_coa = d_east_anglia_saxon }
			# d_oxford = { set_coa = d_oxford_saxon }
			d_wessex = { set_coa = d_wessex_saxon }
			d_york = { set_coa = d_york_saxon }
		}
		else_if = {
			limit = { has_global_flag = england_is_norman }

			set_coa = k_england_norman
			d_kent = { set_coa = d_kent_norman }
			d_cornwall = { set_coa = d_cornwall_norman }
			d_hwicce = { set_coa = d_hwicce_norman }
			d_mercia = { set_coa = d_mercia_norman }
			d_lancaster = { set_coa = d_lancaster_norman }
			d_east_anglia = { set_coa = d_east_anglia_norman }
			# d_oxford = { set_coa = d_oxford_norman }
			d_wessex = { set_coa = d_wessex_norman }
			d_york = { set_coa = d_york_norman }
		}
		else_if = {
			limit = { has_global_flag = england_is_norwegian }

			set_coa = k_englandnorwegian
			d_kent = { set_coa = d_kent_saxon }
			d_cornwall = { set_coa = d_cornwall_saxon }
			d_hwicce = { set_coa = d_hwicce_saxon }
			d_mercia = { set_coa = d_mercia_saxon }
			d_lancaster = { set_coa = d_lancaster_saxon }
			d_east_anglia = { set_coa = d_east_anglia_saxon }
			# d_oxford = { set_coa = d_oxford_saxon }
			d_wessex = { set_coa = d_wessex_saxon }
			d_york = { set_coa = d_york_saxon }
		}
		else = { # Failsafe
			reset_coa = k_england
			reset_coa = d_kent
			reset_coa = d_cornwall
			reset_coa = d_hwicce
			reset_coa = d_mercia
			reset_coa = d_lancaster
			reset_coa = d_east_anglia
			# reset_coa = d_oxford
			reset_coa = d_wessex
			reset_coa = d_york
		}
	}
}

set_carpathia_coas = {
	k_carpathia = {
		if = {
			limit = { has_global_flag = carpathia_is_avaria }
			set_coa = k_avaria
		}
		else = {
			reset_coa = THIS # Failsafe
		}
	}
}

set_finland_coas = {
	d_finland = {
		if = {
			limit = { has_global_flag = finland_is_satakunta }
			set_coa = d_satakunta
		}
		else = {
			reset_coa = THIS # Failsafe
		}
	}
}

set_historical_emperors = {
	# Apply Imperial government to all historical Roman/Byzantine Emperors
	# Doesn't work well based on title history and government potential
	# and `any_previous_holder` is not an effect scope
	# and `any_character` only target living characters
	c_1000094084 = { set_government_type = imperial_government } # Olybrius
	c_1000094088 = { set_government_type = imperial_government } # Anthemius
	c_1000094514 = { set_government_type = imperial_government } # Petronius Maximus
	c_1000094525 = { set_government_type = imperial_government } # Avitus
	c_1000094526 = { set_government_type = imperial_government } # Majorianus
	c_1000094527 = { set_government_type = imperial_government } # Libius Severus
	c_1000094533 = { set_government_type = imperial_government } # Glycerius
	c_1000094534 = { set_government_type = imperial_government } # Julius Nepos
	c_1000094535 = { set_government_type = imperial_government } # Romulus Augustulus
	c_1000094557 = { set_government_type = imperial_government } # Nicolas
	c_125710 = { set_government_type = imperial_government } # Alexios V
	c_125741 = { set_government_type = imperial_government } # John III
	c_125742 = { set_government_type = imperial_government } # Theodore II
	c_125743 = { set_government_type = imperial_government } # John IV
	c_145068 = { set_government_type = imperial_government } # Philippikos
	c_145069 = { set_government_type = imperial_government } # Tiberius III
	c_145070 = { set_government_type = imperial_government } # Heraklonas
	c_145071 = { set_government_type = imperial_government } # Heraclius
	c_145072 = { set_government_type = imperial_government } # Phocas
	c_145073 = { set_government_type = imperial_government } # Tiberius II
	c_145075 = { set_government_type = imperial_government } # Tiberius
	c_145223 = { set_government_type = imperial_government } # Stephanos Lekapenos
	c_145225 = { set_government_type = imperial_government } # Artavasdos
	c_145226 = { set_government_type = imperial_government } # Zeno
	c_145227 = { set_government_type = imperial_government } # Honorius
	c_145228 = { set_government_type = imperial_government } # Constantius IV
	c_145229 = { set_government_type = imperial_government } # Valentinianus III
	c_145231 = { set_government_type = imperial_government } # Valentinianus I
	c_145232 = { set_government_type = imperial_government } # Valens
	c_145233 = { set_government_type = imperial_government } # Gratian
	c_145234 = { set_government_type = imperial_government } # Valentinianus II
	c_145235 = { set_government_type = imperial_government } # Jovianus
	c_145237 = { set_government_type = imperial_government } # Julianus
	c_145239 = { set_government_type = imperial_government } # Maximinus
	c_145240 = { set_government_type = imperial_government } # Severus
	c_145241 = { set_government_type = imperial_government } # Diocletianus
	c_145242 = { set_government_type = imperial_government } # Carus
	c_145243 = { set_government_type = imperial_government } # Numerianus
	c_145244 = { set_government_type = imperial_government } # Carinus
	c_145245 = { set_government_type = imperial_government } # Probus
	c_145247 = { set_government_type = imperial_government } # Tacitus
	c_145248 = { set_government_type = imperial_government } # Florianus
	c_145249 = { set_government_type = imperial_government } # Severina
	c_145250 = { set_government_type = imperial_government } # Aurelianus
	c_145252 = { set_government_type = imperial_government } # Claudius Gothicus
	c_145253 = { set_government_type = imperial_government } # Quintillus
	c_145254 = { set_government_type = imperial_government } # Valerianus
	c_145255 = { set_government_type = imperial_government } # Gallienus
	c_145256 = { set_government_type = imperial_government } # Aemilianus
	c_145257 = { set_government_type = imperial_government } # Trebonianus Gallus
	c_145258 = { set_government_type = imperial_government } # Decius
	c_145259 = { set_government_type = imperial_government } # Gordianus
	c_145260 = { set_government_type = imperial_government } # Gordianus II
	c_145262 = { set_government_type = imperial_government } # Gordianus III
	c_145263 = { set_government_type = imperial_government } # Balbinus
	c_145264 = { set_government_type = imperial_government } # Pupienus
	c_145265 = { set_government_type = imperial_government } # Maximinus
	c_145266 = { set_government_type = imperial_government } # Severus Alexander
	c_145267 = { set_government_type = imperial_government } # Heliogabalus
	c_145268 = { set_government_type = imperial_government } # Macrinus
	c_145269 = { set_government_type = imperial_government } # Septimius Severus
	c_145270 = { set_government_type = imperial_government } # Caracalla
	c_145271 = { set_government_type = imperial_government } # Geta
	c_145272 = { set_government_type = imperial_government } # Didius Julianus
	c_145273 = { set_government_type = imperial_government } # Pertinax
	c_145274 = { set_government_type = imperial_government } # Marcus Aurelius
	c_145275 = { set_government_type = imperial_government } # Commodus
	c_145276 = { set_government_type = imperial_government } # Lucius Verus
	c_145277 = { set_government_type = imperial_government } # Antoninus Pius
	c_145278 = { set_government_type = imperial_government } # Hadrianus
	c_145279 = { set_government_type = imperial_government } # Trajanus
	c_145280 = { set_government_type = imperial_government } # Nerva
	c_145281 = { set_government_type = imperial_government } # Vespasianus
	c_145282 = { set_government_type = imperial_government } # Titus
	c_145283 = { set_government_type = imperial_government } # Domitianus
	c_145284 = { set_government_type = imperial_government } # Vitellius
	c_145285 = { set_government_type = imperial_government } # Otho
	c_145286 = { set_government_type = imperial_government } # Galba
	c_145287 = { set_government_type = imperial_government } # Nero
	c_145288 = { set_government_type = imperial_government } # Claudius
	c_145289 = { set_government_type = imperial_government } # Caligula
	c_145290 = { set_government_type = imperial_government } # Augustus
	c_145293 = { set_government_type = imperial_government } # Maximianus
	c_1700 = { set_government_type = imperial_government } # Basileios I
	c_1702 = { set_government_type = imperial_government } # Leo VI
	c_1704 = { set_government_type = imperial_government } # Alexander I
	c_1706 = { set_government_type = imperial_government } # Romanos I
	c_1708 = { set_government_type = imperial_government } # Constantine VII - first reign
	c_1710 = { set_government_type = imperial_government } # Romanos II
	c_1712 = { set_government_type = imperial_government } # Nikephoros II
	c_1714 = { set_government_type = imperial_government } # John I
	c_1716 = { set_government_type = imperial_government } # Basil II
	c_1717 = { set_government_type = imperial_government } # Zo� Porphyrogenita
	c_1718 = { set_government_type = imperial_government } # Constantine VIII
	c_1719 = { set_government_type = imperial_government } # Theodora Porphyrogenita
	c_1720 = { set_government_type = imperial_government } # Romanos III
	c_1722 = { set_government_type = imperial_government } # Michael IV
	c_1724 = { set_government_type = imperial_government } # Michael V
	c_1726 = { set_government_type = imperial_government } # Constantine IX
	c_1730 = { set_government_type = imperial_government } # Isaac I
	c_1732 = { set_government_type = imperial_government } # Constantine X
	c_1733 = { set_government_type = imperial_government } # Eudokia Makrembolites
	c_1734 = { set_government_type = imperial_government } # Romanos IV
	c_1736 = { set_government_type = imperial_government } # Michael VII
	c_1740 = { set_government_type = imperial_government } # Nikephoros III
	c_1742 = { set_government_type = imperial_government } # Alexios I
	c_215500 = { set_government_type = imperial_government } # Isaac II
	c_215503 = { set_government_type = imperial_government } # Alexios III
	c_215507 = { set_government_type = imperial_government } # Alexios IV
	c_215529 = { set_government_type = imperial_government } # Andronikos
	c_215530 = { set_government_type = imperial_government } # Manuel I
	c_215531 = { set_government_type = imperial_government } # Alexios I
	c_215674 = { set_government_type = imperial_government } # Theodore I
	c_223023 = { set_government_type = imperial_government } # John II
	c_465500 = { set_government_type = imperial_government } # Andronikos III
	c_465501 = { set_government_type = imperial_government } # Michel IX
	c_465521 = { set_government_type = imperial_government } # Andronikos II
	c_465527 = { set_government_type = imperial_government } # Michael VIII
	c_70432 = { set_government_type = imperial_government } # Michael VI
	c_70490 = { set_government_type = imperial_government } # Michael III
	c_70491 = { set_government_type = imperial_government } # Theophilos
	c_70492 = { set_government_type = imperial_government } # Michel II
	c_70493 = { set_government_type = imperial_government } # Leo V
	c_70494 = { set_government_type = imperial_government } # Michael I
	c_70496 = { set_government_type = imperial_government } # Staurakios
	c_70497 = { set_government_type = imperial_government } # Nikephoros I
	c_70498 = { set_government_type = imperial_government } # Irene
	c_70499 = { set_government_type = imperial_government } # Constantine VI
	c_70500 = { set_government_type = imperial_government } # Leo IV
	c_70501 = { set_government_type = imperial_government } # Constantine V
	c_70502 = { set_government_type = imperial_government } # Leo III
	c_70504 = { set_government_type = imperial_government } # Anastasios II
	c_70505 = { set_government_type = imperial_government } # Lentios
	c_70506 = { set_government_type = imperial_government } # Justinian II
	c_70507 = { set_government_type = imperial_government } # Constantine IV
	c_70508 = { set_government_type = imperial_government } # Constans II
	c_70509 = { set_government_type = imperial_government } # Constantine III
	c_70510 = { set_government_type = imperial_government } # Maurice
	c_70511 = { set_government_type = imperial_government } # Justin II
	c_70512 = { set_government_type = imperial_government } # Justinian I
	c_70513 = { set_government_type = imperial_government } # Justin I
	c_70514 = { set_government_type = imperial_government } # Anastasios I
	c_70515 = { set_government_type = imperial_government } # Basiliscus
	c_70516 = { set_government_type = imperial_government } # Leo II
	c_70517 = { set_government_type = imperial_government } # Leo I
	c_70518 = { set_government_type = imperial_government } # Marcian
	c_70519 = { set_government_type = imperial_government } # Arcadius
	c_70520 = { set_government_type = imperial_government } # Constantinus II
	c_70521 = { set_government_type = imperial_government } # Constantius II
	c_70522 = { set_government_type = imperial_government } # Constans I
	c_70523 = { set_government_type = imperial_government } # Constantinus I
	c_70524 = { set_government_type = imperial_government } # Constantius I
	c_70526 = { set_government_type = imperial_government } # Philip I
	c_70532 = { set_government_type = imperial_government } # Theodosios III
	c_70533 = { set_government_type = imperial_government } # Theodosius II
	c_70534 = { set_government_type = imperial_government } # Theodosius
}

remove_irrelevant_claims = {
	any_character = {
		any_claim = {
			limit = {
				has_holder = no
				controls_religion = no
			}

			log = "Unheld title: Removed [Prev.GetBestName]'s ([Prev.GetID]) claim on the [This.GetFullBaseName] ([This.GetID])"
			remove_claim = PREV
		}

		if = {
			limit = {
				is_female = yes
				is_ruler = no
			}

			any_claim = {
				limit = {
					succ_law_title = { has_law = agnatic_succession }

					OR = {
						is_tribal = yes
						is_nomadic = yes
					}
				}

				log = "Agnatic title: Removed [Prev.GetBestName]'s ([Prev.GetID]) claim on the [This.GetFullBaseName] ([This.GetID])"
				remove_claim = PREV
			}
		}

		add_cousin_opinion_effect = yes
		bloodlust_control_effect = yes
		indian_caste_fix_effect = yes
	}
}

crown_distribution = {
	any_independent_ruler = {
		limit = {
			is_feudal = yes
			has_horde_culture = no
			is_offmap_trigger = no
			higher_real_tier_than = DUKE

			NOR = { # grouped for ease of reading
				is_crowned_trigger = yes
				trait = uncrowned
			}
		}

		if = {
			limit = { is_adult = yes }

			trigger_switch = {
				on_trigger = has_landed_title
				e_byzantium = {
					# TODO: This needs more nuance
					random_list = {
						50 = {
							mult_modifier = {
								factor = 2
								ruled_years >= 10
							}
							add_trait = strong_basileus
						}
						50 = {
							add_trait = weak_basileus
						}
					}
				}
				e_hre = {
					if = {
						limit = { trait = excommunicated }
						add_trait = uncrowned
					}
					else = {
						add_trait = crowned_by_pope
					}
				}
				fallback = { add_trait = crowned }
			}
		}
		else = {
			add_trait = uncrowned
		}
	}
}

imperial_decadence_setup = {
	# NOTE: Needs reworked
	any_independent_ruler = {
		limit = {
			real_tier = EMPEROR
			is_offmap_trigger = no
			is_nomadic = no
			uses_decadence = no
		}

		character_event = { id = Plus.1852 days = 1 }
	}
}