#	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 }
				is_pagan_religion = no
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# Prefer an existing heresy in the realm
	top_liege = {
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# Or one not far away
	random_independent_ruler = {
		limit = {
			any_realm_province = {
				is_heresy_of = ROOT
				ROOT = {
					location = {
						NOT = { distance = { where = PREVPREV value = 300 } }
					}
				}
			}
		}
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
				ROOT = {
					location = {
						NOT = { distance = { where = PREVPREV value = 300 } }
					}
				}
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# ...otherwise, just pick a heresy
	if = {
		limit = { religion_group = christian }
		if = {
			limit = {
				religion = chalcedonian
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_aquitaine }
							location = { region = custom_burgundy }
							culture = occitan
						}
					}
					modifier = {
						factor = 1.5
						culture = occitan
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_france }
							culture = frankish
						}
					}
					modifier = {
						factor = 1.5
						culture = frankish
					}
					religion = waldensian
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_brittania } }
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							NOR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = world_europe_west_iberia } }
					}
					modifier = {
						factor = 1.5
						culture_group = iberian
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = custom_bulgaria }
							location = { region = custom_croatia }
							location = { region = custom_serbia }
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}
					religion = bogomilist
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = world_middle_east }
							location = { region = custom_azerbaijan }
							location = { region = custom_persia }
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				75 = {
					modifier = {
						factor = 0
						location = {
							OR = {
								region = world_europe_west
								region = world_europe_north
								region = world_europe_south_italy
							}
						}
					}
					modifier = {
						factor = 0.25
						NOT = { location = { region = custom_byzantium } }
					}
					modifier = {
						factor = 1.5
						OR = {
							culture = greek
							culture = pontic_greek
						}
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
							culture = armenian
						}
					}
					religion = paulician
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.25
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				10 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = catholic
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_south_italy }
							is_italian_trigger = yes
						}
					}
					religion = fraticelli
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_aquitaine }
							location = { region = custom_burgundy }
							culture = occitan
						}
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe_west_brittania } }
					}		
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = custom_england }
							culture = english
						}
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_france }
							culture = frankish
						}
					}
					religion = waldensian
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe_west_iberia } }
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_south_east }
							location = { region = world_europe_east }
							location = { region = world_asia_minor }
							location = { region = world_middle_east_jerusalem }
						}
					}
					modifier = {
						factor = 0.35
						NOR = {
							location = { region = custom_byzantium }
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}
					religion = orthodox
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = orthodox
			}
			random_list = {
				50 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_bulgaria }
							location = { region = custom_croatia }
							location = { region = custom_serbia }
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_bulgaria }
					}
					religion = bogomilist
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { location = { region = custom_byzantium } }
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
							culture = armenian
						}
					}
					religion = paulician
				}
				50 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = custom_azerbaijan }
							location = { region = custom_persia }
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_middle_east }
							location = { region = world_asia_minor }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							location = { region = world_india }
							location = { region = world_steppe }
							location = { region = world_persia }
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = custom_armenia }
							location = { region = custom_georgia }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = custom_armenia }
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_middle_east }
							location = { region = world_africa }
						}
					}
					modifier = {
						factor = 1.5
						location = { region = world_africa_east }
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_persia }
							location = { region = world_steppe_east }
							location = { region = world_steppe_tarim }
							location = { region = world_middle_east_arabia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_europe_west }
							location = { region = world_europe_north }
							location = { region = world_europe_south_italy }
							location = { region = custom_croatia }
							location = { region = custom_poland }
							location = { region = custom_carpathia }
						}
					}
					religion = catholic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							location = { region = world_middle_east_jerusalem }
							culture_group = israelite
							trait = sympathy_judaism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_judaism
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = nestorian
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_india }
							location = { region = world_middle_east }
							location = { region = world_steppe }
							location = { region = world_persia }
							trait = sympathy_zoroastrianism
						}
					}
					modifier = {
						factor = 2
						trait = sympathy_zoroastrianism
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							location = { region = world_africa }
							location = { region = world_middle_east }
						}
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOT = {
							location = { region = world_asia_minor }
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOT = { location = { region = world_europe } }
					}
					if = {
						limit = { 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 }
			is_pagan_religion = no
		}
		ROOT = { religion = PREV }
		break = yes
	}
	# Prefer an existing heresy in the realm
	owner = {
		top_liege = {
			random_realm_province = {
				limit = {
					is_heresy_of = ROOT
					ROOT = { NOT = { has_province_flag = found_heresy } }
				}
				ROOT = { religion = PREV }
				break = yes
			}
		}
	}
	# Or one not far away
	random_independent_ruler = {
		limit = {
			any_realm_province = {
				is_heresy_of = ROOT
				NOT = { distance = { where = ROOT value = 300 } }
			}
		}
		random_realm_province = {
			limit = {
				is_heresy_of = ROOT
				NOT = { distance = { where = ROOT value = 300 } }
			}
			ROOT = { religion = PREV }
			break = yes
		}
	}
	# ...otherwise, just pick a heresy
	if = {
		limit = { religion_group = christian }
		if = {
			limit = {
				religion = chalcedonian
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}
					modifier = {
						factor = 1.5
						culture = occitan
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_france
							culture = frankish
						}
					}
					modifier = {
						factor = 1.5
						culture = frankish
					}
					religion = waldensian
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_brittania }
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = world_europe_west_iberia }
					}
					modifier = {
						factor = 1.5
						culture_group = iberian
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						region = custom_bulgaria
					}
					religion = bogomilist
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				75 = {
					modifier = {
						factor = 0
						OR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
						}
					}
					modifier = {
						factor = 0.25
						NOT = { region = custom_byzantium }
					}
					modifier = {
						factor = 1.5
						OR = {
							culture = greek
							culture = pontic_greek
						}
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}
					religion = paulician
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.25
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				10 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = catholic
			}
			random_list = {
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_south_italy
							is_italian_trigger = yes
						}
					}
					religion = fraticelli
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_aquitaine
							region = custom_burgundy
							culture = occitan
						}
					}
					religion = cathar
				}
				75 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe_west_brittania }
					}		
					modifier = {
						factor = 0.5
						NOR = {
							region = custom_england
							culture = english
						}
					}
					religion = lollard
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_france
							culture = frankish
						}
					}
					religion = waldensian
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe_west_iberia }
					}
					religion = adoptionist
				}
				75 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_south_east
							region = world_europe_east
							region = world_asia_minor
							region = world_middle_east_jerusalem
						}
					}
					modifier = {
						factor = 0.35
						NOR = {
							region = custom_byzantium
							culture_group = byzantine
							culture_group = east_slavic
							culture_group = south_slavic
						}
					}
					religion = orthodox
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = orthodox
			}
			random_list = {
				50 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_bulgaria
							region = custom_croatia
							region = custom_serbia
							culture_group = south_slavic
						}
					}
					modifier = {
						factor = 1.5
						region = custom_bulgaria
					}
					religion = bogomilist
				}
				50 = {
					modifier = {
						factor = 0
						NOT = { region = custom_byzantium }
					}
					religion = iconoclast
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
							culture = armenian
						}
					}
					religion = paulician
				}
				50 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = custom_azerbaijan
							region = custom_persia
							culture_group = arabic
						}
					}
					religion = monothelite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_steppe
							region = world_middle_east
							region = world_asia_minor
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						NOR = {
							region = world_india
							region = world_steppe
							region = world_persia
						}
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = nestorian
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_middle_east
							region = world_africa
						}
					}
					modifier = {
						factor = 1.5
						region = world_africa_east
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = custom_armenia
							region = custom_georgia
						}
					}
					modifier = {
						factor = 1.5
						region = custom_armenia
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_persia
							region = world_steppe_east
							region = world_steppe_tarim
							region = world_middle_east_arabia
						}
					}
					modifier = {
						factor = 0.5
						year = 1100
					}
					modifier = {
						factor = 0.5
						year = 1200
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_europe_west
							region = world_europe_north
							region = world_europe_south_italy
							region = custom_croatia
							region = custom_poland
							region = custom_carpathia
						}
					}
					religion = catholic
				}
				25 = {
					modifier = {
						factor = 0.1
						NOR = {
							region = world_middle_east_jerusalem
							culture_group = israelite
						}
					}
					religion = jewish
				}
				25 = {
					become_heretic = yes
				}
			}
			break = yes
		}
		if = {
			limit = {
				religion = nestorian
			}
			random_list = {
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_india
							region = world_middle_east
							region = world_steppe
							region = world_persia
						}
					}
					religion = manichean
				}
				25 = {
					modifier = {
						factor = 0
						NOR = {
							region = world_africa
							region = world_middle_east
						}
					}
					religion = miaphysite
				}
				25 = {
					modifier = {
						factor = 0
						NOT = {
							region = world_asia_minor
						}
					}
					religion = apostolic
				}
				25 = {
					modifier = {
						factor = 0
						NOT = { region = world_europe }
					}
					if = {
						limit = { 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
	}
}

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 }
			NOT = { religion = bogomilist }
		}
		set_government_type = imperial_government
	}
	if = {
		limit = { religion = bogomilist }
		set_government_type = imperial_bogomilist_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
				}
			}
		}
	}
}

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 = { has_global_flag = gender_equality }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = cognatic_succession } }
		add_law = cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = true_cognatic_succession } }
		add_law = true_cognatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = agnatic_succession } }
		add_law = agnatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_succession } }
		add_law = enatic_succession
		break = yes
	}
	if = {
		limit = { event_target:liege_primary_title = { has_law = enatic_cognatic_succession } }
		add_law = enatic_cognatic_succession
		break = yes
	}
}

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

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

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

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

# Roll a random congenital trait. If it succeeds repeat until it fails

generate_potential_congenital_trait = {
	random_list = {
		95 = {}
		5 = {
			random_list = {
				5 = { add_trait = genius }
				15 = { add_trait = quick }
				15 = { add_trait = slow }
				5 = { add_trait = imbecile }
				10 = { add_trait = fair }
				10 = { add_trait = ugly }
				15 = { add_trait = tall }
				5 = { add_trait = dwarf }
				10 = { add_trait = strong }
				10 = { add_trait = weak }
			}
			generate_potential_congenital_trait = yes
		}
	}
}

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

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

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

israel_culture_religion_effect = { # Convert to ROOT's religion and a culture based on FROM's origin
	religion = ROOT
	if = { # Culture depends on Origin
		limit = { # Ashkenazi
			FROM = {
				location = {
					OR = {
						region = world_europe_west_germania
						region = world_europe_east
						region = world_europe_west_brittania
						region = world_europe_south_east
					}
				}
			}
		}
		culture = ashkenazi
	}
	if = { # Sephardi
		limit = {
			FROM = {
				location = {
					OR = {
						region = world_europe_west_iberia
						region = world_africa_north
						region = world_europe_west_francia
						region = custom_roman_italia
						region = world_africa_west
					}
				}
			}
		}
		culture = sephardi
	}
	if = { # Mizrahim
		limit = {
			FROM = {
				location = {
					NOR = {
						region = world_europe_west_germania
						region = world_europe_east
						region = world_europe_west_brittania
						region = world_europe_south_east
						region = world_europe_west_iberia
						region = world_africa_north
						region = world_europe_west_francia
						region = custom_roman_italia
						region = world_africa_west
					}
				}
			}
		}
		culture = mizrahim
	}
}

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

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

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

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

			### Intrigue ###
			amateurish_plotter = {
				remove_trait = amateurish_plotter
			}
			flamboyant_schemer = {
				remove_trait = flamboyant_schemer
				add_trait = amateurish_plotter 
			}
			intricate_webweaver = {
				remove_trait = intricate_webweaver
				add_trait = flamboyant_schemer 
			}
			elusive_shadow = {
				remove_trait = elusive_shadow
				add_trait = intricate_webweaver 
			}
			
			### Diplomacy ###
			naive_appeaser = {
				remove_trait = naive_appeaser
			}
			underhanded_rogue = {
				remove_trait = underhanded_rogue
				add_trait = naive_appeaser 
			}
			charismatic_negotiator = {
				remove_trait = charismatic_negotiator
				add_trait = underhanded_rogue 
			}
			grey_eminence = {
				remove_trait = grey_eminence
				add_trait = charismatic_negotiator 
			}

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

			### Martial ###
			misguided_warrior = {
				remove_trait = misguided_warrior
			}
			tough_soldier = {
				remove_trait = tough_soldier
				add_trait = misguided_warrior 
			}
			skilled_tactician = {
				remove_trait = skilled_tactician
				add_trait = tough_soldier 
			}
			brilliant_strategist = {
				remove_trait = brilliant_strategist
				add_trait = skilled_tactician 
			}
			
			### Learning ###
			detached_priest = {
				remove_trait = detached_priest
			}
			martial_cleric = {
				remove_trait = martial_cleric
				add_trait = detached_priest 
			}
			scholarly_theologian = {
				remove_trait = scholarly_theologian
				add_trait = martial_cleric 
			}
			mastermind_theologian = {
				remove_trait = mastermind_theologian
				add_trait = scholarly_theologian 
			}
		}
	}
}

upgrade_education_intrigue_effect = {
	trigger_switch = {
		on_trigger = trait

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

upgrade_education_diplomacy_effect = {
	trigger_switch = {
		on_trigger = trait

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

upgrade_education_stewarship_effect = {
	trigger_switch = {
		on_trigger = trait

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

upgrade_education_martial_effect = {
	trigger_switch = {
		on_trigger = trait

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

upgrade_education_learning_effect = {
	trigger_switch = {
		on_trigger = trait
		
		### Learning ###
		detached_priest = {
			remove_trait = detached_priest
			add_trait = martial_cleric
		}
		martial_cleric = {
			remove_trait = martial_cleric
			add_trait = scholarly_theologian 
		}
		scholarly_theologian = {
			remove_trait = scholarly_theologian
			add_trait = mastermind_theologian 
		}
		mastermind_theologian = {
			# already maxed
		}
	}
}

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

remove_do_not_disturb_effect = {
	remove_character_modifier = do_not_disturb
	clr_character_flag = do_not_disturb
}

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

remove_court_educator_effect = {
	if = {
		limit = { has_dlc = "Zeus"} 
		remove_title = title_teacher
	}
	if = {
		limit = { NOT = { has_dlc = "Zeus"} }
		remove_title = title_court_educator
	}
}

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

#in character scope
default_succession_effect = {
	if = { # Elective Gavelkind
		limit = {
			is_offmap_trigger = no
			NOT = { religion = celtic_pagan }
			PREV = { NOT = { has_law = succ_elective_gavelkind } }
			OR = {
				is_feudal = yes
				is_tribal = yes
			}
			elective_gavelkind_culture_trigger = yes
		}
		PREV = {
			add_law = {
				law = succ_elective_gavelkind
				cooldown = no
				opinion_effect = no
			}
		}
	}			
	if = { # Seniority
		limit = {
			is_offmap_trigger = no
			PREV = { NOT = { has_law = succ_seniority } }
			OR = {
				is_republic = no
				is_patrician = yes
			}
			OR = {
				is_feudal = yes
				is_patrician = yes
			}
			seniority_culture_trigger = yes
		}
		PREV = {
			add_law = {
				law = succ_seniority
				cooldown = no
				opinion_effect = no
			}
		}
	}
	if = { # Tanistry
		limit = {
			is_offmap_trigger = no
			PREV = { NOT = { has_law = succ_tanistry } }
			OR = {
				is_feudal = yes
				is_tribal = yes
			}
			OR = {
				culture_group = celtic
				religion = celtic_pagan
			}
		}
		PREV = {
			add_law = {
				law = succ_tanistry
				cooldown = no
				opinion_effect = no
			}
		}
	}
	if = { # Late Medieval Primogeniture
		limit = {
			is_offmap_trigger = no
			is_feudal = yes
			OR = {
				year = 1150
				total_years_played = 300
			}
			NOR = {
				has_law = succ_tanistry
				has_law = succ_seniority
				has_law = succ_elective_gavelkind
				has_law = succ_primogeniture
				has_law = succ_feudal_elective
				has_law = succ_appointment
				has_law = succ_catholic_bishopric
				has_law = succ_turkish_succession
				has_law = succ_ultimogeniture
			}					
			capital_scope = { TECH_LEGALISM = 3 }
		}
		PREV = {
			add_law = {
				law = succ_primogeniture
				cooldown = no
				opinion_effect = no
			}
		}
	}
	if = { # Late Medieval Elective
		limit = {
			is_offmap_trigger = no
			is_feudal = yes
			OR = {
				year = 1150
				total_years_played = 300
			}
			has_law = succ_elective_gavelkind
			capital_scope = { TECH_LEGALISM = 3 }
		}
		PREV = {
			add_law = {
				law = succ_feudal_elective
				cooldown = no
				opinion_effect = no
			}
		}
	}
	if = { # Default primo cultures + imperial gov
		limit = {
			is_feudal = yes
			NOR = {
				has_law = succ_tanistry
				has_law = succ_seniority
				has_law = succ_elective_gavelkind
				has_law = succ_primogeniture
				has_law = succ_feudal_elective
				has_law = succ_appointment
				has_law = succ_catholic_bishopric
				has_law = succ_turkish_succession
				has_law = succ_ultimogeniture
			}
			OR = {
				has_imperial_government_trigger = yes
				primogeniture_culture_trigger = yes
			}
			
		}
		PREV = {
			add_law = {
				law = succ_primogeniture
				cooldown = no
				opinion_effect = no
			}
		}
	}
}