eligible_for_tgp_china_legacy_trigger = {
	has_tgp_dlc_trigger = yes
	OR = {
		game_rule_unrestricted_dynasty_legacies_trigger = yes
		dynasty = {
			OR = {
				dynast = {
					government_has_flag = government_has_merit
				}
				has_dynasty_perk = tgp_chinese_legacy_1
			}
		}
	}
}
eligible_for_tgp_japan_legacy_trigger = {
	has_tgp_dlc_trigger = yes
	OR = {
		game_rule_unrestricted_dynasty_legacies_trigger = yes
		dynasty = {
			OR = {
				dynast = {
					government_is_japanese_trigger = yes
				}
				has_dynasty_perk = tgp_japan_legacy_1
			}
		}
	}
}
eligible_for_tgp_sea_legacy_trigger = {
	has_tgp_dlc_trigger = yes
	OR = {
		game_rule_unrestricted_dynasty_legacies_trigger = yes
		dynasty = {
			OR = {
				dynast = {
					OR = {
						government_has_flag = government_is_mandala
						government_has_flag = government_is_wanua
					}
				}
				has_dynasty_perk = tgp_sea_legacy_1
			}
		}
	}
}

tgp_distant_realm_marriage_trigger = {
	$RECIPIENT_SPOUSE$ = {
		culture = { has_cultural_parameter = reduced_marriage_acceptance_distant_realms }
		top_liege != $ACTOR_SPOUSE$.top_liege
		trigger_if = {
			limit = { exists = capital_province }
			capital_province = { save_temporary_scope_as = from }
		}
		trigger_else = {
			location = { save_temporary_scope_as = from }
		}
		trigger_if = {
			limit = { exists = $ACTOR_SPOUSE$.capital_province }
			$ACTOR_SPOUSE$.capital_province = { save_temporary_scope_as = to }
		}
		trigger_else = {
			$ACTOR_SPOUSE$.location = { save_temporary_scope_as = to }
		}
		"scope:from.squared_distance(scope:to)" > squared_distance_medium
	}
}

tgp_dynastic_realm_name_trigger = {
	NOT = {
		any_ruler = {
			any_held_title = {
				has_custom_title_name = yes
				custom_title_name = $DYNASTY_REALM_NAME$
			}
		}
	}
	domicile.domicile_location = {
		geographical_region = $DOMICILE_REGION$
	}
}

administrative_tier_allows_independence = {
	trigger_if = {
		limit = {
			administrative_counts_can_be_independent = yes
		}
		highest_held_title_tier >= tier_county
	}
	trigger_else = { # Administrative/default
		highest_held_title_tier >= tier_kingdom
	}
}

administrative_counts_can_be_independent = {
	OR = {
		government_has_flag = government_is_celestial
		government_has_flag = government_is_japan_administrative
	}
}

tgp_examination_should_spend_treasury_trigger = {
	has_treasury = yes
	government_allows = replace_gold_cost_by_treasury
}

# Trigger to enable ministry features in script - Made into a scripted trigger for ease of changing it if needed
tgp_has_access_to_ministry_trigger = {
	always = no
#	has_title = title:h_china
#	government_has_flag = government_is_celestial
}

tgp_is_any_minister = {
	always = no
#	liege ?= { tgp_has_access_to_ministry_trigger = yes }
#	tgp_has_minister_title = yes
}

tgp_has_minister_title = {
	always = no
#	OR = {
#		has_title = title:e_minister_chancellor
#		has_title = title:e_minister_censor
#		has_title = title:e_minister_grand_marshal
#		has_title = title:e_minister_of_personnel
#		has_title = title:e_minister_of_revenue
#		has_title = title:e_minister_of_rites
#		has_title = title:e_minister_of_war
#		has_title = title:e_minister_of_justice
#		has_title = title:e_minister_of_works
#	}
}

tgp_has_civilian_minister_title = {
	always = no
#	OR = {
#		has_title = title:e_minister_chancellor
#		has_title = title:e_minister_censor
#		has_title = title:e_minister_of_personnel
#		has_title = title:e_minister_of_revenue
#		has_title = title:e_minister_of_rites
#		has_title = title:e_minister_of_war
#		has_title = title:e_minister_of_justice
#		has_title = title:e_minister_of_works
#	}
}

tgp_is_civilian_minister_title = {
	always = no
#	OR = {
#		this = title:e_minister_chancellor
#		this = title:e_minister_censor
#		this = title:e_minister_of_personnel
#		this = title:e_minister_of_revenue
#		this = title:e_minister_of_rites
#		this = title:e_minister_of_war
#		this = title:e_minister_of_justice
#		this = title:e_minister_of_works
#	}
}

tgp_is_minister_title = {
	always = no
#	OR = {
#		this = title:e_minister_chancellor
#		this = title:e_minister_censor
#		this = title:e_minister_grand_marshal
#		this = title:e_minister_of_personnel
#		this = title:e_minister_of_revenue
#		this = title:e_minister_of_rites
#		this = title:e_minister_of_war
#		this = title:e_minister_of_justice
#		this = title:e_minister_of_works
#	}
}

tgp_can_be_a_minister_trigger = {
	can_be_councillor_basics_trigger = yes
	# Has to be celestial or a non-ruler
	OR = {
		is_ruler = no
		government_has_flag = government_is_celestial
	}
	# Gender is based on laws of the liege
	OR = {
		has_variable = can_be_councillor_override
		AND = {
			is_female = yes
			$COURT_OWNER$ = {
				NOR = {
					has_realm_law = male_only_law
					has_realm_law = male_preference_law
				}
			}
		}
		AND = {
			is_male = yes
			$COURT_OWNER$ = {
				NOR = {
					has_realm_law = female_only_law
					has_realm_law = female_preference_law
				}
			}
		}
	}
	# Players are only allowed if they have enough merit or is a councillor already, unless they are friends or disciples/elders
	# We do this to prevent the AI from "randomly" requesting the player to be on their council
	trigger_if = {
		limit = {
			is_ai = no
			$COURT_OWNER$ = { is_ai = yes }
			NOT = { is_councillor_of = $COURT_OWNER$ }
		}
		OR = {
			merit_level >= merit_level_expected_empire_value
			has_relation_friend = $COURT_OWNER$
			has_relation_disciple = $COURT_OWNER$
			has_relation_elder = $COURT_OWNER$
		}
	}
}

tgp_can_be_grand_marshal_trigger = {
	can_be_councillor_basics_trigger = yes
	# Has to be celestial or a non-ruler
	OR = {
		is_ruler = no
		government_has_flag = government_is_celestial
	}
	# Has to be able to lead armies
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = $COURT_OWNER$ }
}

tgp_is_above_retirement_age_trigger = {
	$REALM_OWNER$.top_liege = {
		has_realm_law_flag = celestial_retirement_law
	}
	trigger_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_4 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_4
			age >= retirement_age_4_value
		}
	}
	trigger_else_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_3 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_3
			age >= retirement_age_3_value
		}
	}
	trigger_else_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_2 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_2
			age >= retirement_age_2_value
		}
	}
	trigger_else_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_1 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_1
			age >= retirement_age_1_value
		}
	}
	trigger_else_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_0 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_0
			age >= retirement_age_0_value
		}
	}
	trigger_else_if = {
		limit = {
			$REALM_OWNER$.top_liege ?= { has_realm_law_flag = celestial_retirement_age_5 }
		}
		custom_tooltip = {
			text = tgp_is_above_retirement_age_5
			always = yes
		}
	}
	trigger_else = {
		custom_tooltip = {
			text = tgp_is_above_retirement_age_law_not_set
			always = yes
		}
	}
}

# Civilian/military triggers
is_civilian_candidate_trigger = {
	trigger_if = {
		limit = {
			has_variable = appointment_trait_override
		}
		var:appointment_trait_override = trait:education_stewardship_1
	}
	trigger_else = {
		has_trait_with_flag = civilian_province
	}
}
is_military_candidate_trigger = {
	trigger_if = {
		limit = {
			has_variable = appointment_trait_override
		}
		var:appointment_trait_override = trait:education_martial_1
	}
	trigger_else = {
		has_trait_with_flag = military_province
	}
}

# Trigger if scoped character is able to join the war(s) of the target character
# $TARGET_GOVERNOR$ - Target governor in need of troops
# $MINISTER_OF_WAR$ - The Minister of War
tgp_celestial_military_governor_can_join_war_trigger = {
	save_temporary_scope_as = joining_governor
	OR = {
		vassal_contract_has_flag = celestial_military_appointment
		vassal_contract_has_flag = meritocratic_military_appointment
		has_title = title:e_minister_grand_marshal
	}
	NOR = {
		scope:joining_governor = $TARGET_GOVERNOR$
		scope:joining_governor = $MINISTER_OF_WAR$
		any_war_ally = { this = $TARGET_GOVERNOR$ }
		is_at_war_with = $TARGET_GOVERNOR$
		is_at_war_with = $MINISTER_OF_WAR$
		$TARGET_GOVERNOR$ = {
			any_war_enemy = {
				OR = {
					is_vassal_of = scope:joining_governor
					is_liege_or_above_of = scope:joining_governor
					is_allied_to = scope:joining_governor
					is_tributary_of = scope:joining_governor
					is_at_war_with = scope:joining_governor
				}
			}
		}
	}
}

should_be_mandala_tributary_trigger = {
	OR = {
		AND = {
			$SUZERAIN$ = { has_government = mandala_government }
			$TRIBUTARY$ = { has_government = mandala_government }
		}
		AND = {
			$SUZERAIN$ = { has_government = mandala_government }
			$TRIBUTARY$ = {
				OR = {
					has_government = tribal_government
					has_government = wanua_government
				}
			}
		}
	}
}

should_be_wanua_tributary_trigger = {
	AND = {
		$SUZERAIN$ = { has_government = wanua_government }
		$TRIBUTARY$ = { has_government = wanua_government }
	}
}

is_valid_for_japan_events_trigger = {
	OR = {
		religion = religion:shintoism_religion
		faith = { has_doctrine = special_doctrine_immaterial_harmony }
	}
	culture = { has_cultural_pillar = heritage_japonic }
}

# Check if a top liege primary title has a ceremonial liege title
tgp_realm_has_ceremonial_liege_trigger = {
	custom_tooltip = {
		text = tgp_realm_has_ceremonial_liege_tt
		exists = top_liege.primary_title.var:administrative_ui_special_title.holder
	}
}

# Check if a character is a ceremonial liege, since they have the title but are a vassal
tgp_is_ceremonial_liege_trigger = {
	custom_tooltip = {
		text = tgp_is_ceremonial_liege_tt
		this != top_liege
		tgp_has_ceremonial_liege_title_trigger = yes
	}
}

tgp_portrait_liege_or_ceremonial_liege_emperor_trigger = {
	# Ceremonial Liege
	trigger_if = {
		limit = { tgp_realm_has_ceremonial_liege_trigger = yes }
		tgp_has_ceremonial_liege_title_trigger = yes
		primary_title.holder.top_liege.highest_held_title_tier >= tier_empire
	}
	# Standard Liege
	trigger_else = {
		trigger_if = {
			limit = {
				is_alive = yes
			}
			highest_held_title_tier >= tier_empire
			is_independent_ruler = yes
		}
		trigger_else = {
			scope:highest_held_title_tier >= tier_empire
		}
	}
}

tgp_portrait_liege_or_ceremonial_liege_king_trigger = {
	# Ceremonial Liege
	trigger_if = {
		limit = { tgp_realm_has_ceremonial_liege_trigger = yes }
		tgp_has_ceremonial_liege_title_trigger = yes
		primary_title.holder.top_liege.highest_held_title_tier = tier_kingdom
	}
	# Standard Liege
	trigger_else = {
		trigger_if = {
			limit = {
				is_alive = yes
			}
			highest_held_title_tier = tier_kingdom
		}
		trigger_else = {
			scope:highest_held_title_tier = tier_kingdom
		}
	}
}

# Check if a character has a ceremonial liege title (but not if they are actually a ceremonial liege)
tgp_has_ceremonial_liege_title_trigger = {
	trigger_if = {
		limit = { tgp_realm_has_ceremonial_liege_trigger = yes }
		custom_tooltip = {
			text = tgp_has_ceremonial_liege_title_tt
			has_title = top_liege.primary_title.var:administrative_ui_special_title
		}
	}
	trigger_else = {
		custom_tooltip = {
			text = tgp_has_ceremonial_liege_title_no_title_tt
			always = no
		}
	}
}

# Used to save temp scope of the ceremonial liege for other triggers
tgp_ceremonial_liege_scope_trigger = {
	top_liege = {
		save_temporary_scope_as = ruler_temp
		primary_title.var:administrative_ui_special_title.holder ?= {
			top_liege ?= scope:ruler_temp.top_liege
			this = scope:ruler_temp
			save_temporary_scope_as = ceremonial_liege_temp
		}
	}
	is_independent_ruler = no
}

# Check if character is part of their realm's ceremonial liege's house
tgp_is_in_ceremonial_house_trigger = {
	custom_tooltip = {
		text = tgp_is_in_ceremonial_house_tt
		house.house_head.top_liege.primary_title.var:administrative_ui_special_title.holder.house ?= house
	}
}

 # Check if two characters are from the same ceremonial house
tgp_shared_ceremonial_house_trigger = {
	exists = $COMPARE_1$.house
	$COMPARE_2$.house ?= $COMPARE_1$.house
	OR = {
		$COMPARE_1$ = { tgp_is_in_ceremonial_house_trigger = yes }
		$COMPARE_2$ = { tgp_is_in_ceremonial_house_trigger = yes }
	}
}

 # Check if a character is a ruler over a ceremonial liege
tgp_is_ceremonial_regent_trigger = {
	is_independent_ruler = yes
	is_landed = yes
	tgp_realm_has_ceremonial_liege_trigger = yes
	tgp_has_ceremonial_liege_title_trigger = no
}

tgp_should_become_meritocratic_trigger = {
	has_tgp_dlc_trigger = yes
	OR = {
		top_liege = {
			OR = {
				has_government = meritocratic_government
				any_neighboring_and_across_water_top_liege_realm_owner = { government_allows = merit }
			}
		}
		AND = {
			OR = {
				is_independent_ruler = yes
				liege = {
					NOT = {
						government_has_flag = government_is_administrative
					}
				}
			}
			capital_province = {
				OR = {
					geographical_region = world_asia
					geographical_region = world_tibet
					geographical_region = world_burma
					geographical_region = world_steppe_east
				}
			}
		}
		#Becoming admin with creation of meritocratic great yuan
		exists = scope:great_yuan_ruler
	}
}

tgp_can_become_japan_administrative_trigger = {
	OR = {
		top_liege = {
			OR = {
				government_is_japanese_trigger = yes
				has_character_flag = tgp_japan_restore_japanese_government_flag
			}
		}
		government_is_japanese_trigger = yes
		has_character_flag = tgp_japan_restore_japanese_government_flag
	}
}

tgp_can_become_celestial_trigger = {
	top_liege = {
		OR = {
			has_government = celestial_government
			has_title = title:h_china
			culture = {
				culture_is_or_has_ancestor_trigger = { CULTURE = culture:han }
			}
		}
	}
}

tgp_mongol_vassal_will_become_admin = {
	highest_held_title_tier > tier_barony
	primary_title = {
		OR = {
			target_is_de_jure_liege_or_above = scope:administrative_liege.primary_title #We only auto convert de jure vassals
			target_is_de_jure_liege_or_above = title:h_china
		}
	}
	OR = {
		government_has_flag = government_is_feudal
		government_has_flag = government_is_clan
		government_has_flag = government_is_japan_feudal
		government_has_flag = government_is_nomadic
	}
	OR = {
		#An admin type
		has_trait = governor
		faith.religion = religion:confucianism_religion
		culture = {
			has_cultural_pillar = heritage_chinese
		}
		culture = {
			has_cultural_pillar = heritage_korean
		}
		#Nomad type
		government_has_flag = government_is_nomadic
		has_trait = nomadic_philosophy
	}
}

tgp_japanese_high_nobility_clothing_trigger = {
	tgp_is_ceremonial_liege_trigger = no
	trigger_if = {
		limit = { has_character_flag = murasaki }
		always = yes
	}
	trigger_else_if = {
		limit = { government_has_flag = government_is_japan_feudal }
		OR = {
			is_independent_ruler = yes
			trigger_if = {
				limit = { exists = top_liege }
				OR = {
					is_councillor_of = top_liege
					is_spouse_of = top_liege
				}
				AND = {
					is_house_head = yes
					has_same_government = top_liege
				}
			}
		}
	}
	trigger_else_if = {
		limit = { government_has_flag = government_is_japan_administrative }
		OR = {
			highest_held_title_tier >= tier_county
			tgp_is_in_ceremonial_house_trigger = yes
		}
	}
	trigger_else = { highest_held_title_tier >= tier_kingdom }
}

tgp_japanese_high_nobility_clothing_family_trigger = {
	AND = {
		government_has_flag = government_is_japan_administrative
		is_lowborn = no
		OR = {
			highest_held_title_tier >= tier_county
			court_owner ?= { highest_held_title_tier >= tier_county }
		}
	}
}

tgp_is_chinese_style_emperor_trigger = {
	highest_held_title_tier >= tier_empire
	is_independent_ruler = yes
	government_allows = merit
}

is_valid_for_east_asian_events_trigger = {
	culture = {
		OR = {
			has_cultural_pillar = heritage_japonic
			has_cultural_pillar = heritage_chinese
			has_cultural_pillar = heritage_korean
		}
	}
}

is_valid_for_east_asian_events_geo_trigger = {
	capital_province = {
		OR = {
			geographical_region = world_asia_china
			geographical_region = world_asia_japan
			geographical_region = world_asia_korea
			geographical_region = world_asia_southeast
		}
	}
}

shared_raid_estate_participant_valid_trigger = {
	is_adult = yes
	is_house_head = yes
	is_independent_ruler = no
	custom_tooltip = {
		text = is_house_head_of_noble_family_tt
		any_held_title = { is_noble_family_title = yes }
		house.house_head ?= this
	}
	OR = {
		government_allows = administrative
		government_is_japanese_trigger = yes
	}
	tgp_is_ceremonial_liege_trigger = no
}

should_use_asian_maa_graphics = {
	OR = {
		has_unit_gfx = chinese_unit_gfx
		has_unit_gfx = japanese_unit_gfx
		has_unit_gfx = indian_unit_gfx
		has_unit_gfx = southeast_asian_unit_gfx
		has_unit_gfx = mongol_unit_gfx
	}
}

eligible_for_elder_trigger = {
	merit_level > $DISCIPLE$.merit_level
	num_of_relation_disciple < disciples_limit_value
	NOT = { has_relation_disciple = $DISCIPLE$ }
	$DISCIPLE$ = {
		is_adult = yes
	}
}

# Treasury budget triggers
prefers_salary_favored_budget_trigger = {
	$CHARACTER$ = {
		OR = {
			top_participant_group:dynastic_cycle ?= { participant_group_type = conservative_movement }
			has_title = title:e_minister_of_personnel
			AND = {
				this = top_liege
				OR = {
					ai_compassion > 75
					ai_honor > 75
				}
			}
			ai_greed >= 0
		}
		trigger_if = {
			limit = { this != top_liege }
			NOT = { has_trait = loyal }
		}
	}
}

prefers_ministry_favored_budget_trigger = {
	$CHARACTER$ = {
		OR = {
			top_participant_group:dynastic_cycle ?= { participant_group_type = advancement_movement }
			AND = {
				this = top_liege
				OR = {
					ai_greed < 0
					ai_rationality > 75
					situation:dynastic_cycle ?= { situation_current_phase = situation_dynastic_cycle_phase_stability_advancement }
				}
			}
		}
		trigger_if = {
			limit = { this != top_liege }
			NOT = { has_trait = loyal }
		}
	}
}

prefers_military_favored_budget_trigger = {
	$CHARACTER$ = {
		OR = {
			top_participant_group:dynastic_cycle ?= { participant_group_type = expansion_movement }
			has_title = title:e_minister_grand_marshal
			has_title = title:e_minister_of_war
			AND = {
				this = top_liege
				OR = {
					ai_boldness > 90
					situation:dynastic_cycle ?= {
						OR = {
							situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
							situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
						}
					}
				}
			}
			ai_greed < 0
		}
		trigger_if = {
			limit = { this != top_liege }
			NOT = { has_trait = loyal }
		}
	}
}

prefers_hegemon_favored_budget_trigger = {
	$CHARACTER$ = {
		OR = {
			top_participant_group:dynastic_cycle ?= { participant_group_type = pro_hegemon_movement }
			has_trait = loyal
			AND = {
				this = top_liege
				ai_greed > 90
			}
		}
	}
}

can_suggest_budget_salary_template_trigger = {
	NOT = {
		liege = {
			has_realm_law = budget_allocation_salary_45
			has_realm_law = budget_allocation_ministry_25
			has_realm_law = budget_allocation_military_20
		}
	}
}

can_suggest_budget_ministry_template_trigger = {
	NOT = {
		liege = {
			has_realm_law = budget_allocation_salary_25
			has_realm_law = budget_allocation_ministry_45
			has_realm_law = budget_allocation_military_20
		}
	}
}

can_suggest_budget_military_template_trigger = {
	NOT = {
		liege = {
			has_realm_law = budget_allocation_salary_30
			has_realm_law = budget_allocation_ministry_20
			has_realm_law = budget_allocation_military_40
		}
	}
}

can_suggest_budget_hegemon_template_trigger = {
	NOT = {
		liege = {
			has_realm_law = budget_allocation_salary_30
			has_realm_law = budget_allocation_ministry_25
			has_realm_law = budget_allocation_military_25
		}
	}
}

can_suggest_budget_balanced_template_trigger = {
	NOT = {
		liege = {
			has_realm_law = budget_allocation_salary_35
			has_realm_law = budget_allocation_ministry_30
			has_realm_law = budget_allocation_military_25
		}
	}
}
###

peasant_war_should_escalated_trigger = {
	has_variable = peasant_war_escalates
}

tgp_gender_can_be_exam_entrant_trigger = {
	trigger_if = {
		limit = {
			scope:host ?= {
				OR = {
					has_realm_law = female_only_law
					has_realm_law = female_preference_law
				}
			}
		}
		OR = {
			is_female = yes
			AND = {
				is_ai = no
				is_male = yes
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:host ?= {
				OR = {
					has_realm_law = male_only_law
					has_realm_law = male_preference_law
				}
			}
		}
		OR = {
			is_male = yes
			AND = {
				is_ai = no
				is_female = yes
			}
		}
	}
	trigger_else = {
		always = yes
	}
}

tgp_root_gender_can_be_exam_entrant_trigger = {
	trigger_if = {
		limit = {
			root ?= {
				OR = {
					has_realm_law = female_only_law
					has_realm_law = female_preference_law
				}
			}
		}
		is_female = yes
	}
	trigger_else_if = {
		limit = {
			root ?= {
				OR = {
					has_realm_law = male_only_law
					has_realm_law = male_preference_law
				}
			}
		}
		is_female = no
	}
	trigger_else = {
		always = yes
	}
}

is_merit_based_official = {
	government_has_flag = government_has_merit
	OR = {
		is_governor_or_admin_count = yes
		AND = {
			is_councillor = yes
			NOT = { has_council_position = councillor_spouse }
			liege = {
				OR = {
					is_landed = yes # to exclude councilors of landless noble family heads
					highest_held_title_tier >= tier_empire # for councilors of ministers
				}
			}
		}
	}
}

has_highest_merit_rank = {
	trigger_if = {
		limit = { government_has_flag = government_is_celestial }
		merit_level = 9
	}
	trigger_else = { merit_level = 5 }
}

tgp_is_ceremonial_petition_shown_trigger = {
	is_playable_character = yes
	has_dlc_feature = royal_court
	has_tgp_dlc_trigger = yes
	tgp_realm_has_ceremonial_liege_trigger = yes
	tgp_has_ceremonial_liege_title_trigger = no
	top_liege = { tgp_is_ceremonial_regent_trigger = yes } # Not 'actual' ruler
	top_liege.primary_title.var:administrative_ui_special_title.holder ?= { has_royal_court = yes }
}

tgp_is_ceremonial_petition_valid_trigger = {
	has_dlc_feature = royal_court
	has_tgp_dlc_trigger = yes
	is_at_war = no
	tgp_realm_has_ceremonial_liege_trigger = yes
	top_liege.primary_title.var:administrative_ui_special_title.holder ?= {
		is_available_adult = yes
		has_royal_court = yes
		NOT = { is_at_war = yes }
	}
}

take_vows_available_trigger = {
	OR = {
		faith = { has_doctrine_parameter = take_vows_active }
		AND = {
			religion:buddhism_religion ?= religion
			faith = { has_doctrine = special_doctrine_immaterial_harmony }
		}
	}
}

tgp_use_chinese_naming_trigger = {
	government_has_flag = government_is_celestial
}

tgp_is_in_chinese_naming_region = {
	OR = {
		# whole startup h_china
		geographical_region = world_asia_china
		# outside h_china
		geographical_region = tgp_bao_region
		geographical_region = tgp_kang_region
		geographical_region = tgp_liao_region
		geographical_region = tgp_yuan_ferghana_region
		# partly outside
		geographical_region = tgp_liang_west_region
		geographical_region = tgp_cheng_region
	}
}

tgp_has_cultural_naming_in_chinese = {
	OR = {
		has_cultural_pillar = heritage_viet
		has_cultural_pillar = heritage_japonic
		has_cultural_pillar = heritage_tibetan
		has_cultural_pillar = heritage_buyeo
		has_cultural_pillar = heritage_korean
		has_name_list = name_list_jurchen
		has_cultural_pillar = heritage_mongolic
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:bouxcuengh }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:bai }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:yi }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:tai }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:yughur }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:uyghur }
		has_cultural_pillar = heritage_hmongic
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:cham }
		has_cultural_pillar = heritage_byzantine
#		culture_is_or_has_ancestor_trigger = { CULTURE = culture:roman }
		culture_is_or_has_ancestor_trigger = { CULTURE = culture:avar }
	}
}

tgp_has_unique_chinese_naming = {
	OR = {
		capital_county.title_province ?= { tgp_is_in_chinese_naming_region = yes }
		scope:title.capital_county.title_province ?= { tgp_is_in_chinese_naming_region = yes }
		culture = { tgp_has_cultural_naming_in_chinese = no }
	}
}

tgp_chinese_naming_tier_trigger = {
	save_temporary_scope_as = ruler_temp
	OR = {
		capital_county.title_province ?= { 
			trigger_if = {
				limit = {
					geographical_region = tgp_county_chinese_naming_region
				}
				scope:ruler_temp.highest_held_title_tier >= tier_county
			}
			trigger_else_if = {
				limit = {
					geographical_region = tgp_duchy_chinese_naming_region
				}
				scope:ruler_temp.highest_held_title_tier >= tier_duchy
			}
			trigger_else = {
				scope:ruler_temp.highest_held_title_tier >= tier_kingdom
			}
		}
		scope:title ?= {
			capital_county.title_province ?= { 
				trigger_if = {
					limit = {
						geographical_region = tgp_county_chinese_naming_region
					}
					scope:ruler_temp.highest_held_title_tier >= tier_county
				}
				trigger_else_if = {
					limit = {
						geographical_region = tgp_duchy_chinese_naming_region
					}
					scope:ruler_temp.highest_held_title_tier >= tier_duchy
				}
				trigger_else = {
					scope:ruler_temp.highest_held_title_tier >= tier_kingdom
				}
			}
		}
	}
}

farm_estates_3_4_trigger = {
	custom_tooltip = {
		text = farm_estates_3_4_trigger
		OR = {
			AND = {
				building_requirement_castle_city_church = { LEVEL = 02 }
				scope:holder.culture = {
					has_innovation = innovation_manorialism
				}
				building_farm_estates_requirement_terrain = yes
			}
			AND = {
				has_building_or_higher = pastures_04
				culture = {
					has_cultural_parameter = farm_estates_pastures_unlock
				}
			}
			AND = {
				building_paddy_fields_requirement_terrain = yes
				scope:holder.culture = {
					has_innovation = innovation_champa_rice
					has_innovation = innovation_manorialism
				}
				building_requirement_castle_city_church = { LEVEL = 02 }
			}
		}
	}
}
