# These are here because they malfunction when cross-referencing within the actual government potentials and allows
# NOTE: Holdings and Laws are not loaded until after the game starts. EXTREMELY DELICATE, modify at your own risk

# Feudal Group
feudal_group_potential_trigger = {
	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
	is_patrician = no
	NOR = { # Special governments that should be prioritized (only feudal by technicality)
		is_government_potential = chinese_imperial_government
		is_government_potential = order_government
		is_government_potential = roman_imperial_government
	}
}

feudal_group_allow_trigger = { plus_imperial_group_allow = no } # Be careful with this as it might break fallbacks

# Chinese Imperial
chinese_imperial_government_potential_trigger = { # Special snowflake government. Doesn't get the group triggers
	chinese_imperial_government_culture_trigger = yes
	is_patrician = no
	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead (shouldn't happen, safety check)

	primary_title = {
		real_tier = EMPEROR
		has_title_flag = pretender_chinese_empire
	}
}

chinese_imperial_government_allow_trigger = {} # Special snowflake government. Doesn't get the group triggers

# Feudal
feudal_government_potential_trigger = {
	feudal_group_potential_trigger = yes

	NOR = {
		is_government_potential = muslim_feudal_government
		is_government_potential = monastic_feudal_government
		is_government_potential = bogomilist_government
	}
}

feudal_government_allow_trigger = {
	feudal_group_allow_trigger = yes
}

# Iqta
muslim_feudal_government_potential_trigger = {
	feudal_group_potential_trigger = yes
	religion_group = muslim
	NOT = { religion = druze }
}

muslim_feudal_government_allow_trigger = {
	feudal_group_allow_trigger = yes
}

# Holy Orders
order_government_potential_trigger = {
	trigger_if = {
		limit = { holy_order = no }

		ai = yes

		any_liege = {
			holy_order = yes
			religion = ROOT
		}

		NOT = { is_government_potential = merchant_republic_government }
		could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
	}
}

order_government_allow_trigger = {}

# Imperial Roman
roman_imperial_government_potential_trigger = {
	always = no # Plus uses various more generalised Imperial government forms
	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
	primary_title = {
		OR = {
			title = e_byzantium
			title = e_roman_empire
			title = event_target:alternate_byz
		}

		trigger_if = { # so it shows on the title selection screen
			limit = {
				NOT = { has_law = succ_byzantine_elective }
			}

			is_save_game = no
			has_game_started = no
		}
	}
}

roman_imperial_government_allow_trigger = {}

# Theocratic Feudal
monastic_feudal_government_potential_trigger = {
	feudal_group_potential_trigger = yes
	culture_group = tibetan_group
	higher_real_tier_than = BARON

	OR = {
		religion_openly_bon_or_reformed_trigger = yes
		religion = buddhist
	}
}

monastic_feudal_government_allow_trigger = {
	feudal_group_allow_trigger = yes
}

# Nomadic Group
# In case someone wants to add more Nomads for some reason
nomadic_group_potential_trigger = {
	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
	is_patrician = no
	mercenary = no
	holy_order = no
}

nomadic_group_allow_trigger = {}

# Nomad Government
nomadic_government_potential_trigger = {
	nomadic_group_potential_trigger = yes
}

nomadic_government_allow_trigger = {
	nomadic_group_allow_trigger = yes
}

# Republic Group
republic_group_potential_trigger = {
	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
}

republic_group_allow_trigger = {}

# Confucian Bureaucracy
confucian_government_potential_trigger = { # Special snowflake government. Doesn't get the group triggers
	is_offmap_tag = offmap_china
}

confucian_government_allow_trigger = {} # Special snowflake government. Doesn't get the group triggers

# Merchant Republic
merchant_republic_government_potential_trigger = {
	republic_group_potential_trigger = yes

	trigger_if = { # Established MR requiremends
		limit = {
			is_merchant_republic = yes
			has_game_started = yes
		}

		# Require at least one province and be Duke tier or higher
		higher_real_tier_than = COUNT
		num_of_count_titles >= 1

		# MR can't be under MR
		trigger_if = {
			limit = { independent = no }

			liege_before_war = {
				is_merchant_republic = no
			}
		}
	}
	trigger_else_if = { # Established Patrician requirements
		limit = {
			is_patrician = yes
			has_game_started = yes
		}

		# Liege must be MR
		liege_before_war = {
			is_merchant_republic = yes

			# MR can't be under MR
			trigger_if = {
				limit = { independent = no }

				liege_before_war = {
					is_merchant_republic = no
				}
			}
		}
	}
	trigger_else = { # Pre-game and new MR requirements
		OR = {
			is_patrician = yes

			trigger_if = {
				limit = { capital_scope = { is_coastal = yes } }

				# Require at least one province and be Duke tier or higher
				higher_real_tier_than = COUNT
				num_of_count_titles >= 1

				# MR can't be under MR
				trigger_if = {
					limit = { independent = no }

					liege_before_war = {
						is_merchant_republic = no
					}
				}
			}
		}
	}
}

merchant_republic_government_allow_trigger = {
	republic_group_allow_trigger = yes
}

# Republic Government
republic_government_potential_trigger = {
	republic_group_potential_trigger = yes

	# Necessary to keep Merchant Republics from reverting on some successions
	NOT = { is_government_potential = merchant_republic_government }
}

republic_government_allow_trigger = {
	republic_group_allow_trigger = yes
}

# Theocratic Group
# In case someone wants to add more Theocracies for some reason
theocratic_group_potential_trigger = {
	holy_order = no
	is_patrician = no

	trigger_if = {
		limit = { controls_religion = yes }

		could_be_temporal_religious_head_trigger = no
	}
	trigger_else = {
		NOT = { is_government_potential = muslim_feudal_government }
	}

	trigger_if = {
		limit = { is_female = yes }
		religion_allows_female_temple_holders = yes
	}
	trigger_else = {
		religion_allows_male_temple_holders = yes
	}
}

theocratic_group_allow_trigger = {}

# Theocracy Government
theocratic_government_potential_trigger = {
	theocratic_group_potential_trigger = yes
}

theocratic_government_allow_trigger = {
	theocratic_group_allow_trigger = yes
}

# Tribal Group
# In case someone wants to add more Tribals for some reason
tribal_group_potential_trigger = {
	mercenary = no
	is_patrician = no
	holy_order = no
	NOT = { is_government_potential = order_government }

	trigger_if = {
		limit = { has_game_started = yes }
		is_feudal = no
	}

	could_be_temporal_religious_head_trigger = yes # If holder is a religion head, makes sure they shouldn't be a theocracy instead
}

tribal_group_allow_trigger = {}

# Tribal Government
tribal_government_potential_trigger = {
	tribal_group_potential_trigger = yes
}

tribal_government_allow_trigger = {
	tribal_group_allow_trigger = yes
}
