###########
#Plus Faction Goals:
#
#Total = 7
###########

# Court faction: desires more power for vassals
faction_court = {
	type = character

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes # Need a barony/county so they can potentially rebel- just a family palace doesn't count, had problems with these kind of patricians revolting
		is_adult = yes
		independent = no
		is_nomadic = no
		prisoner = no
		holy_order = no
		is_incapable = no
		in_revolt = no

		liege = {
			is_nomadic = no
			in_revolt = no
			NOT = { has_character_flag = faction_court_war }
		}

		trigger_if = {
			limit = { has_character_flag = former_faction_leader }

			had_character_flag = {
				flag = former_faction_leader
				days >= 7
			}
		}

		primary_title = {
			is_primary_type_title = no # Why?
		}

		NOR = {
			in_faction = faction_prosperity
			in_faction = faction_glory
			in_faction = faction_tradition
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }

			any_faction_backer = {
				in_faction = faction_court
				higher_real_tier_than = ROOT
				NOT = { has_character_flag = removed_from_leadership }
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			independent = no
			is_nomadic = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			NOR = {
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}

			trigger_if = {
				limit = {
					OR = {
						AND = {
							is_inaccessible_trigger = yes
							NOT = { in_faction = faction_court }
						}

						in_faction = faction_prosperity
						in_faction = faction_glory
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war
			}
		}
	}

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 200

		trigger = {
			FROM = {
				prisoner = no
				in_seclusion = no

				NOR = {
					is_heir = liege
					any_heir_title = { title = ROOT }
					rightful_religious_head = THIS
				}
			}
		}

		faction_court_start_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			FROM = { in_faction = faction_court }
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_modifier = {
			value = 1000

			FROM = {
				trigger_if = {
					limit = { real_tier = KING }
					liege = { real_tier = EMPEROR }
				}
				trigger_else = {
					real_tier = DUKE
					liege = { real_tier = KING }
				}
			}
		}

		additive_modifier = {
			value = -150

			FROM = {
				OR = {
					is_republic = yes
					is_theocracy = yes
				}
			}
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			FROM = {
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
				}
			}
		}

		additive_modifier = {
			value = 300

			FROM = {
				OR = {
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}

		additive_modifier = {
			value = 150
			FROM = { trait = ambitious }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = proud }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = gluttonous }
		}

		additive_modifier = {
			value = 150
			FROM = { has_lifestyle_intrigue_trigger = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = content }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = humble }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = temperate }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100

		trigger = {
			trigger_if = {
				limit = {
					OR = {
						in_faction = faction_prosperity
						in_faction = faction_glory
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war

				FROM = {
					has_character_flag = civil_war_faction_leader
					pf_not_regular_faction_war_trigger = no
				}
			}

			NOR = {
				is_heir = liege
				rightful_religious_head = THIS
			}
		}

		faction_court_join_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			in_faction = faction_court
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_opinion_modifier = {
			factor = 0.75
			this = ROOT
			who = FROM
		}

		additive_modifier = {
			value = -150

			OR = {
				is_republic = yes
				is_theocracy = yes
			}
		}

		additive_modifier = {
			value = 1000
			has_character_flag = will_join_civil_war
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			OR = {
				trait = amateurish_plotter
				trait = flamboyant_schemer
			}
		}

		additive_modifier = {
			value = 300

			OR = {
				trait = intricate_webweaver
				trait = elusive_shadow
			}
		}

		additive_modifier = {
			value = 150
			trait = ambitious
		}

		additive_modifier = {
			value = 150
			trait = proud
		}

		additive_modifier = {
			value = 150
			trait = gluttonous
		}

		additive_modifier = {
			value = 150
			has_lifestyle_intrigue_trigger = yes
		}

		additive_modifier = {
			value = -150
			trait = content
		}

		additive_modifier = {
			value = -150
			trait = humble
		}

		additive_modifier = {
			value = -150
			trait = charitable
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}

# Prosperity faction: desires wealth and a healthy economy
faction_prosperity = {
	type = character

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes # Need a barony/county so they can potentially rebel- just a family palace doesn't count, had problems with these kind of patricians revolting
		is_adult = yes
		independent = no
		is_nomadic = no
		prisoner = no
		holy_order = no
		is_incapable = no
		in_revolt = no

		liege = {
			is_nomadic = no
			in_revolt = no
			NOT = { has_character_flag = faction_prosperity_war }
		}

		trigger_if = {
			limit = { has_character_flag = former_faction_leader }

			had_character_flag = {
				flag = former_faction_leader
				days >= 7
			}
		}

		primary_title = {
			is_primary_type_title = no # Why?
		}

		NOR = {
			in_faction = faction_court
			in_faction = faction_glory
			in_faction = faction_tradition
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }

			any_faction_backer = {
				in_faction = faction_prosperity
				higher_real_tier_than = ROOT
				NOT = { has_character_flag = removed_from_leadership }
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			independent = no
			is_nomadic = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			NOR = {
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}

			trigger_if = {
				limit = {
					OR = {
						AND = {
							is_inaccessible_trigger = yes
							NOT = { in_faction = faction_court }
						}

						in_faction = faction_court
						in_faction = faction_glory
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war
			}
		}
	}

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 200

		trigger = {
			FROM = {
				prisoner = no
				in_seclusion = no

				NOR = {
					is_heir = liege
					any_heir_title = { title = ROOT }
					rightful_religious_head = THIS
				}
			}
		}

		faction_prosperity_start_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			FROM = { in_faction = faction_prosperity }
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_modifier = {
			value = 1000

			FROM = {
				trigger_if = {
					limit = { real_tier = KING }
					liege = { real_tier = EMPEROR }
				}
				trigger_else = {
					real_tier = DUKE
					liege = { real_tier = KING }
				}
			}
		}

		additive_modifier = {
			value = 300
			FROM = { is_republic = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { is_theocracy = yes }
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			FROM = {
				OR = {
					trait = indulgent_wastrel
					trait = thrifty_clerk
				}
			}
		}

		additive_modifier = {
			value = 300

			FROM = {
				OR = {
					trait = fortune_builder
					trait = midas_touched
				}
			}
		}

		additive_modifier = {
			value = 200
			FROM = { trait = greedy }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = diligent }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = envious }
		}

		additive_modifier = {
			value = 150
			FROM = { has_lifestyle_stewardship_trigger = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = charitable }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = slothful }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = kind }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100

		trigger = {
			trigger_if = {
				limit = {
					OR = {
						in_faction = faction_court
						in_faction = faction_glory
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war

				FROM = {
					has_character_flag = civil_war_faction_leader
					pf_not_regular_faction_war_trigger = no
				}
			}

			NOR = {
				is_heir = liege
				rightful_religious_head = THIS
			}
		}

		faction_prosperity_join_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			in_faction = faction_prosperity
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_opinion_modifier = {
			factor = 0.75
			this = ROOT
			who = FROM
		}

		additive_modifier = {
			value = 1000
			has_character_flag = will_join_civil_war
		}

		additive_modifier = {
			value = 300
			is_republic = yes
		}

		additive_modifier = {
			value = -150
			is_theocracy = yes
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			OR = {
				trait = indulgent_wastrel
				trait = thrifty_clerk
			}
		}

		additive_modifier = {
			value = 300

			OR = {
				trait = fortune_builder
				trait = midas_touched
			}
		}

		additive_modifier = {
			value = 200
			trait = greedy
		}

		additive_modifier = {
			value = 150
			trait = diligent
		}

		additive_modifier = {
			value = 150
			trait = envious
		}

		additive_modifier = {
			value = 150
			has_lifestyle_stewardship_trigger = yes
		}

		additive_modifier = {
			value = -150
			trait = charitable
		}

		additive_modifier = {
			value = -150
			trait = slothful
		}

		additive_modifier = {
			value = -150
			trait = kind
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}

# Glory faction: desires prestige and the spoils of war
faction_glory = {
	type = character

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes # Need a barony/county so they can potentially rebel- just a family palace doesn't count, had problems with these kind of patricians revolting
		is_adult = yes
		independent = no
		is_nomadic = no
		prisoner = no
		holy_order = no
		is_incapable = no
		in_revolt = no

		liege = {
			is_nomadic = no
			in_revolt = no
			NOT = { has_character_flag = faction_glory_war }
		}

		trigger_if = {
			limit = { has_character_flag = former_faction_leader }

			had_character_flag = {
				flag = former_faction_leader
				days >= 7
			}
		}

		primary_title = {
			is_primary_type_title = no # Why?
		}

		NOR = {
			in_faction = faction_court
			in_faction = faction_prosperity
			in_faction = faction_tradition
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }

			any_faction_backer = {
				in_faction = faction_glory
				higher_real_tier_than = ROOT
				NOT = { has_character_flag = removed_from_leadership }
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			independent = no
			is_nomadic = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			NOR = {
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}

			trigger_if = {
				limit = {
					OR = {
						AND = {
							is_inaccessible_trigger = yes
							NOT = { in_faction = faction_court }
						}

						in_faction = faction_court
						in_faction = faction_prosperity
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war
			}
		}
	}

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 200

		trigger = {
			FROM = {
				prisoner = no
				in_seclusion = no

				NOR = {
					is_heir = liege
					any_heir_title = { title = ROOT }
					rightful_religious_head = THIS
				}
			}
		}

		faction_glory_start_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			FROM = { in_faction = faction_glory }
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_modifier = {
			value = 1000

			FROM = {
				trigger_if = {
					limit = { real_tier = KING }
					liege = { real_tier = EMPEROR }
				}
				trigger_else = {
					real_tier = DUKE
					liege = { real_tier = KING }
				}
			}
		}

		additive_modifier = {
			value = -150

			FROM = {
				OR = {
					is_republic = yes
					is_theocracy = yes
				}
			}
		}

		additive_modifier = {
			value = -200
			FROM = { pacifist = yes }
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			FROM = {
				OR = {
					trait = misguided_warrior
					trait = tough_soldier
					trait = poor_warrior
					trait = trained_warrior
				}
			}
		}

		additive_modifier = {
			value = 300

			FROM = {
				OR = {
					trait = skilled_tactician
					trait = brilliant_strategist
					trait = skilled_warrior
					trait = master_warrior
				}
			}
		}

		additive_modifier = {
			value = 200

			FROM = {
				OR = {
					trait = viking
					trait = berserker
				}
			}
		}

		additive_modifier = {
			value = 150
			FROM = { has_crusade_trait_trigger = yes }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = brave }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = wroth }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = cruel }
		}

		additive_modifier = {
			value = 150
			FROM = { has_lifestyle_martial_trigger = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = craven }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = patient }
		}

		additive_modifier = {
			value = -150
			FROM = {  trait = kind }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100

		trigger = {
			trigger_if = {
				limit = {
					OR = {
						in_faction = faction_court
						in_faction = faction_prosperity
						in_faction = faction_tradition
					}
				}

				has_character_flag = will_join_civil_war

				FROM = {
					has_character_flag = civil_war_faction_leader
					pf_not_regular_faction_war_trigger = no
				}
			}

			NOR = {
				is_heir = liege
				rightful_religious_head = THIS
			}
		}

		faction_glory_join_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			in_faction = faction_glory
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_opinion_modifier = {
			factor = 0.75
			this = ROOT
			who = FROM
		}

		additive_modifier = {
			value = -150

			OR = {
				is_republic = yes
				is_theocracy = yes
			}
		}

		additive_modifier = {
			value = -200
			pacifist = yes
		}

		additive_modifier = {
			value = 1000
			has_character_flag = will_join_civil_war
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			OR = {
				trait = misguided_warrior
				trait = tough_soldier
				trait = poor_warrior
				trait = trained_warrior
				martial >= 15
			}
		}

		additive_modifier = {
			value = 300

			OR = {
				trait = skilled_tactician
				trait = brilliant_strategist
				trait = skilled_warrior
				trait = master_warrior
			}
		}

		additive_modifier = {
			value = 200

			OR = {
				trait = viking
				trait = berserker
			}
		}

		additive_modifier = {
			value = 150
			has_crusade_trait_trigger = yes
		}

		additive_modifier = {
			value = 150
			trait = brave
		}

		additive_modifier = {
			value = 150
			trait = wroth
		}

		additive_modifier = {
			value = 150
			trait = cruel
		}

		additive_modifier = {
			value = 150
			has_lifestyle_martial_trigger = yes
		}

		additive_modifier = {
			value = -150
			trait = craven
		}

		additive_modifier = {
			value = -150
			trait = patient
		}

		additive_modifier = {
			value = -150
			trait = kind
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}

# Tradition faction: desires piety and support for religion
faction_tradition = {
	type = character

	# Plotter scope
	potential = {
		is_playable = yes
		religion = liege
		is_landed = yes # Need a barony/county so they can potentially rebel- just a family palace doesn't count, had problems with these kind of patricians revolting
		is_adult = yes
		independent = no
		is_nomadic = no
		prisoner = no
		holy_order = no
		is_incapable = no
		in_revolt = no

		liege = {
			is_nomadic = no
			in_revolt = no
			NOT = { has_character_flag = faction_tradition_war }
		}

		trigger_if = {
			limit = { has_character_flag = former_faction_leader }

			had_character_flag = {
				flag = former_faction_leader
				days >= 7
			}
		}

		primary_title = {
			is_primary_type_title = no # Why?
		}

		NOR = {
			trait = excommunicated
			in_faction = faction_court
			in_faction = faction_glory
			in_faction = faction_prosperity
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }

			any_faction_backer = {
				in_faction = faction_tradition
				higher_real_tier_than = ROOT
				NOT = { has_character_flag = removed_from_leadership }
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			independent = no
			is_nomadic = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			NOR = {
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}

			trigger_if = {
				limit = {
					OR = {
						AND = {
							is_inaccessible_trigger = yes
							NOT = { in_faction = faction_court }
						}

						in_faction = faction_court
						in_faction = faction_glory
						in_faction = faction_prosperity
						NOT = { religion = liege }
						trait = excommunicated
					}
				}

				has_character_flag = will_join_civil_war
			}
		}
	}

	# AI creation weight (ROOT = title, FROM = faction creator)
	chance = {
		factor = 200

		trigger = {
			FROM = {
				prisoner = no
				in_seclusion = no

				NOR = {
					trait = cynical
					trait = excommunicated
					is_heir = liege
					any_heir_title = { title = ROOT }
					rightful_religious_head = THIS
				}
			}
		}

		faction_tradition_start_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			FROM = { in_faction = faction_tradition }
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_modifier = {
			value = 1000

			FROM = {
				trigger_if = {
					limit = { real_tier = KING }
					liege = { real_tier = EMPEROR }
				}
				trigger_else = {
					real_tier = DUKE
					liege = { real_tier = KING }
				}
			}
		}

		additive_modifier = {
			value = 300
			FROM = { is_theocracy = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { is_republic = yes }
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			FROM = {
				OR = {
					trait = detached_priest
					trait = dutiful_cleric
				}
			}
		}

		additive_modifier = {
			value = 300

			FROM = {
				OR = {
					trait = scholarly_theologian
					trait = mastermind_theologian
				}
			}
		}

		additive_modifier = {
			value = 300
			FROM = { trait = zealous }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = content }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = humble }
		}

		additive_modifier = {
			value = 150
			FROM = { trait = temperate }
		}

		additive_modifier = {
			value = 150
			FROM = { has_lifestyle_learning_trigger = yes }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = ambitious }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = proud }
		}

		additive_modifier = {
			value = -150
			FROM = { trait = gluttonous }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 100

		trigger = {
			trigger_if = {
				limit = {
					OR = {
						trait = cynical
						trait = excommunicated
					}
				}

				has_character_flag = will_join_civil_war
			}

			trigger_if = {
				limit = {
					OR = {
						in_faction = faction_court
						in_faction = faction_prosperity
						in_faction = faction_glory
					}
				}

				has_character_flag = will_join_civil_war

				FROM = {
					has_character_flag = civil_war_faction_leader
					pf_not_regular_faction_war_trigger = no
				}
			}

			NOR = {
				is_heir = liege
				rightful_religious_head = THIS
			}
		}

		faction_tradition_join_score = yes

		# More likely to stay in the same faction for a while
		additive_modifier = {
			value = 500
			in_faction = faction_tradition
		}

		# Never leave during faction meetings
		additive_modifier = {
			value = 10000
			FROM = { has_character_flag = faction_meeting_begun }
		}

		additive_opinion_modifier = {
			factor = 0.75
			this = ROOT
			who = FROM
		}

		additive_modifier = {
			value = 1000
			has_character_flag = will_join_civil_war
		}

		additive_modifier = {
			value = 300
			is_theocracy = yes
		}

		additive_modifier = {
			value = -50
			is_republic = yes
		}

		# Personality reasons
		additive_modifier = {
			value = 150

			OR = {
				trait = detached_priest
				trait = dutiful_cleric
			}
		}

		additive_modifier = {
			value = 300

			OR = {
				trait = scholarly_theologian
				trait = mastermind_theologian
			}
		}

		additive_modifier = {
			value = 300
			trait = zealous
		}

		additive_modifier = {
			value = 150
			trait = content
		}

		additive_modifier = {
			value = 150
			trait = humble
		}

		additive_modifier = {
			value = 150
			trait = temperate
		}

		additive_modifier = {
			value = 150
			has_lifestyle_learning_trigger = yes
		}

		additive_modifier = {
			value = -150
			trait = ambitious
		}

		additive_modifier = {
			value = -150
			trait = proud
		}

		additive_modifier = {
			value = -150
			trait = gluttonous
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}

# Separatist faction, forms purely for the purpose of waging an independence war
faction_separatist = {
	type = character

	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		is_adult = yes
		faction_council_trigger = yes
		independent = no
		is_patrician = no # No independence factions in merchant republics
		mercenary = no
		holy_order = no
		in_revolt = no
		is_incapable = no

		NOR = {
			has_non_aggression_pact_with = liege
			has_truce = liege
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			has_landed_title = k_orthodox
			has_character_modifier = faction_independence_ultimatum_timer
		}

		trigger_if = {
			limit = { ai = yes }

			OR = {
				is_feudal = yes
				is_tribal = yes
				is_nomadic = yes
				higher_real_tier_than = COUNT
			}
		}

		liege = {
			independent = yes
			in_revolt = no

			NOR = {
				has_character_flag = faction_separatist_war
			}

			# Mongols and Aztecs do not have independence revolt problems before 1350
			trigger_if = {
				limit = { has_horde_culture = yes }

				NAND = {
					year < 1350
					culture = ROOT
					religion = ROOT
				}
			}

			# Not allowed to start factions like this if our capital borders the liege's capital
			NOT = {
				capital_scope = {
					any_neighbor_province = {
						ROOT = {
							capital_scope = { province = PREVPREV }
						}
					}
				}
			}
		}

		# Can't join factions when in blood oath with liege
		trigger_if = {
			limit = { is_nomadic = yes }
			NOT = { has_blood_oath_with = liege }
		}
	}

	# Target scope
	allow = {
		prisoner = no

		trigger_if = {
			limit = { is_nomadic = yes }

			clan_opinion = {
				who = liege
				value < 0
			}
		}

		NOT = {
			has_opinion_modifier = {
				name = opinion_coerced_into_leaving_faction
				who = liege
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			faction_council_trigger = yes
			independent = no
			is_patrician = no # No independence factions in merchant republics
			mercenary = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			trigger_if = {
				limit = { is_inaccessible_trigger = yes }
				in_faction = faction_separatist
			}

			NOR = {
				has_truce = liege
				has_non_aggression_pact_with = liege
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
				has_landed_title = k_orthodox
				has_character_modifier = faction_independence_ultimatum_timer
			}

			# Can't join factions when in blood oath with liege
			trigger_if = {
				limit = { is_nomadic = yes }

				NOT = { has_blood_oath_with = liege }

				clan_opinion = {
					who = liege
					value < 0
				}
			}
		}
	}

	# AI creation weight (ROOT = faction creator, FROM = target)
	chance = {
		factor = 8

		trigger = {
			war = no
			preparing_invasion = no
			prisoner = no
			in_seclusion = no

			NOR = {
				leads_faction = faction_religious
				is_primary_heir  = liege
			}

			opinion = {
				who = liege
				value < 40
			}

			# Not at all if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
			NAND = {
				lower_real_tier_than = KING
				is_not_unreformed_pagan_trigger = yes
				capital_scope = { has_province_flag = contingent_territory }

				liege = {
					religion = ROOT
					compare_cultures_ROOT_trigger = yes
					de_jure_vassal_or_below = ROOT
					over_vassal_limit <= 0

					NOR = {
						has_law = taifa_law_0
						has_law = taifa_law_1
					}
				}
			}

			# Avoid joining faction if independence would put me beside a stronger neighbor eligible for holy war
			NOT = {
				any_neighbor_independent_ruler = {
					shares_realm_border_with = ROOT
					higher_real_tier_than = ROOT

					trigger_if = {
						limit = { religion_group = ROOT }

						OR = {
							is_heresy_of = ROOT
							is_parent_religion = ROOT

							trigger_if = {
								limit = { religion_group = muslim }
								NOT = { religion = ROOT }
							}
						}
					}
				}
			}

			# Try to exclude people who should rather support a claimant
			NAND = {
				lower_real_tier_than = KING

				liege = {
					NAND  = {
						religion = ROOT
						culture = ROOT
					}

					any_demesne_title = {
						OR = {
							is_primary_holder_title = yes
							higher_real_tier_than = DUKE
						}

						ROOT = {
							primary_title = { de_jure_liege_or_above = PREVPREV }
						}

						any_claimant = {
							compare_cultures_ROOT_trigger = yes
							religion = ROOT
							dynasty = ROOT
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8
			liege = { has_imperial_government_trigger = yes }
		}

		mult_modifier = {
			factor = 0.2
			pacifist = yes
		}

		mult_modifier = {
			factor = 3.0

			liege = { has_law = taifa_law_0 }
			capital_scope = { region = world_europe_west_iberia }
			religion_group = muslim
		}

		mult_modifier = {
			factor = 2.0

			liege = { has_law = taifa_law_1 }
			capital_scope = { region = world_europe_west_iberia }
			religion_group = muslim
		}

		mult_modifier = {
			factor = 2.0
			is_unreformed_pagan_trigger = yes
		}

		mult_modifier = {
			factor = 1.5
			is_vice_royalty = yes
		}

		mult_modifier = {
			factor = 2.0
			higher_real_tier_than = DUKE
		}

		mult_modifier = {
			factor = 0.1

			has_opinion_modifier = {
				who = liege
				name = sworn_to_support_heir
			}

			NOT = { trait = deceitful }
		}

		mult_modifier = {
			factor = 0.75

			opinion = {
				who = liege
				value = 0
			}
		}

		mult_modifier = {
			factor = 0.5

			opinion = {
				who = liege
				value >= 20
			}
		}

		mult_modifier = {
			factor = 1.5

			opinion = {
				who = liege
				value < -20
			}
		}

		mult_modifier = {
			factor = 2.0

			opinion = {
				who = liege
				value < -50
			}
		}

		mult_modifier = {
			factor = 4.0

			opinion = {
				who = liege
				value < -75
			}
		}

		# Lower if liege is a close relative or is allied
		mult_modifier = {
			factor = 0.1

			OR = {
				is_close_relative = liege
				is_allied_with = liege
				has_non_aggression_pact_with = liege
			}
		}

		# Lower if liege is the same dynasty but not close relative or allied
		mult_modifier = {
			factor = 0.3

			liege = {
				dynasty = ROOT

				NOR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}

		# Lower if king & if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		mult_modifier = {
			factor = 0.25

			real_tier = KING
			is_not_unreformed_pagan_trigger = yes
			capital_scope = { has_province_flag = contingent_territory }

			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes
				de_jure_vassal_or_below = ROOT
				over_vassal_limit < 1
				NOT = { has_law = taifa_law_0 }
			}
		}

		# Lower if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		mult_modifier = {
			factor = 0.5

			lower_real_tier_than = KING
			capital_scope = { has_province_flag = contingent_territory }

			liege = {
				de_jure_vassal_or_below = ROOT

				OR = {
					NOT = { religion = ROOT }
					compare_cultures_ROOT_trigger = no
					over_vassal_limit > 0
				}
			}
		}

		# Lower if king & if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		mult_modifier = {
			factor = 0.75

			real_tier = KING
			capital_scope = { has_province_flag = contingent_territory }

			liege = {
				de_jure_vassal_or_below = ROOT

				OR = {
					NOT = { religion = ROOT }
					compare_cultures_ROOT_trigger = no
					over_vassal_limit > 0
				}
			}
		}

		# Lower if liege is same religion & same culture & not over vassal limit -- but either not de jure or not connected to the capital
		mult_modifier = {
			factor = 0.75

			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes
				over_vassal_limit <= 0
			}

			calc_true_if = {
				amount == 1

				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Higher if liege is both not de jure vassal and not connected
		mult_modifier = {
			factor = 1.5

			NOR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Higher if liege is not same religion and culture
		mult_modifier = {
			factor = 2.0

			liege = {
				NOT = { religion = ROOT }
				compare_cultures_ROOT_trigger = no
			}
		}

		# Higher if liege is not same religion group
		mult_modifier = {
			factor = 2.0
			NOT = { religion_group = liege }
		}

		# Higher if liege is not same culture group
		mult_modifier = {
			factor = 2.0
			liege = { compare_cultures_ROOT_trigger = no }
		}

		# Higher if liege is very over vassal limit
		mult_modifier = {
			factor = 1.5
			liege = { over_vassal_limit >= 5 }
		}

		mult_modifier = {
			factor = 1.5
			liege = { over_vassal_limit >= 10 }
		}

		# Very reduced chance of joining if close to liege's capital (except for unreformed pagans)
		mult_modifier = {
			factor = 0.1

			is_not_unreformed_pagan_trigger = yes

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value < 200
							}
						}
					}
				}
			}
		}

		# Chance of joining increases the further the liege's capital is away from the ruler's
		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 300
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 400
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 500
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 600
							}
						}
					}
				}
			}
		}

		# Personality considerations
		mult_modifier = {
			factor = 0.025
			trait = content
		}

		mult_modifier = {
			factor = 0.025
			trait = imbecile
		}

		mult_modifier = {
			factor = 0.025
			trait = craven
		}

		mult_modifier = {
			factor = 0.1
			trait = inbred
		}

		mult_modifier = {
			factor = 0.1

			OR = {
				trait = slow
				trait = dull
			}
		}

		mult_modifier = {
			factor = 0.5
			trait = kind
		}

		mult_modifier = {
			factor = 0.5
			trait = charitable
		}

		mult_modifier = {
			factor = 0.5
			trait = honest
		}

		mult_modifier = {
			factor = 0.75
			trait = humble
		}

		mult_modifier = {
			factor = 0.75
			trait = just
		}

		mult_modifier = {
			factor = 1.5
			trait = proud
		}

		mult_modifier = {
			factor = 1.5
			trait = brave
		}

		mult_modifier = {
			factor = 1.5
			trait = arbitrary
		}

		mult_modifier = {
			factor = 2.0
			trait = envious
		}

		mult_modifier = {
			factor = 2.0
			trait = greedy
		}

		mult_modifier = {
			factor = 2.0
			trait = impaler
		}

		mult_modifier = {
			factor = 2.0
			trait = deceitful
		}

		mult_modifier = {
			factor = 4.0
			trait = ambitious
		}

		# Vassals care less if they have higher autonomy
		mult_modifier = {
			factor = 0.8

			liege = {
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
			}
		}

		mult_modifier = {
			factor = 0.8
			liege = { has_law = law_voting_power_1 }
		}

		mult_modifier = { # More likely to want to go independent from the WP if China is unstable
			factor = 10.0

			liege = {
				government = confucian_bureaucracy
			}

			offmap_china = {
				NOR = {
					has_status = china_stable
					has_status = china_golden_age
				}
			}
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 10

		trigger = {
			war = no
			preparing_invasion = no

			NOR = {
				in_faction = faction_religious
				leads_faction = faction_religious
				is_primary_heir = liege
				has_landed_title = k_orthodox
			}

			opinion = {
				who = liege
				value < 40
			}

			# Not at all if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
			NAND = {
				religion = liege
				lower_real_tier_than = KING
				is_not_unreformed_pagan_trigger = yes
				capital_scope = { has_province_flag = contingent_territory }

				liege = {
					compare_cultures_ROOT_trigger = yes
					de_jure_vassal_or_below = ROOT
					over_vassal_limit <= 0

					NOR = {
						has_law = taifa_law_0
						has_law = taifa_law_1
					}
				}

				NAND = {
					religion_group = muslim
					capital_scope = { region = world_europe_west_iberia }

					crownlaw_title = {
						NOR = {
							has_law = crown_authority_3
							has_law = crown_authority_4
						}
					}
				}
			}

			# Avoid joining faction if independence would put me beside a stronger neighbor eligible for holy war
			NOT = {
				any_neighbor_independent_ruler = {
					higher_real_tier_than = ROOT
					shares_realm_border_with = ROOT

					trigger_if = {
						limit = { religion_group = ROOT }

						OR = {
							is_heresy_of = ROOT
							is_parent_religion = ROOT

							trigger_if = {
								limit = { religion_group = muslim }
								NOT = { religion = ROOT }
							}
						}
					}
				}
			}

			# Try to exclude people who should rather support a claimant
			NAND = {
				lower_real_tier_than = KING

				NAND = {
					culture = liege
					religion = liege
				}

				liege = {
					any_demesne_title = {
						OR = {
							is_primary_holder_title = yes
							higher_real_tier_than = DUKE
						}

						ROOT = {
							primary_title = { de_jure_liege_or_above = PREVPREV }
						}

						any_claimant = {
							dynasty = ROOT
							religion = ROOT
							compare_cultures_ROOT_trigger = yes
						}
					}
				}
			}

			# Won't join this type of faction if our capital borders the liege's capital
			NOT = {
				liege = {
					capital_scope = {
						any_neighbor_province = {
							ROOT = {
								capital_scope = {
									province = PREVPREV
								}
							}
						}
					}
				}
			}
		}

		# Stay if coerced into the faction (by favor, or otherwise)
		mult_modifier = {
			factor = 1000

			has_opinion_modifier = {
				name = opinion_coerced_into_joining_faction
				who = FROM
			}
		}

		mult_modifier = {
			factor = 0.8
			liege = { has_imperial_government_trigger = yes }
		}

		mult_modifier = {
			factor = 0.2
			pacifist = yes
		}

		# Clans are very unlikely to join Independence factions led by non-nomads
		mult_modifier = {
			factor = 0.01

			is_nomadic = yes
			FROM = { is_nomadic = no }
		}

		mult_modifier = {
			factor = 3.0

			liege = { has_law = taifa_law_0 }
			capital_scope = { region = world_europe_west_iberia }
			religion_group = muslim
		}

		mult_modifier = {
			factor = 2.0

			liege = { has_law = taifa_law_1 }
			capital_scope = { region = world_europe_west_iberia }
			religion_group = muslim
		}

		mult_modifier = {
			factor = 2.0
			is_unreformed_pagan_trigger = yes
		}

		mult_modifier = {
			factor = 1.5
			is_vice_royalty = yes
		}

		mult_modifier = {
			factor = 2.0
			higher_real_tier_than = DUKE
		}

		mult_modifier = {
			factor = 0.1

			has_opinion_modifier = {
				name = sworn_to_support_heir
				who = liege
			}

			NOT = { trait = deceitful }
		}

		mult_modifier = {
			factor = 0.75

			opinion = {
				who = liege
				value >= 0
			}
		}

		mult_modifier = {
			factor = 0.5

			opinion = {
				who = liege
				value >= 20
			}
		}

		mult_modifier = {
			factor = 1.5

			opinion = {
				who = liege
				value < -20
			}
		}

		mult_modifier = {
			factor = 2.0

			opinion = {
				who = liege
				value < -50
			}
		}

		mult_modifier = {
			factor = 4.0

			opinion = {
				who = liege
				value < -75
			}
		}

		# Lower if liege is a close relative or is allied
		mult_modifier = {
			factor = 0.1

			liege = {
				OR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}

		# Lower if liege is the same dynasty but not close relative or allied
		mult_modifier = {
			factor = 0.3

			liege = {
				dynasty = ROOT

				NOR = {
					is_close_relative = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
				}
			}
		}

		# Lower if king & if liege is same culture & religion, is de jure liege, not over vassal limit, and connected to capital
		mult_modifier = {
			factor = 0.25

			real_tier = KING
			capital_scope = { has_province_flag = contingent_territory }
			is_not_unreformed_pagan_trigger = yes

			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes
				de_jure_vassal_or_below = ROOT
				over_vassal_limit <= 0
				NOT = { has_law = taifa_law_0 }
			}
		}

		# Lower if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		mult_modifier = {
			factor = 0.25

			lower_tier_than = KING
			capital_scope = { has_province_flag = contingent_territory }

			liege = {
				de_jure_vassal_or_below = ROOT
				NOT = { has_law = taifa_law_0 }

				OR = {
					NOT = { religion = ROOT }
					compare_cultures_ROOT_trigger = no
					over_vassal_limit > 0
				}
			}
		}

		# Lower if king & if liege is both de jure liege and connected to capital but either not the same religion or the same culture or is over vassal limit
		mult_modifier = {
			factor = 0.5

			real_tier = KING
			capital_scope = { has_province_flag = contingent_territory }

			liege = {
				de_jure_vassal_or_below = ROOT

				OR = {
					NOT = { religion = ROOT }
					compare_cultures_ROOT_trigger = no
					over_vassal_limit > 0
				}
			}
		}

		# Lower if liege is same religion & same culture & not over vassal limit -- but either not de jure or not connected to the capital
		mult_modifier = {
			factor = 0.5

			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes
				over_vassal_limit <= 0
			}

			calc_true_if = {
				amount == 1

				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Lower if liege is same religion & same culture but over vassal limit -- but either not de jure or not connected to the capital
		mult_modifier = {
			factor = 0.75

			liege = {
				religion = ROOT
				compare_cultures_ROOT_trigger = yes
				over_vassal_limit > 0
			}

			calc_true_if = {
				amount == 1

				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Lower if liege is either different religion/culture (but not both) and not over vassal limit -- but either not de jure or not connected to the capital
		mult_modifier = {
			factor = 0.75

			liege = {
				calc_true_if = {
					amount == 1

					religion = ROOT
					compare_cultures_ROOT_trigger = yes
				}

				over_vassal_limit <= 0
			}

			calc_true_if = {
				amount == 1

				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Higher if liege is both not de jure vassal and not connected
		mult_modifier = {
			factor = 1.5

			NOR = {
				liege = { de_jure_vassal_or_below = ROOT }
				capital_scope = { has_province_flag = contingent_territory }
			}
		}

		# Higher if liege is both not same religion and culture
		mult_modifier = {
			factor = 1.5

			liege = {
				NOT = { religion = ROOT }
				compare_cultures_ROOT_trigger = no
			}
		}

		# Higher if liege is not same religion group
		mult_modifier = {
			factor = 2.0
			NOT = { religion_group = liege }
		}

		# Higher if liege is not same culture group
		mult_modifier = {
			factor = 1.5
			NOT = { culture_group = liege }
		}

		# Higher if liege is very over vassal limit
		mult_modifier = {
			factor = 1.5
			liege = { over_vassal_limit >= 5 }
		}

		mult_modifier = {
			factor = 1.5
			liege = { over_vassal_limit >= 10 }
		}

		# Very reduced chance of joining if close to liege's capital (except for unreformed pagans)
		mult_modifier = {
			factor = 0.1

			is_not_unreformed_pagan_trigger = yes

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value < 200
							}
						}
					}
				}
			}
		}

		# Chance of joining increases the further the liege's capital is away from the ruler's
		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 300
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 400
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			liege = {
				capital_scope = {
					ROOT = {
						capital_scope = {
							distance = {
								where = PREVPREV
								value >= 500
							}
						}
					}
				}
			}
		}

		# Personality considerations
		mult_modifier = {
			factor = 0.025
			trait = content
		}

		mult_modifier = {
			factor = 0.025
			trait = imbecile
		}

		mult_modifier = {
			factor = 0.025
			trait = craven
		}

		mult_modifier = {
			factor = 0.1
			trait = inbred
		}

		mult_modifier = {
			factor = 0.1

			OR = {
				trait = slow
				trait = dull
			}
		}

		mult_modifier = {
			factor = 0.5
			trait = kind
		}

		mult_modifier = {
			factor = 0.5
			trait = charitable
		}

		mult_modifier = {
			factor = 0.5
			trait = honest
		}

		mult_modifier = {
			factor = 0.75
			trait = humble
		}

		mult_modifier = {
			factor = 0.75
			trait = just
		}

		mult_modifier = {
			factor = 1.5
			trait = proud
		}

		mult_modifier = {
			factor = 1.5
			trait = brave
		}

		mult_modifier = {
			factor = 1.5
			trait = arbitrary
		}

		mult_modifier = {
			factor = 2.0
			trait = envious
		}

		mult_modifier = {
			factor = 2.0
			trait = greedy
		}

		mult_modifier = {
			factor = 2.0
			trait = impaler
		}

		mult_modifier = {
			factor = 2.0
			trait = deceitful
		}

		mult_modifier = {
			factor = 4.0
			trait = ambitious
		}

		# Vassals care less if they have higher autonomy
		mult_modifier = {
			factor = 0.8

			liege = {
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
			}
		}

		mult_modifier = {
			factor = 0.8
			liege = { has_law = law_voting_power_1 }
		}

		mult_modifier = { # More likely to want to go independent from the WP if China is unstable
			factor = 10.0

			liege = {
				government = confucian_bureaucracy
			}

			offmap_china = {
				NOR = {
					has_status = china_stable
					has_status = china_golden_age
				}
			}
		}
	}

	success = {
		independent = yes
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
		FROM = {
			any_faction_backer = {
				faction = faction_separatist

				reverse_opinion = {
					name = opinion_grateful
					who = FROM
					years = 5
				}
			}
		}
	}
}

# Faction supports claimant to the throne
faction_pretender = {
	type = liege_titles_w_claimant # 'new_character' is a Claimant, or, if the title is Elective, anyone eligible for election
	exclusive = yes # Can only lead or be in one faction of this type

	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.

	# Plotter scope
	potential = {
		is_playable = yes
		higher_real_tier_than = BARON
		is_landed = yes
		faction_council_trigger = yes
		prisoner = no
		independent = no
		is_adult = yes
		holy_order = no
		is_incapable = no
		in_revolt = no

		NOR = {
			has_truce = liege
			has_non_aggression_pact_with = liege
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
		}

		liege = {
			is_vice_royalty = no
			in_revolt = no

			OR = {
				is_feudal = yes
				is_tribal = yes
				is_nomadic = yes
			}

			## Hordes should have less problems with this type of faction until ca 1350
			trigger_if = {
				limit = { has_horde_culture = yes }

				NAND = {
					year < 1350
					culture = ROOT
					religion = ROOT
				}
			}
		}

		trigger_if = {
			limit = { crownlaw_title = { always = yes } }

			OR = {
				crownlaw_title = {
					holder_scope = { is_liege_of = ROOT }
				}

				AND = {
					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}
		}

		# Only nomads can start pretender factions in nomadic realms, and only for themselves
		trigger_if = {
			limit = { liege = { is_nomadic = yes } }

			character = new_character
			is_nomadic = yes
			NOT = { has_blood_oath_with = liege }
		}
	}

	# Target scope
	allow = {
		# Primary or king titles
		OR = {
			is_primary_holder_title = yes
			higher_real_tier_than = DUKE
		}

		# Is either the primary title or my de jure liege
		OR = {
			is_primary_holder_title = yes
			de_jure_vassal_or_below = FROM
		}

		# Claimant must be the same religion for religious head titles
		trigger_if = {
			limit = { controls_religion = yes }
			new_character = { religion = ROOT }
		}

		# No claimant factions to return duke/king titles to emperor within imperial realm
		trigger_if = {
			limit = { holder_scope = { has_imperial_government_trigger = yes } }

			OR = {
				new_character = {
					OR = {
						lower_real_tier_than = EMPEROR

						ROOT = {
							holder_scope = {
								NOT = { same_realm = PREVPREV }
							}
						}
					}
				}

				NOR = {
					real_tier = DUKE
					real_tier = KING
				}
			}
		}

		new_character = {
			prisoner = no
			is_incapable = no
			NOT = { has_character_flag = refused_pretender_faction }

			# Claimant is either landless or is feudal/tribal/nomadic
			trigger_if = {
				limit = { is_ruler = yes }

				OR = {
					is_feudal = yes
					is_tribal = yes
					is_nomadic = yes
				}
			}

			# Ensure adherence to succession laws and religious prescriptions
			trigger_if = {
				limit = { is_female = no }

				NOR = {
					has_religion_feature = religion_matriarchal

					ROOT = {
						succ_law_title = {
							has_law = enatic_succession
						}
					}
				}
			}
			trigger_else = {
				NOR = {
					has_religion_feature = religion_patriarchal

					ROOT = {
						succ_law_title = {
							has_law = agnatic_succession
						}
					}
				}
			}

			# Holder is not currently defending against that claimant for that title
			ROOT = {
				holder_scope = {
					NOR = {
						defending_against_claimant = {
							character = PREVPREV
							title = ROOT
						}

						reverse_has_truce = PREVPREV
					}
				}
			}

			# Either holder is independent or claimant is in the same realm/not a ruler
			trigger_if = {
				limit = { is_ruler = yes }

				ROOT = {
					holder_scope = {
						OR = {
							independent = yes
							same_realm = PREVPREV
						}
					}
				}
			}

			# Has not failed as a pretender against the holder previously
			ROOT = {
				holder_scope = {
					NOT = {
						has_opinion_modifier = {
							name = failed_to_claim_my_title
							who = PREVPREV
						}
					}
				}
			}
		}

		# Is either not dynastic elective or the claimant is a non-ruler/de jure vassal of the title
		trigger_if = {
			limit = {
				OR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}

			new_character = {
				OR = {
					is_ruler = no
					primary_title = { de_jure_liege_or_above = PREVPREV }
				}
			}
		}

		holder_scope = {
			NOR = {
				character = new_character

				reverse_has_opinion_modifier = {
					name = opinion_coerced_into_leaving_faction
					who = FROM
				}
			}
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			faction_council_trigger = yes
			independent = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			trigger_if = {
				limit = {
					is_inaccessible_trigger = yes
					NOT = { in_faction = faction_pretender }
				}

				has_character_flag = will_join_civil_war
			}

			NOR = {
				has_non_aggression_pact_with = liege
				has_truce = liege
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}

			# Can't join factions when in blood oath with liege
			trigger_if = {
				limit = { is_nomadic = yes }
				NOT = { has_blood_oath_with = liege }
			}
		}
	}

	# AI creation weight
	chance = {
		factor = 4

		trigger = {
			FROM = {
				religion = new_character
				prisoner = no
				in_seclusion = no
				preparing_invasion = no
				NOT = { rightful_religious_head = THIS }

				trigger_if = {
					limit = { new_character = { trait = decadent } }
					FROM = { trait = decadent }
				}

				trigger_if = {
					limit = {
						rightful_religious_head_scope = {
							has_landed_title = ROOT
							ai = yes
						}
					}

					trait = cynical
				}

				# If there is an antiking faction, prioritize that
				trigger_if = {
					limit = {
						has_character_flag = opposes_the_antipope

						OR = {
							religion = catholic
							religion = fraticelli
						}

						liege = {
							is_liege_of = FROM
							religion = FROM

							# Has an antipope
							rightful_religious_head_scope = {
								is_antipope = yes
								vassal_of = PREV
							}
						}
					}

					liege = {
						NOT = {
							faction_exists = {
								faction = faction_antiking
								title = ROOT
							}
						}
					}
				}

				# Will not support a claim for the title if the claimant already has a faction for a higher tier one
				liege = {
					NOT = {
						any_vassal = {
							leads_faction = faction_pretender
							supported_claimant = { character = new_character }
							supported_claimant_title = { higher_real_tier_than = ROOT }
						}
					}
				}
			}

			holder_scope = {
				# Will not support a claimant against someone you installed in the position
				NOT = {
					reverse_has_opinion_modifier = {
						name = opinion_fought_for_claimant
						who = FROM
					}
				}

				# Don't cause bordergore
				trigger_if = {
					limit = { independent = no }
					same_realm  = FROM
				}
			}

			# Will not support women for an agnatic title unless they have a son or are formidable
			trigger_if = {
				limit = {
					new_character = { is_female = yes }
					has_law = agnatic_succession
					FROM = { is_feminist_trigger = no }
				}

				new_character = {
					OR = {
						character = FROM

						any_child = {
							is_female = no
							OR = {
								dynasty = PREV
								dynasty = FROM
							}

							NOT = { trait = bastard }
						}

						calc_true_if = {
							amount >= 2

							is_ruler = yes
							prestige >= 1000
							diplomacy >= 12
							diplomacy >= 20
							intrigue >= 12
						}
					}
				}
			}

			# Will not support men for an enatic title unless they have a daughter or are formidable
			trigger_if = {
				limit = {
					new_character = { is_female = no }
					has_law = enatic_succession
				}

				new_character = {
					OR = {
						character = FROM

						any_child = {
							is_female = yes

							OR = {
								dynasty = PREV
								dynasty = FROM
							}

							NOT = { trait = bastard }
						}

						calc_true_if = {
							amount >= 2

							is_ruler = yes
							prestige >= 1000
							diplomacy >= 12
							diplomacy >= 20
							intrigue >= 12
						}
					}
				}
			}

			# Will not support a woman at all if zealous or in tradition faction
			trigger_if = {
				limit = {
					FROM = {
						is_feminist_trigger = no

						OR = {
							trait = zealous
							leads_faction = faction_tradition
							in_faction = faction_tradition
						}
					}

					NOR = {
						has_law = true_cognatic_succession
						has_law = enatic_cognatic_succession
						has_law = enatic_succession
					}
				}

				new_character = { is_female = no }
			}

			# Will not support claimants against their own spouse
			holder_scope = {
				NOT = { is_married = FROM }
			}

			new_character = {
				# Limits on who the AI will install in the title
				NOR = {
					is_rival = FROM
					trait = blinded
					trait = eunuch
					trait = imbecile
					trait = inbred
					trait = monk
					trait = nun
					trait = abdicated
					trait = druid
					trait = bad_druid
					trait = retired_vestalis
					trait = vestalis
				}

				# Not old women, period
				trigger_if = {
					limit = { is_female = yes }
					practical_age < 40
				}

				# Not over 65 or celibate unless they have a legitimate son
				trigger_if = {
					limit = {
						OR = {
							practical_age >= 65
							trait = celibate
						}
					}

					any_child = {
						is_female = no
						has_inheritance_blocker = no
					}
				}

				# Will not install a parent of the current ruler
				ROOT = {
					holder_scope = {
						NOT = { is_child_of = PREVPREV }
					}
				}
			}

			# Will not install the current heir & will not install anyone if the heir, unless non-dynastic elective
			trigger_if = {
				limit = {
					current_heir = {
						OR = {
							character = FROM
							character = new_character
						}
					}
				}

				OR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}

			# Will not support a claimant to a title they also have a claim to
			trigger_if = {
				limit = { claimed_by = FROM }
				new_character = { character = FROM }
			}

			# Will not support a claimant of a different dynasty if holder is same dynasty, religion and culture
			trigger_if = {
				limit = {
					holder_scope = {
						dynasty = FROM
						religion = FROM
						culture = FROM
					}
				}

				new_character = {
					dynasty = FROM
				}
			}

			# Will not put oneself forward for a non-dynastic elective title unless ambitious, proud, or a justified/strong claimant
			trigger_if = {
				limit = {
					new_character = {
						character = FROM
					}

					OR = {
						has_law = succ_feudal_elective
						has_law = succ_hre_elective
						has_law = succ_byzantine_elective
					}
				}

				FROM = {
					OR = {
						trait = ambitious
						trait = proud
						has_strong_claim = PREV
						has_character_flag = justified_claimant
					}
				}
			}

			# Will not support a claimant for a title that is currently contested by someone of a different religion/culture group
			NAND = {
				holder_scope = {
					culture_group = FROM
					religion = FROM

					any_war = {
						war_title = ROOT

						attacker = {
							NAND = {
								culture_group = FROM
								religion = FROM
							}
						}
					}
				}

				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}

			# Will not support a claim for the primary title if there is an equal-tier title they are de jure vassal of
			trigger_if = {
				limit = {
					is_primary_holder_title = yes
					NOT = { de_jure_vassal_or_below = FROM }
				}

				holder_scope = {
					NOT = {
						any_demesne_title = {
							is_primary_holder_title_tier = yes
							de_jure_vassal_or_below = FROM
							NOT = { title = ROOT }
						}
					}
				}
			}

			# If recently conquered, will not support a claimant of a different culture
			trigger_if = {
				limit = { is_conquered = yes }
				new_character = { culture = FROM }
			}

			# Opinions
			holder_scope = {
				trigger_if = {
					limit = {
						culture = FROM
						religion = FROM
					}

					FROM = {
						trigger_if = {
							limit = {
								OR = {
									trait = deceitful
									trait = ambitious
									trait = envious
									trait = proud
									trait = brave
								}
							}

							opinion = {
								who = PREV
								value < 25
							}
						}
						trigger_else = {
							opinion = {
								who = PREV
								value < 0
							}
						}
					}
				}
				trigger_else = {
					trigger_if = {
						limit = {
							OR = {
								trait = deceitful
								trait = ambitious
								trait = envious
								trait = proud
								trait = brave
							}

							opinion = {
								who = PREV
								value < 50
							}
						}
					}
					trigger_else = {
						opinion = {
							who = PREV
							value < 25
						}
					}
				}
			}

			# I must not dislike the proposed claimant
			new_character = {
				reverse_opinion = {
					who = FROM
					value >= 0
				}

				trigger_if = {
					limit = { NOT = { character = FROM } }

					# I must like the Claimant more than the current ruler
					FROM = {
						opinion_diff = {
							first = PREV
							second = liege
							value >= 10
							as_if_liege = yes
						}
					}

					# The new claimant cannot like the holder
					ROOT = {
						holder_scope = {
							new_character = {
								trigger_if = {
									limit = {
										NOR = {
											trait = deceitful
											trait = ambitious
											trait = envious
											trait = proud
											trait = greedy
										}
									}

									opinion = {
										who = PREVPREV
										value < 25
									}
								}
							}
						}
					}
				}
			}

			# Personal traits of the claimant
			trigger_if = {
				limit = {
					new_character = {
						OR = {
							trait = lunatic
							trait = possessed
						}
					}
				}

				FROM = {
					NOR = {
						trait = lunatic
						trait = possessed
					}
				}

				holder_scope = {
					NOR = {
						trait = lunatic
						trait = possessed
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.2
			FROM = { pacifist = yes }
		}

		mult_modifier = {
			factor = 0.9

			holder_scope = {
				liege = {
					trait = crowned_by_vip
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				liege = {
					OR = {
						trait = crowned_by_pope
						trait = crowned_by_relhead
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.75

			holder_scope = {
				liege = {
					trait = strong_basileus
				}
			}
		}

		mult_modifier = {
			factor = 0.5
			is_primary_holder_title = no
		}

		mult_modifier = {
			factor = 3.0

			holder_scope = {
				OR = {
					prisoner = yes
					is_adult = no
					is_incapable = yes
					trait = uncrowned
				}
			}
		}

		mult_modifier = {
			factor = 3
			new_character = { has_character_flag = justified_claimant }
		}

		mult_modifier = {
			factor = 10
			new_character = { character = FROM }
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				dynasty = FROM
				NOT = { character = FROM }
			}
		}

		mult_modifier = {
			factor = 1.5
			new_character = { is_close_relative = FROM }
		}

		mult_modifier = {
			factor = 0.25
			new_character = { NOT = { culture = FROM } }
		}

		mult_modifier = {
			factor = 0.25
			new_character = { NOT = { culture_group = FROM } }
		}

		mult_modifier = {
			factor = 0.1

			holder_scope = {
				reverse_has_opinion_modifier = {
					name = sworn_to_support_heir
					who = FROM
				}
			}

			FROM = { NOT = { trait = deceitful } }
		}

		# Will support a claimant of the same religion & culture against a liege who is either not of the same religion group or the same culture group
		mult_modifier = {
			factor = 3.0

			holder_scope = {
				is_liege_of = FROM
				NAND = {
					culture_group = FROM
					religion_group = FROM
				}
			}

			new_character = {
				culture = FROM
				religion = FROM
			}
		}

		# Less likely to support young children
		mult_modifier = {
			factor = 0.5
			new_character = { age < 13 }
		}

		mult_modifier = {
			factor = 0.5
			new_character = { age < 10 }
		}

		mult_modifier = {
			factor = 0.5
			new_character = { age < 5 }
		}

		# More likely to support a male claimant against a female holding an agnatic title
		mult_modifier = {
			factor = 3.0

			new_character = { is_female = no }
			has_law = agnatic_succession
			holder_scope = { is_female = yes }
			FROM = { is_feminist_trigger = no }
		}

		# More likely to support a female claimant against a male holding an enatic title
		mult_modifier = {
			factor = 3.0

			new_character = { is_female = yes }
			has_law = enatic_succession
			holder_scope = { is_female = no }
		}

		# Unlikely to support women for an cognatic title unless they have a son or are formidable
		mult_modifier = {
			factor = 0.5

			has_law = cognatic_succession

			new_character = {
				is_female = yes

				NOR = {
					character = FROM

					any_child = {
						is_female = no
						has_inheritance_blocker = no

						OR = {
							dynasty = PREV
							dynasty = FROM
						}
					}

					calc_true_if = {
						amount >= 2

						is_ruler = yes
						prestige >= 1000
						diplomacy >= 12
						diplomacy >= 20
						intrigue >= 12
					}
				}
			}
			FROM = { is_feminist_trigger = no }
		}

		# Unlikely to support a woman in any case unless you are a woman
		mult_modifier = {
			factor = 0.5

			new_character = { is_female = yes }

			FROM = {
				is_female = no
				is_feminist_trigger = no
			}

			NOR = {
				has_law = true_cognatic_succession
				has_law = enatic_cognatic_succession
				has_law = enatic_succession
			}
		}

		# Unlikely to support men for an enatic-cognatic title unless they have a daughter or are formidable
		mult_modifier = {
			factor = 0.5

			has_law = enatic_cognatic_succession

			new_character = {
				is_female = no

				NOR = {
					character = FROM

					any_child = {
						is_female = yes
						has_inheritance_blocker = no

						OR = {
							dynasty = PREV
							dynasty = FROM
						}
					}

					calc_true_if = {
						amount >= 2

						is_ruler = yes
						prestige >= 1000
						diplomacy >= 12
						diplomacy >= 20
						intrigue >= 12
					}
				}
			}
		}

		# Unlikely to support a man in any case unless you are a man
		mult_modifier = {
			factor = 0.5

			new_character = { is_female = no }
			FROM = { is_female = yes }

			NOR = {
				has_law = true_cognatic_succession
				has_law = cognatic_succession
				has_law = agnatic_succession
			}
		}

		# Less likely to support a weak claimant when a strong claimant of the same religion, culture and dynasty exists in the realm
		mult_modifier = {
			factor = 0.25

			new_character = { has_weak_claim = ROOT }

			FROM = {
				liege = {
					any_vassal = {
						leads_faction = faction_pretender

						supported_claimant = {
							religion = FROM
							culture = FROM
							dynasty = FROM
							has_strong_claim = ROOT
						}
					}
				}
			}
		}

		# There's already another claimant that I like
		mult_modifier = {
			factor = 0.75

			new_character = {
				NOT = { character = FROM }
			}

			holder_scope = {
				any_vassal = {
					leads_faction = faction_pretender

					supported_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
						dynasty = FROM
						NOT = { character = new_character }

						reverse_opinion = {
							who = FROM
							value >= 20
						}
					}
				}
			}
		}

		# Will not support a claimant when they are a claimant of another pretender faction
		mult_modifier = {
			factor = 0.25

			new_character = {
				NOT = { character = FROM }
			}

			FROM = {
				liege = {
					any_vassal = {
						leads_faction = faction_pretender
						supported_claimant = { character = FROM }
						supported_claimant_title = { title = ROOT }
					}
				}
			}
		}

		# If recently conquered, more likely to support a claimant of the same culture
		mult_modifier = {
			factor = 4.0

			is_conquered = yes
			NOT = { conquest_culture = FROM }
			new_character = { culture = FROM }
		}

		# If we are conquered, tend to unite behind one single claimant
		mult_modifier = {
			factor = 0.1

			is_conquered = yes
			NOT = { conquest_culture = FROM }

			holder_scope = {
				any_vassal = {
					in_faction = faction_pretender
					NOT = { character = FROM }

					supported_claimant = {
						compare_cultures_FROM_trigger = yes
						religion = FROM
						NOT = { character = new_character }

						reverse_opinion = {
							who = FROM
							value >= 25
						}
					}
				}
			}
		}

		# More likely to support claimants from less powerful dynasties
		mult_modifier = {
			factor = 2.0

			holder_scope = {
				dynasty_realm_power >= 0.25
				NOT = { dynasty = new_character }
			}
		}

		mult_modifier = {
			factor = 2.0

			holder_scope = {
				dynasty_realm_power >= 0.4
				NOT = { dynasty = new_character }
			}
		}

		# Less likely to support a claimant not born in the purple against a holder who is
		mult_modifier = {
			factor = 0.5

			OR = {
				title = e_byzantium
				title = e_roman_empire
			}

			FROM = {
				OR = {
					culture_group = byzantine
					culture = roman
				}
			}

			holder_scope = { trait = born_in_the_purple }
			new_character = { NOT = { trait = born_in_the_purple } }
		}

		# More likely to support a claimant born in the purple against a holder who isn't
		mult_modifier = {
			factor = 2.0

			OR = {
				title = e_byzantium
				title = e_roman_empire
			}

			FROM = {
				OR = {
					culture_group = byzantine
					culture = roman
				}
			}

			holder_scope = { NOT = { trait = born_in_the_purple } }
			new_character = { trait = born_in_the_purple }
		}

		# More likely to support sayyid against a holder who isn't
		mult_modifier = {
			factor = 2.0

			new_character = { trait = sayyid }
			FROM = { religion_group = muslim }
			holder_scope = { NOT = { trait = sayyid } }
		}

		# More likely to support mirza against a holder who is neither sayyid nor mirza
		mult_modifier = {
			factor = 1.5

			new_character = { trait = mirza }
			FROM = { religion_group = muslim }

			holder_scope = {
				NOR = {
					trait = sayyid
					trait = mirza
				}
			}
		}

		# Members of the tradition faction are less likely to support claimants unless the holder is excommunicated
		mult_modifier = {
			factor = 2

			holder_scope = { excommunicated_for = FROM }
			FROM = { in_faction = faction_tradition }
		}

		mult_modifier = {
			factor = 0.25

			holder_scope = { NOT = { excommunicated_for = FROM } }
			FROM = { in_faction = faction_tradition }
		}

		# Members of the court faction are more likely to support claimants
		mult_modifier = {
			factor = 2.0

			FROM = {
				in_faction = faction_court

				liege = {
					OR = {
						has_character_flag = faction_court_angry
						has_character_flag = faction_court_unhappy
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			holder_scope = {
				reverse_opinion = {
					who = FROM
					value < -25
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			holder_scope = {
				reverse_opinion = {
					who = FROM
					value < -50
				}
			}
		}

		mult_modifier = {
			factor = 4.0

			holder_scope = {
				reverse_opinion = {
					who = FROM
					value < -75
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			new_character = {
				reverse_opinion = {
					who = FROM
					value < 20
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				NOT = { character = FROM }

				FROM = {
					opinion_diff = {
						first = PREV
						second = liege
						value >= 25
						as_if_liege = yes
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				NOT = { character = FROM }

				FROM = {
					opinion_diff = {
						first = PREV
						second = liege
						value >= 50
						as_if_liege = yes
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				NOT = { character = FROM }

				FROM = {
					opinion_diff = {
						first = PREV
						second = liege
						value >= 75
						as_if_liege = yes
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				NOT = { character = FROM }

				FROM = {
					opinion_diff = {
						first = PREV
						second = liege
						value >= 100
						as_if_liege = yes
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5
			new_character = { is_smart_trigger = yes }
			holder_scope = { is_smart_trigger = no }
		}

		mult_modifier = {
			factor = 0.5

			new_character = {
				OR = {
					trait = slow
					trait = dull
					trait = infirm
					trait = content
					health < 4
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = { trait = zealous }
			FROM = { trait = zealous }
			holder_scope = { NOT = { trait = zealous } }
		}

		mult_modifier = {
			factor = 0.5

			new_character = { trait = cynical }
			FROM = { trait = zealous }
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value <= -2
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value <= -4
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value <= -6
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value <= -8
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value <= -10
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value >= 2
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value >= 4
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value >= 6
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value >= 8
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = diplomacy
					value >= 10
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = stewardship
					value <= -5
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = stewardship
					value >= 5
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = intrigue
					value <= -5
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			holder_scope = {
				attribute_diff = {
					character = new_character
					attribute = intrigue
					value >= 5
				}
			}
		}

		# Personal traits
		mult_modifier = {
			factor = 0.01

			FROM = { trait = content }

			OR = {
				is_conquered = no
				conquest_culture = FROM
			}
		}

		mult_modifier = {
			factor = 0.01
			FROM = { trait = imbecile }
		}

		mult_modifier = {
			factor = 0.1

			new_character = {
				character = FROM
				trait = humble
			}
		}

		mult_modifier = {
			factor = 0.1

			new_character = {
				character = FROM
				trait = content
			}
		}

		mult_modifier = {
			factor = 0.1
			FROM = { trait = inbred }
		}

		mult_modifier = {
			factor = 0.1
			FROM = { trait = craven }
		}

		mult_modifier = {
			factor = 0.2

			FROM = {
				OR = {
					trait = slow
					trait = dull
				}
			}
		}

		mult_modifier = {
			factor = 0.5
			FROM = { trait = slothful }
		}

		mult_modifier = {
			factor = 0.5

			FROM = {
				trait = humble
				NOT = { character = new_character }
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				character = FROM
				trait = brave
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				character = FROM
				trait = proud
			}
		}

		mult_modifier = {
			factor = 1.5

			new_character = {
				character = FROM

				OR = {
					trait = envious
					trait = greedy
					trait = deceitful
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			is_conquered = yes
			NOT = { conquest_culture = FROM }
			new_character = { culture = FROM }

			FROM = {
				OR = {
					trait = diligent
					trait = just
					trait = wroth
				}
			}
		}

		mult_modifier = {
			factor = 3.0
			FROM = { trait = lunatic }
		}

		mult_modifier = {
			factor = 4.0

			new_character = {
				OR = {
					character = FROM
					is_child_of = FROM
					is_married = FROM
				}
			}

			FROM = { trait = ambitious }
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 4

		trigger = {
			preparing_invasion = no
			NOT = { rightful_religious_head = THIS }

			# The following require spymaster/favor coercion to overrule
			trigger_if = {
				limit = {
					OR = {
						AND = {
							rightful_religious_head_scope = {
								has_landed_title = FROMFROM
								ai = yes
							}

							NOT = { trait = cynical }
						}

						FROMFROM = {
							OR = {
								holder_scope = {
									OR = {
										AND = {
											independent = no
											NOT = { same_realm = ROOT }
										}

										# Will not support a claimant against someone you installed in the position
										reverse_has_opinion_modifier = {
											name = opinion_fought_for_claimant
											who = ROOT
										}

										# Will not support claimants against their own spouse
										is_married = ROOT

										trigger_if = {
											limit = {
												culture = ROOT
												religion = ROOT
											}

											ROOT = {
												trigger_if = {
													limit = {
														OR = {
															trait = deceitful
															trait = ambitious
															trait = envious
															trait = proud
															trait = brave
														}
													}

													opinion = {
														who = PREV
														value >= 25
													}
												}
												trigger_else = {
													opinion = {
														who = PREV
														value >= 0
													}
												}
											}
										}
										trigger_else = {
											ROOT = {
												trigger_if = {
													limit = {
														OR = {
															trait = deceitful
															trait = ambitious
															trait = envious
															trait = proud
															trait = brave
														}
													}

													opinion = {
														who = PREV
														value >= 50
													}
												}
												trigger_else = {
													opinion = {
														who = PREV
														value >= 25
													}
												}
											}
										}
									}
								}

								# Will not support a claimant for a non-dynastic elective title that is currently contested by someone of a different religion/culture group
								AND = {
									holder_scope = {
										culture_group = ROOT
										religion = ROOT
											any_war = {
											war_title = PREVPREV

											attacker = {
												NAND = {
													culture_group = ROOT
													religion = ROOT
												}
											}
										}
									}

									NOR = {
										has_law = succ_feudal_elective
										has_law = succ_hre_elective
										has_law = succ_byzantine_elective
									}
								}

								# Will not support a claim for the primary title if there is an equal-tier title they are de jure vassal of
								AND = {
									is_primary_holder_title = yes
									NOT = { de_jure_vassal_or_below = ROOT }

									holder_scope = {
										any_demesne_title = {
											is_primary_holder_title_tier = yes
											de_jure_vassal_or_below = ROOT
											NOT = { title = PREVPREV }
										}
									}
								}
							}
						}

						FROM = {
							supported_claimant = {
								OR = {
									NOT = { religion = ROOT }

									reverse_opinion = {
										who = ROOT
										value < 0
									}

									# Limits on who the AI will install in the title
									OR = {
										is_rival = ROOT
										trait = blinded
										trait = eunuch
										trait = imbecile
										trait = inbred
										trait = monk
										trait = nun
										trait = abdicated
										trait = druid
										trait = bad_druid
										trait = retired_vestalis
										trait = vestalis
									}

									# Not old women, period
									trigger_if = {
										limit = { is_female = yes }
										practical_age >= 40
									}

									# Not over 65 or celibate unless they have a legitimate son
									trigger_if = {
										limit = {
											OR = {
												practical_age >= 65
												trait = celibate
											}
										}

										NOT = {
											any_child = {
												is_female = no
												has_inheritance_blocker = no
											}
										}
									}

									# I must like the Claimant more than the current ruler
									trigger_if = {
										limit = { NOT = { character = ROOT } }

										ROOT = {
											opinion_diff = {
												first = PREV
												second = liege
												value < 10
												as_if_liege = yes
											}
										}
									}

									# Personal traits of the claimant
									trigger_if = {
										limit = {
											OR = {
												trait = lunatic
												trait = possessed
											}
										}

										NAND = {
											ROOT = {
												OR = {
													trait = lunatic
													trait = possessed
												}
											}

											ROOT_FROMFROM = {
												holder_scope = {
													NOR = {
														trait = lunatic
														trait = possessed
													}
												}
											}
										}
									}
								}
							}
						}

						# Will not support women for an agnatic title unless they have a son or are formidable
						AND = {
							FROMFROM = {
								has_law = agnatic_succession
							}

							FROM = {
								supported_claimant = {
									is_female = yes

									NOR = {
										character = ROOT

										any_child = {
											is_female = no
											has_inheritance_blocker = no

											OR = {
												dynasty = PREV
												dynasty = ROOT
											}
										}

										calc_true_if = {
											amount >= 2

											is_ruler = yes
											prestige >= 1000
											diplomacy >= 12
											diplomacy >= 20
											intrigue >= 12
										}
									}
								}
							}

							is_feminist_trigger = no
						}

						# Will not support men for an enatic title unless they have a daughter or are formidable
						AND = {
							FROMFROM = {
								has_law = enatic_succession
							}

							FROM = {
								supported_claimant = {
									is_female = no

									NOR = {
										character = ROOT

										any_child = {
											is_female = yes
											has_inheritance_blocker = no

											OR = {
												dynasty = PREV
												dynasty = ROOT
											}
										}

										calc_true_if = {
											amount >= 2

											is_ruler = yes
											prestige >= 1000
											diplomacy >= 12
											diplomacy >= 20
											intrigue >= 12
										}
									}
								}
							}
						}

						# Will not support a woman at all if zealous or in tradition faction
						AND = {
							is_feminist_trigger = no

							OR = {
								trait = zealous
								in_faction = faction_tradition
							}

							FROMFROM = {
								NOR = {
									has_law = true_cognatic_succession
									has_law = enatic_cognatic_succession
									has_law = enatic_succession
								}
							}

							FROM = {
								supported_claimant = { is_female = yes }
							}
						}

						# Will not install anyone else if the current heir
						AND = {
							FROMFROM = {
								current_heir = { character = ROOT }
							}

							FROM = {
								supported_claimant = {
									NOT = { character = ROOT }
								}
							}
						}

						# Will not support a claimant when they are a claimant of another pretender faction
						AND = {
							liege = {
								faction_exists = {
									faction = faction_pretender
									title = FROMFROM
									thirdparty = ROOT
								}
							}

							FROM = {
								supported_claimant = {
									NOT = { character = ROOT }
								}
							}
						}

						# Will not support a claimant for a title they also have a strong claim to
						AND = {
							has_strong_claim = FROMFROM

							FROM = {
								supported_claimant = {
									NOT = { character = ROOT }
								}
							}
						}

						# Will not support a claimant of a different dynasty if holder is same dynasty, religion and culture
						AND = {
							FROMFROM = {
								holder_scope = {
									dynasty = ROOT
									religion = ROOT
									culture = ROOT
								}
							}

							FROM = {
								supported_claimant = {
									NOT = { dynasty = ROOT }
								}
							}
						}

						# Will not support oneself for a non-dynastic elective title unless ambitious, proud, or a justified/strong claimant
						AND = {
							FROM = {
								supported_claimant = {
									character = ROOT
								}
							}

							FROMFROM = {
								NOR = {
									has_law = succ_feudal_elective
									has_law = succ_hre_elective
									has_law = succ_byzantine_elective
								}
							}

							NOR = {
								trait = ambitious
								trait = proud
								has_strong_claim = FROMFROM
								has_character_flag = justified_claimant
							}
						}

						# If recently conquered, will not support a claimant of a different culture
						AND = {
							FROMFROM = { is_conquered = yes }

							FROM = {
								supported_claimant = {
									NOT = { culture = ROOT }
								}
							}
						}
					}
				}

				has_opinion_modifier = {
					name = opinion_coerced_into_joining_faction
					who = FROM
				}
			}

			# Under some circumstances, only join impending civil war
			trigger_if = {
				limit = {
					OR = {
						AND = {
							FROM = {
								supported_claimant = { trait = decadent }
							}

							NOT = { trait = decadent }
						}

						# Should not be supporting a different claimant unless it's yourself
						AND = {
							in_faction = faction_pretender

							supported_claimant = {
								FROM = {
									supported_claimant = {
										NOR = {
											character = ROOT
											character = PREVPREV
										}
									}
								}
							}
						}

						# If there is an antiking faction, prioritize that
						AND = {
							has_character_flag = opposes_the_antipope
							religion = liege

							OR = {
								religion = catholic
								religion = fraticelli
							}

							liege = {
								rightful_religious_head_scope = {
									is_antipope = yes
									vassal_of = PREV
								}

								faction_exists = {
									faction = faction_antiking
									title = FROMFROM
								}
							}
						}
					}
				}

				has_character_flag = will_join_civil_war
			}
		}

		# Stay if coerced into the faction (by favor, or otherwise)
		mult_modifier = {
			factor = 1000

			has_opinion_modifier = {
				name = opinion_coerced_into_joining_faction
				who = FROM
			}
		}

		# Stay if willingly joined at the outset of civil war
		mult_modifier = {
			factor = 100

			has_character_flag = will_join_civil_war

			FROM = {
				has_character_flag = preparing_claimant_faction_war
				has_character_flag = civil_war_faction_leader
			}
		}

		mult_modifier = {
			factor = 0.2
			pacifist = yes
		}

		mult_modifier = {
			factor = 0.9
			liege = { trait = crowned_by_vip }
		}

		mult_modifier = {
			factor = 0.8

			liege = {
				OR = {
					trait = crowned_by_pope
					trait = crowned_by_relhead
				}
			}
		}

		mult_modifier = {
			factor = 0.75
			liege = { trait = strong_basileus }
		}

		mult_modifier = {
			factor = 3.0

			FROMFROM = {
				holder_scope = {
					OR = {
						prisoner = yes
						is_adult = no
						is_incapable = yes
						trait = uncrowned
					}
				}
			}
		}

		mult_modifier = {
			factor = 3.0

			FROM = {
				supported_claimant = { has_character_flag = justified_claimant }
			}
		}

		mult_modifier = {
			factor = 10.0

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					dynasty = ROOT
					NOT = { character = ROOT }
				}
			}
		}

		mult_modifier = {
			factor = 1.5
			FROM = {
				supported_claimant = { is_close_relative = ROOT }
			}
		}

		mult_modifier = {
			factor = 0.25

			FROM = {
				supported_claimant = { NOT = { culture = ROOT } }
			}
		}

		mult_modifier = {
			factor = 0.25

			FROM = {
				supported_claimant = { NOT = { culture_group = ROOT } }
			}
		}

		mult_modifier = {
			factor = 0.1

			FROMFROM = {
				holder_scope = {
					reverse_has_opinion_modifier = {
						name = sworn_to_support_heir
						who = ROOT
					}
				}
			}

			NOT = { trait = deceitful }
		}

		# Will support a claimant of the same religion & culture against a liege who is either not of the same religion group or the same culture group
		mult_modifier = {
			factor = 10.0

			FROM = {
				supported_claimant = {
					culture = ROOT
					religion = ROOT
				}
			}

			FROMFROM = {
				holder_scope = {
					is_liege_of = ROOT

					NAND = {
						culture_group = ROOT
						religion_group = ROOT
					}
				}
			}
		}

		# Less likely to support young children
		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = { age < 13 }
			}
		}

		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = { age < 10 }
			}
		}

		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = { age < 5 }
			}
		}

		# More likely to support a male claimant against a female holding an agnatic title
		mult_modifier = {
			factor = 3.0

			FROMFROM = {
				has_law = agnatic_succession
				holder_scope = { is_female = yes }
			}

			FROM = {
				supported_claimant = { is_female = no }
			}

			is_feminist_trigger = no
		}

		# More likely to support a female claimant against a male holding an enatic title
		mult_modifier = {
			factor = 3.0

			FROMFROM = {
				has_law = enatic_succession
				holder_scope = { is_female = no }
			}

			FROM = {
				supported_claimant = { is_female = yes }
			}
		}

		# Unlikely to support women for an cognatic title unless they have a son or are formidable
		mult_modifier = {
			factor = 0.5

			FROMFROM = {
				has_law = cognatic_succession
			}

			is_feminist_trigger = no

			FROM = {
				supported_claimant = {
					is_female = yes

					NOR = {
						character = ROOT

						any_child = {
							is_female = no
							has_inheritance_blocker = no

							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
						}

						calc_true_if = {
							amount >= 2

							is_ruler = yes
							prestige >= 1000
							diplomacy >= 12
							diplomacy >= 20
							intrigue >= 12
						}
					}
				}
			}
		}

		# Unlikely to support a woman in any case unless you are a woman
		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = { is_female = yes }
			}

			is_female = no
			is_feminist_trigger = no

			FROMFROM = {
				NOR = {
					has_law = true_cognatic_succession
					has_law = enatic_cognatic_succession
					has_law = enatic_succession
				}
			}
		}

		# Unlikely to support men for an enatic-cognatic title unless they have a daughter or are formidable
		mult_modifier = {
			factor = 0.5

			FROMFROM = {
				has_law = enatic_cognatic_succession
			}

			FROM = {
				supported_claimant = {
					is_female = no

					NOR = {
						character = ROOT

						any_child = {
							is_female = yes
							has_inheritance_blocker = no

							OR = {
								dynasty = PREV
								dynasty = ROOT
							}
						}

						calc_true_if = {
							amount >= 2

							is_ruler = yes
							prestige >= 1000
							diplomacy >= 12
							diplomacy >= 20
							intrigue >= 12
						}
					}
				}
			}
		}

		# Unlikely to support a man in any case unless you are a man
		mult_modifier = {
			factor = 0.5

			is_female = yes

			FROM = {
				supported_claimant = { is_female = no }
			}

			FROMFROM = {
				NOR = {
					has_law = true_cognatic_succession
					has_law = cognatic_succession
					has_law = agnatic_succession
				}
			}
		}

		# Less likely to support a weak claimant when a strong claimant of the same religion, culture and dynasty exists in the realm
		mult_modifier = {
			factor = 0.25

			FROM = {
				supported_claimant = { has_weak_claim = FROMFROM }
			}

			liege = {
				any_vassal = {
					leads_faction = faction_pretender

					supported_claimant = {
						dynasty = ROOT
						has_strong_claim = FROMFROM
						religion = ROOT
						culture = ROOT
					}
				}
			}
		}

		# There's already another claimant that I like
		mult_modifier = {
			factor = 0.75

			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}

			FROMFROM = {
				holder_scope = {
					any_vassal = {
						leads_faction = faction_pretender

						supported_claimant = {
							culture = ROOT
							religion = ROOT
							dynasty = ROOT

							reverse_opinion = {
								who = FROM
								value >= 20
							}

							FROM = {
								supported_claimant = {
									NOT = { character = PREVPREV }
								}
							}
						}
					}
				}
			}
		}

		# Less likely to support a weak claimant for a title they also have a weak claim to unless it has good backing
		mult_modifier = {
			factor = 0.1

			has_weak_claim = FROMFROM

			FROM = {
				supported_claimant = {
					has_weak_claim = FROMFROM
					NOT = { character = ROOT }
				}

				faction_power = {
					faction = faction_pretender
					power < 0.3
				}

				num_of_faction_backers = {
					faction = faction_pretender
					value < 3
				}
			}

			FROMFROM = {
				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}
		}

		# Still reluctant to support a weak claimant for a title they also have a weak claim to even when it has good backing
		mult_modifier = {
			factor = 0.5

			has_weak_claim = FROMFROM

			FROM = {
				supported_claimant = {
					has_weak_claim = FROMFROM
					NOT = { character = ROOT }
				}

				OR = {
					faction_power = {
						faction = faction_pretender
						power >= 0.3
					}

					num_of_faction_backers = {
						faction = faction_pretender
						value >= 3
					}
				}
			}

			FROMFROM = {
				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}
		}

		# Less likely to support a strong claimant for a title they have a weak claim to unless it has good backing
		mult_modifier = {
			factor = 0.25

			has_weak_claim = FROMFROM

			FROM = {
				supported_claimant = {
					has_strong_claim = FROMFROM
					NOT = { character = ROOT }
				}

				faction_power = {
					faction = faction_pretender
					power < 0.3
				}

				num_of_faction_backers = {
					faction = faction_pretender
					value < 3
				}
			}

			FROMFROM = {
				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}
		}

		# Still less likely to support a strong claimant for a title they have a weak claim even when it has good backing
		mult_modifier = {
			factor = 0.75

			has_weak_claim = FROMFROM

			FROMFROM = {
				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
					has_law = succ_byzantine_elective
				}
			}

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
					has_strong_claim = FROMFROM
				}

				OR = {
					faction_power = {
						faction = faction_pretender
						power >= 0.3
					}

					num_of_faction_backers = {
						faction = faction_pretender
						value >= 3
					}
				}
			}
		}

		# More likely to support claimants from less powerful dynasties
		mult_modifier = {
			factor = 2.0

			FROMFROM = {
				holder_scope = {
					dynasty_realm_power >= 0.25

					ROOT_FROM = {
						supported_claimant = {
							NOT = { dynasty = PREVPREV }
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			FROMFROM = {
				holder_scope = {
					dynasty_realm_power >= 0.4

					ROOT_FROM = {
						supported_claimant = {
							NOT = { dynasty = PREVPREV }
						}
					}
				}
			}
		}

		# Less likely to support a claimant not born in the purple against a holder who is
		mult_modifier = {
			factor = 0.5

			FROMFROM = {
				OR = {
					title = e_byzantium
					title = e_roman_empire
				}

				holder_scope = { trait = born_in_the_purple }
			}

			FROM = {
				supported_claimant = { NOT = { trait = born_in_the_purple } }
			}

			OR = {
				culture_group = byzantine
				culture = roman
			}
		}

		# More likely to support a claimant born in the purple against a holder who isn't
		mult_modifier = {
			factor = 2.0

			FROMFROM = {
				OR = {
					title = e_byzantium
					title = e_roman_empire
				}

				holder_scope = { NOT = { trait = born_in_the_purple } }
			}

			FROM = {
				supported_claimant = { trait = born_in_the_purple }
			}

			OR = {
				culture_group = byzantine
				culture = roman
			}
		}

		# More likely to support sayyid against a holder who isn't
		mult_modifier = {
			factor = 2.0

			FROM = {
				supported_claimant = { trait = sayyid }
			}

			religion_group = muslim

			FROMFROM = {
				holder_scope = { NOT = { trait = sayyid } }
			}
		}

		# More likely to support mirza against a holder who is neither sayyid nor mirza
		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = { trait = mirza }
			}

			religion_group = muslim

			FROMFROM = {
				holder_scope = {
					NOR = {
						trait = sayyid
						trait = mirza
					}
				}
			}
		}

		# Members of the tradition faction are less likely to support claimants unless the holder is excommunicated
		mult_modifier = {
			factor = 2

			in_faction = faction_tradition

			FROMFROM = {
				holder_scope = { excommunicated_for = ROOT }
			}
		}

		mult_modifier = {
			factor = 0.5

			in_faction = faction_tradition

			FROMFROM = {
				holder_scope = { NOT = { excommunicated_for = ROOT } }
			}
		}

		# Members of the court faction are more likely to support claimants
		mult_modifier = {
			factor = 2.0

			in_faction = faction_court

			liege = {
				OR = {
					has_character_flag = faction_court_angry
					has_character_flag = faction_court_unhappy
				}
			}
		}

		# Faction leader is a member of the same faction, which is angry
		mult_modifier = {
			factor = 5.0

			trigger_if = {
				limit = { in_faction = faction_court }

				FROM = {
					OR = {
						leads_faction = faction_court

						any_faction_backer = {
							faction = faction_pretender
							leads_faction = faction_court
						}
					}

					liege = { has_character_flag = faction_court_angry }
				}
			}
			trigger_else_if = {
				limit = { in_faction = faction_prosperity }

				FROM = {
					OR = {
						leads_faction = faction_prosperity

						any_faction_backer = {
							faction = faction_pretender
							leads_faction = faction_prosperity
						}
					}

					liege = { has_character_flag = faction_prosperity_angry }
				}
			}
			trigger_else_if = {
				limit = { in_faction = faction_glory }

				FROM = {
					OR = {
						leads_faction = faction_glory

						any_faction_backer = {
							faction = faction_pretender
							leads_faction = faction_glory
						}
					}

					liege = { has_character_flag = faction_glory_angry }
				}
			}
			trigger_else = {
				in_faction = faction_tradition

				FROM = {
					OR = {
						leads_faction = faction_tradition

						any_faction_backer = {
							faction = faction_pretender
							leads_faction = faction_tradition
						}
					}

					liege = { has_character_flag = faction_tradition_angry }
				}
			}
		}

		# Opinions
		mult_modifier = {
			factor = 100.0

			FROM = {
				supported_claimant = {
					reverse_has_opinion_modifier = {
						name = opinion_support_claimant
						who = ROOT
					}
				}
			}
		}

		# If recently conquered, more likely to support a claimant of the same culture
		mult_modifier = {
			factor = 4.0

			FROMFROM = {
				is_conquered = yes
				NOT = { conquest_culture = ROOT }
			}

			FROM = {
				supported_claimant = { culture = ROOT }
			}
		}

		mult_modifier = {
			factor = 1.5

			FROMFROM = {
				holder_scope = {
					reverse_opinion = {
						who = ROOT
						value < -25
					}
				}
			}
		}

		mult_modifier = {
			factor = 2.0

			FROMFROM = {
				holder_scope = {
					reverse_opinion = {
						who = ROOT
						value < -50
					}
				}
			}
		}

		mult_modifier = {
			factor = 4.0

			FROMFROM = {
				holder_scope = {
					reverse_opinion = {
						who = ROOT
						value < -75
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = {
					reverse_opinion = {
						who = ROOT
						value < 20
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }

					ROOT = {
						opinion_diff = {
							first = PREV
							second = liege
							value >= 25
							as_if_liege = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }

					ROOT = {
						opinion_diff = {
							first = PREV
							second = liege
							value >= 50
							as_if_liege = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }

					ROOT = {
						opinion_diff = {
							first = PREV
							second = liege
							value >= 75
							as_if_liege = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }

					ROOT = {
						opinion_diff = {
							first = PREV
							second = liege
							value >= 100
							as_if_liege = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.1

			opinion = {
				who = FROM
				value >= 25
			}
		}

		mult_modifier = {
			factor = 1.1

			opinion = {
				who = FROM
				value >= 50
			}
		}

		mult_modifier = {
			factor = 1.1

			opinion = {
				who = FROM
				value >= 75
			}
		}

		mult_modifier = {
			factor = 0.9

			opinion = {
				who = FROM
				value < -25
			}
		}

		mult_modifier = {
			factor = 0.9

			opinion = {
				who = FROM
				value < -50
			}
		}

		mult_modifier = {
			factor = 0.9

			opinion = {
				who = FROM
				value < -75
			}
		}

		mult_modifier = {
			factor = 1.5

			FROM = {
				supported_claimant = {
					is_smart_trigger = yes
				}
			}

			FROMFROM = {
				holder_scope = {
					is_smart_trigger = no
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			FROM = {
				supported_claimant = {
					OR = {
						trait = slow
						trait = dull
						trait = infirm
						trait = content
						health < 4
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.5

			trait = zealous

			FROM = {
				supported_claimant = { trait = zealous }
			}

			FROMFROM = {
				holder_scope = { NOT = { trait = zealous } }
			}
		}

		mult_modifier = {
			factor = 0.5

			trait = cynical

			FROM = {
				supported_claimant = { trait = cynical }
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value >= 2
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value >= 4
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value >= 6
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value >= 8
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = diplomacy
							value >= 10
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value >= 2
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value >= 4
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value >= 6
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value >= 8
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = diplomacy
								value >= 10
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = stewardship
							value >= 5
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = stewardship
								value >= 5
							}
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.2

			liege = {
				FROM = {
					supported_claimant = {
						attribute_diff = {
							character = PREVPREV
							attribute = intrigue
							value >= 5
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.8

			FROM = {
				supported_claimant = {
					FROMFROM = {
						holder_scope = {
							attribute_diff = {
								character = PREVPREV
								attribute = intrigue
								value >= 5
							}
						}
					}
				}
			}
		}

		# Personal traits
		mult_modifier = {
			factor = 0.01

			trait = content
			NOT = { has_character_flag = will_join_civil_war }

			FROMFROM = {
				OR = {
					is_conquered = no
					conquest_culture = FROM
				}
			}
		}

		mult_modifier = {
			factor = 0.01

			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = humble
			NOT = { has_character_flag = will_join_civil_war }

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 0.1

			trait = content
			NOT = { has_character_flag = will_join_civil_war }

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 0.1

			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.2

			OR = {
				trait = slow
				trait = dull
			}
		}

		mult_modifier = {
			factor = 0.5
			trait = slothful
		}

		mult_modifier = {
			factor = 0.5

			trait = humble

			FROM = {
				supported_claimant = { NOT = { character = ROOT } }
			}
		}

		mult_modifier = {
			factor = 1.5

			trait = brave

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 1.5

			trait = proud

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 1.5

			OR = {
				trait = envious
				trait = greedy
				trait = deceitful
			}

			FROM = {
				supported_claimant = { character = ROOT }
			}
		}

		mult_modifier = {
			factor = 2.0

			FROMFROM = {
				is_conquered = yes
				NOT = { conquest_culture = ROOT }
			}

			FROM = {
				supported_claimant = { culture = ROOT }
			}

			OR = {
				trait = diligent
				trait = just
				trait = wroth
			}
		}

		mult_modifier = {
			factor = 3.0
			trait = lunatic
		}

		mult_modifier = {
			factor = 4.0

			trait = ambitious

			FROM = {
				supported_claimant = {
					OR = {
						character = ROOT
						is_child_of = ROOT
						is_married = ROOT
					}
				}
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no		# Factions will abort if the Potential or Allow triggers are no longer valid
	}

	abort_effect = {
	}

	effect = {
	}
}

# Religious Faction
faction_religious = {
	type = character

	warning_level = 0.7 # At this level of faction power we give player an alert. Set to 0 for no alerts.

	# Plotter scope
	potential = {
		is_playable = yes
		is_landed = yes
		is_adult = yes
		faction_council_trigger = yes
		independent = no
		prisoner = no
		holy_order = no
		is_incapable = no
		in_revolt = no

		OR = {
			higher_real_tier_than = COUNT
			liege = { lower_real_tier_than = KING }
		}

		OR = {
			is_parent_religion = liege
			is_heresy_of = liege
		}

		NOR = {
			has_truce = liege
			has_non_aggression_pact_with = liege
			has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
		}

		liege = {
			independent = yes
			in_revolt = no
			NOT = { has_character_flag = faction_religious_war }
		}
	}

	# Faction member scope (ROOT = joiner, FROM = target)
	allow_join = {
		ROOT = {
			is_playable = yes
			is_landed = yes
			is_adult = yes
			faction_council_trigger = yes
			independent = no
			prisoner = no
			in_revolt = no
			is_incapable = no

			trigger_if = {
				limit = {
					is_inaccessible_trigger = yes
					NOT = { in_faction = faction_religious }
				}

				has_character_flag = will_join_civil_war
			}

			OR = {
				is_parent_religion = liege
				is_heresy_of = liege
			}

			NOR = {
				has_non_aggression_pact_with = liege
				has_opinion_modifier = { who = liege name = opinion_coerced_into_leaving_faction }
			}
		}
	}

	# AI creation weight (ROOT = faction creator)
	chance = {
		factor = 50

		trigger = {
			prisoner = no
			in_seclusion = no
			pacifist = no

			NOR = {
				leads_faction = faction_separatist
				trait = cynical
				rightful_religious_head = THIS
				is_primary_heir = liege
			}

			opinion = {
				who = liege
				value < 0
			}
		}

		mult_modifier = {
			factor = 5
			trait = zealous
		}

		mult_modifier = {
			factor = 1.5
			trait = brave
		}

		mult_modifier = {
			factor = 0.5
			trait = arbitrary
		}

		mult_modifier = {
			factor = 0.5
			trait = slothful
		}

		mult_modifier = {
			factor = 0.1
			trait = humble
		}

		mult_modifier = {
			factor = 0.1
			trait = content
		}

		mult_modifier = {
			factor = 0.1
			trait = craven
		}

		mult_modifier = {
			factor = 0.1
			trait = imbecile
		}

		mult_modifier = {
			factor = 0.1
			trait = inbred
		}

		mult_modifier = {
			factor = 0.5

			opinion = {
				who = liege
				value >= -25
			}
		}
	}

	# AI membership weight: ROOT is the prospective member. FROM is the faction leader. FROMFROM is the target title or character.
	membership = {
		factor = 10

		trigger = {
			religion = FROM
			pacifist = no

			NOR = {
				leads_faction = faction_separatist
				is_primary_heir = liege
			}

			opinion = {
				who = liege
				value < 0
			}

			trigger_if = {
				limit = { trait = cynical }
				has_character_flag = will_join_civil_war
			}
		}

		# Stay if coerced into the faction (by favor, or otherwise)
		mult_modifier = {
			factor = 1000

			has_opinion_modifier = {
				name = opinion_coerced_into_joining_faction
				who = FROM
			}
		}

		mult_modifier = {
			factor = 100

			has_character_flag = will_join_civil_war

			FROM = {
				has_character_flag = preparing_religious_faction_war
				has_character_flag = civil_war_faction_leader
			}
		}

		mult_modifier = {
			factor = 10
			rightful_religious_head = ROOT
		}

		mult_modifier = {
			factor = 5
			trait = zealous
		}

		mult_modifier = {
			factor = 1.5
			trait = brave
		}

		mult_modifier = {
			factor = 0.5
			trait = arbitrary
		}

		mult_modifier = {
			factor = 0.5
			trait = slothful
		}

		mult_modifier = {
			factor = 0.1

			trait = humble
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = content
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = craven
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = imbecile
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.1

			trait = inbred
			NOT = { has_character_flag = will_join_civil_war }
		}

		mult_modifier = {
			factor = 0.5

			opinion = {
				who = liege
				value >= -25
			}
		}
	}

	success = {
		always = no
	}

	abort = {
		always = no
	}

	abort_effect = {
	}

	effect = {
	}
}