#############################################
# Hire Agents								#
# by Emil Tisander							#
#############################################

estate_hire_agents_decisions = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_misc.dds"
	}
	sort_order = 105
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	desc = estate_hire_agents_decisions_desc
	selection_tooltip = estate_hire_agents_decisions_tooltip
	decision_group_type = admin
	
	cooldown = { years = 15 }
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		domicile ?= {
			has_domicile_parameter = estate_unlock_hire_agents_decision
		}
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes # Skulduggery isn't for children
	}

	effect = {
		add_character_modifier = {
			modifier = ep3_estate_hired_agents_modifier
			years = 15
		}
	}
	
	cost = {
		influence = major_influence_value
	}

	ai_potential = {
		is_governor = yes
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = 20
			has_trait = deceitful
		}
		modifier = {
			add = 20
			has_trait = vengeful
		}
		modifier = {
			add = 20
			has_trait = paranoid
		}
		modifier = {
			add = 10
			has_trait = ambitious
		}
		modifier = {
			add = -20
			has_trait = content
		}
		modifier = {
			add = -20
			has_trait = compassionate
		}
	}
}

#############################################
# Bolster Security							#
# by Emil Tisander							#
#############################################

### Bolster Estate Security ###
estate_bolster_security_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_invite_knights.dds"
	}
	sort_order = 105
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	desc = estate_bolster_security_decision_desc
	selection_tooltip = estate_bolster_security_decision_tooltip
	decision_group_type = admin
	
	cooldown = { years = 15 }
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		domicile ?= {
			has_domicile_parameter = estate_unlock_bolster_security_decision
		}
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
	}

	effect = {
		add_character_modifier = {
			modifier = ep3_estate_bolster_security_modifier
			years = 15
		}
	}
	
	cost = {
		influence = major_influence_value
	}

	ai_potential = {
		is_governor = yes
		NOR = {
			has_trait = trusting
			has_trait = gregarious
		}
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = 50
			has_trait = paranoid
		}
		modifier = {
			add = 10
			has_trait = deceitful
		}
		modifier = {
			add = 10
			has_trait = craven
		}
		modifier = {
			add = 10
			dread >= 50
		}
	}
}

#############################################
# Patrol Governorship						#
# by Emil Tisander							#
#############################################

### Conduct Patrols in Governorship ###
estate_governor_patrols_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp2_decision_struggle_opening.dds"
	}
	sort_order = 105
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	desc = estate_governor_patrols_decision_desc
	selection_tooltip = estate_governor_patrols_decision_tooltip
	decision_group_type = admin
	
	cooldown = { years = 15 }
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		domicile ?= {
			has_domicile_parameter = estate_unlock_patrol_decision
		}
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
		is_governor = yes
	}

	effect = {
		every_held_title = {
			title_tier = county
			add_to_list = counties_in_governorship
		}
		every_vassal = {
			limit = {
				any_held_title = { title_tier = county }
			}
			every_held_title = {
				title_tier = county
				add_to_list = counties_in_governorship
			}
		}
		every_in_list = {
			list = counties_in_governorship
			add_county_modifier = {
				modifier = ep3_estate_governor_patrols_modifier
				years = 15
			}
		}
		increase_governance_effect = { VALUE = 6 }
	}
	
	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = medium_gold_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = medium_gold_value
			}
		}
	}
	
	ai_potential = {
		is_governor = yes
	}
	
	ai_will_do = {
		base = 20
		modifier = {
			add = 50
			influence > monumental_influence_value
		}
		modifier = {
			add = 10
			has_trait = just
		}
		modifier = {
			add = 10
			has_trait = loyal
		}
		modifier = {
			add = 10
			has_trait = diligent
		}
		modifier = {
			add = -25
			has_trait = lazy
		}
		modifier = {
			add = -20
			opinion = {
				target = liege
				value < -20
			}
		}
	}
}

#############################################
# Manipulate Grain Market					#
# by Emil Tisander							#
#############################################

### Manipulate Grain Market ###
estate_granary_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_spend_money.dds"
	}
	sort_order = 105
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	desc = estate_granary_decision_desc
	selection_tooltip = estate_granary_decision_tooltip
	decision_group_type = admin
	
	cooldown = { years = 20 }
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		domicile ?= {
			has_domicile_parameter = estate_unlock_granary_decision
		}
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
	}

	effect = {
		add_character_modifier = {
			modifier = ep3_estate_granary_modifier
			years = 10
		}
		
		# Descriptions - Make sure the triggers below matches the ones in the granary_modifier_scaling_value scripted value
		save_scope_as = domicile_owner # We save it for the descriptions
		custom_description_no_bullet = { text = estate_unlock_granary_decision_factors_tt }
		if = {
			limit = {
				domicile ?= { has_domicile_building_or_higher = grain_field_01 }
			}
			custom_tooltip = estate_unlock_granary_decision_grain_building_tt
		}
		if = {
			limit = {
				domicile ?= { has_domicile_building_or_higher = east_asian_estate_rice_field_01 }
			}
			custom_tooltip = estate_unlock_granary_decision_rice_building_tt
		}
		if = {
			limit = {
				domicile ?= {
					domicile_location = {
						this = root.top_liege.capital_province
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_capital_tt
		}
		if = {
			limit = {
				domicile ?= {
					domicile_location = {
						OR = {
							terrain = farmlands
							terrain = floodplains
							terrain = terraced_hills
						}
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_terrain_tt
		}
		if = {
			limit = {
				domicile ?= {
					domicile_location.county = {
						county_control < 100
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_control_tt
		}
		if = {
			limit = {
				domicile ?= {
					domicile_location.county = {
						development_level >= estate_granary_development_bonus_2_value
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_development_2_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					domicile_location.county = {
						development_level >= estate_granary_development_bonus_1_value
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_development_1_tt
		}
		if = {
			limit = {
				domicile ?= {
					domicile_location = {
						any_province_epidemic = { }
					}
				}
			}
			custom_tooltip = estate_unlock_granary_decision_epidemic_tt
		}
		if = {
			limit = {
				granary_modifier_scaling_value <= 1
			}
			custom_tooltip = estate_unlock_granary_decision_no_factors_tt
		}
	}
	
	cost = {
		prestige = major_prestige_value
	}
	
	ai_potential = {
		is_governor = yes
	}
	
	ai_will_do = {
		base = 20
		modifier = {
			add = 30
			prestige > massive_prestige_value
		}
		modifier = {
			add = 20
			has_trait = greedy
		}
		modifier = {
			add = 10
			has_trait = deceitful
		}
		modifier = {
			add = 10
			has_trait = arbitrary
		}
		modifier = {
			add = 10
			has_trait = callous
		}
		modifier = {
			add = 10
			domicile ?= { has_domicile_building_or_higher = grain_field_01 }
		}
		modifier = {
			add = -10
			has_trait = generous
		}
		modifier = {
			add = -20
			has_trait = compassionate
		}
		modifier = {
			add = -25
			has_trait = just
		}
	}
}

#############################################
# Governorship Confirmation					#
# by Joe Parkin								#
#############################################

### Governorship Confirmation ###
admin_confirmation_decision = {
	picture = {
		trigger = {
			government_allows = merit
		}
		reference = "gfx/interface/illustrations/decisions/tgp_kowtow.dds"
	}
	ai_check_interval_by_tier = {
		barony = 0
		county = 45
		duchy = 45
		kingdom = 45
		empire = 45
		hegemony = 0
	}
	sort_order = 1000
#	picture = {
#		trigger = {
#			NOR = {
#				government_has_flag = government_is_tribal
#				government_has_flag = government_is_theocracy
#				top_liege ?= { government_has_flag = government_is_tribal }
#				top_liege ?= { government_has_flag = government_is_theocracy }
#			}
#			OR = {
#				culture = { has_cultural_pillar = heritage_byzantine }
#				top_liege ?= {
#					OR = {
#						culture = { has_cultural_pillar = heritage_byzantine }
#						capital_barony ?= title:b_constantinople
#						is_roman_emperor_primary_title_trigger = yes
#					}
#				}
#			}
#		}
#		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
#	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_knight_kneeling.dds"
	}
	decision_group_type = admin

	cost = {
		prestige = standard_activity_base_cost
	}

	is_shown = {
		has_ep3_dlc_trigger = yes
		is_playable_character = yes
		is_governor = yes
		liege ?= top_liege
		top_liege = { tgp_is_ceremonial_regent_trigger = no } # Not 'actual' ruler
	}

	is_valid = {
		custom_tooltip = {
			text = admin_confirmation_rank_tt
			primary_title.tier >= main_administrative_tier # Governs a Province
		}
		custom_tooltip = {
			text = admin_confirmation_liege_tt
			top_liege != this
			liege ?= top_liege
		}
		custom_tooltip = {
			text = admin_confirmation_time_tt
			primary_title ?= {
				title_held_years >= 1
			}
		}
		custom_tooltip = {
			text = admin_confirmation_grace_valid_tt
			NOR = {
				has_variable = confirmation_grace
				has_variable = confirmation_cooldown_vassal
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		liege ?= { is_available_adult = yes }
		is_at_war_with_liege = no
		trigger_if = {
			limit = {
				is_ai = no
				has_royal_court = yes
			}
			has_spawned_court_events = no # should only be used for human players
		}
		trigger_if = {
			limit = { is_ai = yes }
			NOT = {
				liege = { has_variable = confirmation_cooldown }
			}
		}
	}

	effect = {
		set_variable = {
			name = confirmation_liege_scope
			value = liege
		}
		custom_tooltip = admin_confirmation_decision_effects
		show_as_tooltip = {
			stress_impact = {
				shy = medium_stress_impact_gain
				humble = medium_stress_impact_gain
			}
			custom_description_no_bullet = {
				text = admin_confirmation_decision_tt_if_accepted
				subject = root
			}
			admin_confirmation_vassal_reward_guts_effect = yes
		}
		save_scope_as = confirmation_vassal
		liege ?= { save_scope_as = confirmation_liege }
		switch = {
			trigger = has_trait
			shy = { add_stress = medium_stress_impact_gain }
			humble = { add_stress = medium_stress_impact_gain }
		}
		start_travel_plan = {
			destination = liege.capital_province
			on_start_on_action = admin_confirmation_start
			on_travel_planner_cancel_on_action = admin_confirmation_travel_planner_exit
			on_arrival_event = ep3_decisions_event.2090
			on_arrival_destinations = all_but_last
		}
	}
	
	ai_potential = {
		is_at_war = no
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 50
			prestige > standard_activity_base_cost
		}
		modifier = {
			add = -50
			has_relation_rival = liege
		}
		modifier = {
			add = -25
			opinion = {
				target = liege
				value < 0
			}
		}
		modifier = { # Kings should be more weighted
			add = 25
			primary_title.tier >= tier_kingdom
		}
	}
}

#############################################
# Consolidate Rule							#
#############################################

### Consolidate Rule ###
consolidate_rule_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_family_tree.dds"
	}
	sort_order = 105
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 120
		hegemony = 120
	}

	desc = consolidate_rule_decision_desc
	selection_tooltip = consolidate_rule_decision_tooltip
	decision_group_type = admin
	
	cooldown = { years = 15 }
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		highest_held_title_tier >= tier_empire # Only for Emperors
		culture = { # Byzantium and others
			has_cultural_tradition = tradition_religious_patronage
		}
		faith = { # You cannot consolidate yourself... kinda
			religious_head ?= {
				this != root
			}
		}
	}

	is_valid = {
		government_allows = administrative
	}

	is_valid_showing_failures_only = {
		culture = {
			has_cultural_parameter = consolidate_rule_decision
		}
		any_held_title = { is_head_of_faith = no }
	}

	effect = {
		custom_tooltip = consolidate_rule_decision_effect_tt
		trigger_event = ep3_decisions_event.4050
	}
	
	cost = {
		influence = medium_influence_value
		piety = medium_piety_value
	}

	ai_potential = {
		highest_held_title_tier = tier_empire # Only for Emperors
		culture = { # Byzantium and others
			has_cultural_tradition = tradition_religious_patronage
		}
		faith = { # You cannot consolidate yourself... kinda
			religious_head ?= {
				this != root
			}
		}
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = 20
			legitimacy_level <= 2
		}
		modifier = {
			add = 20
			legitimacy_level <= 1
		}
		modifier = {
			add = 20
			legitimacy_level = 0
		}
	}
}

###################################
# Convert Realm to Administrative #
###################################

### Adopt Centralized Administration ###
convert_to_administrative_decision = {
	picture = {
		trigger = {
			culture_has_asian_heritage_pillar_trigger = yes
		}
		reference = "gfx/interface/illustrations/decisions/tgp_kowtow.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
	}
	decision_group_type = major
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_tgp_dlc_trigger = yes
				}
				desc = convert_to_administrative_decision_title_multiple
			}
			desc = convert_to_administrative_decision
		}
	}
	desc = convert_to_administrative_decision_desc
	selection_tooltip = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_tgp_dlc_trigger = yes
				}
				desc = convert_to_administrative_decision_tooltip_multiple
			}
			desc = convert_to_administrative_decision_tooltip
		}
	}
	confirm_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_tgp_dlc_trigger = yes
				}
				desc = convert_to_administrative_decision_confirm_multiple
			}
			desc = convert_to_administrative_decision_confirm
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 36
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 0
	}

	is_shown = {
		OR = {
			has_ep3_dlc_trigger = yes
			has_tgp_dlc_trigger = yes
		}
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
			government_has_flag = government_is_japan_feudal
		}
		trigger_if = {
			limit = { top_liege != this }
			liege = { government_allows = administrative }
		}
	}

	is_valid = {
		trigger_if = {
			limit = { top_liege != this }
			liege = { government_allows = administrative }
		}
		trigger_else = {
			OR = {
				custom_tooltip = {
					text = HAS_SEAL_OF_INVESTITURE
					any_character_artifact = {
						OR = {
							artifact_type = seal_of_investiture
							artifact_type = seal_of_investiture_court
						}
					}
				}
				trigger_if = {
					limit = {
						culture = { has_cultural_parameter = can_adopt_administrative_government_as_kingdom_tier }
					}
					custom_tooltip = {
						text = king_tier_tt
						primary_title.tier >= tier_kingdom
					}
				}
				trigger_else = {
					AND = { # To force the correct tooltip in loc
						custom_tooltip = {
							text = empire_tier_tt
							primary_title.tier >= tier_empire
						}
						root = { save_temporary_scope_as = root_scope }
						custom_tooltip = {
							text = small_realm_size_tt
							realm_size >= small_empire_size_value
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				top_liege = this
				is_ai = no
			}
			prestige_level >= 3
		}
		trigger_if = {
			limit = {
				top_liege = this
				is_ai = no
			}
			custom_tooltip = {
				text = all_powerful_vassals_required_tt
				any_powerful_vassal = {
					count = all
					opinion = {
						target = root
						value >= 50
					}
				}
			}
		}
		trigger_if = {
			limit = { is_ai = yes }
			calc_true_if = {
				amount >= 2
				culture = { has_cultural_pillar = ethos_bureaucratic }
				culture = { has_cultural_pillar = ethos_courtly }
				culture = { has_cultural_pillar = ethos_egalitarian }
				culture = { has_cultural_tradition = tradition_legalistic }
				has_realm_law = crown_authority_3
				capital_county = { development_level > medium_development_level }
				faith = { has_doctrine = tenet_legalism }
				dynasty = { has_dynasty_perk = erudition_legacy_5 }
				dynasty = { has_dynasty_perk = law_legacy_5 }
			}
		}
	}
	
	is_valid_showing_failures_only = {
		OR = {
			has_ep3_dlc_trigger = yes
			tgp_should_become_meritocratic_trigger = yes
		}
		is_at_war = no
	}

	cost = {
		prestige = {
			value = 1000
			if = {
				limit = {
					is_ai = no
					primary_title.tier = tier_kingdom
				}
				multiply = 1.5
			}
			if = { # Much cheaper for vassals wanting to adopt their admin liege's government
				limit = { top_liege != this }
				multiply = 0.1
			}
		}
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 800
				if = {
					limit = { is_ai = no }
					#Realm size
					if = {
						limit = { root.realm_size >= 300 }
						multiply = 3.5
					}
					else_if = {
						limit = { root.realm_size >= 250 }
						multiply = 3
					}
					else_if = {
						limit = { root.realm_size >= 200 }
						multiply = 2.5
					}
					else_if = {
						limit = { root.realm_size >= 150 }
						multiply = 2
					}
					else_if = {
						limit = { root.realm_size >= 100 }
						multiply = 1.5
					}
				}
				#Era
				culture = {
					if = {
						limit = { has_cultural_era_or_later = culture_era_late_medieval }
						multiply = 1.75
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_high_medieval }
						multiply = 1.25
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_early_medieval }
						multiply = 1
					}
					else = {
						multiply = 0.75
					}
				}
				#Income
				if = {
					limit = { root.monthly_character_income >= 100 }
					multiply = 3
				}
				else_if = {
					limit = { root.monthly_character_income >= 80 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 60 }
					multiply = 2
				}
				else_if = {
					limit = { root.monthly_character_income >= 40 }
					multiply = 1.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 20 }
					multiply = 1.1
				}

				max = 3000
				
				if = { # Much cheaper for vassals wanting to adopt their admin liege's government
					limit = {
						is_independent_ruler = no
					}
					multiply = 0.1
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 800
				if = {
					limit = { is_ai = no }
					#Realm size
					if = {
						limit = { root.realm_size >= 300 }
						multiply = 3.5
					}
					else_if = {
						limit = { root.realm_size >= 250 }
						multiply = 3
					}
					else_if = {
						limit = { root.realm_size >= 200 }
						multiply = 2.5
					}
					else_if = {
						limit = { root.realm_size >= 150 }
						multiply = 2
					}
					else_if = {
						limit = { root.realm_size >= 100 }
						multiply = 1.5
					}
				}
				#Era
				culture = {
					if = {
						limit = { has_cultural_era_or_later = culture_era_late_medieval }
						multiply = 1.75
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_high_medieval }
						multiply = 1.25
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_early_medieval }
						multiply = 1
					}
					else = {
						multiply = 0.75
					}
				}
				#Income
				if = {
					limit = { root.monthly_character_income >= 100 }
					multiply = 3
				}
				else_if = {
					limit = { root.monthly_character_income >= 80 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 60 }
					multiply = 2
				}
				else_if = {
					limit = { root.monthly_character_income >= 40 }
					multiply = 1.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 20 }
					multiply = 1.1
				}

				max = 3000
				
				if = { # Much cheaper for vassals wanting to adopt their admin liege's government
					limit = {
						top_liege != this
					}
					multiply = 0.1
				}
			}
		}
	}
	
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = no

		item = { # Administrative
			value = go_administrative_government
			is_shown = {
				has_ep3_dlc_trigger = yes
			}
			is_valid = {
				top_liege = {
					NOR = {
						has_government = celestial_government
						has_government = meritocratic_government
						has_government = japan_administrative_government
					}
				}
			}
			current_description = go_administrative_government_desc
			localization = go_administrative_government_name
			icon = "gfx/interface/icons/government_types/administrative_government.dds"
			ai_chance = {
				value = 10
			}
		}
		item = { # Celestial
			value = go_celestial_government
			is_shown = {
				has_tgp_dlc_trigger = yes
			}
			is_valid = {
				top_liege = {
					NOR = {
						has_government = administrative_government
						has_government = meritocratic_government
						has_government = japan_administrative_government
					}
				}
				custom_tooltip = {
					text = convert_to_administrative_celestial_desc
					tgp_can_become_celestial_trigger = yes
				}
			}
			current_description = go_celestial_government_desc
			localization = go_celestial_government_name
			icon = "gfx/interface/icons/government_types/celestial_government.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Meritocratic
			value = go_meritocratic_government
			is_shown = {
				has_tgp_dlc_trigger = yes
			}
			is_valid = {
				top_liege = {
					NOR = {
						has_government = administrative_government
						has_government = celestial_government
						has_government = japan_administrative_government
					}
				}
				custom_tooltip = {
					text = convert_to_administrative_meritocratic_desc
					tgp_should_become_meritocratic_trigger = yes
				}
			}
			current_description = go_meritocratic_government_desc
			localization = go_meritocratic_government_name
			icon = "gfx/interface/icons/government_types/meritocratic_government.dds"
			ai_chance = {
				value = 50
			}
		}
		item = { # Ritsuryo / AKA Japan Administrative
			value = go_japan_administrative_government
			is_shown = {
				has_tgp_dlc_trigger = yes
			}
			is_valid = {
				top_liege = {
					NOR = {
						has_government = administrative_government
						has_government = celestial_government
						has_government = meritocratic_government
					}
				}
				custom_tooltip = {
					text = convert_to_administrative_japanese_desc
					tgp_can_become_japan_administrative_trigger = yes
				}
			}
			current_description = go_japan_administrative_government_desc
			localization = go_japan_administrative_government_name
			icon = "gfx/interface/icons/government_types/japan_administrative_government.dds"
			ai_chance = {
				value = 100
			}
		}
	}

	effect = {
		# Change to your selected government
		if = {
			limit = {
				scope:go_administrative_government = yes
			}
			convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:administrative }
		}
		else_if = {
			limit = { scope:go_celestial_government = yes }
			convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:celestial }
		}
		else_if = {
			limit = { scope:go_meritocratic_government = yes }
			convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:meritocratic }
		}
		else_if = {
			limit = { scope:go_japan_administrative_government = yes }
			convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:japan_administrative }
		}
		save_scope_as = actor
		if = {
			limit = {
				is_independent_ruler = yes
			}
			add_legitimacy_effect = { LEGITIMACY = admin_convert_legitimacy_value } #One Time Legitimacy Boost
		}
		trigger_event = ep3_decisions_event.4060 #Also sends information event to human vassals
		#Letter event for the vassals
		hidden_effect = {
			if = {
				limit = {
					is_ai = no
				}
				add_achievement_global_variable_effect = {
					VARIABLE = achieved_epic_paperwork_achievement
					VALUE = yes
				}
			}
			if = {
				limit = {
					is_ai = no
					religion = religion:islam_religion
					has_title = title:k_rum
					OR = {
						has_title = title:c_byzantion
						any_sub_realm_title = {
							this = title:c_byzantion
						}
					}
				}
				add_achievement_global_variable_effect = {
					VARIABLE = finished_new_management_achievement
					VALUE = yes
				}
			}
		}
	}

	ai_potential = {
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
		}
		top_liege = this
	}

	ai_will_do = {
		base = 0
	#	modifier = {
	#		OR = {
	#			is_roman_emperor_primary_title_trigger = yes
	#		}
	#		add = 100
	#	}
		modifier = {
			culture = {
				OR = {
					has_cultural_pillar = ethos_bureaucratic 
					has_cultural_pillar = ethos_courtly 
					has_cultural_pillar = ethos_egalitarian 
				}
			}
			add = 50
		}
		modifier = {
			culture = {
				has_cultural_tradition = tradition_legalistic
			}
			add = 50
		}
		modifier = {
			culture = {
				OR = {
					has_cultural_tradition = tradition_fp3_enlightened_magnates 
					has_cultural_tradition = tradition_loyal_soldiers 
				}
			}
			add = 20
		}
		modifier = {
			culture = {
				OR = {
					has_cultural_tradition = tradition_staunch_traditionalists
					has_cultural_tradition = tradition_ep3_audacious_cadets
				}
			}
			add = -20
		}
		modifier = {
			culture = {
				has_cultural_tradition = tradition_hereditary_hierarchy
			}
			add = -20
		}
		modifier = {
			culture = {
				OR = {
					has_cultural_tradition = tradition_ep3_indomitable_azatani
					has_cultural_tradition = tradition_quarrelsome
					has_cultural_tradition = tradition_warrior_culture
					has_cultural_tradition = tradition_fp3_fierce_independence
				}
			}
			add = -50
		}
		modifier = {
			culture = {
				OR = {
					has_cultural_pillar = ethos_stoic
					has_cultural_pillar = ethos_bellicose 
					has_cultural_pillar = ethos_communal 
				}
			}
			add = -50
		}
	}
}

##################################################
# Convert Realm to Feudalism from Administrative #
##################################################

### Adopt [ROOT.Char.Custom('GetTribalReformGovernment')|U] Ways ###
convert_to_feudalism_from_administrative_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	desc = convert_to_feudalism_from_administrative_decision_desc

	is_shown = {
		trigger_if = {
			limit = { has_title = title:h_china }
			NOT = { government_has_flag = government_is_celestial }
		}
		government_allows = administrative
		tgp_is_ceremonial_liege_trigger = no
		tgp_is_ceremonial_regent_trigger = no
		tgp_is_any_minister = no
		# Ritsuryo gov has its own decisions
		NOT = { government_has_flag = government_is_japan_administrative }
	}

	is_valid = {
		is_landed = yes
		trigger_if = {
			limit = {
				is_independent_ruler = no
			}
			top_liege ?= {
				trigger_if = {
					limit = {
						has_realm_law_in_group = imperial_bureaucracy
					}
					has_realm_law = imperial_bureaucracy_0 
				}
				trigger_if = {
					limit = {
						has_realm_law_in_group = celestial_bureaucracy
					}
					has_realm_law = celestial_bureaucracy_0 
				}
				trigger_if = {
					limit = {
						has_realm_law_in_group = meritocratic_bureaucracy
					}
					has_realm_law = meritocratic_bureaucracy_0 
				}
				trigger_if = {
					limit = {
						has_realm_law_in_group = japanese_bureaucracy
					}
					has_realm_law = japanese_bureaucracy_0 
				}
			}
			custom_tooltip = {
				text = governorship_is_on_the_border_tt
				any_sub_realm_county = {
					any_neighboring_county = {
						holder.top_liege != root.top_liege
					}
				}
			}
			custom_tooltip = {
				text = you_have_governorship_rights_tt
				primary_title.var:petition_house_rights ?= house
			}
			prestige_level >= 3
			influence_level >= 3
		}
		trigger_else = {
			prestige_level >= { # Depends on tier
				value = 2
				if = {
					limit = {
						primary_title.tier >= tier_empire
					}
					add = 1
				}
			}
		}
	}

	cost = {
		prestige = 1000
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 1000 #Them pens be expensive
				#Realm size
				if = {
					limit = { root.realm_size >= 300 }
					multiply = 3.5
				}
				else_if = {
					limit = { root.realm_size >= 250 }
					multiply = 3
				}
				else_if = {
					limit = { root.realm_size >= 200 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.realm_size >= 150 }
					multiply = 2
				}
				else_if = {
					limit = { root.realm_size >= 100 }
					multiply = 1.5
				}
				#Era
				culture = {
					if = {
						limit = { has_cultural_era_or_later = culture_era_late_medieval }
						multiply = 1.75
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_high_medieval }
						multiply = 1.25
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_early_medieval }
						multiply = 1
					}
					else = {
						multiply = 0.75
					}
				}
				#Income
				if = {
					limit = { root.monthly_character_income >= 100 }
					multiply = 3
				}
				else_if = {
					limit = { root.monthly_character_income >= 80 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 60 }
					multiply = 2
				}
				else_if = {
					limit = { root.monthly_character_income >= 40 }
					multiply = 1.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 20 }
					multiply = 1.1
				}
				
				# Vassals has a slightly reduced cost
				if = {
					limit = {
						is_independent_ruler = no
					}
					multiply = 0.7
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 1000  #Them pens be expensive
				#Realm size
				if = {
					limit = { root.realm_size >= 300 }
					multiply = 3.5
				}
				else_if = {
					limit = { root.realm_size >= 250 }
					multiply = 3
				}
				else_if = {
					limit = { root.realm_size >= 200 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.realm_size >= 150 }
					multiply = 2
				}
				else_if = {
					limit = { root.realm_size >= 100 }
					multiply = 1.5
				}
				#Era
				culture = {
					if = {
						limit = { has_cultural_era_or_later = culture_era_late_medieval }
						multiply = 1.75
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_high_medieval }
						multiply = 1.25
					}
					else_if = {
						limit = { has_cultural_era_or_later = culture_era_early_medieval }
						multiply = 1
					}
					else = {
						multiply = 0.75
					}
				}
				#Income
				if = {
					limit = { root.monthly_character_income >= 100 }
					multiply = 3
				}
				else_if = {
					limit = { root.monthly_character_income >= 80 }
					multiply = 2.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 60 }
					multiply = 2
				}
				else_if = {
					limit = { root.monthly_character_income >= 40 }
					multiply = 1.5
				}
				else_if = {
					limit = { root.monthly_character_income >= 20 }
					multiply = 1.1
				}
				
				# Vassals has a slightly reduced cost
				if = {
					limit = {
						is_independent_ruler = no
					}
					multiply = 0.7
				}
			}
		}
	}

	effect = {
		convert_to_feudalism_from_administrative_effect = yes
		save_scope_as = actor
		trigger_event = ep3_decisions_event.4070
		hidden_effect = {
			every_vassal = {
				trigger_event = {
					id = ep3_decisions_event.4075
					days = 3
				}
			}
		}
	}

	ai_check_interval = 0

	ai_potential = {
		always = no
	}
}

#############################################
# Renounce Governorship						#
#############################################

### Withdraw from Governorship ###
### Withdraw from Ministry ###
renounce_governorship_decision = {
	picture = {
		trigger = {
			government_allows = merit
		}
		reference = "gfx/interface/illustrations/decisions/tgp_retire.dds"
	}
	picture = {
		trigger = {
			government_is_japanese_trigger = yes
		}
		reference = "gfx/interface/illustrations/decisions/tgp_house_fief.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	sort_order = 85
	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 0
	}
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					tgp_is_any_minister = yes
				}
				desc = renounce_ministership_decision
			}
			desc = renounce_governorship_decision
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {	
				trigger = {
					government_allows = merit
				}
				desc = renounce_governorship_decision_desc_merit
			}
			triggered_desc = {	
				trigger = {
					government_is_japanese_trigger = yes
				}
				desc = renounce_governorship_decision_desc_japan
			}
			desc = renounce_governorship_decision_desc
		}
	}
	selection_tooltip = {
		first_valid = {
			triggered_desc = {
				trigger = {
					tgp_is_any_minister = yes
				}
				desc = renounce_ministership_decision_tooltip
			}
			desc = renounce_governorship_decision_tooltip
		}
	}
	decision_group_type = admin

	is_shown = {
		is_playable_character = yes
		OR = {
			is_governor_or_admin_count = yes
			tgp_is_any_minister = yes
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war_with_liege = no
		custom_tooltip = {
			text = renounce_governorship_family_title_tt
			any_held_title = { # To avoid accidentally game-overing yourself
				is_noble_family_title = yes
			}
		}
	}

	effect = {
		if = {
			limit = {
				tgp_is_any_minister = yes
			}
			custom_tooltip = renounce_ministership_decision_effect_tt
		}
		else = {
			custom_tooltip = renounce_governorship_decision_effect_tt
		}
		show_as_tooltip = {
			tgp_step_down_title_recipient_tooltip_effect = yes
			if = {
				limit = {
					government_allows = merit 
				}
				add_character_modifier = {
					modifier = ep3_renounced_governorship_merit
					years = 15
				}
				set_appointment_timeout = {
					years = 3
					desc = appointment_timeout_desc_retired_governor
				}
			}
			else_if = {
				limit = {
					government_is_japanese_trigger = yes
				}
				add_gold = major_gold_value
				change_influence = major_influence_value
				add_character_modifier = {
					modifier = renounced_governorship_japan
					years = 15
				}
			}
			else = { 
				add_gold = massive_gold_value
				add_character_modifier = {
					modifier = ep3_renounced_governorship
					years = 15
				}
			}
			if = {
				limit = {
					tgp_is_any_minister = yes
				}
				liege = { save_scope_as = councillor_liege } # Needed for the effect
				fired_minister_position_effect = yes
			}
		}
		trigger_event = ep3_decisions_event.4090
		close_view = {
			view = decisions
			player = root
		}
	}
	
	cost = {
		influence = minor_influence_value
	}

	ai_potential = {
		is_at_war = no
		highest_held_title_tier >= main_administrative_tier
		# Don't step down freely if you don't have any other house members holding a governorship or inherit any held governorship
		OR = {
			house ?= {
				any_house_member = {
					is_governor = yes
					top_liege = root.top_liege
				}
			}
			any_held_title = {
				title_tier >= duchy
				is_noble_family_title = no
				current_heir.house = root.house
			}
		}
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 5
			has_trait = lazy
			NOT = {
				any_character_situation = {
					situation_type = dynastic_cycle
				}
			}
		}
		modifier = {
			add = 10
			has_trait = humble
			NOT = {
				any_character_situation = {
					situation_type = dynastic_cycle
				}
			}
		}
		modifier = {
			add = 15
			has_trait = content
			NOT = {
				any_character_situation = {
					situation_type = dynastic_cycle
				}
			}
		}
		modifier = {
			add = 50
			OR = {
				debt_level > 1
				treasury_debt_level > 1
			}
		}
		modifier = {
			add = 5
			OR = {
				has_trait = ambitious
				has_trait = greedy
				has_trait = arrogant
			}
			any_character_situation = {
				situation_type = dynastic_cycle
			}
		}
		modifier = {
			factor = 0
			OR = {
				has_trait = ambitious
				has_trait = greedy
				has_trait = arrogant
			}
			NOT = {
				any_character_situation = {
					situation_type = dynastic_cycle
				}
			}
		}
		modifier = {
			factor = 0 #In China you should step down only if you can pass more exams
			has_character_flag = passed_metropolitan_exam
		}
	}
}

#############################################
# Change Imperial Aspirations				#
#############################################
### Change [GetPlayer.GetTopLiege.Custom('GetRoyalCourtRank')|U] Aspirations ###
change_imperial_aspirations_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
	}
	sort_order = 80
	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	desc = change_imperial_aspirations_decision_desc
	selection_tooltip = change_imperial_aspirations_decision_tooltip
	decision_group_type = admin

	is_shown = {
		has_ep3_dlc_trigger = yes
		is_playable_character = yes
		government_has_flag = government_is_administrative
		liege ?= {
			has_realm_law = acclamation_succession_law
		}
	}

	is_valid = {
		custom_tooltip = {
			text = has_admin_government
			government_has_flag = government_is_administrative
		}
		trigger_if = { # Unavailable if you are the top liege - Unless you have either modifier, so you may remove it.
			limit = {
				top_liege = this
			}
			OR = {
				has_character_modifier = ep3_admin_renounce_throne_personal
				house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
			}
		}
		trigger_else = {
			custom_tooltip = { # The Emperor is your liege
				text = admin_confirmation_liege_tt
				top_liege ?= { highest_held_title_tier >= tier_kingdom }
				liege ?= top_liege
				liege != root
			}
		}
		liege ?= {
			has_realm_law = acclamation_succession_law
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war_with_liege = no
		NOT = { top_liege ?= root }
	}
	
	widget = {
		gui = "decision_view_widget_generic_multichoice_with_effects"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		#show_from_start = yes

		### Remove yourself from competing for the throne
		item = {
			value = admin_renounce_throne_personal
			is_valid = {
				NOR = {
					has_character_modifier = ep3_admin_renounce_throne_personal
					house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
				}
				NOT = { top_liege ?= root }
				is_diarch = no
			}
			current_description = admin_renounce_throne_personal_desc
			localization = admin_renounce_throne_personal_name
			icon = "gfx/interface/icons/character_interactions/icon_liege.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						has_trait = content
					}
					add = 100
				}
			}
		}
		### Make yourself available to compete for the throne
		item = {
			value = admin_desire_throne_personal
			is_valid = {
				has_character_modifier = ep3_admin_renounce_throne_personal
			}
			current_description = admin_desire_throne_personal_desc
			localization = admin_desire_throne_personal_name
			icon = "gfx/interface/icons/character_interactions/icon_liege.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						has_character_modifier = ep3_admin_renounce_throne_personal
						NOT = { has_trait = content }
					}
					add = 100
				}
			}
		}
		### Remove your house from competing for the throne
		item = {
			value = admin_renounce_throne_house
			is_valid = {
				house ?= {
					custom_tooltip = {
						text = HOF_INTERACTION_IS_HOUSE_HEAD
						house_head ?= root
					}
					NOT = { has_house_modifier = ep3_admin_renounce_throne_house }
				}
				NOT = { top_liege.house ?= root.house }
			}
			current_description = admin_renounce_throne_house_desc
			localization = admin_renounce_throne_house_name
			icon = "gfx/interface/icons/character_interactions/icon_dynasty.dds"
			ai_chance = {
				value = 0
			}
		}
		### Make your house available to compete for the throne
		item = {
			value = admin_desire_throne_house
			is_valid = {
				house ?= {
					custom_tooltip = {
						text = HOF_INTERACTION_IS_HOUSE_HEAD
						house_head ?= root
					}
					has_house_modifier = ep3_admin_renounce_throne_house
				}
			}
			current_description = admin_desire_throne_house_desc
			localization = admin_desire_throne_house_name
			icon = "gfx/interface/icons/character_interactions/icon_dynasty.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
					}
					add = 100
				}
			}
		}
	}

	effect = {
		if = {
			limit = {
				scope:admin_renounce_throne_personal = yes
			}
			add_character_modifier = {
				modifier = ep3_admin_renounce_throne_personal
			}
		}
		else_if = {
			limit = {
				scope:admin_desire_throne_personal = yes
			}
			remove_character_modifier = ep3_admin_renounce_throne_personal
		}
		else_if = {
			limit = {
				scope:admin_renounce_throne_house = yes
			}
			house ?= {
				add_house_modifier = ep3_admin_renounce_throne_house
			}
		}
		else_if = {
			limit = {
				scope:admin_desire_throne_house = yes
			}
			house ?= {
				remove_house_modifier = ep3_admin_renounce_throne_house
			}
		}
	}

	ai_potential = {
		OR = {
			has_character_modifier = ep3_admin_renounce_throne_personal
			house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
			has_trait = content
		}
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = 80
			OR = {
				has_character_modifier = ep3_admin_renounce_throne_personal
				house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
			}
			NOT = { has_trait = content }
		}
	}
}
