#	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"
	}
	if = {
		limit = { has_law = succ_elective_gavelkind }
		log = "---> current succession law for [This.GetID]: Elective Gavelkind"
	}
	if = {
		limit = { has_law = succ_seniority }
		log = "---> current succession law for [This.GetID]: Seniority"
	}
	if = {
		limit = { has_law = succ_primogeniture }
		log = "---> current succession law for [This.GetID]: Primogeniture"
	}
	if = {
		limit = { has_law = succ_feudal_elective }
		log = "---> current succession law for [This.GetID]: Feudal Elective"
	}
	if = {
		limit = { has_law = succ_tanistry }
		log = "---> current succession law for [This.GetID]: Tanistry"
	}
	if = {
		limit = { has_law = succ_ultimogeniture }
		log = "---> current succession law for [This.GetID]: Ultimogeniture"
	}
	if = {
		limit = { has_law = succ_turkish_succession }
		log = "---> current succession law for [This.GetID]: Turkish Succession"
	}
	if = {
		limit = { has_law = succ_papal_succession }
		log = "---> current succession law for [This.GetID]: Papal Succession"
	}
	if = {
		limit = { has_law = succ_appointment }
		log = "---> current succession law for [This.GetID]: Appointment"
	}
	if = {
		limit = { has_law = succ_open_elective }
		log = "---> current succession law for [This.GetID]: Open Elective"
	}
	if = {
		limit = { has_law = succ_catholic_bishopric }
		log = "---> current succession law for [This.GetID]: Bishopric"
	}
	if = {
		limit = { has_law = succ_patrician_elective }
		log = "---> current succession law for [This.GetID]: Patrician Elective"
	}
	if = {
		limit = { has_law = succ_nomad_succession }
		log = "---> current succession law for [This.GetID]: Nomadic"
	}
	if = {
		limit = { emf_laws_has_readable_succession_law_trigger = no }
		log = "---> current succession law for [This.GetID]: (None)"
	}
	if = {
		limit = { has_law = cognatic_succession }
		log = "---> current gender law for [This.GetID]: Agnatic-Cognatic"
	}
	if = {
		limit = { has_law = true_cognatic_succession }
		log = "---> current gender law for [This.GetID]: True Cognatic"
	}
	if = {
		limit = { has_law = agnatic_succession }
		log = "---> current gender law for [This.GetID]: Agnatic"
	}
	if = {
		limit = { has_law = enatic_succession }
		log = "---> current gender law for [This.GetID]: Enatic"
	}
	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
	}
	if = {
		limit = {
			trait = dishonorable8
		}
		remove_trait = dishonorable8
		add_trait = dishonorable9
	}
	if = {
		limit = {
			trait = dishonorable7
		}
		remove_trait = dishonorable7
		add_trait = dishonorable8
	}
	if = {
		limit = {
			trait = dishonorable6
		}
		remove_trait = dishonorable6
		add_trait = dishonorable7
	}
	if = {
		limit = {
			trait = dishonorable5
		}
		remove_trait = dishonorable5
		add_trait = dishonorable6
	}
	if = {
		limit = {
			trait = dishonorable4
		}
		remove_trait = dishonorable4
		add_trait = dishonorable5
	}
	if = {
		limit = {
			trait = dishonorable3
		}
		remove_trait = dishonorable3
		add_trait = dishonorable4
	}
	if = {
		limit = {
			trait = dishonorable2
		}
		remove_trait = dishonorable2
		add_trait = dishonorable3
	}
	if = {
		limit = {
			trait = dishonorable1
		}
		remove_trait = dishonorable1
		add_trait = dishonorable2
	}
	if = {
		limit = {
			trait = dyn_dishonorable9
		}
		remove_trait = dyn_dishonorable9
		add_trait = dishonorable10
	}
	if = {
		limit = {
			trait = dyn_dishonorable8
		}
		remove_trait = dyn_dishonorable8
		add_trait = dishonorable9
	}
	if = {
		limit = {
			trait = dyn_dishonorable7
		}
		remove_trait = dyn_dishonorable7
		add_trait = dishonorable8
	}
	if = {
		limit = {
			trait = dyn_dishonorable6
		}
		remove_trait = dyn_dishonorable6
		add_trait = dishonorable7
	}
	if = {
		limit = {
			trait = dyn_dishonorable5
		}
		remove_trait = dyn_dishonorable5
		add_trait = dishonorable6
	}
	if = {
		limit = {
			trait = dyn_dishonorable4
		}
		remove_trait = dyn_dishonorable4
		add_trait = dishonorable5
	}
	if = {
		limit = {
			trait = dyn_dishonorable3
		}
		remove_trait = dyn_dishonorable3
		add_trait = dishonorable4
	}
	if = {
		limit = {
			trait = dyn_dishonorable2
		}
		remove_trait = dyn_dishonorable2
		add_trait = dishonorable3
	}
	if = {
		limit = {
			trait = dyn_dishonorable1
		}
		remove_trait = dyn_dishonorable1
		add_trait = dishonorable2
	}
	if = {
		limit = {
			NOT = { trait = dishonorable1 }
			NOT = { trait = dishonorable2 }
			NOT = { trait = dishonorable3 }
			NOT = { trait = dishonorable4 }
			NOT = { trait = dishonorable5 }
			NOT = { trait = dishonorable6 }
			NOT = { trait = dishonorable7 }
			NOT = { trait = dishonorable8 }
			NOT = { trait = dishonorable9 }
			NOT = { trait = dishonorable10 }
			NOT = { trait = dyn_dishonorable1 }
			NOT = { trait = dyn_dishonorable2 }
			NOT = { trait = dyn_dishonorable3 }
			NOT = { trait = dyn_dishonorable4 }
			NOT = { trait = dyn_dishonorable5 }
			NOT = { trait = dyn_dishonorable6 }
			NOT = { trait = dyn_dishonorable7 }
			NOT = { trait = dyn_dishonorable8 }
			NOT = { trait = dyn_dishonorable9 }
			NOT = { trait = dyn_dishonorable10 }
		}
		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 }
				NOT = { religion_group = pagan_group }
			}
			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
						culture = 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 }
							culture = italian
						}
					}
					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 = { k_papal_state = { has_title_flag = schism_happened } }
						religion = orthodox
					}
					if = {
						limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
						religion = orthodox
					}
					if = {
						limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = orthodox
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = catholic
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = orthodox
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = catholic
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 }
			NOT = { religion_group = pagan_group }
		}
		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
						culture = 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
							culture = italian
						}
					}
					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 = { k_papal_state = { has_title_flag = schism_happened } }
						religion = orthodox
					}
					if = {
						limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
						religion = orthodox
					}
					if = {
						limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = orthodox
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = catholic
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = orthodox
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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 = { k_papal_state = { has_title_flag = schism_happened } }
					religion = catholic
				}
				if = {
					limit = { NOT = { k_papal_state = { has_title_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
			}
			if = {
				limit = { religion = bogomilist }
				log = "----> [Root.GetBestName] has been set to bogomilist government (Liberation Revolt)"
				set_government_type = bogomilist_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
	}
}

# 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
	}
	if = {
		limit = { has_character_modifier = estates_2 }
		remove_character_modifier = estates_2
		wealth = 80
	}
	if = {
		limit = { has_character_modifier = estates_3 }
		remove_character_modifier = estates_3
		wealth = 120
	}
	if = {
		limit = { has_character_modifier = estates_4 }
		remove_character_modifier = estates_4
		wealth = 160
	}
	if = {
		limit = { has_character_modifier = estates_5 }
		remove_character_modifier = estates_5
		wealth = 200
	}
}

set_viceroy_exempt_effect = {
	if = {
		limit = {
			ROOT = { has_imperial_government_trigger = yes }
			is_feudal = yes
			has_imperial_government_trigger = no
			NAND = {
				controls_religion = yes
				NOT = { religion_group = muslim }
				NOT = { religion_group = pagan_group }
				NOT = { religion = paulician }
			}
		}
		any_demesne_title = { clr_title_flag = viceroy_exemption }
		primary_title = { set_title_flag = viceroy_exemption }
		any_realm_lord = {
			limit = {
				is_feudal = yes
				has_imperial_government_trigger = no
				NAND = {
					controls_religion = yes
					NOT = { religion_group = muslim }
					NOT = { religion_group = pagan_group }
					NOT = { religion = paulician }
				}
			}
			any_demesne_title = { clr_title_flag = viceroy_exemption }
			primary_title = { set_title_flag = viceroy_exemption }
		}
	}
}

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 = 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 = {
				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 = 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 }
			religion = bogomilist
		}
		set_government_type = bogomilist_government
	}
	if = {
		limit = {
			NOT = { religion_group = muslim }
			NOT = { religion = bogomilist }
		}
		set_government_type = 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 } }
		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
				}
				if = {
					limit = { has_law = crown_authority_2 }
					add_law_w_cooldown = crown_authority_1
				}
				if = {
					limit = { has_law = crown_authority_3 }
					add_law_w_cooldown = crown_authority_2
				}
				if = {
					limit = { has_law = crown_authority_4 }
					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
				}
				if = {
					limit = { has_law = tribal_organization_2 }
					add_law_w_cooldown = tribal_organization_1
				}
				if = {
					limit = { has_law = tribal_organization_3 }
					add_law_w_cooldown = tribal_organization_2
				}
				if = {
					limit = { has_law = tribal_organization_4 }
					add_law_w_cooldown = tribal_organization_3
				}
			}
		}
	}
}

turn_off_titles_effect = {
	any_title = {
		limit = {
			is_titular = yes
			has_holder = no
			OR = {
				title = e_armenia
				title = e_bohemia
				title = e_cornwall
				title = e_denmark
				title = e_egypt
				title = e_england
				title = e_finland
				title = e_ghana
				title = e_hungary
				title = e_ireland
				title = e_jolof
				title = e_norway
				title = e_nubia
				title = e_scotland
				title = e_serbia
				title = e_sicily
				title = e_wales
				title = e_wend
				title = k_antioch
				title = k_epirus
				title = k_gascony
				title = k_krete
				title = k_mallorca
				title = k_normandy
				title = k_slavonia
				title = k_swiss
			}
		}
		activate_title = { title = THIS status = no }
	}
}

turn_on_titles_effect = {
	any_title = {
		limit = {
			is_titular = yes
			has_holder = no
			OR = {
				title = e_armenia
				title = e_bohemia
				title = e_cornwall
				title = e_denmark
				title = e_egypt
				title = e_england
				title = e_finland
				title = e_ghana
				title = e_hungary
				title = e_ireland
				title = e_jolof
				title = e_norway
				title = e_nubia
				title = e_scotland
				title = e_serbia
				title = e_sicily
				title = e_wales
				title = e_wend
				title = k_antioch
				title = k_epirus
				title = k_gascony
				title = k_krete
				title = k_mallorca
				title = k_normandy
				title = k_slavonia
				title = k_swiss
			}
		}
		activate_title = { title = THIS status = yes }
	}
}

tyrant_plus_1_effect = {
	if = {
		limit = {
			trait = tyrant19
		}
		remove_trait = tyrant19
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant18
		}
		remove_trait = tyrant18
		add_trait = tyrant19
	}
	if = {
		limit = {
			trait = tyrant17
		}
		remove_trait = tyrant17
		add_trait = tyrant18
	}
	if = {
		limit = {
			trait = tyrant16
		}
		remove_trait = tyrant16
		add_trait = tyrant17
	}
	if = {
		limit = {
			trait = tyrant15
		}
		remove_trait = tyrant15
		add_trait = tyrant16
	}
	if = {
		limit = {
			trait = tyrant14
		}
		remove_trait = tyrant14
		add_trait = tyrant15
	}
	if = {
		limit = {
			trait = tyrant13
		}
		remove_trait = tyrant13
		add_trait = tyrant14
	}
	if = {
		limit = {
			trait = tyrant12
		}
		remove_trait = tyrant12
		add_trait = tyrant13
	}
	if = {
		limit = {
			trait = tyrant11
		}
		remove_trait = tyrant11
		add_trait = tyrant12
	}
	if = {
		limit = {
			trait = tyrant10
		}
		remove_trait = tyrant10
		add_trait = tyrant11
	}
	if = {
		limit = {
			trait = tyrant9
		}
		remove_trait = tyrant9
		add_trait = tyrant10
	}
	if = {
		limit = {
			trait = tyrant8
		}
		remove_trait = tyrant8
		add_trait = tyrant9
	}
	if = {
		limit = {
			trait = tyrant7
		}
		remove_trait = tyrant7
		add_trait = tyrant8
	}
	if = {
		limit = {
			trait = tyrant6
		}
		remove_trait = tyrant6
		add_trait = tyrant7
	}
	if = {
		limit = {
			trait = tyrant5
		}
		remove_trait = tyrant5
		add_trait = tyrant6
	}
	if = {
		limit = {
			trait = tyrant4
		}
		remove_trait = tyrant4
		add_trait = tyrant5
	}
	if = {
		limit = {
			trait = tyrant3
		}
		remove_trait = tyrant3
		add_trait = tyrant4
	}
	if = {
		limit = {
			trait = tyrant2
		}
		remove_trait = tyrant2
		add_trait = tyrant3
	}
	if = {
		limit = {
			trait = tyrant1
		}
		remove_trait = tyrant1
		add_trait = tyrant2
	}
	if = {
		limit = {
			NOR = {
				trait = tyrant1
				trait = tyrant2
				trait = tyrant3
				trait = tyrant4
				trait = tyrant5
				trait = tyrant6
				trait = tyrant7
				trait = tyrant8
				trait = tyrant9
				trait = tyrant10
				trait = tyrant11
				trait = tyrant12
				trait = tyrant13
				trait = tyrant14
				trait = tyrant15
				trait = tyrant16
				trait = tyrant17
				trait = tyrant18
				trait = tyrant19
				trait = tyrant20
			}
		}
		add_trait = tyrant1
	}
}

tyrant_plus_2_effect = {
	if = {
		limit = {
			trait = tyrant19
		}
		remove_trait = tyrant19
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant18
		}
		remove_trait = tyrant18
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant17
		}
		remove_trait = tyrant17
		add_trait = tyrant19
	}
	if = {
		limit = {
			trait = tyrant16
		}
		remove_trait = tyrant16
		add_trait = tyrant18
	}
	if = {
		limit = {
			trait = tyrant15
		}
		remove_trait = tyrant15
		add_trait = tyrant17
	}
	if = {
		limit = {
			trait = tyrant14
		}
		remove_trait = tyrant14
		add_trait = tyrant16
	}
	if = {
		limit = {
			trait = tyrant13
		}
		remove_trait = tyrant13
		add_trait = tyrant15
	}
	if = {
		limit = {
			trait = tyrant12
		}
		remove_trait = tyrant12
		add_trait = tyrant14
	}
	if = {
		limit = {
			trait = tyrant11
		}
		remove_trait = tyrant11
		add_trait = tyrant13
	}
	if = {
		limit = {
			trait = tyrant10
		}
		remove_trait = tyrant10
		add_trait = tyrant12
	}
	if = {
		limit = {
			trait = tyrant9
		}
		remove_trait = tyrant9
		add_trait = tyrant11
	}
	if = {
		limit = {
			trait = tyrant8
		}
		remove_trait = tyrant8
		add_trait = tyrant10
	}
	if = {
		limit = {
			trait = tyrant7
		}
		remove_trait = tyrant7
		add_trait = tyrant9
	}
	if = {
		limit = {
			trait = tyrant6
		}
		remove_trait = tyrant6
		add_trait = tyrant8
	}
	if = {
		limit = {
			trait = tyrant5
		}
		remove_trait = tyrant5
		add_trait = tyrant7
	}
	if = {
		limit = {
			trait = tyrant4
		}
		remove_trait = tyrant4
		add_trait = tyrant6
	}
	if = {
		limit = {
			trait = tyrant3
		}
		remove_trait = tyrant3
		add_trait = tyrant5
	}
	if = {
		limit = {
			trait = tyrant2
		}
		remove_trait = tyrant2
		add_trait = tyrant4
	}
	if = {
		limit = {
			trait = tyrant1
		}
		remove_trait = tyrant1
		add_trait = tyrant3
	}
	if = {
		limit = {
			NOT = {
				trait = tyrant1
				trait = tyrant2
				trait = tyrant3
				trait = tyrant4
				trait = tyrant5
				trait = tyrant6
				trait = tyrant7
				trait = tyrant8
				trait = tyrant9
				trait = tyrant10
				trait = tyrant11
				trait = tyrant12
				trait = tyrant13
				trait = tyrant14
				trait = tyrant15
				trait = tyrant16
				trait = tyrant17
				trait = tyrant18
				trait = tyrant19
				trait = tyrant20
			}
		}
		add_trait = tyrant2
	}
}

tyrant_plus_4_effect = {
	if = {
		limit = {
			trait = tyrant19
		}
		remove_trait = tyrant19
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant18
		}
		remove_trait = tyrant18
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant17
		}
		remove_trait = tyrant17
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant16
		}
		remove_trait = tyrant16
		add_trait = tyrant20
	}
	if = {
		limit = {
			trait = tyrant15
		}
		remove_trait = tyrant15
		add_trait = tyrant19
	}
	if = {
		limit = {
			trait = tyrant14
		}
		remove_trait = tyrant14
		add_trait = tyrant18
	}
	if = {
		limit = {
			trait = tyrant13
		}
		remove_trait = tyrant13
		add_trait = tyrant17
	}
	if = {
		limit = {
			trait = tyrant12
		}
		remove_trait = tyrant12
		add_trait = tyrant16
	}
	if = {
		limit = {
			trait = tyrant11
		}
		remove_trait = tyrant11
		add_trait = tyrant15
	}
	if = {
		limit = {
			trait = tyrant10
		}
		remove_trait = tyrant10
		add_trait = tyrant14
	}
	if = {
		limit = {
			trait = tyrant9
		}
		remove_trait = tyrant9
		add_trait = tyrant13
	}
	if = {
		limit = {
			trait = tyrant8
		}
		remove_trait = tyrant8
		add_trait = tyrant12
	}
	if = {
		limit = {
			trait = tyrant7
		}
		remove_trait = tyrant7
		add_trait = tyrant11
	}
	if = {
		limit = {
			trait = tyrant6
		}
		remove_trait = tyrant6
		add_trait = tyrant10
	}
	if = {
		limit = {
			trait = tyrant5
		}
		remove_trait = tyrant5
		add_trait = tyrant9
	}
	if = {
		limit = {
			trait = tyrant4
		}
		remove_trait = tyrant4
		add_trait = tyrant8
	}
	if = {
		limit = {
			trait = tyrant3
		}
		remove_trait = tyrant3
		add_trait = tyrant7
	}
	if = {
		limit = {
			trait = tyrant2
		}
		remove_trait = tyrant2
		add_trait = tyrant6
	}
	if = {
		limit = {
			trait = tyrant1
		}
		remove_trait = tyrant1
		add_trait = tyrant5
	}
	if = {
		limit = {
			NOT = {
				trait = tyrant1
				trait = tyrant2
				trait = tyrant3
				trait = tyrant4
				trait = tyrant5
				trait = tyrant6
				trait = tyrant7
				trait = tyrant8
				trait = tyrant9
				trait = tyrant10
				trait = tyrant11
				trait = tyrant12
				trait = tyrant13
				trait = tyrant14
				trait = tyrant15
				trait = tyrant16
				trait = tyrant17
				trait = tyrant18
				trait = tyrant19
				trait = tyrant20
			}
		}
		add_trait = tyrant4
	}
}

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
					}
				}
			}
			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 = {
			region = custom_swabian
		}
		culture = swabian
	}
	if = {
		limit = {
			region = custom_bavarian
		}
		culture = bavarian
	}
	if = {
		limit = {
			region = custom_colognian
		}
		culture = colognian
	}		
	if = {
		limit = {
			region = custom_franconian
		}
		culture = franconian
	}
	if = {
		limit = {
			region = custom_swiss
		}
		culture = swiss
	}
	if = {
		limit = {
			region = custom_old_saxon
		}
		culture = old_saxon
	}
	if = {
		limit = {
			region = custom_thuringian
		}
		culture = thuringian
	}
}

culture_spread_effect = {
	any_courtier = {
		limit = {
			is_ruler = no
			prisoner = no
			dynasty = ROOT
			culture = german
		}
		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
	}
}

german_culture_spread_effect = {
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_swabian }
		}
		culture = swabian
	}
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_bavarian }
		}
		culture = bavarian
	}	
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_franconian }
		}
		culture = franconian
	}
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_swiss }
		}
		culture = swiss
	}
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_old_saxon }
		}
		culture = old_saxon
	}
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_thuringian }
		}
		culture = thuringian
	}
	if = {
		limit = {
			event_target:melting_pot_province = { region = custom_colognian }
		}
		culture = colognian
	}
	
	any_courtier = {
		limit = {
			is_ruler = no
			prisoner = no
			dynasty = ROOT
			culture = german
		}
		culture = PREV
	}
	event_target:melting_pot_province = {
		add_province_modifier = {
			name = recent_culture_change
			duration = -1
		}
		culture = PREV
		set_province_flag = melting_pot
	}
}

adjust_gender_law_effect = {
	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
	}
}

generate_daughters_early_bm_effect = {
	if = {
		limit = { NOT = { age = 35 } }
		create_character = {
			random_traits = yes
			age = 16
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 35
			NOT = { age = 38 }
		}
		create_character = {
			random_traits = yes
			age = 17
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 38
			NOT = { age = 41 }
		}
		create_character = {
			random_traits = yes
			age = 18
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 41
			NOT = { age = 44 }
		}
		create_character = {
			random_traits = yes
			age = 19
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 44
			NOT = { age = 47 }
		}
		create_character = {
			random_traits = yes
			age = 20
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 47
			NOT = { age = 50 }
		}
		create_character = {
			random_traits = yes
			age = 24
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 50
			NOT = { age = 53 }
		}
		create_character = {
			random_traits = yes
			age = 27
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 53
			NOT = { age = 56 }
		}
		create_character = {
			random_traits = yes
			age = 30
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 56
			NOT = { age = 59 }
		}
		create_character = {
			random_traits = yes
			age = 33
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 59
			NOT = { age = 62 }
		}
		create_character = {
			random_traits = yes
			age = 36
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 62
			NOT = { age = 65 }
		}
		create_character = {
			random_traits = yes
			age = 42
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 65
			NOT = { age = 68 }
		}
		create_character = {
			random_traits = yes
			age = 45
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 68
			NOT = { age = 72 }
		}
		create_character = {
			random_traits = yes
			age = 48
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = { age = 72 }
		create_character = {
			random_traits = yes
			age = 51
			female = yes
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
}

generate_sons_early_bm_effect = {
	if = {
		limit = { NOT = { age = 35 } }
		create_character = {
			random_traits = yes
			age = 16
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 35
			NOT = { age = 38 }
		}
		create_character = {
			random_traits = yes
			age = 17
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 38
			NOT = { age = 41 }
		}
		create_character = {
			random_traits = yes
			age = 18
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 41
			NOT = { age = 44 }
		}
		create_character = {
			random_traits = yes
			age = 19
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 44
			NOT = { age = 47 }
		}
		create_character = {
			random_traits = yes
			age = 20
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 47
			NOT = { age = 50 }
		}
		create_character = {
			random_traits = yes
			age = 24
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 50
			NOT = { age = 53 }
		}
		create_character = {
			random_traits = yes
			age = 27
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 53
			NOT = { age = 56 }
		}
		create_character = {
			random_traits = yes
			age = 30
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 56
			NOT = { age = 59 }
		}
		create_character = {
			random_traits = yes
			age = 33
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 59
			NOT = { age = 62 }
		}
		create_character = {
			random_traits = yes
			age = 36
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 62
			NOT = { age = 65 }
		}
		create_character = {
			random_traits = yes
			age = 42
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 65
			NOT = { age = 68 }
		}
		create_character = {
			random_traits = yes
			age = 45
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = {
			age = 68
			NOT = { age = 72 }
		}
		create_character = {
			random_traits = yes
			age = 48
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
	if = {
		limit = { age = 72 }
		create_character = {
			random_traits = yes
			age = 51
			female = no
			culture = ROOT
			religion = ROOT
			dynasty = ROOT
		}
	}
}

prov_prosperity_decrease_effect = {
	if = {
		limit = {
			has_dlc = "Reapers"
		}
		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 }
		character_event = { id = Plus.3758 }
	}
	if = {
		limit = { culture = danish }
		character_event = { id = Plus.3761 }
	}
	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
		}
		character_event = { id = Plus.3805 }
	}
	if = {
		limit = {
			culture = catalan
		}
		character_event = { id = Plus.3807 }
	}
	if = {
		limit = {
			culture = old_frankish
		}
		character_event = { id = Plus.3809 }
	}
	if = {
		limit = {
			culture = greek
		}
		character_event = { id = Plus.3811 }
	}
	if = {
		limit = {
			culture = russian
		}
		character_event = { id = Plus.3814 }
	}
	if = {
		limit = {
			culture = italian
		}
		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 }
	}
}