﻿
is_child_of_concubine_trigger = {
	OR = {
		has_trait = child_of_concubine_male
		has_trait = child_of_concubine_female
		has_trait = child_of_concubine_disinherited_female 
		has_trait = child_of_concubine_disinherited_male
		has_trait = child_of_concubine_legitimized_female 
		has_trait = child_of_concubine_legitimized_male 
	}	
}

is_legitimized_child_of_concubine_trigger = {
	OR = {
		has_trait = child_of_concubine_legitimized_female 
		has_trait = child_of_concubine_legitimized_male 
	}		
}

is_disinherited_child_of_concubine_trigger = {
	OR = {
		has_trait = child_of_concubine_disinherited_female 
		has_trait = child_of_concubine_disinherited_male 
	}
}

parent_has_legal_heir_trigger = {
	any_parent = {
		is_ruler = yes
		any_child = { 
			is_alive = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
			OR = {
				AND = {
					prev.faith = { has_doctrine_parameter = bastards_none }
					is_disinherited_child_of_concubine_trigger = no
				}
				is_child_of_concubine_trigger = no
				is_legitimized_child_of_concubine_trigger = yes
			}
		}
	}
}

parent_has_legal_male_heir_trigger = {
	any_parent = {
		is_ruler = yes
		any_child = { 
			is_alive = yes
			is_male = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
			OR = {
				AND = {
					prev.faith = { has_doctrine_parameter = bastards_none }
					is_disinherited_child_of_concubine_trigger = no
				}
				is_child_of_concubine_trigger = no
				is_legitimized_child_of_concubine_trigger = yes
			}
		}
	}
}

parent_has_legal_female_heir_trigger = {
	any_parent = {
		is_ruler = yes
		any_child = { 
			is_alive = yes
			is_female = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
			OR = {
				AND = {
					prev.faith = { has_doctrine_parameter = bastards_none }
					is_disinherited_child_of_concubine_trigger = no
				}
				is_child_of_concubine_trigger = no
				is_legitimized_child_of_concubine_trigger = yes
			}
		}
	}
}

culture_or_faith_is_male_dominated_trigger = {
	NOT = {
		culture = {
			OR = {
				has_cultural_parameter = gender_equal_inheritance
				has_cultural_parameter = female_only_inheritance
				has_cultural_parameter = female_preference_inheritance
			}							
		}
	}
	OR = {
		culture = {
			OR = {
				has_cultural_parameter = male_only_inheritance
				has_cultural_parameter = male_preference_inheritance
			}
		}
		faith = { has_doctrine = doctrine_gender_male_dominated }
	}
}

parent_inheritance_is_male_dominated_trigger = {
	any_parent = {
		is_ruler = yes
		culture_or_faith_is_male_dominated_trigger = yes
	}
}

culture_or_faith_has_equal_inheritance_trigger = {
	NOT = {
		culture = {
			OR = {
				has_cultural_parameter = male_only_inheritance
				has_cultural_parameter = male_preference_inheritance
				has_cultural_parameter = female_only_inheritance
				has_cultural_parameter = female_preference_inheritance
			}							
		}
	}
	OR = {
		culture = { has_cultural_parameter = gender_equal_inheritance }	
		faith = { has_doctrine = doctrine_gender_equal }
	}
}

parent_inheritance_is_equal_trigger = {
	any_parent = {
		is_ruler = yes
		culture_or_faith_has_equal_inheritance_trigger = yes
	}
}

culture_or_faith_is_female_dominated_trigger = {
	NOT = {
		culture = {
			OR = {
				has_cultural_parameter = gender_equal_inheritance
				has_cultural_parameter = male_only_inheritance
				has_cultural_parameter = male_preference_inheritance
			}							
		}
	}
	OR = {
		culture = {
			OR = {
				has_cultural_parameter = female_only_inheritance
				has_cultural_parameter = female_preference_inheritance
			}
		}
		faith = { has_doctrine = doctrine_gender_female_dominated }	
	}
}

parent_inheritance_is_female_dominated_trigger = {
	any_parent = {
		is_ruler = yes
		culture_or_faith_is_female_dominated_trigger = yes
	}
}

any_parent_has_legal_heir_trigger = {
	OR = {
		AND = {
			parent_inheritance_is_male_dominated_trigger = yes
			parent_has_legal_male_heir_trigger = yes
		}
		AND = {
			parent_inheritance_is_equal_trigger = yes
			parent_has_legal_heir_trigger = yes
		}
		AND = {
			parent_inheritance_is_female_dominated_trigger = yes
			parent_has_legal_female_heir_trigger = yes
		}
	}
}

has_eligible_child_heir_trigger = {
	trigger_if = { 
		limit = { culture_or_faith_is_male_dominated_trigger = yes }
		any_child = { 
			is_male = yes
			is_alive = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
		}
	}
	trigger_else_if = { 
		limit = { culture_or_faith_is_female_dominated_trigger = yes }
		any_child = { 
			is_female = yes
			is_alive = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
		}
	}
	trigger_else = {
		any_child = { 
			is_alive = yes
			has_unelectable_trait_trigger = no 
			NOT = { has_trait = concubine }
		}		
	}
}
