﻿confederate_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 0

	can_keep = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_japan_feudal
				tgp_realm_has_ceremonial_liege_trigger = yes
			}
			is_independent_ruler = no
		}
		trigger_else = { always = yes } # for readability
	}
	can_pass = {
		can_change_partition_succession_law_trigger = yes
		trigger_if = {
			limit = {
				exists = primary_title
			}
			is_confederation_member = no
		}
	}
	can_have = {
		can_have_confederate_partition_succession_law_trigger = yes
		trigger_if = {
			limit = {
				exists = primary_title
			}
			is_confederation_member = no
		}
	}
	should_start_with = {
		NOR = {
			historical_succession_access_single_heir_succession_law_trigger = yes
			historical_succession_access_single_heir_succession_law_youngest_trigger = yes
			historical_succession_access_single_heir_dynasty_house_trigger = yes
		}
		OR = {
			AND = {
				government_has_flag = government_is_feudal
				culture = {
					NOR = {
						has_innovation = innovation_hereditary_rule
						has_innovation = innovation_heraldry
					}
				}
			}
			government_has_flag = government_is_tribal
		}
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
		create_primary_tier_titles = yes
	}
	flag = partition_succession_law
	modifier = {
		glory_hound_opinion = 10
		parochial_opinion = 5
		belligerent_opinion = -10
		dynasty_house_opinion = 5
		eligible_child_opinion = 10
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}

	potential = {
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_clan
			government_has_flag = government_is_administrative
			government_has_flag = government_is_mandala
			government_has_flag = government_is_celestial
			government_has_flag = government_is_meritocratic
			government_has_flag = government_is_steppe_admin
		}
	}
}

partition_succession_law = {
	law_group_type = succession_order_laws
	index = 1

	can_keep = {
		OR = {
			can_keep_partition_succession_law_trigger = yes
			trigger_if = {
				limit = {
					exists = primary_title
				}
				is_confederation_member = yes
			}
		}
	}
	can_pass = {
		# it's failure only block, workaround for showing correct toolip.
		trigger_if = {
			limit = {
				exists = primary_title
				is_confederation_member = yes
			}
			is_confederation_member = yes
		}
		trigger_else = {
			can_change_partition_succession_law_trigger = yes
		}
	}
	can_have = {
		# it's failure only block, workaround for showing correct toolip.
		trigger_if = {
			limit = {
				exists = primary_title
				is_confederation_member = yes
			}
			is_confederation_member = yes
		}
		trigger_else = {
			can_have_partition_succession_law_trigger = yes
		}
	}
	should_start_with = {
		NOR = {
			historical_succession_access_single_heir_succession_law_trigger = yes
			historical_succession_access_single_heir_succession_law_youngest_trigger = yes
			historical_succession_access_single_heir_dynasty_house_trigger = yes
		}
		government_has_flag = government_is_feudal
		culture = {
			has_innovation = innovation_hereditary_rule
			NOT = {
				has_innovation = innovation_heraldry
			}
		}
		NOT = { government_has_mechanic = administrative }
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
	}
	flag = partition_succession_law
	modifier = {
		glory_hound_opinion = 10
		parochial_opinion = 5
		belligerent_opinion = -10
		player_heir_opinion = 10
		eligible_child_except_player_heir_opinion = 5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = { has_realm_law = confederate_partition_succession_law }
			value = 1
		}
	}

	potential = {
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_clan
			government_has_flag = government_is_administrative
			government_has_flag = government_is_mandala
			government_has_flag = government_is_celestial
			government_has_flag = government_is_meritocratic
			government_has_flag = government_is_steppe_admin
		}
	}
}

high_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 2

	can_keep = {
		can_keep_high_partition_succession_law_trigger = yes
	}
	can_pass = {
		can_change_partition_succession_law_trigger = yes
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_high_partition_succession_law_trigger = yes
	}
	should_start_with = {
		NOR = {
			historical_succession_access_single_heir_succession_law_trigger = yes
			historical_succession_access_single_heir_succession_law_youngest_trigger = yes
			historical_succession_access_single_heir_dynasty_house_trigger = yes
		}
		government_has_flag = government_is_feudal
		culture = {
			has_innovation = innovation_heraldry
			NOT = {
				has_innovation = innovation_primogeniture
			}
		}
		NOT = { government_has_mechanic = administrative }
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
		primary_heir_minimum_share = 0.5
	}
	flag = partition_succession_law
	modifier = {
		glory_hound_opinion = 5
		belligerent_opinion = -10
		player_heir_opinion = 15
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
				}
			}
			value = 2
		}
	}

	potential = {
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_clan
			government_has_flag = government_is_administrative
			government_has_flag = government_is_mandala
			government_has_flag = government_is_celestial
			government_has_flag = government_is_meritocratic
			government_has_flag = government_is_steppe_admin
		}
	}
}

single_heir_succession_law = {
	law_group_type = succession_order_laws
	index = 3

	can_keep = {
		can_keep_single_heir_succession_law_trigger = yes
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				top_liege != this
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_title_have = {
		# Ceremonial Regent
		NOT = { exists = var:administrative_ui_special_title.holder }
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_single_heir_succession_law_trigger = yes
	}
	can_pass = {
		can_change_succession_law_trigger = yes
		trigger_if = {
			limit = {
				government_has_flag = government_is_clan
			}
			piety_level >= 3
		}
		trigger_if = {
			limit = {
				government_has_mechanic = administrative
			}
			influence_level >= 4
			has_active_diarchy = no
			primary_title = { title_held_years >= 10 }
		}
	}
	should_start_with = {
		OR = {
			historical_succession_access_single_heir_succession_law_trigger = yes
			culture = {
				has_innovation = innovation_primogeniture
			}
		}
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = single_heir
	}
	flag = advanced_succession_law
	modifier = {
		glory_hound_opinion = -10
		parochial_opinion = -5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
		piety = {
			value = 0
			if = {
				limit = {
					government_has_flag = government_is_clan
				}
				add = {
					desc = "clan_government_cost_tooltip"
					value = 1500
				}
			}
		}
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		value = 3
	}

	potential = {
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_mandala
		}
		trigger_if = {
			limit = {
				government_has_mechanic = administrative
			}
			OR = {
				is_independent_ruler = yes
				tgp_is_ceremonial_liege_trigger = yes
			}
		}
	}
}

single_heir_succession_kurultai_law = {
	law_group_type = succession_order_laws
	index = 4

	can_keep = {
		government_has_flag = government_is_nomadic
	}
	can_have = {
		government_has_flag = government_is_nomadic
	}
	can_pass = {
		government_has_flag = government_is_nomadic
	}
	should_start_with = {
		government_has_flag = government_is_nomadic
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = single_heir
	}
	flag = advanced_succession_law
	flag = can_designate_heirs
	modifier = {
		belligerent_opinion = 10
		glory_hound_opinion = 5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -20
	}
	pass_cost = {
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		value = 3
	}

	potential = {
		government_has_flag = government_is_nomadic
	}
}

single_heir_succession_law_youngest = {
	law_group_type = succession_order_laws
	index = 5

	can_keep = {
		can_keep_single_heir_youngest_succession_law_trigger = yes
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				top_liege != this
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_single_heir_youngest_succession_law_trigger = yes
	}
	can_pass = {
		can_change_succession_law_trigger = yes
		trigger_if = {
			limit = {
				government_has_flag = government_is_clan
			}
			piety_level >= 3
		}
		trigger_if = {
			limit = {
				government_has_mechanic = administrative
			}
			influence_level >= 4
			has_active_diarchy = no
			primary_title = { title_held_years >= 10 }
		}
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = youngest
		title_division = single_heir
	}

	flag = advanced_succession_law
	modifier = {
		glory_hound_opinion = -10
		parochial_opinion = -5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
		piety = {
			value = 0
			if = {
				limit = {
					government_has_flag = government_is_clan
				}
				add = {
					desc = "clan_government_cost_tooltip"
					value = 1500
				}
			}
		}
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	potential = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_administrative
			}
			is_independent_ruler = yes
		}
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_mandala
		}
	}
}

single_heir_dynasty_house = { # LAST CALL
	law_group_type = succession_order_laws
	index = 6

	can_keep = {
		can_keep_single_heir_dynasty_house_trigger = yes
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				top_liege != this
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_single_heir_dynasty_house_trigger = yes
	}
	can_pass = {
		can_change_single_heir_dynasty_house_succession_law_trigger = yes
		trigger_if = {
			limit = {
				government_has_flag = government_is_clan
			}
			piety_level >= 3
		}
	}
	should_start_with = {
		historical_succession_access_single_heir_dynasty_house_trigger = yes
		NOT = { government_has_mechanic = administrative }
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = dynasty_house
		rank = oldest
		title_division = single_heir
	}

	flag = advanced_succession_law
	modifier = {
		glory_hound_opinion = -5
		eligible_child_except_player_heir_opinion = -15
		dynasty_house_opinion = 5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
		piety = {
			value = 0
			if = {
				limit = {
					government_has_flag = government_is_clan
				}
				add = {
					desc = "clan_government_cost_tooltip"
					value = 1500
				}
			}
		}
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				exists = primary_title
				primary_title.tier > tier_county
				OR = {
					#West Slavic
					culture = { has_cultural_pillar = heritage_west_slavic }
				}
			}
			value = 2
		}
	}

	potential = {
		NOR = {
			government_has_flag = government_is_administrative
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_mandala
		}
	}
}

acclamation_succession_law = {
	law_group_type = succession_order_laws
	index = 7

	can_keep = {
		can_keep_acclamation_succession_law_trigger = yes
	}
	can_pass = {
		can_change_acclamation_succession_law_trigger = yes
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_acclamation_succession_law_trigger = yes
	}
	should_start_with = {
		has_ep3_dlc_trigger = yes
		has_title = title:e_byzantium
		government_has_mechanic = administrative
	}
	succession = {
		order_of_succession = appointment
		appointment_type = admin_emperor
	}
	flag = advanced_succession_law
	flag = can_designate_heirs
	flag = appointment_type_succession
	pass_cost = {
		prestige = {
			value = change_succession_law_prestige_cost
			multiply = {
				value = 0.5 # We reduce the cost to ensure that going back to acclamation is easy
				desc = "[administrative_government|E]"
			}
		}
	}
	ai_will_do = {
		if = {
			limit = { has_realm_law = confederate_partition_succession_law }
			value = 1
		}
	}
	potential = {
		government_has_mechanic = administrative
		is_independent_ruler = yes
		NOR = {
			government_has_flag = government_is_japan_administrative
			government_has_flag = government_has_merit
		}
	}
}

appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 8

	can_keep = {
		can_keep_appointment_succession_law_trigger = yes
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				top_liege != this
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		NOT = { government_has_flag = government_is_nomadic }
		can_have_appointment_succession_law_trigger = yes
	}
	can_pass = {
		can_change_appointment_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_mechanic = administrative
		NOR = {
			government_has_flag = government_is_japan_administrative
			government_has_flag = government_has_merit
		}
		is_independent_ruler = no
	}
	succession = {
		order_of_succession = appointment
		appointment_type = admin_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	modifier = {
		glory_hound_opinion = -10
		parochial_opinion = -5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		government_has_mechanic = administrative # Default succession law for all admin types...
		NOR = { # ... Unless you have a unique succession available
			government_has_flag = government_is_japan_administrative
			government_has_flag = government_has_merit
		}
		is_independent_ruler = no
	}
}

#The prowess succession of LAAMPs is determined in code
landless_adventurer_succession_law = {
	law_group_type = succession_order_laws
	index = 9

	can_keep = {
		government_has_flag = government_is_landless_adventurer
	}
	can_have = {
		government_has_flag = government_is_landless_adventurer
	}
	can_pass = {
		government_has_flag = government_is_landless_adventurer
	}
	should_start_with = {
		government_has_flag = government_is_landless_adventurer
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_remove_from_title = {
		always = no
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = single_heir
		exclude_rulers = yes
		limit_to_courtiers = yes
	}
	flag = can_designate_heirs

	potential = {
		government_has_flag = government_is_landless_adventurer
	}
}


theocratic_elective_succession_law = {
	law_group_type = succession_order_laws
	index = 10

	can_have = {
		should_use_theocratic_elective_succession_law_trigger = yes
	}
	can_pass = {
		always = yes
	}
	can_title_have = {
		always = yes
	}
	succession = {
		order_of_succession = election
		election_type = theocratic_elective
		faith = same_faith
		resign_outside_realm = yes
	}
	flag = elective_succession_law
	title_allegiance_opinion = 10
	revoke_cost = {
		prestige = change_title_succession_law_prestige_cost
	}
	pass_cost = {
		prestige = change_title_succession_law_prestige_cost
	}
	potential = {
		should_use_theocratic_elective_succession_law_trigger = yes
	}

	modifier = {
		rite_creation_piety_cost_mult = 3 # Steers the Pope toward Bulls and Councils rather than editing rites directly
		character_travel_speed = 15
		character_travel_safety = 15 # He has to reach coronations and councils across Europe
		enemy_hostile_scheme_success_chance_max_add = -20
		enemy_hostile_scheme_success_chance_growth_add = -2 # The Curia around him makes murder harder
	}
}

clerical_appointment_law = {
	law_group_type = succession_order_laws
	index = 11

	can_keep = {
		should_use_clerical_appointment_law_trigger = yes
	}
	can_pass = {
		should_use_clerical_appointment_law_trigger = yes
	}
	can_have = {
		should_use_clerical_appointment_law_trigger = yes
	}
	should_start_with = {
		should_use_clerical_appointment_law_trigger = yes
	}
	succession = {
		order_of_succession = appointment
		appointment_type = clerical_christian
		faith = same_faith
	}
	flag = appointment_type_succession
	pass_cost = {
		prestige = {
			value = change_succession_law_prestige_cost
		}
	}
	ai_will_do = {
		if = {
			limit = { has_realm_law = confederate_partition_succession_law }
			value = 1
		}
	}
	potential = {
		should_use_clerical_appointment_law_trigger = yes
	}
}

bishop_theocratic_succession_law = {
	law_group_type = succession_order_laws
	index = 12

	can_keep = {
		can_have_bishop_theocratic_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_bishop_theocratic_succession_law_trigger = yes
	}
	should_start_with = {
		always = yes
	}
	succession = {
		order_of_succession = theocratic
		faith = same_faith
		pool_character_config = pool_theocratic_succession
	}

	potential = {
		can_have_bishop_theocratic_succession_law_trigger = yes
	}
}

holy_order_succession_law = {
	law_group_type = succession_order_laws
	index = 13

	can_keep = {
		can_have_holy_order_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_holy_order_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_military_holy_order
		NOT = {
			primary_title ?= {
				has_variable = order_heritage
			}
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_faith
		pool_character_config = pool_holy_order_succession
	}

	potential = {
		can_have_holy_order_succession_law_trigger = yes
	}
}
cultural_holy_order_succession_law = {
	law_group_type = succession_order_laws
	index = 14

	can_keep = {
		can_have_cultural_holy_order_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_cultural_holy_order_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_military_holy_order
		primary_title ?= {
			has_variable = order_heritage
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_faith
		pool_character_config = pool_cultural_holy_order_succession
	}

	potential = {
		can_have_cultural_holy_order_succession_law_trigger = yes
	}
}
monastic_holy_order_succession_law = {
	law_group_type = succession_order_laws
	index = 15

	can_keep = {
		can_have_monastic_holy_order_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_monastic_holy_order_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_monastic_holy_order
		NOR = {
			primary_title ?= {
				has_variable = female_order
			}
			primary_title ?= {
				has_variable = male_order
			}
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_rite
		pool_character_config = pool_monastic_holy_order_succession
	}

	potential = {
		can_have_monastic_holy_order_succession_law_trigger = yes
	}
}
female_monastic_holy_order_succession_law = {
	law_group_type = succession_order_laws
	index = 16

	can_keep = {
		can_have_female_monastic_holy_order_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_female_monastic_holy_order_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_monastic_holy_order
		primary_title ?= {
			has_variable = female_order
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_rite
		pool_character_config = pool_female_monastic_holy_order_succession
	}

	potential = {
		can_have_female_monastic_holy_order_succession_law_trigger = yes
	}
}
male_monastic_holy_order_succession_law = {
	law_group_type = succession_order_laws
	index = 17

	can_keep = {
		can_have_male_monastic_holy_order_succession_law_trigger = yes # same as can_have
	}
	can_have = {
		can_have_male_monastic_holy_order_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_monastic_holy_order
		primary_title ?= {
			has_variable = male_order
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_rite
		pool_character_config = pool_male_monastic_holy_order_succession
	}

	potential = {
		can_have_male_monastic_holy_order_succession_law_trigger = yes
	}
}

mercenary_company_succession_law = {
	law_group_type = succession_order_laws
	index = 18

	can_keep = {
		can_have_mercenary_succession_law_trigger = yes
	}
	can_have = {
		can_have_mercenary_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_mercenary
	}
	succession = {
		order_of_succession = company
		pool_character_config = pool_mercenary_succession
	}

	potential = {
		can_have_mercenary_succession_law_trigger = yes
	}
}

city_succession_law = {
	law_group_type = succession_order_laws
	index = 19

	can_keep = {
		can_have_city_succession_law_trigger = yes
	}
	can_have = {
		can_have_city_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_republic
	}
	succession = {
		order_of_succession = generate
		pool_character_config = pool_city_succession
	}

	potential = {
		can_have_city_succession_law_trigger = yes
	}
}

clan_antagonistic_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 20

	can_keep = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = antagonistic
		}
	}
	can_pass = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = antagonistic
		}
	}
	can_have = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = antagonistic
		}
	}

	should_start_with = {
		government_has_flag = government_is_clan
		house ?= { has_house_unity_stage = antagonistic }
	}

	potential = {
		government_has_flag = government_is_clan
	}

	requires_approve = {
		NOT = {
			government_has_flag = government_is_clan
		}
	}

	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
	}

	flag = same_house_vassals_gain_claim_on_primary_title
	flag = house_unity_stage_antagonistic

	modifier = {
		dynasty_house_opinion = -10
		glory_hound_opinion = 15
		zealot_opinion = 10
		belligerent_opinion = -10
		player_heir_opinion = 10
		eligible_child_except_player_heir_opinion = 5
	}

	widget_name = "widget_clan_law"
}

clan_competitive_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 21

	can_keep = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = competitive
		}
	}
	can_pass = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = competitive
		}
	}
	can_have = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = competitive
		}
	}
	should_start_with = {
		government_has_flag = government_is_clan
		house ?= { has_house_unity_stage = competitive }
	}

	potential = {
		government_has_flag = government_is_clan
	}

	requires_approve = {
		NOT = {
			government_has_flag = government_is_clan
		}
	}

	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
	}

	flag = same_house_vassals_gain_claim_on_primary_title
	flag = house_unity_stage_competitive

	modifier = {
		glory_hound_opinion = 10
		zealot_opinion = 5
		belligerent_opinion = -5
		player_heir_opinion = 10
		eligible_child_except_player_heir_opinion = 5
	}

	widget_name = "widget_clan_law"
}

clan_impassive_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 22

	can_keep = {
		government_has_flag = government_is_clan
		house ?= {
			OR = {
				has_house_unity_stage = impassive
				# In case the house is fully unlanded
				has_house_unity = no
			}
		}
	}
	can_pass = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = impassive
		}
	}
	can_have = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = impassive
		}
	}
	should_start_with = {
		government_has_flag = government_is_clan
		house ?= {
			OR = {
				has_house_unity_stage = impassive
				# In case the house is fully unlanded
				has_house_unity = no
			}
		}
	}

	potential = {
		government_has_flag = government_is_clan
	}

	requires_approve = {
		NOT = {
			government_has_flag = government_is_clan
		}
	}

	flag = house_unity_stage_impassive

	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
		primary_heir_minimum_share = 0.25
	}
	modifier = {
		glory_hound_opinion = 5
		parochial_opinion = 5
		player_heir_opinion = 15
	}

	widget_name = "widget_clan_law"
}

clan_friendly_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 23

	can_keep = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = friendly
		}
	}
	can_pass = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = friendly
		}
	}
	can_have = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = friendly
		}
	}
	should_start_with = {
		government_has_flag = government_is_clan
		house ?= { has_house_unity_stage = friendly }
	}

	potential = {
		government_has_flag = government_is_clan
	}

	requires_approve = {
		NOT = {
			government_has_flag = government_is_clan
		}
	}

	flag = house_unity_stage_friendly

	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
		primary_heir_minimum_share = 0.5
	}
	modifier = {
		parochial_opinion = 10
		courtly_opinion = 5
		player_heir_opinion = 25
	}

	widget_name = "widget_clan_law"
}

clan_harmonious_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 24

	can_keep = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = harmonious
		}
	}
	can_pass = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = harmonious
		}
	}
	can_have = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = harmonious
		}
	}
	should_start_with = {
		government_has_flag = government_is_clan
		house ?= {
			has_house_unity_stage = harmonious
		}
	}
	potential = {
		government_has_flag = government_is_clan
	}

	requires_approve = {
		NOT = {
			government_has_flag = government_is_clan
		}
	}

	flag = house_unity_stage_harmonious

	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = partition
		primary_heir_minimum_share = 0.75
	}
	modifier = {
		parochial_opinion = 15
		courtly_opinion = 10
		player_heir_opinion = 40
	}

	widget_name = "widget_clan_law"
}

herder_succession_law = {
	law_group_type = succession_order_laws
	index = 25

	can_keep = {
		can_have_herder_succession_law_trigger = yes
	}
	can_have = {
		can_have_herder_succession_law_trigger = yes
	}
	should_start_with = {
		government_has_flag = government_is_herder
	}
	can_remove_from_title = {
		always = no
	}
	succession = {
		order_of_succession = generate
		pool_character_config = pool_herder_succession
	}

	potential = {
		can_have_herder_succession_law_trigger = yes
	}
}

celestial_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 26

	can_keep = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = celestial_military_appointment }
		}
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				is_independent_ruler = no
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	can_pass = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	should_start_with = {
		government_has_flag = government_is_celestial
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = celestial_military_appointment }
		}
	}
	succession = {
		order_of_succession = appointment
		appointment_type = celestial_civic_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	flag = appointment_with_level_requirement
	modifier = {
		glory_hound_opinion = -10
		courtly_opinion = 5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		government_has_flag = government_is_celestial
		is_independent_ruler = no
	}
}

celestial_military_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 27

	can_keep = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = celestial_military_appointment
		}
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				is_independent_ruler = no
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	can_pass = {
		can_change_succession_law_trigger = yes
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	should_start_with = {
		government_has_flag = government_is_celestial
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = celestial_military_appointment
		}
	}
	succession = {
		order_of_succession = appointment
		appointment_type = celestial_military_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	flag = appointment_with_level_requirement
	modifier = {
		glory_hound_opinion = 5
		courtly_opinion = -10
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		government_has_flag = government_is_celestial
		is_independent_ruler = no
	}
}

japanese_regency_succession_law = {
	law_group_type = succession_order_laws
	index = 28

	can_keep = {
		can_have_japanese_regency_succession_law_trigger = yes
	}
	can_pass = {
		can_have_japanese_regency_succession_law_trigger = yes
	}
	can_have = {
		can_have_japanese_regency_succession_law_trigger = yes
	}
	can_title_have = {
		exists = var:administrative_ui_special_title
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_remove_from_title = {
		always = no
	}
	should_start_with = {
		always = no
	}
	succession = {
		order_of_succession = appointment
		appointment_type = japanese_regent
	}
	flag = advanced_succession_law
	flag = can_designate_heirs
	flag = appointment_type_succession
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	ai_will_do = {
		if = {
			limit = { has_realm_law = confederate_partition_succession_law }
			value = 1
		}
	}
	potential = {
		government_has_flag = government_is_japan_administrative
	}
}

japanese_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 29

	can_keep = {
		can_keep_japanese_appointment_succession_law_trigger = yes
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = japan_administrative_military_appointment }
		}
	}
	can_pass = {
		can_change_japanese_appointment_succession_law_trigger = yes
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = japan_administrative_military_appointment }
		}
	}
	can_have = {
		can_have_japanese_appointment_succession_law_trigger = yes
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = japan_administrative_military_appointment }
		}
	}
	should_start_with = {
		government_has_flag = government_is_japan_administrative
		is_independent_ruler = no
		NOT = { has_title = title:k_chrysanthemum_throne }
		NOT = { vassal_contract_has_flag = japan_administrative_military_appointment }
	}
	succession = {
		order_of_succession = appointment
		appointment_type = japanese_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	modifier = {
		glory_hound_opinion = -10
		parochial_opinion = -5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		government_has_flag = government_is_japan_administrative
		is_independent_ruler = no
	}
}

japanese_military_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 30

	can_keep = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = japan_administrative_military_appointment
		}
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				is_independent_ruler = no
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		vassal_contract_has_flag = japan_administrative_military_appointment
	}
	can_pass = {
		can_change_succession_law_trigger = yes
		government_has_mechanic = administrative
		is_independent_ruler = no
		vassal_contract_has_flag = japan_administrative_military_appointment
	}
	should_start_with = {
		government_has_flag = government_is_japan_administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = japan_administrative_military_appointment
		}
	}
	succession = {
		order_of_succession = appointment
		appointment_type = japanese_military_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	modifier = {
		glory_hound_opinion = 5
		courtly_opinion = -10
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		government_has_flag = government_is_japan_administrative
		is_independent_ruler = no
	}
}

mandala_succession_law = {
	law_group_type = succession_order_laws
	index = 31

	can_keep = {
		realm_law_is_mandala = yes
	}
	can_have = {
		realm_law_is_mandala = yes
	}
	can_pass = {
		realm_law_is_mandala = yes
	}
	should_start_with = {
		realm_law_is_mandala = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_remove_from_title = {
		always = no
	}
	succession = {
		order_of_succession = inheritance
		traversal_order = children
		rank = oldest
		title_division = single_heir
	}
	flag = can_designate_heirs

	potential = {
		realm_law_is_mandala = yes
	}
}

meritocratic_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 32

	can_keep = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = meritocratic_military_appointment }
		}
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				is_independent_ruler = no
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	can_pass = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	should_start_with = {
		OR = {
			government_has_flag = government_is_meritocratic
			government_has_flag = government_is_steppe_admin
		}
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_appointment_allowed_desc
			NOT = { vassal_contract_has_flag = meritocratic_military_appointment }
		}
	}
	succession = {
		order_of_succession = appointment
		appointment_type = meritocratic_civic_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	flag = appointment_with_level_requirement
	modifier = {
		glory_hound_opinion = -10
		courtly_opinion = 5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		OR = {
			government_has_flag = government_is_steppe_admin
			government_has_flag = government_is_meritocratic
		}
		is_independent_ruler = no
	}
}

meritocratic_military_appointment_succession_law = {
	law_group_type = succession_order_laws
	index = 33

	can_keep = {
		government_has_mechanic = administrative
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = meritocratic_military_appointment
		}
		# Vassal Contract allows it
		custom_description = {
			text = succession_laws_must_not_be_forced_partition
			NAND = {
				is_independent_ruler = no
				vassal_contract_has_flag = locked_to_partition
			}
		}
	}
	can_have = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	can_pass = {
		government_has_mechanic = administrative
		is_independent_ruler = no
	}
	should_start_with = {
		OR = {
			government_has_flag = government_is_meritocratic
			government_has_flag = government_is_steppe_admin
		}
		is_independent_ruler = no
		custom_tooltip = {
			text = celestial_military_appointment_allowed_desc
			vassal_contract_has_flag = meritocratic_military_appointment
		}
	}
	succession = {
		order_of_succession = appointment
		appointment_type = meritocratic_military_governor
	}
	flag = advanced_succession_law
	flag = appointment_type_succession
	flag = appointment_with_level_requirement
	modifier = {
		glory_hound_opinion = -10
		courtly_opinion = 5
		player_heir_opinion = 20
		eligible_child_except_player_heir_opinion = -5
	}
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				OR = {
					has_realm_law = confederate_partition_succession_law
					has_realm_law = partition_succession_law
					has_realm_law = high_partition_succession_law
				}
			}
			value = 3
		}
	}

	potential = {
		OR = {
			government_has_flag = government_is_steppe_admin
			government_has_flag = government_is_meritocratic
		}
		is_independent_ruler = no
	}
}

meritocratic_regency_succession_law = {
	law_group_type = succession_order_laws
	index = 34

	can_keep = {
		can_have_meritocratic_regency_succession_law_trigger = yes
	}
	can_pass = {
		can_have_meritocratic_regency_succession_law_trigger = yes
	}
	can_have = {
		can_have_meritocratic_regency_succession_law_trigger = yes
	}
	can_title_have = {
		exists = var:administrative_ui_special_title
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_remove_from_title = {
		always = no
	}
	should_start_with = {
		always = no
	}
	succession = {
		order_of_succession = appointment
		appointment_type = meritocratic_regent
	}
	flag = advanced_succession_law
	flag = can_designate_heirs
	flag = appointment_type_succession
	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	ai_will_do = {
		if = {
			limit = { has_realm_law = confederate_partition_succession_law }
			value = 1
		}
	}
	potential = {
		government_has_mechanic = administrative
		government_allows = merit
		tgp_realm_has_ceremonial_liege_trigger = yes
	}
}


male_only_law = {
	law_group_type = succession_gender_laws
	index = 0

	can_title_have = {
		can_title_have_law_general_trigger = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_keep = {
		trigger_if = {
			limit = {
				can_have_male_monastic_holy_order_succession_law_trigger = yes
			}
			always = yes
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_must_be_male }
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = male_only_law }
		}
		trigger_else = {
			custom_tooltip = {
				text = culture_not_male_only_tt
				rite = { rite_has_parameter = male_dominated_law }
				NOT = {
					culture = { has_cultural_parameter = female_only_inheritance }
				}
			}
		}
	}
	can_have = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
				NOT = { can_have_male_monastic_holy_order_succession_law_trigger = yes }
			}
			rite = { rite_has_parameter = clergy_must_be_male }
		}
	}
	can_pass = {
		can_change_succession_law_trigger = yes
	}
	should_start_with = {
		trigger_if = {
			limit = {
				can_have_male_monastic_holy_order_succession_law_trigger = yes
			}
			always = yes
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = male_only_law }
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_has_merit
			}
			rite = {
				rite_has_parameter = male_dominated_law
			}
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = {
				rite_has_parameter = clergy_must_be_male
			}
		}
		trigger_else = {
			AND = {
				faith = {
					religion_tag = islam_religion
				}
				rite = {
					rite_has_parameter = male_dominated_law
				}
			}
		}
	}
	succession = {
		gender_law = male_only
	}
	flag = men_can_have_multiple_spouses
	flag = men_can_have_consorts
	flag = no_female_commanders

	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}
}

male_preference_law = {
	law_group_type = succession_gender_laws
	index = 1

	can_title_have = {
		can_title_have_law_general_trigger = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_keep = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			custom_tooltip = {
				text = gender_preference_law_not_for_clergy_tt
				always = no
			}
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = male_preference_law }
		}
		trigger_else = {
			custom_description = {
				text = change_law_male_preference_faith_requirement
				rite = {
					NOT = { rite_has_parameter = female_dominated_law }
				}
			}
			custom_tooltip = {
				text = male_preference_law_can_keep_faith_or_culture_trigger
				OR = {
					rite = { rite_has_parameter = male_dominated_law }
					NOT = {
						culture = { has_cultural_parameter = female_only_inheritance }
					}
				}
			}
		}
	}
	can_have = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			custom_tooltip = {
				text = gender_preference_law_not_for_clergy_tt
				always = no
			}
		}
	}
	can_pass = {
		can_change_succession_law_trigger = yes
	}
	should_start_with = {
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = male_preference_law }
		}
		trigger_else = {
			NOT = {
				culture = { has_cultural_parameter = female_preference_inheritance }
			}
			OR = {
				faith = {
					NOR = {
						religion_tag = islam_religion
						AND = {
							root = {
								government_has_flag = government_has_merit
							}
							root.rite = {
								rite_has_parameter = male_dominated_law
							}
						}
					}
					root.rite = {
						rite_has_parameter = male_dominated_law
					}
				}
				AND = {
					has_realm_law = male_only_law # For when male_only_law ceases to be a legal option
					trigger_if = {
						limit = { should_synchronize_liege_law = yes }
						NOT = {
							top_liege = { has_realm_law = male_only_law }
						}
					}
					trigger_else = {
						custom_tooltip = {
							text = culture_not_female_only_tt
							NOR = {
								rite = { rite_has_parameter = male_dominated_law }
								NOT = {
									culture = { has_cultural_parameter = female_only_inheritance }
								}
							}
						}
					}
				}
			}
		}
	}
	succession = {
		gender_law = male_preference
	}
	flag = men_can_have_multiple_spouses
	flag = men_can_have_consorts
	flag = no_female_commanders

	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}
}

equal_law = {
	law_group_type = succession_gender_laws
	index = 2

	can_title_have = {
		can_title_have_law_general_trigger = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_keep = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_can_be_either_gender }
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = equal_law }
		}
		trigger_else = {
			custom_tooltip = {
				text = equal_law_culture_faith_or_innovation_trigger
				OR = {
					culture = { has_cultural_parameter = gender_equal_inheritance }
					#culture = { has_innovation = innovation_visigothic_codes }
					rite = { rite_has_parameter = gender_equal_law }
					AND = { #Culture is female dominated but religion is male dominated
						rite = { rite_has_parameter = male_dominated_law }
						culture = { has_cultural_parameter = female_only_inheritance }
					}
					AND = { #Culture is male dominated but faith is female dominated
						rite = { rite_has_parameter = female_dominated_law }
						NOT = { culture = { has_cultural_parameter = female_only_inheritance } }
					}
					primary_title.var:can_keep_realm_law ?= flag:equal_law
				}
			}
		}
	}
	can_have = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_can_be_either_gender }
		}
	}
	can_pass = {
		#can_change_to_equal_succession_law_trigger = yes
		can_change_succession_law_trigger = yes
	}
	should_start_with = {
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = equal_law }
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_can_be_either_gender }
		}
		trigger_else = {
			NOR = {
				culture = { has_cultural_parameter = female_preference_inheritance }
				culture = { has_cultural_tradition = tradition_nubian_warrior_queens }
			}
			rite = {
				rite_has_parameter = gender_equal_law
			}
			NOT = { has_realm_law = female_only_law } # For when female_only_law ceases to be valid
		}
	}
	succession = {
		gender_law = equal
	}
	flag = men_can_have_multiple_spouses
	flag = men_can_have_consorts
	flag = women_can_have_multiple_spouses
	flag = women_can_have_consorts

	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	ai_will_do = {
		if = {
			limit = {
				exists = primary_title
				primary_title.tier > tier_county
				rite = {
					NOT = {
						rite_has_dominant_ruling_gender = prev
					}
				}
			}
			value = 2
		}
	}
}

female_preference_law = {
	law_group_type = succession_gender_laws
	index = 3

	can_title_have = {
		can_title_have_law_general_trigger = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_keep = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			custom_tooltip = {
				text = gender_preference_law_not_for_clergy_tt
				always = no
			}
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = female_preference_law }
		}
		trigger_else_if = {
			limit = {
				culture = { has_cultural_parameter = female_preference_inheritance }
			}
			culture = { has_cultural_parameter = female_preference_inheritance }
		}
		trigger_else = {
			custom_description = {
				text = change_law_female_preference_faith_requirement
				OR = {
					rite = {
						NOT = { rite_has_parameter = male_dominated_law }
					}
					rite = {
						rite_has_parameter = tenet_hyperdulia_female_preference_law
					}
				}
			}
			custom_tooltip = {
				text = female_preference_law_faith_or_culture_trigger
				OR = {
					rite = { rite_has_parameter = female_dominated_law }
					NOT = {
						culture = { has_cultural_parameter = male_only_inheritance }
					}
				}
			}
		}
	}
	can_have = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			custom_tooltip = {
				text = gender_preference_law_not_for_clergy_tt
				always = no
			}
		}
	}
	should_start_with = {
		trigger_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = female_preference_law }
		}
		trigger_else = {
			OR = {
				culture = { has_cultural_parameter = female_preference_inheritance }
				rite = {
					rite_has_parameter = female_dominated_law
				}
				rite = {
					rite_has_parameter = tenet_hyperdulia_female_preference_law
				}
				has_realm_law = female_only_law # For when male_only_law ceases to be a legal option
			}
		}
	}
	can_pass = {
		can_change_succession_law_trigger = yes
	}
	succession = {
		gender_law = female_preference
	}
	flag = women_can_have_multiple_spouses
	flag = women_can_have_consorts

	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}
}

female_only_law = {
	law_group_type = succession_gender_laws
	index = 4

	can_title_have = {
		can_title_have_law_general_trigger = yes
	}
	should_show_for_title = { # Never show this in the UI, just apply it through script
		always = no
	}
	can_keep = {
		trigger_if = {
			limit = {
				can_have_female_monastic_holy_order_succession_law_trigger = yes
			}
			always = yes
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_must_be_female }
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = female_only_law }
		}
		trigger_else_if = {
			limit = {
				culture = { has_cultural_parameter = female_only_inheritance }
			}
			culture = { has_cultural_parameter = female_only_inheritance }
		}
		trigger_else = {
			custom_tooltip = {
				text = female_only_law_can_keep_faith_or_culture_trigger
				rite = { rite_has_parameter = female_dominated_law }
				NOT = {
					culture = { has_cultural_parameter = male_only_inheritance }
				}
			}
		}
	}
	can_have = {
		trigger_if = {
			limit = {
				government_has_flag = government_is_theocracy
				NOT = { can_have_female_monastic_holy_order_succession_law_trigger = yes }
			}
			rite = { rite_has_parameter = clergy_must_be_female }
		}
	}
	can_pass = {
		can_change_succession_law_trigger = yes
	}
	succession = {
		gender_law = female_only
	}
	flag = women_can_have_multiple_spouses
	flag = women_can_have_consorts

	pass_cost = {
		prestige = change_succession_law_prestige_cost
	}
	revoke_cost = {
		prestige = change_succession_law_prestige_cost
	}

	should_start_with = {
		trigger_if = {
			limit = {
				can_have_female_monastic_holy_order_succession_law_trigger = yes
			}
			always = yes
		}
		trigger_else_if = {
			limit = { should_synchronize_liege_law = yes }
			top_liege = { has_realm_law = female_only_law }
		}
		trigger_else_if = {
			limit = {
				government_has_flag = government_is_theocracy
			}
			rite = { rite_has_parameter = clergy_must_be_female }
		}
		trigger_else = {
			culture = { has_cultural_parameter = female_only_inheritance }
		}
	}
}


same_faith_only_law = {
	law_group_type = succession_faith
	index = 0

	can_keep = {
		should_have_same_faith_succession_trigger = yes
	}
	can_pass = {
		should_have_same_faith_succession_trigger = yes
	}
	should_start_with = {
		should_have_same_faith_succession_trigger = yes
	}
	succession = {
		faith = same_faith
	}
}


same_faith_theocratic_succession_law = {
	law_group_type = succession_rel_head
	index = 0

	shown_in_encyclopedia = no
	can_keep = {
		religion != religion:christianity_religion
		faith = {
			religious_head = root
			has_doctrine = doctrine_spiritual_head
		}
	}
	succession = {
		order_of_succession = theocratic
		faith = same_faith
		pool_character_config = pool_theocratic_succession
	}
}
same_faith_succession_law = {
	law_group_type = succession_rel_head
	index = 1

	shown_in_encyclopedia = no
	can_keep = {
		faith = {
			religious_head = root
			has_doctrine = doctrine_temporal_head
		}
	}
	succession = {
		faith = same_faith
	}
}

# Rise and Fall: temporary script-owned succession laws.
riseandfall_warlord_succession_law = {
	law_group_type = succession_order_laws
	index = 100
        # Script-only temporary succession for Rebel Warlord rulers.
        can_keep = {
                is_independent_ruler = no
                OR = {
                        government_has_flag = government_is_japan_administrative
                        government_has_flag = government_is_meritocratic
                        government_has_flag = government_is_celestial
                }
        }
        can_have = {
                always = no
        }
        can_pass = {
                always = no
        }
        should_start_with = {
                always = no
        }
        succession = {
                order_of_succession = appointment
                appointment_type = riseandfall_warlord_family
        }
        flag = advanced_succession_law
        flag = appointment_type_succession
        potential = {
                is_independent_ruler = no
                OR = {
                        government_has_flag = government_is_japan_administrative
                        government_has_flag = government_is_meritocratic
                        government_has_flag = government_is_celestial
                }
        }
}

riseandfall_puppet_regency_partition_succession_law = {
	law_group_type = succession_order_laws
	index = 101
        # Script-only partition succession for independent Puppet Regency realms.
        can_keep = {
                is_independent_ruler = yes
                has_diarchy_type = puppet_regency
                has_active_diarchy = yes
        }
        can_have = {
                always = no
        }
        can_pass = {
                always = no
        }
        should_start_with = {
                always = no
        }
        succession = {
                order_of_succession = inheritance
                traversal_order = children
                title_division = partition
                exclude_rulers = yes
        }
        flag = advanced_succession_law
        potential = {
                is_independent_ruler = yes
                has_diarchy_type = puppet_regency
                has_active_diarchy = yes
        }
}

riseandfall_puppet_regency_single_heir_succession_law = {
	law_group_type = succession_order_laws
	index = 102
        # Script-only unified succession for independent Puppet Regency realms.
        can_keep = {
                is_independent_ruler = yes
                has_diarchy_type = puppet_regency
                has_active_diarchy = yes
        }
        can_have = {
                always = no
        }
        can_pass = {
                always = no
        }
        should_start_with = {
                always = no
        }
        succession = {
                order_of_succession = inheritance
                traversal_order = children
                rank = oldest
                title_division = single_heir
                exclude_rulers = yes
        }
        flag = advanced_succession_law
        potential = {
                is_independent_ruler = yes
                has_diarchy_type = puppet_regency
                has_active_diarchy = yes
        }
}
