﻿### EK NOTE: Removed references to vanilla culture & regional innovations
### EK NOTE: Added Autocracy government

character_gender_can_rule_title_trigger = {
	trigger_if = {
		limit = {
			$GENDER$ = { is_male = yes }
			exists = $TITLE$
			$TITLE$ = {
				NOT = {
					has_title_law = female_only_law
				}
			}
		}
		always = yes
	}
	trigger_else_if = {
		limit = {
			$GENDER$ = { is_female = yes }
			exists = $TITLE$
			$TITLE$ = {
				NOT = {
					has_title_law = male_only_law
				}
			}
		}
		always = yes
	}
	trigger_else = {
		always = no
	}
}

character_gender_can_inherit_from_trigger = {
	save_temporary_scope_as = heir

	trigger_if = {
		limit = {
			$CHARACTER$ = { exists = primary_title }
		}
		$CHARACTER$ = {
			character_gender_can_rule_title_trigger = {
				GENDER = scope:heir
				TITLE = primary_title
			}
		}
	}
	trigger_else = {
		always = no
	}
}

has_partition_succession_realm_law_trigger = {
	OR = {
		has_realm_law = confederate_partition_succession_law
		has_realm_law = partition_succession_law
		has_realm_law = high_partition_succession_law
		has_realm_law = clan_antagonistic_partition_succession_law
		has_realm_law = clan_competitive_partition_succession_law
		has_realm_law = clan_impassive_partition_succession_law
		has_realm_law = clan_friendly_partition_succession_law
		has_realm_law = clan_harmonious_partition_succession_law
	}
}

realm_law_use_crown_authority = {
	# We separate this out into a different trigger for moddability purposes, per community request: this allows more diverse authority laws to be easily modded in without needing to override 00_realm_laws.txt, and thus for greater inter-mod compatibility.
	realm_law_use_tribal_authority = no
	realm_law_use_camp_purpose = no
	realm_law_use_imperial_bureaucracy = no
	realm_law_use_nomadic_authority = no
}

realm_law_use_tribal_authority = {
	government_has_flag = government_is_tribal
}

realm_law_use_camp_purpose = {
	government_has_flag = government_is_landless_adventurer
}

realm_law_use_imperial_bureaucracy = {
	government_allows = administrative
}

realm_law_use_nomadic_authority = {
	government_has_flag = government_is_nomadic
}

can_have_confederate_partition_succession_law_trigger = {
	OR = {
		has_feudal_like_succession = yes #EK EDIT
		government_has_flag = government_is_tribal
	}
	
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_keep_partition_succession_law_trigger = {
	# The 'can_keep' triggers are dependent on actually having the law. If they aren't, the trigger breakdown for the player breaks and shows incomplete information.
	trigger_if = {
		limit = {
			has_realm_law = partition_succession_law
		}
		OR = {
			can_have_partition_succession_law_trigger = yes

			# Mongol Empires
			#EK DISABLED
			# has_title = title:e_mongol_empire
			# has_title = title:e_ilkhanate
			# has_title = title:e_golden_horde
			# has_title = title:e_chagatai
			# has_title = title:e_black_horde
			# has_title = title:e_white_horde
			# has_title = title:e_aarlud_khanate
			# has_title = title:e_togskol_khanate
			# has_title = title:e_baruun_khanate
		}
	}
	NOT = { government_has_flag = government_is_clan }
}

can_have_partition_succession_law_trigger = {
	culture = {
		has_innovation = innovation_gavelkind #EK EDIT
	}
	custom_description = {
		text = succession_laws_must_have_organised_government_tooltip
		has_feudal_like_succession = yes #EK EDIT
	}
	
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_keep_high_partition_succession_law_trigger = {
	# The 'can_keep' triggers are dependent on actually having the law. If they aren't, the trigger breakdown for the player breaks and shows incomplete information.
	trigger_if = {
		limit = {
			has_realm_law = high_partition_succession_law
		}
		OR = {
			can_have_high_partition_succession_law_trigger = yes

			# Mongol Empires
			#EK DISABLED
			# has_title = title:e_mongol_empire
			# has_title = title:e_ilkhanate
			# has_title = title:e_golden_horde
			# has_title = title:e_chagatai
			# has_title = title:e_black_horde
			# has_title = title:e_white_horde
			# has_title = title:e_aarlud_khanate
			# has_title = title:e_togskol_khanate
			# has_title = title:e_baruun_khanate
		}
	}
	NOT = { government_has_flag = government_is_clan}
}

can_have_high_partition_succession_law_trigger = {
	trigger_if = {
		limit = {
			NOT = { 
				culture = { has_cultural_parameter = can_enact_high_partition_succession_law }
			}
		}
		culture = { has_innovation = innovation_heraldry }
	}
	#EK EDIT
	trigger_else = {
		culture = { has_innovation = innovation_heraldry }
	}
	custom_description = {
		text = succession_laws_must_have_organised_government_tooltip
		has_feudal_like_succession = yes #EK EDIT
	}
	
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_keep_single_heir_succession_law_trigger = {
	# The 'can_keep' triggers are dependent on actually having the law. If they aren't, the trigger breakdown for the player breaks and shows incomplete information.
	trigger_if = {
		limit = {
			has_realm_law = single_heir_succession_law
		}
		OR = {
			can_have_single_heir_succession_law_trigger = yes
			# Byzantine Empire
			historical_succession_access_single_heir_succession_law_trigger = yes
		}
	}
}

can_have_single_heir_succession_law_trigger = {
	culture = {
		has_innovation = innovation_primogeniture
	}
	# Non-tribals only
	trigger_if = { # We split the tooltip into two, to make sure we don't show admin unless you actually have it
		limit = {
			has_ep3_dlc_trigger = yes
		}
		custom_tooltip = {
			text = has_feudal_like_government_trigger_desc #EK EDIT: our governments
			OR = {
				#EK EDIT
				#government_has_flag = government_is_feudal
				#government_has_flag = government_is_clan
				has_feudal_like_succession = yes
				government_allows = administrative
			}
		}
	}
	trigger_else = {
		custom_description = {
			text = succession_laws_must_have_organised_government_tooltip
			OR = {
				#EK EDIT
				#government_has_flag = government_is_feudal
				#government_has_flag = government_is_clan
				has_feudal_like_succession = yes
			}
		}
	}
	trigger_if = {
		limit = {
			government_allows = administrative
		}
		is_independent_ruler = yes
	}
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_keep_single_heir_youngest_succession_law_trigger = {
	# The 'can_keep' triggers are dependent on actually having the law. If they aren't, the trigger breakdown for the player breaks and shows incomplete information.
	trigger_if = {
		limit = {
			has_realm_law = single_heir_succession_law_youngest
		}
		OR = {
			can_have_single_heir_youngest_succession_law_trigger = yes
			historical_succession_access_single_heir_succession_law_youngest_trigger = yes
		}
	}
}

can_have_single_heir_youngest_succession_law_trigger = {
	culture = {
		has_innovation = innovation_primogeniture
	}
	# Non-tribals only
	trigger_if = { # We split the tooltip into two, to make sure we don't show admin unless you actually have it
		limit = {
			has_ep3_dlc_trigger = yes
		}
		custom_tooltip = {
			text = has_feudal_like_government_trigger_desc #EK EDIT: our governments
			OR = {
				#EK EDIT
				#government_has_flag = government_is_feudal
				#government_has_flag = government_is_clan
				has_feudal_like_succession = yes
				government_allows = administrative
			}
		}
	}
	trigger_else = {
		custom_description = {
			text = succession_laws_must_have_organised_government_tooltip
			OR = {
				#EK EDIT
				#government_has_flag = government_is_feudal
				#government_has_flag = government_is_clan
				has_feudal_like_succession = yes
			}
		}
	}
	trigger_if = {
		limit = {
			government_allows = administrative
		}
		is_independent_ruler = yes
	}
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_keep_single_heir_dynasty_house_trigger = {
	# The 'can_keep' triggers are dependent on actually having the law. If they aren't, the trigger breakdown for the player breaks and shows incomplete information.
	trigger_if = {
		limit = {
			has_realm_law = single_heir_dynasty_house
		}
		OR = {
			can_have_single_heir_dynasty_house_trigger = yes
			historical_succession_access_single_heir_dynasty_house_trigger = yes
		}
	}
}

can_have_single_heir_dynasty_house_trigger = {
	exists = house
	trigger_if = {
		limit = {
			always = no
			#EK DISABLED
			#culture = {
			#	OR = {
			#		has_cultural_pillar = heritage_west_slavic
			#		NOT = {	has_innovation = innovation_heraldry }
			#	}
			#}
		}
		culture = {
			# has_innovation = innovation_table_of_princes
		}
	}
	trigger_else = {
		culture = {
			has_innovation = innovation_heraldry
		}
	}
	custom_description = {
		text = succession_laws_must_have_organised_government_tooltip
		has_feudal_like_succession = yes #EK EDIT
	}
	NOT = { government_allows = administrative }
	NOT = { ek_uses_special_succession_law = yes } #EK ADDITION
}

can_have_bishop_theocratic_succession_law_trigger = {
	OR = {
		is_theocratic_lessee = yes
		government_has_flag = government_is_theocracy
	}
}

### EK ADDITION: mage academy succession law
can_have_mage_magocratic_succession_law_trigger = {
	government_has_flag = government_is_academy
	any_sub_realm_barony = {
		title_province = {
			OR = {
				has_building = academymag_01
				has_building = academymag_02
				has_building = academymag_03
				has_building = academymag_04
				has_building = academymag_05
				has_building = academymag_06
				has_building = academymag_07
				has_building = academymag_08
			}
		}
	}
}
#EK ADDITION END

is_temporal_head_of_faith_trigger = {
	is_head_of_faith = yes
	holder.faith = { has_doctrine = doctrine_temporal_head }
}

can_title_have_law_general_trigger = {
	tier >= tier_duchy
	is_temporal_head_of_faith_trigger = no
}

can_have_holy_order_succession_law_trigger = {
	government_has_flag = government_is_holy_order
}

can_have_mercenary_succession_law_trigger = {
	OR = {
		government_has_flag = government_is_mercenary
		government_has_flag = government_is_landed_order # EK EDIT, military orders also use this succession
	}	
}

can_have_city_succession_law_trigger = {
	#EK EDIT - Academies
	OR = {
		government_has_flag = government_is_republic
		government_has_flag = government_is_academy
	}
}

can_have_herder_succession_law_trigger = {
	government_has_flag = government_is_herder
}

#EK ADDITION: Pirate
can_have_pirate_succession_law_trigger = {
	government_has_flag = government_is_pirate
}
#EK ADDITION END

title_can_reduce_partition_law_trigger = {
	holder ?= {
		OR = {
			has_realm_law = single_heir_succession_law
			can_have_high_partition_succession_law_trigger = yes
		}
		OR = {
			has_realm_law = high_partition_succession_law
			can_have_high_partition_succession_law_trigger = yes
		}
		OR = {
			has_realm_law = partition_succession_law
			can_have_confederate_partition_succession_law_trigger = yes
		}
	}
}

can_pass_law_ca1_trigger = {
	culture = { has_innovation = innovation_plenary_assemblies }
}

can_pass_law_ca2_trigger = {
	culture = { has_innovation = innovation_royal_prerogative }
}

can_pass_law_ca3_trigger = {
	culture = { has_innovation = innovation_royal_prerogative }
}

can_have_acclamation_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
	government_allows = administrative
	is_independent_ruler = yes
}

can_keep_acclamation_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
	trigger_if = {
		limit = {
			has_realm_law = acclamation_succession_law 
		}
		OR = {
			can_have_acclamation_succession_law_trigger = yes
			#has_title = title:e_byzantium
		}
	}
}

can_change_acclamation_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
}

can_have_appointment_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
	government_allows = administrative
	is_independent_ruler = no
}

can_keep_appointment_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
	trigger_if = {
		limit = {
			has_realm_law = appointment_succession_law 
		}
		can_have_appointment_succession_law_trigger = yes
	}
}

can_change_appointment_succession_law_trigger = {
	has_ep3_dlc_trigger = yes
}
