﻿succession_order_laws = {
	flag = succession_order_laws

	confederate_partition_succession_law = {
		can_keep = {
			always = yes
		}
		can_pass = {
			can_change_partition_succession_law_trigger = yes
		}
		can_have = {
			can_have_confederate_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
			}
			OR = {
				AND = {
					OR = {
						has_government = feudal_government
						has_government = clan_government
					}
					culture = {
						NOR = {
							has_innovation = innovation_hereditary_rule
							has_innovation = innovation_heraldry
						}
					}
				}
				has_government = tribal_government
			}
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = children
			rank = oldest
			title_division = partition
			create_primary_tier_titles = yes
		}
		flag = partition_succession_law
		modifier = {
			direct_vassal_opinion = 5
			dynasty_house_opinion = 5
			eligible_child_opinion = 10
		}
		pass_cost = {
			prestige = change_succession_law_prestige_cost
		}
	}
	
	partition_succession_law = {
		can_keep = {
			can_keep_partition_succession_law_trigger = yes
		}
		can_pass = {
			can_change_partition_succession_law_trigger = yes
		}
		can_have = {
			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
			}
			OR = {
				has_government = feudal_government
				has_government = clan_government
			}
			culture = {
				has_innovation = innovation_hereditary_rule
				NOT = {
					has_innovation = innovation_heraldry
				}
			}
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = children
			rank = oldest
			title_division = partition
		}
		flag = partition_succession_law
		modifier = {
			direct_vassal_opinion = 5
			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
			}
		}
	}

	high_partition_succession_law = {
		can_keep = {
			can_keep_high_partition_succession_law_trigger = yes
		}
		can_pass = {
			can_change_partition_succession_law_trigger = yes
		}
		can_have = {
			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
			}
			OR = {
				has_government = feudal_government
				has_government = clan_government
			}
			culture = {
				has_innovation = innovation_heraldry
				NOT = {
					has_innovation = innovation_hereditary_rule
				}
			}
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = children
			rank = oldest
			title_division = partition
			primary_heir_minimum_share = 0.5
		}
		flag = partition_succession_law
		modifier = {
			direct_vassal_opinion = 5
			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
			}
		}
	}
	
	single_heir_succession_law = {
		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 = {
					is_independent_ruler = no
					vassal_contract_has_flag = locked_to_partition
				}
			}
		}
		can_have = {
			can_have_single_heir_succession_law_trigger = yes
		}
		can_pass = {
			can_change_succession_law_trigger = yes
		}
		should_start_with = {
			historical_succession_access_single_heir_succession_law_trigger = yes
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = children
			rank = oldest
			title_division = single_heir
		}
		flag = advanced_succession_law
		modifier = {
			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
			}
		}
	}
	
	single_heir_succession_law_youngest = {
		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 = {
					is_independent_ruler = no
					vassal_contract_has_flag = locked_to_partition
				}
			}
		}
		can_have = {
			can_have_single_heir_youngest_succession_law_trigger = yes
		}
		can_pass = {
			can_change_succession_law_trigger = yes
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = children
			rank = youngest
			title_division = single_heir
		}
		
		flag = advanced_succession_law
		modifier = {
			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
		}
	}
	
	single_heir_dynasty_house = {
		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 = {
					is_independent_ruler = no
					vassal_contract_has_flag = locked_to_partition
				}
			}
		}
		can_have = {
			can_have_single_heir_dynasty_house_trigger = yes
		}
		can_pass = {
			can_change_single_heir_dynasty_house_succession_law_trigger = yes
		}
		should_start_with = {
			historical_succession_access_single_heir_dynasty_house_trigger = yes
		}
		succession = {
			order_of_succession = inheritance
			traversal_order = dynasty_house
			rank = oldest
			title_division = single_heir
		}
		
		flag = advanced_succession_law
		modifier = {
			eligible_child_except_player_heir_opinion = -15
			direct_vassal_opinion = -5
			dynasty_house_opinion = 5
		}
		pass_cost = {
			prestige = change_succession_law_prestige_cost
		}
		revoke_cost = {
			prestige = change_succession_law_prestige_cost
		}

		ai_will_do = {
			if = {
				limit = {
					primary_title.tier > tier_county
					OR = {
						#West Slavic
						has_culture = culture:czech
						has_culture = culture:slovien
					}
				}
				value = 2
			}
		}
	}

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

	holy_order_succession_law = {
		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 = {
			has_government = holy_order_government
		}
		succession = {
			order_of_succession = theocratic
			faith = same_faith
			pool_character_config = pool_holy_order_succession
		}
	}
	
	mercenary_company_succession_law = {
		can_keep = {
			can_have_mercenary_succession_law_trigger = yes
		}
		can_have = {
			can_have_mercenary_succession_law_trigger = yes
		}
		should_start_with = {
			has_government = mercenary_government
		}
		succession = {
			order_of_succession = company
			pool_character_config = pool_mercenary_succession
		}
	}

	city_succession_law = {
		can_keep = {
			can_have_city_succession_law_trigger = yes
		}
		can_have = {
			can_have_city_succession_law_trigger = yes
		}
		should_start_with = {
			has_government = republic_government
		}
		succession = {
			order_of_succession = generate
			pool_character_config = pool_city_succession
		}
	}
}

succession_gender_laws = {
	default = male_preference_law
	flag = succession_gender_laws
	
	male_only_law = {
		can_title_have = { tier >= tier_duchy }
		can_keep = {
			faith = {
				has_doctrine = doctrine_gender_male_dominated
			}
		}
		can_pass = {
			can_change_succession_law_trigger = yes
		}
		should_start_with = {
			faith = {
				has_doctrine = doctrine_gender_male_dominated
				religion_tag = islam_religion
			}
		}
		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 = {
		can_title_have = { 
			tier >= tier_duchy 
			holder = { NOT = { has_government = military_command } }
		}
		can_keep = {
			custom_description = {
				text = change_law_male_preference_faith_requirement
				faith = {
					NOT = { has_doctrine = doctrine_gender_female_dominated }
				}
			}
			NOT = { has_government = military_command }
		}
		can_pass = {
			can_change_succession_law_trigger = yes
		}
		should_start_with = {
			OR = {
				faith = {
					NOT = {
						religion_tag = islam_religion
					}
					has_doctrine = doctrine_gender_male_dominated
				}
				has_realm_law = male_only_law # For when male_only_law ceases to be a legal option
			}
			NOT = { has_government = military_command }
		}
		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 = {
		can_title_have = { tier >= tier_duchy }
		can_keep = {
			trigger_if = {
				limit = {
					OR = {
						culture = culture:occitan
						culture = culture:basque
						culture = culture:aragonese
						culture = culture:catalan
					}
					NOT = {
						faith = { has_doctrine = doctrine_gender_equal }
					}
				}
				culture = { has_innovation = innovation_visigothic_codes }
			}
			trigger_else = {
				limit = {
					NOT = {
						OR = {
							culture = culture:hausa
							culture = culture:sumpa
						}
					}
				}
				faith = {
					has_doctrine = doctrine_gender_equal
				}
			}
		}
		can_pass = {
			can_change_to_equal_succession_law_trigger = yes
		}
		should_start_with = {
			faith = {
				has_doctrine = doctrine_gender_equal
			}
			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 = {
					primary_title.tier > tier_county
					has_culture = culture:basque
				}
				value = 2
			}
		}
	}
	
	female_preference_law = {
		can_title_have = { 
			tier >= tier_duchy 
			holder = { NOT = { has_government = military_command } }
		}
		can_keep = {
			custom_description = {
				text = change_law_female_preference_faith_requirement
				faith = {
					NOT = { has_doctrine = doctrine_gender_male_dominated }
				}
			}
			NOT = { has_government = military_command }
		}
		should_start_with = {
			OR = {
				faith = {
					has_doctrine = doctrine_gender_female_dominated
				}
				has_realm_law = female_only_law # For when male_only_law ceases to be a legal option
			}
			NOT = { has_government = military_command }
		}
		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 = {
		can_title_have = { tier >= tier_duchy }
		can_keep = {
			faith = {
				has_doctrine = doctrine_gender_female_dominated
			}
		}
		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
		}
	}
}

succession_rel_head = {
	same_faith_theocratic_succession_law = {
		can_have = {
			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 = {
		can_have = {
			faith = {
				religious_head = root
				has_doctrine = doctrine_temporal_head
			}
		}
		succession = {
			faith = same_faith
		}
	}
}
