# DO NOT ALTER THE NAME OR NUMBER OF THESE!

gender_laws = {
	agnatic_succession = {
		female_dynasty_opinion = -5

		potential = {
			holder_scope = {
				# Theocracies have to allow Male temple holders
				trigger_if = {
					limit = { is_theocracy = yes }

					religion_allows_male_temple_holders = yes
					religion_allows_female_temple_holders = no
				}
				# Matriarchal and Equal religions don't allow male-centric succession
				trigger_else = {
					NOR = {
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_equal
					}
				}
			}

			# Only absolute cognatic is available with the Plus setting, for titles that can have absolute cognatic
			trigger_if = {
				limit = { is_law_potential = true_cognatic_succession }

				NOT = {
					has_game_rule = {
						name = gender
						value = plus
					}
				}
			}
		}

		allow = {
			has_law = cognatic_succession

			holder_scope = {
				show_scope_change = no

				NOT = { trait = uncrowned }
				plus_law_prestige_trigger_1 = yes
			}
		}

		pass_effect = {
			# log = "agnatic_succession pass ([This.GetFullBaseName])"
			plus_law_change_prestige_effect_1 = yes
		}

		effect = {
			# log = "agnatic_succession ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				plus_law_change_prestige_effect_1 = yes
			}

			gender_succ = agnatic
			law_set_allow_matrilineal_marriage = no
		}

		default_selection = {
			factor = 1
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				OR = {
					# Is zealous and title was formerly agnatic and current heir is not female
					AND = {
						is_primary_holder_title = yes
						has_title_flag = former_agnatic_succession

						holder_scope = {
							player_heir = { is_female = no }
							trait = zealous
						}
					}

					# Holder is muslim
					AND = {
						is_primary_holder_title = yes
						holder_scope = { religion_group = muslim }
					}

					# Primary title is agnatic
					AND = {
						is_primary_holder_title = no
						holder_scope = { has_law = agnatic_succession }
					}

					# A very religious older male ruler under cognatic with a son
					AND = {
						is_primary_holder_title = yes

						holder_scope = {
							is_female = no
							practical_age >= 50
							trait = zealous
							is_heretic = no
							is_feminist_trigger = no
							NOT = { culture = basque }

							any_child = {
								dynasty = PREV
								is_female = no
								age >= 6
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}
							}
						}
					}

					# Female heir who will cause title to fall out of dynasty and there
					# is a close family member in the realm who can inherit
					holder_scope = {
						ROOT = {
							current_heir = {
								is_female = yes

								OR = {
									trigger_if = {
										limit = { is_married = yes }
										is_married_matrilineally = no
									}

									any_child = {
										can_inherit_trigger = yes
										NOT = { dynasty = PREVPREVPREV }

										OR = {
											AND = {
												ROOT = {
													NOR = {
														has_law = cognatic_succession
														has_law = agnatic_succession
													}
												}

												is_female = yes
											}

											AND = {
												ROOT = {
													NOR = {
														has_law = enatic_cognatic_succession
														has_law = enatic_succession
													}
												}

												is_female = no
											}
										}
									}
								}
							}
						}

						any_close_relative = {
							dynasty = PREV
							is_female = no
							same_realm = PREV
							can_inherit_trigger = yes
						}

						is_feminist_trigger = no

						NOR = {
							trait = content
							trait = humble
							trait = slothful
						}
					}
				}
			}

			mult_modifier = {
				factor = 20
				has_title_flag = former_agnatic_succession
			}
		}
	}

	cognatic_succession = { # agnatic-cognatic
		potential = {
		#	is_landless_type_title = no
		#	is_primary_type_title = no

			holder_scope = {
				is_theocracy = no

				trigger_if = {
					limit = { is_republic = yes }

					is_patrician = yes

					trigger_if = {
						limit = { independent = no }

						defacto_liege_title = {
							OR = {
								has_law = true_cognatic_succession
								has_law = cognatic_succession
							}
						}
					}
				}
				trigger_else_if = {
					limit = {
						OR = {
							religion_group = muslim
							has_horde_culture = yes
							is_nomadic = yes
							religion = aztec_pagan
						}
					}
				}
				trigger_else_if = {
					limit = { government = order_government }
					independent = yes
				}

				# No exceptions
				NOT = { has_religion_feature = religion_matriarchal }
			}

			# Only absolute cognatic is available with the Plus setting, for titles that can have absolute cognatic
			trigger_if = {
				limit = { is_law_potential = true_cognatic_succession }

				NOT = {
					has_game_rule = {
						name = gender
						value = plus
					}
				}
			}
		}

		allow = {
			holder_scope = {
				show_scope_change = no

				trigger_if = {
					limit = {
						OR = {
							religion_group = muslim
							has_horde_culture = yes
							has_religion_feature = religion_matriarchal
							has_religion_feature = religion_equal
							is_nomadic = yes
							religion = aztec_pagan
						}

						has_gender_equal_game_rule_trigger = no
					}

					OR = {
						has_law = status_of_women_3
						has_law = status_of_women_4
					}
				}

				NOT = { trait = uncrowned }

				# Muslim/Aztec rulers have a harder time
				trigger_if = {
					limit = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}

					plus_law_prestige_trigger_2 = yes
				}
				# Everyone Else
				trigger_else = {
					plus_law_prestige_trigger_1 = yes
				}
			}

			OR = {
				has_law = agnatic_succession
				has_law = true_cognatic_succession
			}
		}

		pass_effect = {
			# log = "cognatic_succession pass ([This.GetFullBaseName])"

			if = {
				limit = {
					holder_scope = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}
				}

				plus_law_change_prestige_effect_2 = yes
			}
			else = {
				plus_law_change_prestige_effect_1 = yes
			}
		}

		effect = {
			# log = "cognatic_succession ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						holder_scope = {
							OR = {
								religion_group = muslim
								religion = aztec_pagan
							}
						}
					}

					plus_law_change_prestige_effect_2 = yes
				}
				else = {
					plus_law_change_prestige_effect_1 = yes
				}
			}

			gender_succ = cognatic
			law_set_allow_matrilineal_marriage = yes
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				OR = {
					# Primary title is cognatic
					AND = {
						is_primary_holder_title = no

						holder_scope = {
							primary_title = { has_law = cognatic_succession }
							player_heir = { is_female = yes }
						}
					}

					# A female ruler under agnatic
					AND = {
						is_primary_holder_title = yes
						has_law = agnatic_succession

						holder_scope = {
							is_female = yes

							NOR = {
								trait = humble
								trait = content
								trait = zealous
							}
						}
					}

					# A very religious older male ruler under true cognatic with a son
					AND = {
						is_primary_holder_title = yes
						has_law = true_cognatic_succession

						holder_scope = {
							is_female = no
							practical_age >= 50
							trait = zealous
							is_heretic = no
							is_feminist_trigger = no
							NOT = { culture = basque }

							any_child = {
								is_female = no
								dynasty = PREV
								age >= 6
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}
							}
						}
					}

					# A male ruler under true cognatic with an adult son and a female heir
					AND = {
						is_primary_holder_title = yes
						has_law = true_cognatic_succession

						OR = {
							has_law = succ_gavelkind
							has_law = succ_primogeniture
						}

						holder_scope = {
							player_heir = { is_female = yes }
							is_female = no
							is_feminist_trigger = no

							NOR = {
								trait = just
								trait = content
							}

							any_child = {
								is_female = no
								dynasty = PREV
								is_adult = yes
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}
							}
						}
					}

					# A ruler under agnatic with an adult daughter who could inherit and no child/grandchild who is heir
					AND = {
						is_primary_holder_title = yes
						has_law = agnatic_succession

						OR = {
							has_law = succ_gavelkind
							has_law = succ_primogeniture
						}

						holder_scope = {
							NOT = {
								player_heir = {
									OR = {
										is_child_of = PREV
										is_grandchild_of = PREV
									}
								}
							}

							any_child = {
								is_female = yes
								is_adult = yes
								dynasty = PREV
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}
							}
						}
					}

					# A ruler under agnatic with an adult diplomatic daughter whom he loves
					AND = {
						is_primary_holder_title = yes
						has_law = agnatic_succession

						holder_scope = {
							any_child = {
								is_female = yes
								is_adult = yes
								dynasty = PREV
								diplomacy >= 12

								reverse_opinion = {
									who = PREV
									value >= 50
								}
							}

							OR = {
								trait = charitable
								trait = kind
								trait = just
							}

							NOR = {
								trait = humble
								trait = craven
								trait = slothful
							}
						}
					}

					# Ruler under agnatic who is feminist or basque
					AND = {
						is_primary_holder_title = yes
						has_law = agnatic_succession

						holder_scope = {
							OR = {
								is_feminist_trigger = yes
								culture = basque
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 20
				has_title_flag = former_cognatic_succession
			}
		}

		default_selection = {
			factor = 1

			additive_modifier = {
				value = 10

				holder_scope = {
					OR = {
						is_female = yes

						culture = welsh
						culture = breton
						culture = zhangzhung
						culture = sumpa
						culture = norman
						culture = english
						culture = basque
						culture = castilian
						culture = portuguese
						culture = outremer

						# Christian
						religion = cathar
						religion = bogomilist
						religion = messalian

						# Indian
						religion = buddhist

						# Pagan
						religion = west_african_pagan
						religion = west_african_pagan_reformed

						# Zoroastrian
						religion = mazdaki

						AND = {
							culture_group = tibetan_group

							NOR = {
								religion = taoist
								culture = tangut
							}
						}

						has_law = status_of_women_3
						has_law = status_of_women_4
					}
				}
			}
		}
	}

	true_cognatic_succession = { # absolute cognatic
		male_dynasty_opinion = -5
		female_dynasty_opinion = 5

		potential = {
		#	is_landless_type_title = no
		#	is_primary_type_title = no

			holder_scope = {
				trigger_if = {
					limit = { is_theocracy = yes }

					religion_allows_male_temple_holders = yes
					religion_allows_female_temple_holders = yes
				}

				# Equality gets a free pass
				trigger_else_if = {
					limit = {
						NOR = {
							has_religion_feature = religion_equal
							has_religion_feature = religion_feature_bon
							has_gender_equal_game_rule_trigger = yes
						}
					}

					# No Exceptions
					NOR = {
						has_religion_feature = religion_matriarchal
						has_religion_feature = religion_patriarchal
					}

					trigger_if = {
						limit = { is_republic = yes }

						is_patrician = yes

						trigger_if = {
							limit = { independent = no }

							defacto_liege_title = {
								OR = {
									has_law = true_cognatic_succession
									has_law = cognatic_succession
									has_law = enatic_cognatic_succession
								}
							}
						}
					}
				}
			}
		}

		allow = {
			holder_scope = {
				show_scope_change = no

				trigger_if = {
					limit = { has_gender_equal_game_rule_trigger = no }

					is_feminist_trigger = yes # This may need narrowed
				}

				NOT = { trait = uncrowned }

				trigger_if = {
					limit = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}

					plus_law_prestige_trigger_2 = yes
				}

				# Everyone else
				trigger_else = {
					plus_law_prestige_trigger_1 = yes
				}
			}

			OR = {
				has_law = cognatic_succession
				has_law = enatic_cognatic_succession
			}
		}

		pass_effect = {
			# log = "true_cognatic_succession pass ([This.GetFullBaseName])"

			if = {
				limit = {
					holder_scope = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}
				}

				plus_law_change_prestige_effect_2 = yes
			}
			else = {
				plus_law_change_prestige_effect_1 = yes
			}
		}

		effect = {
			# log = "true_cognatic_succession ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						holder_scope = {
							OR = {
								religion_group = muslim
								religion = aztec_pagan
							}
						}
					}

					plus_law_change_prestige_effect_2 = yes
				}
				else = {
					plus_law_change_prestige_effect_1 = yes
				}
			}

			gender_succ = true_cognatic
			law_set_allow_matrilineal_marriage = yes
		}

		default_selection = {
			factor = 1

			additive_modifier = {
				value = 20
				is_egalitarian_culture = yes
				is_egalitarian_religion = yes
			}

			mult_modifier = {
				factor = 10000
				has_gender_equal_game_rule_trigger = yes
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				OR = {
					# Is zealous and enatic-cognatic title was formerly true cognatic
					AND = {
						is_primary_holder_title = yes
						has_law = enatic_cognatic_succession
						holder_scope = { trait = zealous }
						has_title_flag = former_true_cognatic_succession
					}

					# Primary title is true cognatic
					AND = {
						is_primary_holder_title = no
						holder_scope = { has_law = true_cognatic_succession }
					}

					# A female ruler under cognatic who is just
					AND = {
						is_primary_holder_title = yes
						has_law = cognatic_succession

						holder_scope = {
							is_female = yes
							OR = {
								trait = just
								trait = proud
								trait = charitable
								diplomacy = 15
							}
							NOR = {
								trait = humble
								trait = content
								trait = arbitrary
							}
						}
					}

					#  Has an awesome older daughter who could be heir instead
					AND = {
						is_primary_holder_title = yes
						has_law = cognatic_succession

						OR = {
							has_law = succ_gavelkind
							has_law = succ_primogeniture
						}

						holder_scope = {
							any_child = {
								is_female = yes
								dynasty = PREV

								calc_true_if = {
									amount >= 3

									diplomacy >= 21
									martial >= 21
									diplomacy >= 15
									martial >= 15
									diplomacy >= 8
									martial >= 8
									stewardship >= 8
									trait = genius
								}

								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}

								any_sibling = {
									is_female = no
									NOT = { is_older_than = PREV }
									any_heir_title = { title = ROOT }

									OR = {
										is_dumb_trigger = yes
										trait = inbred
										trait = incapable
										trait = lunatic

										AND = {
											diplomacy <= 12
											martial < 12
											is_smart_trigger = no
										}
									}
								}
							}
						}
					}

					# A male ruler under enatic-cognatic with a son
					AND = {
						is_primary_holder_title = yes
						has_law = enatic_cognatic_succession

						holder_scope = {
							is_female = no
							is_feminist_trigger = no

							any_child = {
								is_female = no
								dynasty = PREV
								age >= 6
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}
							}
						}
					}

					# A Basque ruler under cognatic with an adult daughter
					AND = {
						is_primary_holder_title = yes
						has_law = cognatic_succession

						holder_scope = {
							culture = basque

							OR = {
								is_female = yes

								any_child = {
									dynasty = PREV
									is_female = yes
									is_adult = yes
									can_inherit_trigger = yes
									is_dumb_trigger = no

									NOR = {
										trait = inbred
										trait = incapable
										trait = lunatic
									}
								}
							}
						}
					}

					# Ruler under cognatic who is feminist
					AND = {
						is_primary_holder_title = yes
						has_law = cognatic_succession
						holder_scope = { is_feminist_trigger = yes }
					}

					# Ruler is learned and believes in equality
					AND = {
						is_primary_holder_title = yes

						holder_scope = {
							trait = just

							OR = {
								trait = scholar
								learning >= 12
							}

							NOR = {
								trait = zealous
								trait = content
								trait = humble
								trait = slothful
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 20
				has_title_flag = former_true_cognatic_succession
			}

			# Slow down vassals from going full
			mult_modifier = {
				factor = 0.1

				holder_scope = {
					independent = no

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

	enatic_cognatic_succession = {
		male_dynasty_opinion = -10
		female_dynasty_opinion = 10

		potential = {
		#	is_landless_type_title = no
		#	is_primary_type_title = no

			holder_scope = {
				is_theocracy = no

				trigger_if = {
					limit = { is_republic = yes }

					is_patrician = yes

					trigger_if = {
						limit = { independent = no }

						defacto_liege_title = {
							OR = {
								has_law = true_cognatic_succession
								has_law = enatic_cognatic_succession
							}
						}
					}
				}

				OR = {
					has_religion_feature = religion_matriarchal
					has_religion_feature = religion_equal

					any_owned_bloodline = {
						has_bloodline_flag = bloodline_enatic_cognatic
						bloodline_is_active_for = PREV
					}

					trigger_if = {
						limit = { has_game_started = no }
						character = c_251187 # Magajiva Daura, necesesary because her historical bloodline doesn't evaluate correctly on game start-up
					}
				}
			}

			# Override laws set by title history, should default to Absolute Cognatic
			trigger_if = {
				limit = { has_game_started = no }

				NOT = {
					has_game_rule = {
						name = gender
						value = all
					}
				}
			}
		}

		allow = {
			OR = {
				has_law = true_cognatic_succession
				has_law = enatic_succession
			}

			holder_scope = {
				show_scope_change = no

				NOT = { trait = uncrowned }

				# Muslim/Aztec rulers have a harder time
				trigger_if = {
					limit = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}

					plus_law_prestige_trigger_2 = yes
				}

				# Everyone else
				trigger_else = {
					plus_law_prestige_trigger_1 = yes
				}
			}
		}

		pass_effect = {
			# log = "enatic_cognatic_succession pass ([This.GetFullBaseName])"

			if = {
				limit = {
					holder_scope = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}
				}

				plus_law_change_prestige_effect_2 = yes
			}
			else = {
				plus_law_change_prestige_effect_1 = yes
			}
		}

		effect = {
			# log = "enatic_cognatic_succession ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						holder_scope = {
							OR = {
								religion_group = muslim
								religion = aztec_pagan
							}
						}
					}

					plus_law_change_prestige_effect_2 = yes
				}
				else = {
					plus_law_change_prestige_effect_1 = yes
				}
			}

			gender_succ = enatic_cognatic
			law_set_allow_matrilineal_marriage = yes
		}

		default_selection = {
			factor = 100
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				# Slow down vassals from going full
				NAND = {
					independent = no
					owner = {
						liege = {
							NOR = {
								has_law = enatic_cognatic_succession
								has_law = enatic_succession
							}
						}
					}
				}

				OR = {
					# Primary title is enatic cognatic
					AND = {
						is_primary_holder_title = no
						holder_scope = { has_law = enatic_cognatic_succession }
					}

					# A female ruler with an awesome daughter who could be heir instead
					AND = {
						is_primary_holder_title = yes
						has_law = true_cognatic_succession

						OR = {
							has_law = succ_gavelkind
							has_law = succ_primogeniture
						}

						holder_scope = {
							is_female = yes

							any_child = {
								is_female = yes
								dynasty = PREV
								can_inherit_trigger = yes
								is_dumb_trigger = no

								NOR = {
									trait = inbred
									trait = incapable
									trait = lunatic
								}

								calc_true_if = {
									amount >= 3

									diplomacy >= 21
									martial >= 21
									diplomacy >= 15
									martial >= 15
									diplomacy >= 8
									martial >= 8
									stewardship >= 8
									trait = genius
								}

								any_sibling = {
									is_female = no
									is_older_than = PREV
									any_heir_title = { title = ROOT }

									OR = {
										is_dumb_trigger = yes
										trait = inbred
										trait = incapable
										trait = lunatic

										AND = {
											diplomacy < 12
											martial < 12
											is_smart_trigger = no
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	enatic_succession = {
		male_dynasty_opinion = -15
		female_dynasty_opinion = 10

		potential = {
		#	is_landless_type_title = no

			holder_scope = {
				trigger_if = {
					limit = { is_theocracy = yes }

					religion_allows_male_temple_holders = no
					religion_allows_female_temple_holders = yes
				}
				trigger_else = {
					has_religion_feature = religion_matriarchal
				}
			}

			# Override laws set by title history, should default to Absolute Cognatic
			trigger_if = {
				limit = { has_game_started = no }

				NOT = {
					has_game_rule = {
						name = gender
						value = all
					}
				}
			}
		}

		allow = {
			has_law = enatic_cognatic_succession

			holder_scope = {
				show_scope_change = no

				NOT = { trait = uncrowned }

				# Muslim/Aztec rulers have a harder time
				trigger_if = {
					limit = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}

					plus_law_prestige_trigger_2 = yes
				}

				# Everyone else
				trigger_else = {
					plus_law_prestige_trigger_1 = yes
				}
			}
		}

		pass_effect = {
			# log = "enatic_succession pass ([This.GetFullBaseName])"

			if = {
				limit = {
					holder_scope = {
						OR = {
							religion_group = muslim
							religion = aztec_pagan
						}
					}
				}

				plus_law_change_prestige_effect_2 = yes
			}
			else = {
				plus_law_change_prestige_effect_1 = yes
			}
		}

		effect = {
			# log = "enatic_succession ([This.GetFullBaseName])"

			tooltip = { # pass_effect doesn't generate tooltips
				if = {
					limit = {
						holder_scope = {
							OR = {
								religion_group = muslim
								religion = aztec_pagan
							}
						}
					}

					plus_law_change_prestige_effect_2 = yes
				}
				else = {
					plus_law_change_prestige_effect_1 = yes
				}
			}

			gender_succ = enatic
			law_set_allow_matrilineal_marriage = yes
		}

		default_selection = {
			factor = 100

			trigger = {
				holder_scope = {
					OR = {
						has_religion_feature = religion_matriarchal

						any_owned_bloodline = {
							has_bloodline_flag = bloodline_enatic_cognatic
							bloodline_is_active_for = PREV
						}
					}
				}
			}
		}
	}
}