﻿succession_gender_laws = {
	default = male_preference_law
	flag = succession_gender_laws

		#Regula gender succession law for the player. Male only inheritance, consorts allowed.
		regula_magister_gender_law = {
			can_title_have = {
				can_title_have_law_general_trigger = yes
			}
			can_keep = {
				# is_independent_ruler = yes
				has_trait = magister_trait_group
				faith = {
					has_doctrine = tenet_regula_devoted
					religion_tag = regula_religion
				}
			}
	
			can_pass = { #UPDATE - figure out what this does.
				can_change_succession_law_trigger = yes
			}
			should_start_with = {
	
			}
			succession = {
				gender_law = male_only
			}
			flag = men_can_have_multiple_spouses
			# flag = elective_succession_law
			flag = no_male_commanders
	
			pass_cost = {
				prestige = change_succession_law_prestige_cost
			}
			revoke_cost = {
				prestige = change_succession_law_prestige_cost
			}
		}
		#Regula gender succession law for the vassals.  Female inheritance only.
		regula_vassal_succession_law = {
			can_title_have = {
				can_title_have_law_general_trigger = yes
			}
			### Update - Are the can_keep and can_have sections really necessary here?
			can_keep = {
				OR = {
					faith = {
						has_doctrine = tenet_regula_devoted  
						religion_tag = regula_religion
					}
					root.top_liege = {
						has_realm_law = regula_magister_gender_law
					}
					liege = {
						OR = {
							has_realm_law = regula_magister_gender_law
							has_realm_law = regula_vassal_succession_law
						}
					}
				}
			}
			
			can_have = {
			}
			can_pass = {
				can_change_succession_law_trigger = yes
				is_independent_ruler = no
			}
			should_start_with = {
				# root.top_liege = {
				# 	has_realm_law = regula_magister_gender_law
				# }
			}
			succession = {
				gender_law = female_only
			}
			pass_cost = {
				prestige = change_succession_law_prestige_cost
			}
			revoke_cost = {
				prestige = change_succession_law_prestige_cost
			}
		}
		# Regula covert gender succession law for vassals. Female preference.
		regula_covert_vassal_succession_law = {
			can_title_have = {
				can_title_have_law_general_trigger = yes
			}
			### Update - Are the can_keep and can_have sections really necessary here?
			can_keep = {
			}
			
			can_have = {
			}
			can_pass = {
				always = no
			}
			should_start_with = {
				# root.top_liege = {
				# 	has_realm_law = regula_magister_gender_law
				# }
			}
			succession = {
				gender_law = female_preference
			}
			# Pass and revoke costs aren't achievable.
			pass_cost = {
				prestige = 10000
			}
			revoke_cost = {
				prestige = 10000
			}
		}

	
	male_only_law = {
		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 = {
			custom_tooltip = {
				text = culture_not_female_only_tt
				OR = {
					faith = { has_doctrine = doctrine_gender_male_dominated }
					NOT = {
						culture = { has_cultural_parameter = female_only_inheritance }
					}
				}
			}
		}
		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 = {
			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 = {
			custom_description = {
				text = change_law_male_preference_faith_requirement
				faith = {
					NOT = { has_doctrine = doctrine_gender_female_dominated }
				}
			}
			custom_tooltip = {
				text = culture_not_female_only_tt
				OR = {
					faith = { has_doctrine = doctrine_gender_male_dominated }
					NOT = {
						culture = { has_cultural_parameter = female_only_inheritance }
					}
				}
			}
		}
		can_pass = {
			can_change_succession_law_trigger = yes
		}
		should_start_with = {
			NOT = {
				culture = { has_cultural_parameter = female_preference_inheritance }
			}
			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
			}
		}
		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 = {
			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 = {
			custom_tooltip = {
				text = equal_law_culture_faith_or_innovation_trigger
				OR = {
					culture = { has_cultural_parameter = gender_equal_inheritance }
					#culture = { has_innovation = innovation_visigothic_codes }
					faith = { has_doctrine = doctrine_gender_equal }
					AND = { #Culture is female dominated but religion is male dominated
						faith = { has_doctrine = doctrine_gender_male_dominated }
						culture = { has_cultural_parameter = female_only_inheritance }
					}
					AND = { #Culture is male dominated but faith is female dominated
						faith = { has_doctrine = doctrine_gender_female_dominated }
						NOT = { culture = { has_cultural_parameter = female_only_inheritance } }
					}
				}
			}
		}
		can_pass = {
			#can_change_to_equal_succession_law_trigger = yes
			can_change_succession_law_trigger = yes
		}
		should_start_with = {
			NOR = {
				culture = { has_cultural_parameter = female_preference_inheritance }
				culture = { has_cultural_tradition = tradition_nubian_warrior_queens }
			}
			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
					faith = {
						NOT = {
							has_dominant_ruling_gender = prev
						}
					}
				}
				value = 2
			}
		}
	}
	
	female_preference_law = {
		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 = {
			custom_tooltip = {
				text = female_preference_law_faith_or_culture_trigger
				OR = {
					faith = {
						NOT = { has_doctrine = doctrine_gender_male_dominated }
					}
					culture = { has_cultural_parameter = female_preference_inheritance }
				}
			}
		}
		should_start_with = {
			OR = {
				culture = { has_cultural_parameter = female_preference_inheritance }
				faith = {
					has_doctrine = doctrine_gender_female_dominated
				}
				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 = {
		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 = {
			custom_tooltip = {
				text = female_only_law_faith_or_culture_trigger
				OR = {
					faith = { has_doctrine = doctrine_gender_female_dominated }
					culture = { has_cultural_parameter = female_only_inheritance }
				}
			}
		}
		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 = {
			OR = {
				culture = { has_cultural_parameter = female_only_inheritance }
			}
		}
	}
}

succession_faith = {
	same_faith_only_law = {
		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
		}
	}
}

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