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

# used in ruler's scope (THIS)
council_decreased_power_effect = {
	any_vassal = {
		limit = {
			is_voter = yes
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_decreased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_decreased_council_power multiplier = 2 years = 5 }
	}
	any_courtier = {
		limit = {
			is_ruler = no
			is_voter = yes
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_decreased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_decreased_council_power multiplier = 2 years = 5 }
	}
	any_vassal = {
		limit = {
			is_voter = no
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_decreased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_decreased_council_power years = 5 }
	}
	any_courtier = {
		limit = {
			is_adult = yes
			prisoner = no
			is_ruler = no
			is_voter = no
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_decreased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_decreased_council_power years = 5 }
	}
}

# used in ruler's scope (THIS)
council_increased_power_effect = {
	any_vassal = {
		limit = {
			is_voter = yes
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_increased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_increased_council_power multiplier = 2 years = 5 }
	}
	any_courtier = {
		limit = {
			is_ruler = no
			is_voter = yes
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_increased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_increased_council_power multiplier = 2 years = 5 }
	}
	any_vassal = {
		limit = {
			is_voter = no
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_increased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_increased_council_power years = 5 }
	}
	any_courtier = {
		limit = {
			is_adult = yes
			prisoner = no
			is_ruler = no
			is_voter = no
			NOT = { has_opinion_modifier = { who = PREV modifier = opinion_increased_council_power } }
		}
		opinion = { who = PREV modifier = opinion_increased_council_power years = 5 }
	}
}

# used in title scope (THIS)
current_inheritance_laws_effect = {
	log = "INFO: law changing for the [This.GetFullName] ([This.GetID]):"
	if = {
		limit = { has_law = succ_gavelkind }
		log = "---> current succession law for [This.GetID]: Gavelkind"
	}
	else_if = {
		limit = { has_law = succ_elective_gavelkind }
		log = "---> current succession law for [This.GetID]: Elective Gavelkind"
	}
	else_if = {
		limit = { has_law = succ_seniority }
		log = "---> current succession law for [This.GetID]: Seniority"
	}
	else_if = {
		limit = { has_law = succ_primogeniture }
		log = "---> current succession law for [This.GetID]: Primogeniture"
	}
	else_if = {
		limit = { has_law = succ_feudal_elective }
		log = "---> current succession law for [This.GetID]: Feudal Elective"
	}
	else_if = {
		limit = { has_law = succ_hre_elective }
		log = "---> current succession law for [This.GetID]: Princely Elective"
	}
	else_if = {
		limit = { has_law = succ_byzantine_elective }
		log = "---> current succession law for [This.GetID]: Imperial Elective"
	}
	else_if = {
		limit = { has_law = succ_tanistry }
		log = "---> current succession law for [This.GetID]: Tanistry"
	}
	else_if = {
		limit = { has_law = succ_eldership }
		log = "---> current succession law for [This.GetID]: Eldership"
	}
	else_if = {
		limit = { has_law = succ_ultimogeniture }
		log = "---> current succession law for [This.GetID]: Ultimogeniture"
	}
	else_if = {
		limit = { has_law = succ_turkish_succession }
		log = "---> current succession law for [This.GetID]: Turkish Succession"
	}
	else_if = {
		limit = { has_law = succ_papal_succession }
		log = "---> current succession law for [This.GetID]: Papal Succession"
	}
	else_if = {
		limit = { has_law = succ_appointment }
		log = "---> current succession law for [This.GetID]: Appointment"
	}
	else_if = {
		limit = { has_law = succ_open_elective }
		log = "---> current succession law for [This.GetID]: Open Elective"
	}
	else_if = {
		limit = { has_law = succ_catholic_bishopric }
		log = "---> current succession law for [This.GetID]: Bishopric"
	}
	else_if = {
		limit = { has_law = succ_patrician_elective }
		log = "---> current succession law for [This.GetID]: Patrician Elective"
	}
	else_if = {
		limit = { has_law = succ_nomad_succession }
		log = "---> current succession law for [This.GetID]: Nomadic"
	}
	else = {
		log = "---> current succession law for [This.GetID]: (None)"
	}
	if = {
		limit = { has_law = cognatic_succession }
		log = "---> current gender law for [This.GetID]: Agnatic-Cognatic"
	}
	else_if = {
		limit = { has_law = true_cognatic_succession }
		log = "---> current gender law for [This.GetID]: True Cognatic"
	}
	else_if = {
		limit = { has_law = agnatic_succession }
		log = "---> current gender law for [This.GetID]: Agnatic"
	}
	else_if = {
		limit = { has_law = enatic_succession }
		log = "---> current gender law for [This.GetID]: Enatic"
	}
	else_if = {
		limit = { has_law = enatic_cognatic_succession }
		log = "---> current gender law for [This.GetID]: Enatic-Cognatic"
	}
}

dishonorable_plus_1_effect = {
	if = {
		limit = {
			trait = dishonorable9
		}
		remove_trait = dishonorable9
		add_trait = dishonorable10
	}
	else_if = {
		limit = {
			trait = dishonorable8
		}
		remove_trait = dishonorable8
		add_trait = dishonorable9
	}
	else_if = {
		limit = {
			trait = dishonorable7
		}
		remove_trait = dishonorable7
		add_trait = dishonorable8
	}
	else_if = {
		limit = {
			trait = dishonorable6
		}
		remove_trait = dishonorable6
		add_trait = dishonorable7
	}
	else_if = {
		limit = {
			trait = dishonorable5
		}
		remove_trait = dishonorable5
		add_trait = dishonorable6
	}
	else_if = {
		limit = {
			trait = dishonorable4
		}
		remove_trait = dishonorable4
		add_trait = dishonorable5
	}
	else_if = {
		limit = {
			trait = dishonorable3
		}
		remove_trait = dishonorable3
		add_trait = dishonorable4
	}
	else_if = {
		limit = {
			trait = dishonorable2
		}
		remove_trait = dishonorable2
		add_trait = dishonorable3
	}
	else_if = {
		limit = {
			trait = dishonorable1
		}
		remove_trait = dishonorable1
		add_trait = dishonorable2
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable9
		}
		remove_trait = dyn_dishonorable9
		add_trait = dishonorable10
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable8
		}
		remove_trait = dyn_dishonorable8
		add_trait = dishonorable9
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable7
		}
		remove_trait = dyn_dishonorable7
		add_trait = dishonorable8
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable6
		}
		remove_trait = dyn_dishonorable6
		add_trait = dishonorable7
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable5
		}
		remove_trait = dyn_dishonorable5
		add_trait = dishonorable6
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable4
		}
		remove_trait = dyn_dishonorable4
		add_trait = dishonorable5
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable3
		}
		remove_trait = dyn_dishonorable3
		add_trait = dishonorable4
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable2
		}
		remove_trait = dyn_dishonorable2
		add_trait = dishonorable3
	}
	else_if = {
		limit = {
			trait = dyn_dishonorable1
		}
		remove_trait = dyn_dishonorable1
		add_trait = dishonorable2
	}
	else = {
		add_trait = dishonorable1
	}
}

empty_province_effect = {
	hidden_tooltip = {
		if = {
			limit = {
				tier = COUNT
				location = {
					NOT = {
						any_province_holding = { NOT = { holding_type = nomad } }
					}
					OR = {
						NOT = { culture = ROOT }
						NOT = { religion = ROOT }
					}
					has_empty_holding = yes
				}
			}
			location = {
				build_holding = { type = tribal }
				random_province_holding = {
					limit = {
						holding_type = tribal
						ROOT = { is_nomadic = no }
					}
					make_capital_holding = yes
				}
			}
		}
		if = {
			limit = { higher_tier_than = COUNT }
			any_de_jure_vassal_title = {
				limit = {
					tier = COUNT
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
					location = {
						NOT = {
							any_province_holding = { NOT = { holding_type = nomad } }
						}
						OR = {
							NOT = { culture = ROOT }
							NOT = { religion = ROOT }
						}
						has_empty_holding = yes
					}
				}
				location = {
					build_holding = { type = tribal }
					random_province_holding = {
						limit = {
							holding_type = tribal
							ROOT = { is_nomadic = no }
						}
						make_capital_holding = yes
					}
				}
			}
		}
	}
}

escape_siege_effect = {
	random_list = {
		9 = {
			modifier = {
				factor = 1.5
				trait = genius
			}
			modifier = {
				factor = 1.25
				OR = {
					trait = quick
					trait = shrewd
				}
			}
			modifier = {
				factor = 0.75
				trait = brave
			}
			modifier = {
				factor = 1.25
				trait = craven
			}
			modifier = {
				factor = 0.75
				trait = wounded
			}
			modifier = {
				factor = 0.5
				trait = infirm
			}
			modifier = {
				factor = 0.5
				trait = maimed
			}
			modifier = {
				factor = 0.9
				is_adult = yes
				NOT = { trait = incapable }
				NOT = { intrigue = 2 }
			}
			modifier = {
				factor = 0.9
				is_adult = yes
				NOT = { trait = incapable }
				NOT = { intrigue = 4 }
			}
			modifier = {
				factor = 0.9
				is_adult = yes
				NOT = { trait = incapable }
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 0.9
				is_adult = yes
				NOT = { trait = incapable }
				NOT = { intrigue = 8 }
			}
			modifier = {
				factor = 1.1
				is_adult = yes
				NOT = { trait = incapable }
				intrigue = 10
			}
			modifier = {
				factor = 1.1
				is_adult = yes
				NOT = { trait = incapable }
				intrigue = 12
			}
			modifier = {
				factor = 1.1
				is_adult = yes
				NOT = { trait = incapable }
				intrigue = 14
			}
			modifier = {
				factor = 1.1
				is_adult = yes
				NOT = { trait = incapable }
				intrigue = 16
			}
			modifier = {
				factor = 1.1
				is_adult = yes
				NOT = { trait = incapable }
				intrigue = 18
			}
			modifier = {
				factor = 0.8
				has_character_flag = in_danger
			}
			custom_tooltip = {
				text = EVTTOOLTIPsiegehide
				hidden_tooltip = {
					add_trait = in_hiding
					set_character_flag = in_hiding_siege
				}
			}
		}
		1 = {
			modifier = {
				factor = 2.5
				has_character_flag = in_danger
			}
			custom_tooltip = {
				text = EVTTOOLTIPsiegeremain
				hidden_tooltip = {
					set_character_flag = has_siege_effect
					add_character_modifier = {
						name = left_at_siege
						duration = 180
					}
				}
			}
		}
	}
}

heresy_character_effect = {
	# Prefer a neighboring heresy
	location = {
		random_neighbor_province = {
			limit = {
				is_land = yes
				is_heresy_of = ROOT
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# Prefer a neighboring member of the same religion group
	location = {
		random_neighbor_province = {
			limit = {
				is_land = yes
				is_heretic = no
				religion_group = ROOT
				NOT = { religion = ROOT }
				is_pagan_religion = no
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# Prefer an existing heresy in the realm
	top_liege = {
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# Or one not far away
	random_independent_ruler = {
		limit = {
			any_realm_province = {
				is_heresy_of = ROOT
				ROOT = {
					location = {
						NOT = { distance = { where = PREVPREV value = 300 } }
					}
				}
			}
		}
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
				ROOT = {
					location = {
						NOT = { distance = { where = PREVPREV value = 300 } }
					}
				}
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# ...otherwise, just pick a heresy
	if = {
		limit = { religion_group = christian }
		if = {
			limit = {
				religion = chalcedonian
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_aquitaine }
							location = { region = custom_burgundy }
							culture = occitan
						}
					}
					modifier = {
						factor = 1.5
						culture = occitan
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_france }
							culture = frankish
						}
					}
					modifier = {
						factor = 1.5
						culture = frankish
					}
					religion = waldensian
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_brittania } }
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_iberia } }
					}
					modifier = {
						factor = 1.5
						culture_group = iberian
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_bulgaria }
							location = { region = custom_croatia }
							location = { region = custom_serbia }
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}
					religion = bogomilist
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = world_middle_east }
							location = { region = custom_azerbaijan }
							location = { region = custom_persia }
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = custom_byzantium } }
					}
					modifier = {
						factor = 1.5
						OR = {
							culture = greek
							culture = pontic_greek
						}
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
							culture = armenian
						}
					}
					religion = paulician
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				10 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = catholic
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_south_italy }
							is_italian_trigger = yes
						}
					}
					religion = fraticelli
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_aquitaine }
							location = { region = custom_burgundy }
							culture = occitan
						}
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe_west_brittania } }
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = custom_england }
							culture = english
						}
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_france }
							culture = frankish
						}
					}
					religion = waldensian
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe_west_iberia } }
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_south_east }
							location = { region = world_europe_east }
							location = { region = world_asia_minor }
							location = { region = world_middle_east_jerusalem }
						}
					}
					modifier = {
						factor = 0.35
						NOR = {
							location = { region = custom_byzantium }
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}
					religion = orthodox
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = orthodox
			}
			random_list = {
				50 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_bulgaria }
							location = { region = custom_croatia }
							location = { region = custom_serbia }
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}
					religion = bogomilist
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { location = { region = custom_byzantium } }
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
							culture = armenian
						}
					}
					religion = paulician
				}
				50 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = custom_azerbaijan }
							location = { region = custom_persia }
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_west }
							location = { region = world_europe_north }
							location = { region = world_europe_south_italy }
							location = { region = custom_croatia }
							location = { region = custom_poland }
							location = { region = custom_carpathia }
						}
					}
					religion = catholic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = nestorian
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_middle_east }
							location = { region = world_steppe }
							location = { region = world_persia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_africa }
							location = { region = world_middle_east }
						}
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOT = {
							location = { region = world_asia_minor }
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe } }
					}
					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					if = {
						limit = { NOT = { has_global_flag = schism_happened } }
						religion = chalcedonian
					}
				}
				50 = { become_heretic = yes }
			}
			break = yes
		}
		if = {
			limit = {
				religion = miaphysite
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOT = {
							location = { region = world_asia_minor }
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_middle_east }
							location = { region = world_steppe }
							location = { region = world_persia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_africa }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe }
							location = { region = world_middle_east }
						}
					}
					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					if = {
						limit = { NOT = { has_global_flag = schism_happened } }
						religion = chalcedonian
					}
				}
				25 = { religion = monophysite }
			}
			break = yes
		}
		become_heretic = yes
		break = yes
	}
	if = {
		limit = {
			religion_group = muslim
		}
		random_list = {
			40 = {
				modifier = {
					factor = 0
					religion = sunni
				}
				modifier = {
					factor = 0.25
					religion = shiite
				}
				religion = sunni
			}
			20 = {
				modifier = {
					factor = 0
					religion = yazidi
				}
				modifier = {
					factor = 0
					NOR = {
						culture = kurdish
						location = { region = custom_armenia }
						location = { region = custom_azerbaijan }
						location = { region = custom_mesopotamia }
						trait = sympathy_zoroastrianism
					}
				}
				modifier = {
					factor = 2
					culture = kurdish
				}
				modifier = {
					factor = 0.25
					NOT = { culture = kurdish }
					location = { region = custom_mesopotamia }
				}
				religion = yazidi
			}
			20 = {
				modifier = {
					factor = 0
					religion = ibadi
				}
				modifier = {
					factor = 0.5
					NOR = {
						location = { region = world_africa }
						location = { region = custom_arabia }
						culture = bedouin_arabic
					}
				}
				modifier = {
					factor = 2
					culture = bedouin_arabic
				}
				religion = ibadi
			}
			20 = {
				modifier = {
					factor = 0
					religion = kharijite
				}
				modifier = {
					factor = 0
					NOR = {
						religion = ibadi
						location = { region = world_middle_east_arabia }
					}
				}
				religion = kharijite
			}
			40 = {
				modifier = {
					factor = 0
					religion = shiite
				}
				modifier = {
					factor = 1.5
					religion = sunni
				}
				religion = shiite
			}
			20 = {
				modifier = {
					factor = 0
					religion = bektashi
				}
				modifier = {
					factor = 0
					NOT = { location = { region = world_europe_south_east } }
				}
				religion = bektashi
			}
			20 = {
				modifier = {
					factor = 0
					religion = druze
				}
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_middle_east_jerusalem }
						culture = levantine_arabic
					}
				}
				modifier = {
					factor = 0.25
					culture = levantine_arabic
					NOT = { location = { region = world_middle_east_jerusalem } }
				}
				religion = druze
			}
			20 = {
				modifier = {
					factor = 0
					religion = hurufi
				}
				religion = hurufi
			}
			10 = {
				modifier = {
					factor = 2
					location = { region = custom_persia }
				}
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_persia }
						location = { region = custom_mesopotamia }
						location = { region = custom_khwarizm }
						culture = persian
						trait = sympathy_zoroastrianism
					}
				}
				modifier = {
					factor = 2
					trait = sympathy_zoroastrianism
				}
				modifier = {
					factor = 0.5
					year = 1200
				}
				religion = zoroastrian
			}
			10 = {
				modifier = {
					factor = 2
					location = { region = world_steppe }
				}
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_india }
						location = { region = world_middle_east }
						location = { region = custom_azerbaijan }
						location = { region = world_persia }
						location = { region = world_steppe }
					}
				}
				modifier = {
					factor = 0.5
					year = 1100
				}
				modifier = {
					factor = 0.5
					year = 1200
				}
				religion = manichean
			}
			10 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = custom_jerusalem }
						trait = sympathy_judaism
					}
				}
				religion = jewish
			}
			10 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = custom_armenia }
					}
				}
				modifier = {
					factor = 3
					culture = armenian
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				religion = apostolic
			}
			10 = {
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_africa_north }
						location = { region = world_africa_east }
						culture = egyptian_arabic
					}
				}
				modifier = {
					factor = 2.5
					culture = egyptian_arabic
				}
				modifier = {
					factor = 0.5
					NOR = {
						location = { region = custom_egypt }
						location = { region = custom_abyssinia }
						location = { region = custom_nubia }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				religion = miaphysite
			}
			10 = {
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_europe_south_east }
						location = { region = world_europe_east }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				modifier = {
					factor = 2.5
					OR = {
						culture_group = byzantine
						culture_group = east_slavic
						culture_group = south_slavic
					}
				}
				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
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			10 = {
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_europe_west }
						location = { region = world_europe_north }
						location = { region = world_europe_south_italy }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			10 = {
				become_heretic = yes
			}
		}
		break = yes
	}
	if = {
		limit = {
			religion_group = jewish_group
		}
		random_list = {
			75 = {
				modifier = {
					factor = 0
					NOT = { culture_group = altaic }
				}
				modifier = {
					factor = 0
					religion = karaite
				}
				religion = karaite
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_europe_south_east }
						location = { region = world_europe_east }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				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
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						location = { region = world_europe_west }
						location = { region = world_europe_north }
						location = { region = world_europe_south_italy }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			25 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = world_asia_minor }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				religion = apostolic
			}
			25 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = world_africa }
					}
				}
				modifier = {
					factor = 1.5
					trait = sympathy_christendom
				}
				religion = miaphysite
			}
			50 = {
				modifier = {
					factor = 0.25
					culture_group = altaic
				}
				become_heretic = yes
			}
		}
		break = yes
	}
	if = {
		limit = {
			religion_group = zoroastrian_group
		}
		random_list = {
			50 = {
				modifier = {
					factor = 0
					religion = zoroastrian
				}
				modifier = {
					factor = 0.5
					religion = manichean
				}
				religion = zoroastrian
			}
			50 = {
				modifier = {
					factor = 0
					religion = manichean
				}
				modifier = {
					factor = 0.5
					religion = zoroastrian
				}
				religion = manichean
			}
			50 = {
				modifier = {
					factor = 0
					religion = yazidi
				}
				modifier = {
					factor = 0
					NOR = {
						culture = kurdish
						location = { region = custom_armenia }
						location = { region = custom_azerbaijan }
						location = { region = custom_mesopotamia }
					}
				}
				modifier = {
					factor = 2
					trait = sympathy_islam
				}
				modifier = {
					factor = 2
					culture = kurdish
				}
				religion = yazidi
			}
			50 = {
				modifier = {
					factor = 2
					trait = sympathy_islam
				}
				religion = shiite
			}
			50 = {
				modifier = {
					factor = 0
					NOT = { religion = manichean }
				}
				modifier = {
					factor = 2
					trait = sympathy_christendom
				}
				religion = nestorian
			}
			20 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = world_asia_minor }
					}
				}
				modifier = {
					factor = 2
					trait = sympathy_christendom
				}
				religion = apostolic
			}
			20 = {
				modifier = {
					factor = 0
					NOT = {
						location = { region = world_africa }
					}
				}
				modifier = {
					factor = 2
					trait = sympathy_christendom
				}
				religion = miaphysite
			}
			50 = {
				become_heretic = yes
			}
		}
		break = yes
	}
	become_heretic = yes
}

heresy_province_effect = {
	# Prefer a neighboring heresy
	random_neighbor_province = {
		limit = {
			is_land = yes
			is_heresy_of = ROOT
		}
		ROOT = { religion = PREV }
		break = yes
	}
	# Prefer a neighboring member of the same religion group
	random_neighbor_province = {
		limit = {
			is_land = yes
			is_heretic = no
			religion_group = ROOT
			NOT = { religion = ROOT }
			is_pagan_religion = no
		}
		ROOT = { religion = PREV }
		break = yes
	}
	# Prefer an existing heresy in the realm
	owner = {
		top_liege = {
			random_realm_province = {
				limit = {
					is_heresy_of = ROOT
					ROOT = { NOT = { has_province_flag = found_heresy } }
				}
				ROOT = { religion = PREV }
				break = yes
			}
		}
	}
	# Or one not far away
	random_independent_ruler = {
		limit = {
			any_realm_province = {
				is_heresy_of = ROOT
				NOT = { distance = { where = ROOT value = 300 } }
			}
		}
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
				NOT = { distance = { where = ROOT value = 300 } }
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# ...otherwise, just pick a heresy
	if = {
		limit = { religion_group = christian }
		if = {
			limit = {
				religion = chalcedonian
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}
					modifier = {
						factor = 1.5
						culture = occitan
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_france
							culture = frankish
						}
					}
					modifier = {
						factor = 1.5
						culture = frankish
					}
					religion = waldensian
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_brittania }
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_iberia }
					}
					modifier = {
						factor = 1.5
						culture_group = iberian
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						region = custom_bulgaria
					}
					religion = bogomilist
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = custom_byzantium }
					}
					modifier = {
						factor = 1.5
						OR = {
							culture = greek
							culture = pontic_greek
						}
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}
					religion = paulician
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.25
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				10 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = catholic
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_south_italy
							is_italian_trigger = yes
						}
					}
					religion = fraticelli
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe_west_brittania }
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = custom_england
							culture = english
						}
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_france
							culture = frankish
						}
					}
					religion = waldensian
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe_west_iberia }
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_south_east
							region = world_europe_east
							region = world_asia_minor
							region = world_middle_east_jerusalem
						}
					}
					modifier = {
						factor = 0.35
						NOR = {
							region = custom_byzantium
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}
					religion = orthodox
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = orthodox
			}
			random_list = {
				50 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						region = custom_bulgaria
					}
					religion = bogomilist
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { region = custom_byzantium }
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}
					religion = paulician
				}
				50 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							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 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = nestorian
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_middle_east
							region = world_steppe
							region = world_persia
						}
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_africa
							region = world_middle_east
						}
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOT = {
							region = world_asia_minor
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe }
					}
					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					if = {
						limit = { NOT = { has_global_flag = schism_happened } }
						religion = chalcedonian
					}
				}
				50 = { become_heretic = yes }
			}
			break = yes
		}
		if = {
			limit = {
				religion = miaphysite
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_middle_east
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_africa
							region = world_steppe
							region = world_middle_east
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOT = {
							region = world_asia_minor
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe
							region = world_middle_east
						}
					}
					if = {
						limit = { has_global_flag = schism_happened }
						religion = orthodox
					}
					if = {
						limit = { NOT = { has_global_flag = schism_happened } }
						religion = chalcedonian
					}
				}
				25 = { religion = monophysite }
			}
			break = yes
		}
		become_heretic = yes
		break = yes
	}
	if = {
		limit = {
			religion_group = muslim
		}
		random_list = {
			40 = {
				modifier = {
					factor = 0
					religion = sunni
				}
				modifier = {
					factor = 0.25
					religion = shiite
				}
				religion = sunni
			}
			20 = {
				modifier = {
					factor = 0
					religion = yazidi
				}
				modifier = {
					factor = 0
					NOR = {
						culture = kurdish
						region = custom_armenia
						region = custom_azerbaijan
						region = custom_mesopotamia
					}
				}
				modifier = {
					factor = 2
					culture = kurdish
				}
				modifier = {
					factor = 0.25
					NOT = { culture = kurdish }
					region = custom_mesopotamia
				}
				religion = yazidi
			}
			20 = {
				modifier = {
					factor = 0
					religion = ibadi
				}
				modifier = {
					factor = 0.5
					NOR = {
						region = world_africa
						region = custom_arabia
						culture = bedouin_arabic
					}
				}
				modifier = {
					factor = 2
					culture = bedouin_arabic
				}
				religion = ibadi
			}
			20 = {
				modifier = {
					factor = 0
					religion = kharijite
				}
				modifier = {
					factor = 0
					NOR = {
						religion = ibadi
						region = world_middle_east_arabia
					}
				}
				religion = kharijite
			}
			40 = {
				modifier = {
					factor = 0
					religion = shiite
				}
				modifier = {
					factor = 1.5
					religion = sunni
				}
				religion = shiite
			}
			20 = {
				modifier = {
					factor = 0
					religion = bektashi
				}
				modifier = {
					factor = 0
					NOT = { region = world_europe_south_east }
				}
				religion = bektashi
			}
			20 = {
				modifier = {
					factor = 0
					religion = druze
				}
				modifier = {
					factor = 0
					NOR = {
						region = world_middle_east_jerusalem
						culture = levantine_arabic
					}
				}
				modifier = {
					factor = 0.25
					culture = levantine_arabic
					NOT = { region = world_middle_east_jerusalem }
				}
				religion = druze
			}
			20 = {
				modifier = {
					factor = 0
					religion = hurufi
				}
				religion = hurufi
			}
			10 = {
				modifier = {
					factor = 2
					region = custom_persia
				}
				modifier = {
					factor = 0
					NOR = {
						region = world_persia
						region = custom_mesopotamia
						region = custom_khwarizm
						culture = persian
					}
				}
				modifier = {
					factor = 0.5
					year = 1200
				}
				religion = zoroastrian
			}
			10 = {
				modifier = {
					factor = 2
					region = world_steppe
				}
				modifier = {
					factor = 0
					NOR = {
						region = world_india
						region = world_middle_east
						region = custom_azerbaijan
						region = world_persia
						region = world_steppe
					}
				}
				modifier = {
					factor = 0.5
					year = 1100
				}
				modifier = {
					factor = 0.5
					year = 1200
				}
				religion = manichean
			}
			10 = {
				modifier = {
					factor = 0
					NOT = { region = custom_jerusalem }
				}
				religion = jewish
			}
			10 = {
				modifier = {
					factor = 0
					NOT = { region = world_africa }
				}
				religion = miaphysite
			}
			10 = {
				modifier = {
					factor = 0
					NOT = { region = world_asia_minor }
				}
				religion = apostolic
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						region = world_europe_south_east
						region = world_europe_east
					}
				}
				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
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						region = world_europe_west
						region = world_europe_north
						region = world_europe_south_italy
					}
				}
				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			10 = {
				become_heretic = yes
			}
		}
		break = yes
	}
	if = {
		limit = {
			religion_group = jewish_group
		}
		random_list = {
			75 = {
				modifier = {
					factor = 0
					NOT = { culture_group = altaic }
				}
				modifier = {
					factor = 0
					religion = karaite
				}
				religion = karaite
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						region = world_europe_south_east
						region = world_europe_east
					}
				}
				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
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			25 = {
				modifier = {
					factor = 0
					NOR = {
						region = world_europe_west
						region = world_europe_north
						region = world_europe_south_italy
					}
				}
				if = {
					limit = { has_global_flag = schism_happened }
					religion = catholic
				}
				if = {
					limit = { NOT = { has_global_flag = schism_happened } }
					religion = chalcedonian
				}
			}
			25 = {
				modifier = {
					factor = 0
					NOT = { region = world_africa }
				}
				religion = miaphysite
			}
			25 = {
				modifier = {
					factor = 0
					NOT = { region = world_asia_minor }
				}
				religion = apostolic
			}
			50 = {
				modifier = {
					factor = 0.25
					culture_group = altaic
				}
				become_heretic = yes
			}
		}
		break = yes
	}
	if = {
		limit = {
			religion_group = zoroastrian_group
		}
		random_list = {
			50 = {
				modifier = {
					factor = 0
					religion = zoroastrian
				}
				modifier = {
					factor = 0.5
					religion = manichean
				}
				religion = zoroastrian
			}
			50 = {
				modifier = {
					factor = 0
					religion = manichean
				}
				modifier = {
					factor = 0.5
					religion = zoroastrian
				}
				religion = manichean
			}
			50 = {
				modifier = {
					factor = 0
					religion = yazidi
				}
				modifier = {
					factor = 0
					NOR = {
						culture = kurdish
						region = custom_armenia
						region = custom_azerbaijan
						region = custom_mesopotamia
					}
				}
				modifier = {
					factor = 2
					culture = kurdish
				}
				religion = yazidi
			}
			50 = {
				modifier = {
					factor = 0
					NOR = {
						culture = kurdish
						region = custom_armenia
						region = custom_azerbaijan
						region = custom_mesopotamia
					}
				}
				modifier = {
					factor = 2
					culture = kurdish
				}
				modifier = {
					factor = 0.25
					NOT = { culture = kurdish }
					region = custom_mesopotamia
				}
				religion = yazidi
			}
			50 = {
				religion = shiite
			}
			50 = {
				modifier = {
					factor = 0
					NOT = { religion = manichean }
				}
				religion = nestorian
			}
			25 = {
				modifier = {
					factor = 0
					NOT = { region = world_africa }
				}
				religion = miaphysite
			}
			25 = {
				modifier = {
					factor = 0
					NOT = { region = world_asia_minor }
				}
				religion = apostolic
			}
			50 = {
				become_heretic = yes
			}
		}
		break = yes
	}
	become_heretic = yes
	break = yes
}

imperial_decadence_minus_1_effect = {
	if = {
		limit = { uses_imperial_decadence_trigger = yes }
		custom_tooltip = { text = IMPERIAL_DECADENCE_MINUS_1 }
		hidden_tooltip = {
			primary_title = { change_variable = { which = "imperial_decadence" value = -1 } }
			character_event = { id = Plus.1852 }
		}
	}
}

imperial_decadence_minus_2_effect = {
	if = {
		limit = { uses_imperial_decadence_trigger = yes }
		custom_tooltip = { text = IMPERIAL_DECADENCE_MINUS_2 }
		hidden_tooltip = {
			primary_title = { change_variable = { which = "imperial_decadence" value = -2 } }
			character_event = { id = Plus.1852 }
		}
	}
}

imperial_decadence_plus_1_effect = {
	if = {
		limit = { uses_imperial_decadence_trigger = yes }
		custom_tooltip = { text = IMPERIAL_DECADENCE_PLUS_1 }
		hidden_tooltip = {
			primary_title = { change_variable = { which = "imperial_decadence" value = 1 } }
			character_event = { id = Plus.1852 }
		}
	}
}

imperial_decadence_plus_2_effect = {
	if = {
		limit = { uses_imperial_decadence_trigger = yes }
		custom_tooltip = { text = IMPERIAL_DECADENCE_PLUS_2 }
		hidden_tooltip = {
			primary_title = { change_variable = { which = "imperial_decadence" value = 2 } }
			character_event = { id = Plus.1852 }
		}
	}
}

# 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
					NOT = {
						any_demesne_title = {
							tier = BARON
							holding_type = castle
						}
					}
				}
				AND = {
					is_tribal = yes
					NOT = {
						any_demesne_title = {
							tier = BARON
							holding_type = tribal
						}
					}
				}
				AND = {
					is_nomadic = yes
					NOT = {
						any_demesne_title = {
							tier = BARON
							holding_type = nomad
						}
					}
				}
			}
		}
		# first priority: feudal
		if = {
			limit = {
				any_demesne_title = {
					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_government
				break = yes
			}
			log = "----> [Root.GetBestName] has been set to feudal government (Liberation Revolt)"
			set_government_type = feudal_government
			break = yes
		}
		# second priority: nomadic
		if = {
			limit = {
				OR = {
					any_demesne_title = {
						tier = BARON
						holding_type = nomad
						location = { culture = ROOT }
					}
					any_demesne_province = {
						culture = ROOT
						NOT = { num_of_settlements = 1 }
					}
				}
			}
			log = "----> [Root.GetBestName] has been set to nomadic government (Liberation Revolt)"
			set_government_type = nomadic_government
			break = yes
		}
		# third priority: tribal
		if = {
			limit = {
				any_demesne_title = {
					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
						father_even_if_dead = { higher_real_tier_than = ROOT }
						mother_even_if_dead = { higher_real_tier_than = ROOT }
						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 }
						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 }
					}
				}
				AND = {
					ROOT = {
						is_ruler = no
						father_even_if_dead = {
							always = yes
							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 = {
							always = yes
							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
		break = yes
	}
	add_spouse = ROOT
	break = yes
}

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

remove_possessed_effect = {
	remove_trait = possessed
	hidden_tooltip = {
		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 = { move_character = ROOT }
	}
	if = {
		limit = { is_ruler = no }
		random_dynasty_member = {
			limit = { is_ruler = yes }
			FROM = { move_character = PREV }
		}
	}
}

save_viceroy_pick_effect = {
	if = {
		limit = {
			event_target:council_first_pick = { always = yes }
			event_target:council_second_pick = { always = yes }
			NOT = { event_target:council_third_pick = { always = yes } }
		}
		save_event_target_as = council_third_pick
	}
	if = {
		limit = {
			event_target:council_first_pick = { always = yes }
			NOT = { event_target:council_second_pick = { always = yes } }
		}
		save_event_target_as = council_second_pick
	}
	if = {
		limit = {
			NOT = { event_target:council_first_pick = { always = yes } }
		}
		save_event_target_as = council_first_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 = {
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = BARON
					father = { higher_tier_than = BARON }
					mother = { higher_tier_than = BARON }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = COUNT
					father = { higher_tier_than = COUNT }
					mother = { higher_tier_than = COUNT }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = DUKE
					father = { higher_tier_than = DUKE }
					mother = { higher_tier_than = DUKE }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = KING
					father = { higher_tier_than = KING }
					mother = { higher_tier_than = KING }
				}
			}
			modifier = {
				factor = 1.5
				is_adult = no
			}
			modifier = {
				factor = 0.5
				trait = infirm
			}
			modifier = {
				factor = 0.5
				trait = wounded
			}
			modifier = {
				factor = 0.25
				trait = maimed
			}
			modifier = {
				factor = 1.25
				intrigue = 12
			}
			modifier = {
				factor = 1.25
				intrigue = 13
			}
			modifier = {
				factor = 1.25
				intrigue = 14
			}
			modifier = {
				factor = 1.25
				intrigue = 15
			}
			modifier = {
				factor = 1.25
				intrigue = 16
			}
			modifier = {
				factor = 1.25
				intrigue = 17
			}
			modifier = {
				factor = 1.25
				intrigue = 18
			}
			modifier = {
				factor = 1.25
				intrigue = 19
			}
			modifier = {
				factor = 1.25
				intrigue = 20
			}
			modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}
			custom_tooltip = { text = "siege_escaped" }
		}
		20 = {
			modifier = {
				factor = 2
				trait = brave
			}
			modifier = {
				factor = 0.5
				trait = craven
			}
			custom_tooltip = {
				text = "siege_injured"
				hidden_tooltip = {
					character_event = { id = Plus.1032 }
				}
			}
		}
		20 = {
			modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}
			modifier = {
				factor = 3 # if the sieger was a warrior lodge member
				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1 #Must be rank 2 or higher
				}
			}
			modifier = {
				factor = 3 # if the sieger has a particular Legendary bloodline
				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
					}
				}
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 11 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 10 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 9 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 8 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 7 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 6 }
			}
			custom_tooltip = {
				text = "siege_captured"
				hidden_tooltip = {
					character_event = { id = Plus.1027 }
				}
			}
		}
	}
}

siege_kill_check_effect = {
	random_list = {
		30 = {
			modifier = {
				factor = 0.5
				trait = brave
			}
			modifier = {
				factor = 2
				trait = craven
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = BARON
					father = { higher_tier_than = BARON }
					mother = { higher_tier_than = BARON }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = COUNT
					father = { higher_tier_than = COUNT }
					mother = { higher_tier_than = COUNT }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = DUKE
					father = { higher_tier_than = DUKE }
					mother = { higher_tier_than = DUKE }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = KING
					father = { higher_tier_than = KING }
					mother = { higher_tier_than = KING }
				}
			}
			modifier = {
				factor = 1.5
				is_adult = no
			}
			modifier = {
				factor = 0.5
				trait = infirm
			}
			modifier = {
				factor = 0.5
				trait = wounded
			}
			modifier = {
				factor = 0.25
				trait = maimed
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 11 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 10 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 9 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 8 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 7 }
			}
			modifier = {
				factor = 0.8
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 1.2
				intrigue = 12
			}
			modifier = {
				factor = 1.2
				intrigue = 13
			}
			modifier = {
				factor = 1.2
				intrigue = 14
			}
			modifier = {
				factor = 1.2
				intrigue = 15
			}
			modifier = {
				factor = 1.2
				intrigue = 16
			}
			modifier = {
				factor = 1.2
				intrigue = 17
			}
			modifier = {
				factor = 1.2
				intrigue = 18
			}
			modifier = {
				factor = 1.2
				intrigue = 19
			}
			modifier = {
				factor = 1.2
				intrigue = 20
			}
			modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}
			custom_tooltip = { text = "siege_escaped" }
		}
		40 = {
			custom_tooltip = {
				text = "siege_injured"
				hidden_tooltip = {
					character_event = { id = Plus.1032 }
				}
			}
		}
		20 = {
			modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}
			custom_tooltip = {
				text = "siege_killed"
				hidden_tooltip = {
					character_event = { id = Plus.1026 }
				}
			}
		}
	}
}

siege_pagan_capture_check_effect = {
	random_list = {
		40 = {
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = BARON
					father = { higher_tier_than = BARON }
					mother = { higher_tier_than = BARON }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = COUNT
					father = { higher_tier_than = COUNT }
					mother = { higher_tier_than = COUNT }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = DUKE
					father = { higher_tier_than = DUKE }
					mother = { higher_tier_than = DUKE }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = KING
					father = { higher_tier_than = KING }
					mother = { higher_tier_than = KING }
				}
			}
			modifier = {
				factor = 0.5
				trait = brave
			}
			modifier = {
				factor = 2.0
				trait = craven
			}
			modifier = {
				factor = 1.5
				is_adult = no
			}
			modifier = {
				factor = 0.5
				trait = infirm
			}
			modifier = {
				factor = 0.5
				trait = wounded
			}
			modifier = {
				factor = 0.25
				trait = maimed
			}
			modifier = {
				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1 #Must be rank 2 or higher
				}
			}
			modifier = {
				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
					}
				}
			}
			modifier = {
				factor = 3
				is_inaccessible_trigger = yes
				intrigue = 12
			}
			modifier = {
				factor = 2.5
				is_inaccessible_trigger = yes
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 2
				is_inaccessible_trigger = yes
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 2.5
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 18
			}
			modifier = {
				factor = 2
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 12
				NOT = { intrigue = 18 }
			}
			modifier = {
				factor = 1.5
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			custom_tooltip = { text = "siege_escaped" }
		}
		20 = {
			modifier = {
				factor = 0.1
				is_inaccessible_trigger = yes
				intrigue = 12
			}
			modifier = {
				factor = 0.25
				is_inaccessible_trigger = yes
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 0.5
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 12
				NOT = { intrigue = 18 }
			}
			modifier = {
				factor = 0.25
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 18
			}
			custom_tooltip = {
				text = "siege_injured"
				hidden_tooltip = {
					character_event = { id = Plus.1032 }
				}
			}
		}
		20 = {
			modifier = {
				factor = 3 # if the sieger was a warrior lodge member
				event_target:siege_attacker = {
					is_member_of_any_warrior_lodge_trigger = yes
					society_rank > 1 #Must be rank 2 or higher
				}
			}
			modifier = {
				factor = 3 # if the sieger has a particular Legendary bloodline
				event_target:siege_attacker = {
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_reaver
					}
				}
			}
			modifier = {
				factor = 0.08
				is_inaccessible_trigger = yes
				intrigue = 12
			}
			modifier = {
				factor = 0.15
				is_inaccessible_trigger = yes
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.25
				is_inaccessible_trigger = yes
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 0.5
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.25
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 12
				NOT = { intrigue = 18 }
			}
			modifier = {
				factor = 0.1
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 18
			}
			custom_tooltip = {
				text = "siege_captured"
				hidden_tooltip = {
					character_event = { id = Plus.1027 }
				}
			}
		}
		20 = {
			modifier = {
				factor = 0
				is_inaccessible_trigger = yes
				intrigue = 12
			}
			modifier = {
				factor = 0.1
				is_inaccessible_trigger = yes
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.25
				is_inaccessible_trigger = yes
				NOT = { intrigue = 6 }
			}
			modifier = {
				factor = 0.5
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 6
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 0.25
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 12
				NOT = { intrigue = 18 }
			}
			modifier = {
				factor = 0
				NOT = { is_inaccessible_trigger = yes }
				intrigue = 18
			}
			custom_tooltip = {
				text = "siege_killed"
				hidden_tooltip = {
					character_event = { id = Plus.1026 }
				}
			}
		}
	}
}

siege_pagan_sacrifice_check_effect = {
	random_list = {
		30 = {
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = BARON
					father = { higher_tier_than = BARON }
					mother = { higher_tier_than = BARON }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = COUNT
					father = { higher_tier_than = COUNT }
					mother = { higher_tier_than = COUNT }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = DUKE
					father = { higher_tier_than = DUKE }
					mother = { higher_tier_than = DUKE }
				}
			}
			modifier = {
				factor = 1.2
				OR = {
					higher_tier_than = KING
					father = { higher_tier_than = KING }
					mother = { higher_tier_than = KING }
				}
			}
			modifier = {
				factor = 1.5
				is_adult = no
			}
			modifier = {
				factor = 0.5
				trait = infirm
			}
			modifier = {
				factor = 0.5
				trait = wounded
			}
			modifier = {
				factor = 0.25
				trait = maimed
			}
			modifier = {
				factor = 1.25
				intrigue = 12
			}
			modifier = {
				factor = 1.25
				intrigue = 13
			}
			modifier = {
				factor = 1.25
				intrigue = 14
			}
			modifier = {
				factor = 1.25
				intrigue = 15
			}
			modifier = {
				factor = 1.25
				intrigue = 16
			}
			modifier = {
				factor = 1.25
				intrigue = 17
			}
			modifier = {
				factor = 1.25
				intrigue = 18
			}
			modifier = {
				factor = 1.25
				intrigue = 19
			}
			modifier = {
				factor = 1.25
				intrigue = 20
			}
			modifier = {
				factor = 4
				is_inaccessible_trigger = yes
			}
			custom_tooltip = { text = "siege_escaped" }
		}
		20 = {
			modifier = {
				factor = 2
				trait = brave
			}
			modifier = {
				factor = 0.5
				trait = craven
			}
			custom_tooltip = {
				text = "siege_injured"
				hidden_tooltip = {
					character_event = { id = Plus.1032 }
				}
			}
		}
		20 = {
			modifier = {
				factor = 0.5
				is_inaccessible_trigger = yes
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 12 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 11 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 10 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 9 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 8 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 7 }
			}
			modifier = {
				factor = 1.25
				NOT = { intrigue = 6 }
			}
			custom_tooltip = {
				text = "siege_sacrificed"
				hidden_tooltip = {
					character_event = { id = Plus.1033 }
				}
			}
		}
	}
}

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

switch_to_feudal_effect = {
	if = {
		limit = { religion_group = muslim }
		set_government_type = muslim_government
	}
	if = {
		limit = {
			NOT = { religion_group = muslim }
			NOT = { religion = bogomilist }
			AND = {
				NOR = {
					controls_religion = yes
					top_liege = { controls_religion = yes }
				}
				NOR = {
					is_pagan_religion = yes
					religion = paulician
					religion = druze
				}
			}
		}
		set_government_type = feudal_government
	}
	if = {
		limit = {
			OR = {
				controls_religion = yes
				top_liege = { controls_religion = yes }
			}
			OR = {
				is_pagan_religion = yes
				religion = paulician
				religion = druze
			}
		}
		set_government_type = western_theocratic_feudal_government
	}
	if = {
		limit = { primary_title = { has_law = imperial_administration } }
		primary_title = {
			revoke_law = imperial_administration
			add_law = late_feudal_administration
		}
	}
	#just in case
	primary_title = {
		clr_title_flag = has_imperial_administration
	}
}

switch_to_imperial_effect = {
	if = {
		limit = { religion_group = muslim }
		set_government_type = muslim_imperial_government
	}
	if = {
		limit = {
			NOT = { religion_group = muslim }
			NOT = { religion = bogomilist }
			AND = {
				NOR = {
					controls_religion = yes
					top_liege = { controls_religion = yes }
				}
				NOR = {
					is_pagan_religion = yes
					religion = paulician
					religion = druze
				}
			}
		}
		set_government_type = imperial_government
	}
	if = {
		limit = { primary_title = { has_law = late_feudal_administration } }
		primary_title = {
			revoke_law = late_feudal_administration
			add_law = imperial_administration
		}
	}
	#just in case
	primary_title = {
		set_title_flag = has_imperial_administration
	}
}

title_reduce_CA_effect = {
	if = {
		limit = {
			higher_tier_than = duke
			OR = {
				has_law = crown_authority_1
				has_law = crown_authority_2
				has_law = crown_authority_3
				has_law = crown_authority_4
			}
		}
		custom_tooltip = {
			text = CA_LOWERED_NO_NAME
			hidden_tooltip = {
				if = {
					limit = { has_law = crown_authority_1 }
					add_law_w_cooldown = crown_authority_0
				}
				else_if = {
					limit = { has_law = crown_authority_2 }
					add_law_w_cooldown = crown_authority_1
				}
				else_if = {
					limit = { has_law = crown_authority_3 }
					add_law_w_cooldown = crown_authority_2
				}
				else = {
					add_law_w_cooldown = crown_authority_3
				}
			}
		}
	}
}

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
			}
		}
		custom_tooltip = {
			text = TO_LOWERED_NO_NAME
			hidden_tooltip = {
				if = {
					limit = { has_law = tribal_organization_1 }
					add_law_w_cooldown = tribal_organization_0
				}
				else_if = {
					limit = { has_law = tribal_organization_2 }
					add_law_w_cooldown = tribal_organization_1
				}
				else_if = {
					limit = { has_law = tribal_organization_3 }
					add_law_w_cooldown = tribal_organization_2
				}
				else = {
					add_law_w_cooldown = tribal_organization_3
				}
			}
		}
	}
}

tyrant_plus_1_effect = {
	custom_tooltip = {
		text = TYRANNY_INCREASE_1
		hidden_tooltip = {
			change_variable = { which = tyrant value = 1 }
		}
	}
	tyrant_trait_effect = yes
}

tyrant_plus_2_effect = {
	custom_tooltip = {
		text = TYRANNY_INCREASE_2
		hidden_tooltip = {
			change_variable = { which = tyrant value = 2 }
		}
	}
	tyrant_trait_effect = yes
}

tyrant_plus_4_effect = {
	custom_tooltip = {
		text = TYRANNY_INCREASE_4
		hidden_tooltip = {
			change_variable = { which = tyrant value = 4 }
		}
	}
	tyrant_trait_effect = yes
}

tyrant_trait_effect = {
	if = {
		limit = {
			check_variable = { which = tyrant value = 50 }
		}
		add_trait = tyrant5
	}
	else_if = {
		limit = {
			check_variable = { which = tyrant value = 40 }
		}
		add_trait = tyrant4
	}
	else_if = {
		limit = {
			check_variable = { which = tyrant value = 30 }
		}
		add_trait = tyrant3
	}
	else_if = {
		limit = {
			check_variable = { which = tyrant value = 20 }
		}
		add_trait = tyrant2
	}
	else_if = {
		limit = {
			check_variable = { which = tyrant value = 10 }
		}
		add_trait = tyrant1
	}
	else = {
		hidden_tooltip = {
			remove_trait = tyrant1
			remove_trait = tyrant2
			remove_trait = tyrant3
			remove_trait = tyrant4
			remove_trait = tyrant5
		}
	}
}

attacked_tributary_cb_effect = {
	# Base scope is FROM, the tributary
	# ROOT = Suzerain
	# Suzerain breach of tributary's trust
	custom_tooltip = {
		text = attacking_tributary # Warn player of consequence of attack a tributary
		if = {
			limit = {
				OR = {
					pays_tribute_to = ROOT
					any_liege = {
						pays_tribute_to = ROOT
					}
					has_opinion_modifier = { who = ROOT modifier = opinion_released_tributary }
				}
			}
			ROOT = {
				custom_tooltip = {
					text = attacked_tributary_vassal_penalty
					hidden_tooltip = {
						any_vassal = {
							limit = { higher_tier_than = BARON }
							opinion = {
								modifier = attacked_tributary_vassal
								who = ROOT
								months = 120
							}
						}
					}
				}
				custom_tooltip = {
					text = attacked_tributary_tributary_penalty
					hidden_tooltip = {
						any_independent_ruler = {
							limit = { pays_tribute_to = ROOT }
							opinion = {
								modifier = attacked_tributary
								who = ROOT
								months = 240
							}
							suzerain = {
								remove_tributary = PREV
							}
						}
					}
				}
			}
		}
	}
}

german_culture_spread_effect_province = {
	if = {
		limit = {
			AND = {
				german_culture_region_trigger = yes
				NOT = {
					region = custom_swiss
				}
				culture = german
			}
		}
		culture = swabian
	}
	if = {
		limit = {
			AND = {
				german_culture_region_trigger = yes
				culture = old_frankish
			}
		}
		culture = franconian
	}
	if = {
		limit = {
			AND = {
				region = custom_swiss
				culture = german
			}
		}
		culture = swiss
	}
}

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

german_culture_spread_from_ROOT_effect = {
	any_courtier = {
		limit = {
			is_ruler = no
			prisoner = no
			dynasty = ROOT
			OR = {
				culture = german
				culture = old_frankish
			}
		}
		culture = ROOT
	}
	event_target:melting_pot_province = {
		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
		culture = ROOT
		set_province_flag = melting_pot
	}
}

austrian_culture_spread_effect = {
	any_courtier = {
		limit = {
			is_ruler = no
			prisoner = no
			dynasty = ROOT
			culture = bavarian
		}
		culture = austrian
	}
	event_target:melting_pot_province = {
		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
		culture = austrian
		set_province_flag = melting_pot
	}
}

teutonic_culture_spread_effect = {
	any_courtier = {
		limit = {
			is_ruler = no
			prisoner = no
			dynasty = ROOT
			OR = {
				culture = old_saxon
				culture = prussian
			}
		}
		culture = teutonic
	}
	event_target:melting_pot_province = {
		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
		culture = teutonic
		set_province_flag = melting_pot
	}
}

adjust_gender_law_effect = {
	if = {
		limit = { has_global_flag = gender_equality }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = cognatic_succession } }
		add_law = cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = true_cognatic_succession } }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = agnatic_succession } }
		add_law = agnatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_succession } }
		add_law = enatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_cognatic_succession } }
		add_law = enatic_cognatic_succession
		break = yes
	}
}

prov_prosperity_decrease_effect = {
	if = {
		limit = {
			has_dlc = "Reapers"
		}
		hidden_tooltip = { set_variable = { which = prosperity_value value = 0 } }
		random = {
			chance = 15 #chance to lower by 1 step
			if = {
				limit = {
					has_province_modifier = prosperity_modifier_1
				}
				remove_province_modifier = prosperity_modifier_1
			}
			if = {
				limit = {
					has_province_modifier = prosperity_modifier_2
				}
				remove_province_modifier = prosperity_modifier_2
				add_province_modifier = { name = prosperity_modifier_1 duration = -1 }
			}
			if = {
				limit = {
					has_province_modifier = prosperity_modifier_3
				}
				remove_province_modifier = prosperity_modifier_3
				add_province_modifier = { name = prosperity_modifier_2 duration = -1 }
			}
		}
	}
	if = {
		limit = {
			NOT = { has_dlc = "Reapers" }
		}
		if = {
			limit = {
				has_province_modifier = province_poverty_1
			}
			remove_province_modifier = province_poverty_1
			add_province_modifier = { name = "province_poverty_2" duration = -1 }
		}
		if = {
			limit = {
				NOT = { has_province_modifier = province_prosperity_2 }
				NOT = { has_province_modifier = province_prosperity_1 }
				NOT = { has_province_modifier = province_poverty_1 }
				NOT = { has_province_modifier = province_poverty_2 }
			}
			add_province_modifier = { name = "province_poverty_1" duration = -1 }
		}
		if = {
			limit = {
				has_province_modifier = province_prosperity_1
			}
			remove_province_modifier = province_prosperity_1
		}
		if = {
			limit = {
				has_province_modifier = province_prosperity_2
			}
			remove_province_modifier = province_prosperity_2
			add_province_modifier = { name = "province_prosperity_1" duration = -1 }
		}
	}
}

prov_prosperity_increase_effect = {
	if = {
		limit = {
			has_dlc = "Reapers"
		}
		custom_tooltip = {
			text = prov_prosperity_increase_tooltip
			hidden_tooltip = {
				change_variable = { which = prosperity_value value = 50 }
			}
		}
	}
	if = {
		limit = {
			NOT = { has_dlc = "Reapers" }
		}
		if = {
			limit = {
				has_province_modifier = province_prosperity_1
			}
			remove_province_modifier = province_prosperity_1
			add_province_modifier = { name = "province_prosperity_2" duration = -1 }
		}
		if = {
			limit = {
				NOT = { has_province_modifier = province_prosperity_2 }
				NOT = { has_province_modifier = province_prosperity_1 }
				NOT = { has_province_modifier = province_poverty_1 }
				NOT = { has_province_modifier = province_poverty_2 }
			}
			add_province_modifier = { name = "province_prosperity_1" duration = -1 }
		}
		if = {
			limit = { has_province_modifier = province_poverty_1 }
			remove_province_modifier = province_poverty_1
		}
		if = {
			limit = { has_province_modifier = province_poverty_2 }
			remove_province_modifier = province_poverty_2
			add_province_modifier = { name = "province_poverty_1" duration = -1 }
		}
	}
}

start_reformed_effect = {
	if = {
		limit = {
			religion = baltic_pagan
		}
		religion = baltic_pagan_reformed
	}
	if = {
		limit = {
			religion = celtic_pagan
		}
		religion = celtic_pagan_reformed
	}
	if = {
		limit = {
			religion = finnish_pagan
		}
		religion = finnish_pagan_reformed
	}
	if = {
		limit = {
			religion = german_pagan
		}
		religion = german_pagan_reformed
	}
	if = {
		limit = {
			religion = slavic_pagan
		}
		religion = slavic_pagan_reformed
	}
	if = {
		limit = {
			religion = norse_pagan
		}
		religion = norse_pagan_reformed
	}
	if = {
		limit = {
			religion = tengri_pagan
		}
		religion = tengri_pagan_reformed
	}
	if = {
		limit = {
			religion = west_african_pagan
		}
		religion = west_african_pagan_reformed
	}
	if = {
		limit = {
			religion = zun_pagan
		}
		religion = zun_pagan_reformed
	}
}

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

# Hides homosexual trait by removing the character modifiers that would reveal it
# (this effect may no longer be needed now that the trait defaults to hidden in children,
# but in case we come up with anything that requires it I didn't remove it
char_closet_homosexual_effect = {
	remove_character_modifier = known_sodomite
	remove_character_modifier = known_sodomite_pagan
	remove_character_modifier = known_lesbian
	remove_character_modifier = known_lesbian_pagan
}

set_mercenaries_to_ar_effect = {
	# Set mercenaries to ancient religions based on their capital
	any_title = {
		limit = {
			owner = { mercenary = yes }
			or = {
				and = {
					owner = { religion = catholic }
					has_global_flag = emf_nwo_only_catholic
				}
				and = {
					owner = { religion = orthodox }
					has_global_flag = emf_nwo_only_orthodox
				}
				and = {
					owner = { religion_group = christian }
					has_global_flag = emf_nwo_only_christian
				}
				and = {
					owner = { religion_group = muslim }
					has_global_flag = emf_nwo_only_muslim
				}
				NOR = {
					has_global_flag = emf_nwo_only_catholic
					has_global_flag = emf_nwo_only_orthodox
					has_global_flag = emf_nwo_only_christian
					has_global_flag = emf_nwo_only_muslim
				}
			}
			capital_scope = { has_province_flag = ar_setup }
		}
		capital_scope = { save_event_target_as = convert_to_religion }
		religion = event_target:convert_to_religion
		holder_scope = {
			religion = event_target:convert_to_religion
		}
		clear_event_target = convert_to_religion
	}
}

set_mercenaries_to_ar_culture_effect = {
	# Set mercenaries to ancient religions based on their capital
	any_title = {
		limit = {
			owner = { mercenary = yes }
			or = {
				and = {
					owner = { religion = catholic }
					has_global_flag = emf_nwo_only_catholic
				}
				and = {
					owner = { religion = orthodox }
					has_global_flag = emf_nwo_only_orthodox
				}
				and = {
					owner = { religion_group = christian }
					has_global_flag = emf_nwo_only_christian
				}
				and = {
					owner = { religion_group = muslim }
					has_global_flag = emf_nwo_only_muslim
				}
				NOR = {
					has_global_flag = emf_nwo_only_catholic
					has_global_flag = emf_nwo_only_orthodox
					has_global_flag = emf_nwo_only_christian
					has_global_flag = emf_nwo_only_muslim
				}
			}
			capital_scope = { has_province_flag = ar_setup }
		}
		holder_scope = {
			emf_nwo_generate_ancient_religion_characters = yes
			reverse_religion = PREV
		}
	}
}

# 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 = fair }
				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
		}
	}
}

make_all_traits_visible_effect = {
	if = {
		limit = { trait = genius }
		remove_character_modifier = hidden_genius
	}
	if = {
		limit = { trait = quick }
		remove_character_modifier = hidden_quick
	}
	if = {
		limit = { trait = slow }
		remove_character_modifier = hidden_slow
	}
	if = {
		limit = { trait = imbecile }
		remove_character_modifier = hidden_imbecile
	}
	if = {
		limit = { trait = strong }
		remove_character_modifier = hidden_strong
	}
	if = {
		limit = { trait = weak }
		remove_character_modifier = hidden_weak
	}
	if = {
		limit = { trait = fair }
		remove_character_modifier = hidden_fair
	}
	if = {
		limit = { trait = ugly }
		remove_character_modifier = hidden_ugly
	}
	if = {
		limit = { trait = tall }
		remove_character_modifier = hidden_tall
	}
	if = {
		limit = { trait = dwarf }
		remove_character_modifier =  hidden_dwarf
	}
}

out_homosexual_effect = {
	if = {
		limit = {
			trait = homosexual
			NOR = {
				has_character_modifier = known_lesbian
				has_character_modifier = known_sodomite
				has_character_modifier = known_sodomite_pagan
			}
		}
		if = {
			limit = { is_female = yes }
			if = {
				limit = {
					is_pagan_religion = yes
				}
				add_character_modifier = {
					name = known_lesbian_pagan
					years = -1
				}
			}
			if = {
				limit = {
					is_pagan_religion = no
				}
				add_character_modifier = {
					name = known_lesbian
					years = -1
				}
			}
		}
		if = {
			limit = { is_female = no }
			if = {
				limit = {
					is_pagan_religion = yes
				}
				add_character_modifier = {
					name = known_sodomite_pagan
					years = -1
				}
			}
			if = {
				limit = {
					is_pagan_religion = no
				}
				add_character_modifier = {
					name = known_sodomite
					years = -1
				}
			}
		}
	}
}

take_loan_effect = {
	if = {
		limit = { ai = no }
		#50g loan
		if = {
			limit = {
				NOT = { monthly_income = 2.5 }
			}
			wealth = 50
			add_character_modifier = {
				name = loan_50
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_50_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#100g loan
		if = {
			limit = {
				monthly_income = 2.5
				NOT = { monthly_income = 5 }
			}
			wealth = 100
			add_character_modifier = {
				name = loan_100
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_100_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#200g loan
		if = {
			limit = {
				monthly_income = 5
				NOT = { monthly_income = 10 }
			}
			wealth = 200
			add_character_modifier = {
				name = loan_200
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_200_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#400g loan
		if = {
			limit = {
				monthly_income = 10
				NOT = { monthly_income = 15 }
			}
			wealth = 400
			add_character_modifier = {
				name = loan_400
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_400_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#600g loan
		if = {
			limit = {
				monthly_income = 15
				NOT = { monthly_income = 20 }
			}
			wealth = 600
			add_character_modifier = {
				name = loan_600
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_600_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#800g loan
		if = {
			limit = {
				monthly_income = 20
				NOT = { monthly_income = 25 }
			}
			wealth = 800
			add_character_modifier = {
				name = loan_800
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_800_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		#1000g loan
		if = {
			limit = {
				monthly_income = 25
			}
			wealth = 1000
			add_character_modifier = {
				name = loan_1000
				duration = 1825
				inherit = yes
			}
			hidden_tooltip = {
				add_character_modifier = {
					name = loan_1000_hidden
					duration = -1
					inherit = yes
					hidden = yes
				}
			}
		}
		set_character_flag = loan_taken
	}
	if = {
		limit = { ai = yes}
		#50g loan
		if = {
			limit = {
				NOT = { monthly_income = 2.5 }
			}
			wealth = 50
			set_variable = { which = "loan_amount" value = 50 }
		}
		#100g loan
		if = {
			limit = {
				monthly_income = 2.5
				NOT = { monthly_income = 5 }
			}
			wealth = 100
			set_variable = { which = "loan_amount" value = 100 }
		}
		#200g loan
		if = {
			limit = {
				monthly_income = 5
				NOT = { monthly_income = 10 }
			}
			wealth = 200
			set_variable = { which = "loan_amount" value = 200 }
		}
		#400g loan
		if = {
			limit = {
				monthly_income = 10
				NOT = { monthly_income = 15 }
			}
			wealth = 400
			set_variable = { which = "loan_amount" value = 400 }
		}
		#600g loan
		if = {
			limit = {
				monthly_income = 15
				NOT = { monthly_income = 20 }
			}
			wealth = 600
			set_variable = { which = "loan_amount" value = 600 }
		}
		#800g loan
		if = {
			limit = {
				monthly_income = 20
				NOT = { monthly_income = 25 }
			}
			wealth = 800
			set_variable = { which = "loan_amount" value = 800 }
		}
		#1000g loan
		if = {
			limit = {
				monthly_income = 25
			}
			wealth = 1000
			set_variable = { which = "loan_amount" value = 1000 }
		}
		add_character_modifier = { name = "loan_timer" duration = -1 }
	}
}

israel_culture_religion_effect = { # Convert to ROOT's religion and a culture based on FROM's origin
	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_brittania
						region = world_europe_south_east
					}
				}
			}
		}
		culture = ashkenazi
	}
	if = { # Sephardi
		limit = {
			FROM = {
				location = {
					OR = {
						region = world_europe_west_iberia
						region = world_africa_north
						region = world_europe_west_francia
						region = custom_roman_italia
						region = world_africa_west
						region = world_africa_central
					}
				}
			}
		}
		culture = sephardi
	}
	if = { # Mizrahim
		limit = {
			FROM = {
				location = {
					NOR = {
						region = world_europe_west_germania
						region = world_europe_east
						region = world_europe_west_brittania
						region = world_europe_south_east
						region = world_europe_west_iberia
						region = world_africa_north
						region = world_europe_west_francia
						region = custom_roman_italia
						region = world_africa_west
						region = world_africa_central
					}
				}
			}
		}
		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_brittania
				region = world_europe_south_east
			}
		}
		ROOT = { culture = ashkenazi }
	}
	if = { # Sephardi
		limit = {
			OR = {
				region = world_europe_west_iberia
				region = world_africa_north
				region = world_europe_west_francia
				region = custom_roman_italia
				region = world_africa_west
				region = world_africa_central
			}
		}
		ROOT = { culture = sephardi }
	}
	if = { # Mizrahim
		limit = {
			NOR = {
				region = world_europe_west_germania
				region = world_europe_east
				region = world_europe_west_brittania
				region = world_europe_south_east
				region = world_europe_west_iberia
				region = world_africa_north
				region = world_europe_west_francia
				region = custom_roman_italia
				region = world_africa_west
				region = world_africa_central
			}
		}
		ROOT = { culture = mizrahim }
	}
}

reeducate_to_tier_4_effect = {
	custom_tooltip = { text = REEDUCATED_TO_TIER_4_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = has_character_flag
			reeducates_to_diplomacy = { add_trait = grey_eminence }
			reeducates_to_martial = { add_trait = brilliant_strategist }
			reeducates_to_stewardship = { add_trait = midas_touched }
			reeducates_to_intrigue = { add_trait = elusive_shadow }
			reeducates_to_learning = { add_trait = mastermind_theologian }
		}
	}
}

reeducate_to_tier_3_effect = {
	custom_tooltip = { text = REEDUCATED_TO_TIER_3_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = has_character_flag
			reeducates_to_diplomacy = { add_trait = charismatic_negotiator }
			reeducates_to_martial = { add_trait = skilled_tactician }
			reeducates_to_stewardship = { add_trait = fortune_builder }
			reeducates_to_intrigue = { add_trait = intricate_webweaver }
			reeducates_to_learning = { add_trait = scholarly_theologian }
		}
	}
}
reeducate_to_tier_2_effect = {
	custom_tooltip = { text = REEDUCATED_TO_TIER_2_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = has_character_flag
			reeducates_to_diplomacy = { add_trait = underhanded_rogue }
			reeducates_to_martial = { add_trait = tough_soldier }
			reeducates_to_stewardship = { add_trait = thrifty_clerk }
			reeducates_to_intrigue = { add_trait = flamboyant_schemer }
			reeducates_to_learning = { add_trait = martial_cleric }
		}
	}
}
reeducate_to_tier_1_effect = {
	custom_tooltip = { text = REEDUCATED_TO_TIER_1_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = has_character_flag
			reeducates_to_diplomacy = { add_trait = naive_appeaser }
			reeducates_to_martial = { add_trait = misguided_warrior }
			reeducates_to_stewardship = { add_trait = indulgent_wastrel }
			reeducates_to_intrigue = { add_trait = amateurish_plotter }
			reeducates_to_learning = { add_trait = detached_priest }
		}
	}
}

reduce_education_effect = {
	custom_tooltip = { text = CURRENT_EDUCATION_REDUCED_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = trait

			### Intrigue ###
			amateurish_plotter = {
				remove_trait = amateurish_plotter
			}
			flamboyant_schemer = {
				remove_trait = flamboyant_schemer
				add_trait = amateurish_plotter
			}
			intricate_webweaver = {
				remove_trait = intricate_webweaver
				add_trait = flamboyant_schemer
			}
			elusive_shadow = {
				remove_trait = elusive_shadow
				add_trait = intricate_webweaver
			}

			### Diplomacy ###
			naive_appeaser = {
				remove_trait = naive_appeaser
			}
			underhanded_rogue = {
				remove_trait = underhanded_rogue
				add_trait = naive_appeaser
			}
			charismatic_negotiator = {
				remove_trait = charismatic_negotiator
				add_trait = underhanded_rogue
			}
			grey_eminence = {
				remove_trait = grey_eminence
				add_trait = charismatic_negotiator
			}

			### Stewardship ###
			indulgent_wastrel = {
				remove_trait = indulgent_wastrel
			}
			thrifty_clerk = {
				remove_trait = thrifty_clerk
				add_trait = indulgent_wastrel
			}
			fortune_builder = {
				remove_trait = fortune_builder
				add_trait = thrifty_clerk
			}
			midas_touched = {
				remove_trait = midas_touched
				add_trait = fortune_builder
			}

			### Martial ###
			misguided_warrior = {
				remove_trait = misguided_warrior
			}
			tough_soldier = {
				remove_trait = tough_soldier
				add_trait = misguided_warrior
			}
			skilled_tactician = {
				remove_trait = skilled_tactician
				add_trait = tough_soldier
			}
			brilliant_strategist = {
				remove_trait = brilliant_strategist
				add_trait = skilled_tactician
			}

			### Learning ###
			detached_priest = {
				remove_trait = detached_priest
			}
			martial_cleric = {
				remove_trait = martial_cleric
				add_trait = detached_priest
			}
			scholarly_theologian = {
				remove_trait = scholarly_theologian
				add_trait = martial_cleric
			}
			mastermind_theologian = {
				remove_trait = mastermind_theologian
				add_trait = scholarly_theologian
			}
		}
	}
}

upgrade_education_intrigue_effect = {
	trigger_switch = {
		on_trigger = trait

		### Intrigue ###
		amateurish_plotter = {
			remove_trait = amateurish_plotter
			add_trait = flamboyant_schemer
		}
		flamboyant_schemer = {
			remove_trait = flamboyant_schemer
			add_trait = intricate_webweaver
		}
		intricate_webweaver = {
			remove_trait = intricate_webweaver
			add_trait = elusive_shadow
		}
		elusive_shadow = {
			# already maxed
		}
	}
}

upgrade_education_diplomacy_effect = {
	trigger_switch = {
		on_trigger = trait

		### Diplomacy ###
		naive_appeaser = {
			remove_trait = naive_appeaser
			add_trait = underhanded_rogue
		}
		underhanded_rogue = {
			remove_trait = underhanded_rogue
			add_trait = charismatic_negotiator
		}
		charismatic_negotiator = {
			remove_trait = charismatic_negotiator
			add_trait = grey_eminence
		}
		grey_eminence = {
			# already maxed
		}
	}
}

upgrade_education_stewarship_effect = {
	trigger_switch = {
		on_trigger = trait

		### Stewardship ###
		indulgent_wastrel = {
			remove_trait = indulgent_wastrel
			add_trait = thrifty_clerk
		}
		thrifty_clerk = {
			remove_trait = thrifty_clerk
			add_trait = fortune_builder
		}
		fortune_builder = {
			remove_trait = fortune_builder
			add_trait = midas_touched
		}
		midas_touched = {
			# already maxed
		}
	}
}

upgrade_education_martial_effect = {
	trigger_switch = {
		on_trigger = trait

		### Martial ###
		misguided_warrior = {
			remove_trait = misguided_warrior
			add_trait = tough_soldier
		}
		tough_soldier = {
			remove_trait = tough_soldier
			add_trait = skilled_tactician
		}
		skilled_tactician = {
			remove_trait = skilled_tactician
			add_trait = brilliant_strategist
		}
		brilliant_strategist = {
			# already maxed
		}
	}
}

upgrade_education_learning_effect = {
	trigger_switch = {
		on_trigger = trait

		### Learning ###
		detached_priest = {
			remove_trait = detached_priest
			add_trait = martial_cleric
		}
		martial_cleric = {
			remove_trait = martial_cleric
			add_trait = scholarly_theologian
		}
		scholarly_theologian = {
			remove_trait = scholarly_theologian
			add_trait = mastermind_theologian
		}
		mastermind_theologian = {
			# already maxed
		}
	}
}

force_two_education_events_effect = {
	if = {
		limit = {
			has_character_flag = had_first_education_event
			NOT = { has_character_flag = had_second_education_event }
		}
		set_character_flag = had_second_education_event
	}
	if = {
		limit = {
			NOT = { has_character_flag = had_first_education_event }
		}
		set_character_flag = had_first_education_event
	}
}

remove_do_not_disturb_effect = {
	remove_character_modifier = do_not_disturb
	clr_character_flag = do_not_disturb
}

make_court_educator_effect = {
	if = {
		limit = { has_dlc = "Zeus"}
		give_minor_title = title_teacher
	}
	if = {
		limit = { NOT = { has_dlc = "Zeus"} }
		give_minor_title = title_court_educator
	}
}

remove_court_educator_effect = {
	if = {
		limit = { has_dlc = "Zeus"}
		remove_title = title_teacher
	}
	if = {
		limit = { NOT = { has_dlc = "Zeus"} }
		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 = { tier = COUNT }
		location = {
			FROM = {
				destroy_tradepost = PREV
			}
		}
	}
}

# Baby Portrait effect - needs to be updated when new graphicalcultures are added
assign_baby_portrait_effect = { # Automatically give correct trait based on skintone/gender
	if = {
		limit = {
			is_female = no
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with fair skin (skin_tone = 0)
					graphical_culture = frankishgfx
					graphical_culture = englishgfx
					graphical_culture = germangfx
					graphical_culture = occitangfx
					graphical_culture = celticgfx
					graphical_culture = norsegfx
					graphical_culture = saxongfx
					graphical_culture = normangfx
					graphical_culture = italiangfx
					graphical_culture = easternslavicgfx
					graphical_culture = westernslavicgfx
					graphical_culture = ugricgfx
					graphical_culture = balticgfx
					graphical_culture = bretongfx
					graphical_culture = bohemiangfx
					graphical_culture = norsegaelgfx
					graphical_culture = hungariangfx
					graphical_culture = dutchgfx
					graphical_culture = pomeraniangfx
					graphical_culture = southernslavicgfx
					graphical_culture = basquegfx
					graphical_culture = lombardgfx
					graphical_culture = ashkenazigfx
					graphical_culture = easterngfx
					graphical_culture = westerngfx
				}
			}
			add_trait = baby_boy_fair
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with tanned skin (skin_tone = 1)
					graphical_culture = southerngfx
					graphical_culture = byzantinegfx
					graphical_culture = mongolgfx
					graphical_culture = andalusiangfx
					graphical_culture = chinesegfx
					graphical_culture = bodpagfx
					graphical_culture = bulgargfx
					graphical_culture = centralasiangfx
					graphical_culture = steppegfx
					graphical_culture = siberiangfx
					graphical_culture = alangfx
					graphical_culture = georgiangfx
					graphical_culture = sogdiangfx
					graphical_culture = levantinegfx
					graphical_culture = siciliangfx
					graphical_culture = pecheneggfx
					graphical_culture = afghangfx
					graphical_culture = assamesegfx
					graphical_culture = khitangfx
					graphical_culture = semitegfx
					graphical_culture = mesoamericangfx
					graphical_culture = jewishgfx
				}
			}
			add_trait = baby_boy_tanned
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with dark skin (skin_tone = 2)
					graphical_culture = arabicgfx
					graphical_culture = copticgfx
					graphical_culture = turkishgfx
					graphical_culture = cumangfx
					graphical_culture = persiangfx
					graphical_culture = maghrebgfx
					graphical_culture = egyptiangfx
					graphical_culture = muslimgfx
					graphical_culture = indiangfx
				}
			}
			add_trait = baby_boy_dark
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with darker skin (skin_tone = 3)
					graphical_culture = africangfx
					graphical_culture = westafricangfx
					graphical_culture = southindiangfx
					graphical_culture = berbergfx
					graphical_culture = centralindiangfx
					graphical_culture = somaligfx
				}
			}
			add_trait = baby_boy_darker
		}
	}
	if = {
		limit = {
			is_female = yes
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with fair skin (skin_tone = 0)
					graphical_culture = frankishgfx
					graphical_culture = englishgfx
					graphical_culture = germangfx
					graphical_culture = occitangfx
					graphical_culture = celticgfx
					graphical_culture = norsegfx
					graphical_culture = saxongfx
					graphical_culture = normangfx
					graphical_culture = italiangfx
					graphical_culture = easternslavicgfx
					graphical_culture = westernslavicgfx
					graphical_culture = ugricgfx
					graphical_culture = balticgfx
					graphical_culture = bretongfx
					graphical_culture = bohemiangfx
					graphical_culture = norsegaelgfx
					graphical_culture = hungariangfx
					graphical_culture = dutchgfx
					graphical_culture = pomeraniangfx
					graphical_culture = southernslavicgfx
					graphical_culture = basquegfx
					graphical_culture = lombardgfx
					graphical_culture = ashkenazigfx
					graphical_culture = easterngfx
					graphical_culture = westerngfx
				}
			}
			add_trait = baby_girl_fair
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with tanned skin (skin_tone = 1)
					graphical_culture = southerngfx
					graphical_culture = byzantinegfx
					graphical_culture = mongolgfx
					graphical_culture = andalusiangfx
					graphical_culture = chinesegfx
					graphical_culture = bodpagfx
					graphical_culture = bulgargfx
					graphical_culture = centralasiangfx
					graphical_culture = steppegfx
					graphical_culture = siberiangfx
					graphical_culture = alangfx
					graphical_culture = georgiangfx
					graphical_culture = sogdiangfx
					graphical_culture = levantinegfx
					graphical_culture = siciliangfx
					graphical_culture = pecheneggfx
					graphical_culture = afghangfx
					graphical_culture = assamesegfx
					graphical_culture = khitangfx
					graphical_culture = semitegfx
					graphical_culture = mesoamericangfx
					graphical_culture = jewishgfx
				}
			}
			add_trait = baby_girl_tanned
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with dark skin (skin_tone = 2)
					graphical_culture = arabicgfx
					graphical_culture = copticgfx
					graphical_culture = turkishgfx
					graphical_culture = cumangfx
					graphical_culture = persiangfx
					graphical_culture = maghrebgfx
					graphical_culture = egyptiangfx
					graphical_culture = muslimgfx
					graphical_culture = indiangfx
				}
			}
			add_trait = baby_girl_dark
		}
		if = {
			limit = {
				OR = { # Exhaustive list of every gfx_culture with darker skin (skin_tone = 3)
					graphical_culture = africangfx
					graphical_culture = westafricangfx
					graphical_culture = southindiangfx
					graphical_culture = berbergfx
					graphical_culture = centralindiangfx
					graphical_culture = somaligfx
				}
			}
			add_trait = baby_girl_darker
		}
	}
}

copy_prev_gender_law_effect = {
	if = {
		limit = { has_global_flag = gender_equality }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { PREV = { has_law = cognatic_succession } }
		add_law = cognatic_succession
		break = yes
	}
	if = {
		limit = { PREV = { has_law = true_cognatic_succession } }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { PREV = { has_law = agnatic_succession } }
		add_law = agnatic_succession
		break = yes
	}
	if = {
		limit = { PREV = { has_law = enatic_succession } }
		add_law = enatic_succession
		break = yes
	}
	if = {
		limit = { PREV = { has_law = enatic_cognatic_succession } }
		add_law = enatic_cognatic_succession
		break = yes
	}
}

#event_target:coronation_ruler is the coronation target
will_perform_coronation_effect = {
	reverse_opinion = { who = event_target:coronation_ruler modifier = opinion_performed_coronation months = 120 }
	opinion = { who = event_target:coronation_ruler modifier = opinion_performed_coronation months = 120 }
	if = {
		limit = { NOT = { has_opinion_modifier = { who = event_target:coronation_ruler modifier = attending_coronation } } }
		reverse_opinion = { who = event_target:coronation_ruler modifier = attending_coronation months = 12 }
		opinion = { who = event_target:coronation_ruler modifier = attending_coronation months = 12 }
		add_character_modifier = { name = do_not_disturb days = 200 hidden = yes }
		end_inaccessibility_effect = yes
	}
	any_spouse = {
		limit = {
			is_ill = no
			is_pregnant = no
			is_ruler = no
			war = no
			NOT = { is_inaccessible_trigger = yes }
			is_not_busy_trigger = yes
			NOT = { has_opinion_modifier = { who = event_target:coronation_ruler modifier = attending_coronation } }
		}
		reverse_opinion = { who = event_target:coronation_ruler modifier = attending_coronation months = 12 }
		opinion = { who = event_target:coronation_ruler modifier = attending_coronation months = 12 }
		add_character_modifier = { name = do_not_disturb days = 200 hidden = yes }
	}
}

send_coronation_invitations_effect = {
	any_character = {
		limit = {
			is_adult = yes
			prisoner = no
			is_within_diplo_range = ROOT
			OR = {
				is_vassal_or_below = ROOT
				is_liege_or_above = ROOT
				is_close_relative = ROOT
				dynasty = ROOT
				is_allied_with = ROOT
				has_non_aggression_pact_with = ROOT
				AND = {
					same_realm = ROOT
					higher_tier_than = BARON
				}
				AND = {
					religion = ROOT
					any_realm_province = {
						ROOT = {
							any_realm_province = {
								NOT = { distance = { where = PREVPREV value = 125 } }
							}
						}
					}
				}
			}
			NOR = {
				character = ROOT
				trait = incapable
				trait = excommunicated
				has_truce = ROOT
				has_opinion_modifier = { who = FROM modifier = opinion_performed_coronation }
				ROOT = { rightful_religious_head_scope = { character = PREVPREV } } #he's either performing it or not comming at all
			}
		}
		letter_event = { id = Plus.1201 }
	}
}
