﻿# Too many Metropolitan provinces
action_too_many_celestial_province_types = {
	type = alert
	icon = action_contract

	check_create_action = {
		if = {
			limit = {
				any_vassal = {
					count > celestial_province_metropolitan_max_value
					vassal_contract_has_flag = celestial_province_metropolitan
				}
			}

			try_create_important_action = {
				important_action_type = action_too_many_celestial_province_types
			}
		}
	}

	effect = {
		open_view = government_administration
	}
}

# Too many Protectorate provinces
action_too_many_celestial_province_types_2 = {
	type = alert
	icon = action_contract

	check_create_action = {
		if = {
			limit = {
				any_vassal = {
					count > celestial_province_protectorate_max_value
					vassal_contract_has_flag = celestial_province_protectorate
				}
			}

			try_create_important_action = {
				important_action_type = action_too_many_celestial_province_types_2
			}
		}
	}

	effect = {
		open_view = government_administration
	}
}

action_mandala_tributary_at_risk_of_breakaway = {
	combine_into_one = yes
	type = action
	icon = action_pacify_tributary

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				any_tributary = {
					is_ai = yes
					subject_can_break_tributary = yes
					cease_tribute_payments_ai_chance > 10
					NOR = { 
						has_variable = tributary_has_been_reasserted_recently
						has_opinion_modifier = {
							modifier = reassertion_request_denied_opinion
							target = root
						}
					}
					save_temporary_scope_as = target_tributary
				}
			}
			every_tributary = {
				limit = {
					is_ai = yes
					subject_can_break_tributary = yes
					cease_tribute_payments_ai_chance > 10
					NOR = { 
						has_variable = tributary_has_been_reasserted_recently
						has_opinion_modifier = {
							modifier = reassertion_request_denied_opinion
							target = root
						}
					}
				}
				save_scope_as = target_tributary
				try_create_important_action = {
					important_action_type = action_mandala_tributary_at_risk_of_breakaway
					actor = root
					recipient = scope:target_tributary
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = reassert_tributary_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_hegemonic_tributary_has_low_subject_standing_tributary = {
	type = action
	icon = action_tax_collector

	check_create_action = {
		if = {
			limit = {
				is_tributary = yes
				suzerain = { highest_held_title_tier = tier_hegemony }
				subject_standing < exact_tribute_subject_standing_value
			}
			try_create_important_action = {
				important_action_type = action_hegemonic_tributary_has_low_subject_standing_tributary
				actor = root
				recipient = suzerain
			}
		}
	}

	effect = {
		if = {
			limit = { suzerain.primary_title = title:h_china }
			decision:tribute_mission_decision_china = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_roman_empire }
			decision:tribute_mission_decision_roman_empire = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_eastern_roman_empire }
			decision:tribute_mission_decision_eastern_roman_empire = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_dar_al_islam }
			decision:tribute_mission_decision_dar_al_islam = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_india }
			decision:tribute_mission_decision_india = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_numenor }
			decision:tribute_mission_decision_numenor = { open_view_data = decision_detail }
		}
		else_if = {
			limit = { suzerain.primary_title = title:h_europa }
			decision:tribute_mission_decision_europa = { open_view_data = decision_detail }
		}
	}
}

action_hegemonic_tributary_has_low_subject_standing_suzerain = {
	type = action
	icon = action_tax_collector
	combine_into_one = yes

	check_create_action = {
		if = {
			limit = {
			highest_held_title_tier = tier_hegemony
				any_tributary = {
					subject_standing < exact_tribute_subject_standing_value
					save_temporary_scope_as = target_tributary
				}
			}
			try_create_important_action = {
				important_action_type = action_hegemonic_tributary_has_low_subject_standing_suzerain
				actor = root
				recipient = scope:target_tributary
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = exact_tribute_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_no_mandala_aspect = {
	type = alert
	icon = action_mandala_red

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				is_house_head = yes
				has_no_mandala_aspect_trigger = yes
			}
			try_create_important_action = {
				important_action_type = action_no_mandala_aspect
				actor = root
			}
		}
	}

	effect = {
		house = {
			open_view_data = {
				view = house_aspiration_window
				player = root
			}
		}
	}
}

action_can_upgrade_mandala_aspect = {
	type = alert
	icon = action_mandala_green

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				is_house_head = yes
				house = { can_change_house_aspiration = yes }
				has_mandala_aspect_level_5_trigger = no
				OR = {
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_creation_01 }
						can_afford_mandala_aspect_level_2_trigger = yes
						creation_second_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_creation_02 }
						can_afford_mandala_aspect_level_3_trigger = yes
						creation_third_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_creation_03 }
						can_afford_mandala_aspect_level_4_trigger = yes
						creation_fourth_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_creation_04 }
						can_afford_mandala_aspect_level_5_trigger = yes
						creation_fifth_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_serenity_01 }
						can_afford_mandala_aspect_level_2_trigger = yes
						serenity_second_tier_trigger = { MANDALA = root }
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_serenity_02 }
						can_afford_mandala_aspect_level_3_trigger = yes
						serenity_third_tier_trigger = { MANDALA = root }
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_serenity_03 }
						can_afford_mandala_aspect_level_4_trigger = yes
						serenity_fourth_tier_trigger = { MANDALA = root }
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_serenity_04 }
						can_afford_mandala_aspect_level_5_trigger = yes
						serenity_fifth_tier_trigger = { MANDALA = root }
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_destruction_01 }
						can_afford_mandala_aspect_level_2_trigger = yes
						destruction_second_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_destruction_02 }
						can_afford_mandala_aspect_level_3_trigger = yes
						destruction_third_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_destruction_03 }
						can_afford_mandala_aspect_level_4_trigger = yes
						destruction_fourth_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_destruction_04 }
						can_afford_mandala_aspect_level_5_trigger = yes
						destruction_fifth_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_trickery_01 }
						can_afford_mandala_aspect_level_2_trigger = yes
						trickery_second_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_trickery_02 }
						can_afford_mandala_aspect_level_3_trigger = yes
						trickery_third_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_trickery_03 }
						can_afford_mandala_aspect_level_4_trigger = yes
						trickery_fourth_tier_trigger = yes
					}
					AND = {
						house ?= { has_house_aspiration_parameter = aspect_of_trickery_04 }
						can_afford_mandala_aspect_level_5_trigger = yes
						trickery_fifth_tier_trigger = yes
					}
				}
			}
			try_create_important_action = {
				important_action_type = action_can_upgrade_mandala_aspect
				actor = root
			}
		}
	}

	effect = {
		house = {
			open_view_data = {
				view = house_aspiration_window
				player = root
			}
		}
	}
}

action_can_go_on_tribute_mission = {
	type = action
	icon = tributary

	check_create_action = {
		if = {
			limit = {
				is_tributary = yes
				overlord = { government_has_flag = government_is_mandala }
				can_execute_decision = tribute_mission_decision_mandala
			}
			try_create_important_action = {
				important_action_type = action_can_go_on_tribute_mission
				actor = root
				recipient = overlord
			}
		}
	}

	effect = {
		decision:tribute_mission_decision_mandala = { open_view_data = decision_detail }
	}
}

action_no_mandala_decree = {
	type = alert
	icon = action_mandala_red

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				is_house_head = yes
				has_mandala_aspect_trigger = yes
				NOT = { has_variable = has_picked_mandala_decree }
			}
			try_create_important_action = {
				important_action_type = action_no_mandala_decree
				actor = root
			}
		}
	}

	effect = {
		scope:actor = {
			open_view_data = {
				view = my_realm
				data = flag:bookmark_laws
			}
		}
	}
}

action_new_mandala_ritual = {
	priority = 330
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				any_character_task_contract = { count > 0 }
			}
			every_character_active_contract = {
				add_to_temporary_list = my_contracts
			}
			every_character_task_contract = {
				limit = {
					NOT = { is_in_list = my_contracts }
				}
				save_scope_as = task_contract
				try_create_important_action = {
					important_action_type = action_new_mandala_ritual
					actor = root
					recipient = scope:task_contract.task_contract_employer
				}
			}
		}
	}
	effect = {
		scope:task_contract = { open_view_data = task_contract }
	}
}

action_could_exact_tribute_from = {
	combine_into_one = yes
	type = action
	icon = action_pacify_tributary

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				save_temporary_scope_as = temp_root_scope
				OR = {
					any_tributary = {
						is_ai = yes
						#Ignore grace if you insist on reverence
						trigger_if = {
							limit = { 
								scope:temp_root_scope = {
									NOT = { has_realm_law = mandala_decree_reverence }
								}
							}
							#Has recently gone on a Tribute Mission (to you)
							custom_tooltip = {
								text = exact_tribute_interaction_recently_tribute_missioned_tt
								NOT = { var:tribute_mission_grace ?= scope:temp_root_scope }
							}
						}
						#Has something to offer as Tribute Mission
						trigger_if = {
							limit = {
								NOR = {
									var:declined_requested_tribute_recently ?= scope:temp_root_scope
									var:requested_tribute_mission ?= scope:temp_root_scope
								}
							}
							custom_tooltip = {
								text = exact_tribute_interaction_no_tribute_tt
								OR = {
									has_gold_tribute_trigger = yes
									has_herd_tribute_trigger = yes
									has_artifact_tribute_trigger = yes
									AND = {
										any_courtier_or_guest = {
											can_become_concubine_of_character_valid_trigger = { CHARACTER = scope:temp_root_scope }
										}
										scope:temp_root_scope = { allowed_more_concubines = yes }
									}
									AND = {
										has_eunuch_tribute_trigger = yes
										scope:temp_root_scope = { 
											culture = { has_cultural_parameter = can_appoint_chief_eunuch }
										}
									}
								}
							}
						}
						#Has recently refused
						custom_tooltip = {
							text = exact_tribute_interaction_recently_refused_tt
							NOT = { var:declined_requested_tribute_recently ?= scope:temp_root_scope }
						}
						#Is already engaged
						custom_tooltip = {
							text = exact_tribute_interaction_already_engaged_tt
							NOT = { var:requested_tribute_mission ?= scope:temp_root_scope }
						}
					}

				}
			}
			every_tributary = {
				limit = {
					is_ai = yes
					#Ignore grace if you insist on reverence
					trigger_if = {
						limit = { 
							scope:temp_root_scope = {
								NOT = { has_realm_law = mandala_decree_reverence }
							}
						}
						#Has recently gone on a Tribute Mission (to you)
						custom_tooltip = {
							text = exact_tribute_interaction_recently_tribute_missioned_tt
							NOT = { var:tribute_mission_grace ?= scope:temp_root_scope }
						}
					}
					#Has something to offer as Tribute Mission
					trigger_if = {
						limit = {
							NOR = {
								var:declined_requested_tribute_recently ?= scope:temp_root_scope
								var:requested_tribute_mission ?= scope:temp_root_scope
							}
						}
						custom_tooltip = {
							text = exact_tribute_interaction_no_tribute_tt
							OR = {
								has_gold_tribute_trigger = yes
								has_herd_tribute_trigger = yes
								has_artifact_tribute_trigger = yes
								AND = {
									any_courtier_or_guest = {
										can_become_concubine_of_character_valid_trigger = { CHARACTER = scope:temp_root_scope }
									}
									scope:temp_root_scope = { allowed_more_concubines = yes }
								}
								AND = {
									has_eunuch_tribute_trigger = yes
									scope:temp_root_scope = { 
										culture = { has_cultural_parameter = can_appoint_chief_eunuch }
									}
								}
							}
						}
					}
					#Has recently refused
					custom_tooltip = {
						text = exact_tribute_interaction_recently_refused_tt
						NOT = { var:declined_requested_tribute_recently ?= scope:temp_root_scope }
					}
					#Is already engaged
					custom_tooltip = {
						text = exact_tribute_interaction_already_engaged_tt
						NOT = { var:requested_tribute_mission ?= scope:temp_root_scope }
					}
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = exact_tribute_interaction
							ai_accept = 50
						}
					}
				}
				save_scope_as = exact_target
				try_create_important_action = {
					important_action_type = action_could_exact_tribute_from
					actor = root
					recipient = scope:exact_target
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = exact_tribute_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_can_call_tributary = {
	priority = 1000
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = { has_realm_law = mandala_decree_expansion }
			every_tributary = {
				save_temporary_scope_as = tributary
				if = {
					limit = {
						prev = {
							is_character_interaction_valid = {
								recipient = scope:tributary
								interaction = call_ally_interaction
							}
						}
					}
					try_create_important_action = {
						important_action_type = action_can_call_tributary
						actor = root
						recipient = scope:tributary
					}
				}
			}
		}
	}
	
	effect = {
		open_interaction_window = {
			interaction = call_ally_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_targeted_by_grand_campaign = {
	type = alert
	icon = action_being_raided
	soundeffect = "event:/SFX/UI/War/sfx_ui_war_declare_war"
	check_create_action = {
		if = {
			limit = {
				any_great_project = {
					save_temporary_scope_as = great_project
					great_project_type = grand_campaign_project
        			great_project_owner != root
        			any_in_list = {
            			variable = grand_campaign_titles
            			any_in_de_jure_hierarchy = {
            				holder ?= {
								OR = {
									any_liege_or_above = {
										this = root
            						}
            						this = root
            					}
            				}
            			}
					}
				}
				NOR = {
					any_character_war = {
						using_cb = grand_campaign_kingdom_invasion_cb
					}
					is_vassal_or_below_of = scope:great_project.great_project_owner
				}
			}
			scope:great_project = {
				if = {
					limit = {
						exists = var:grand_campaign_war
					}
	    			var:grand_campaign_war = {
	    				primary_defender = {
							save_scope_as = defender
	    				}
	    			}
					try_create_important_action = {
						important_action_type = action_targeted_by_grand_campaign
						actor = root
						great_project = scope:great_project
						recipient = scope:defender
						defender = scope:defender
					}
				}
				else = {
					root = {
						save_scope_as = defender # needed for localization to check if the war exists and show proper message
					}
					try_create_important_action = {
						important_action_type = action_targeted_by_grand_campaign
						actor = root
						great_project = scope:great_project
						defender = scope:defender
					}					
				}
			}
		}
	}

	effect = {
		# If there is a war already open offer to join war interaction
		if = {
			limit = {
				exists = scope:great_project.var:grand_campaign_war
			}
			open_interaction_window = {
				interaction = join_war_interaction
				actor = scope:actor
				recipient = scope:recipient
			}
		}
		# Otherwise open the great project window
		else = {
			scope:great_project = {
				open_view_data = {
					view = great_project
					player = scope:actor
				}
			}
		}
	}
}

action_can_upgrade_house_aspiration = {
	type = alert
	icon = action_upgrade_aspiration

	check_create_action = {
		if = {
			limit = {
				is_house_head = yes
				government_is_japanese_trigger = yes
				house = {
					can_change_house_aspiration = yes
					NOT = { has_house_aspiration_parameter = aspiration_level_3 }
					trigger_if = {
						limit = { has_house_aspiration_parameter = aspiration_level_1 }
						root.prestige >= house_aspiration_level_2_cost_value
					}
					trigger_else_if = {
						limit = { has_house_aspiration_parameter = aspiration_level_2 }
						root.prestige >= house_aspiration_level_3_cost_value
					}
					trigger_else = { always = no }
				}
			}
			try_create_important_action = {
				important_action_type = action_can_upgrade_house_aspiration
				actor = root
			}
		}
	}

	effect = {
		house = {
			open_view_data = {
				view = house_aspiration_window
				player = root
			}
		}
	}
}

action_no_house_aspiration = {
	type = alert
	icon = action_no_aspiration

	check_create_action = {
		if = {
			limit = {
				is_house_head = yes
				is_culture_or_descended_from_trigger = { CULTURE = culture:japanese }
				house = {
					can_change_house_aspiration = yes
					has_house_aspiration_trigger = no
				}
			}
			try_create_important_action = {
				important_action_type = action_no_house_aspiration
				actor = root
			}
		}
	}

	effect = {
		house = {
			open_view_data = {
				view = house_aspiration_window
				player = root
			}
		}
	}
}

action_aspiration_does_not_match_house_bloc = {
	priority = 260
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				is_house_head = yes
				house.house_confederation.leading_house ?= {
					this != root.house
					NOT = { has_same_house_aspiration_as = root.house }
				}
			}
			try_create_important_action = {
				important_action_type = action_aspiration_does_not_match_house_bloc
				house = house
				leading_house = house.house_confederation.leading_house
			}
		}
	}

	unimportant = {
		prestige < house_aspiration_level_1_cost_value
	}

	effect = {
		house = {
			open_view_data = {
				view = house_aspiration_window
				player = root
			}
		}
	}
}

action_missing_elder = {
	type = action

	check_create_action = {
		if = {
			limit = {
				is_independent_ruler = no
				num_of_relation_elder = 0
				trigger_if = {
					limit = {
						exists = top_participant_group:dynastic_cycle
					}
					top_participant_group:dynastic_cycle ?= {
						any_situation_group_participant = {
							root = {
								is_character_interaction_potentially_accepted = {
								 	recipient = prev
								 	interaction = find_elder_interaction
								 	secondary_recipient = prev
								}
							}
						}
					}
				}
				trigger_else = {
					any_liege_or_above = {
						root = {
							is_character_interaction_potentially_accepted = {
							 	recipient = prev
							 	interaction = find_elder_interaction
							 	secondary_recipient = prev
							}
						}
					}
				}
			}
			if = {
				limit = {
					exists = top_participant_group:dynastic_cycle
				}
				top_participant_group:dynastic_cycle = {
					ordered_situation_group_participant = {
						order_by = merit
						limit = {
							root = {
								is_character_interaction_potentially_accepted = {
								 	recipient = prev
								 	interaction = find_elder_interaction
								 	secondary_recipient = prev
								}
							}
						}
						save_scope_as = potential_elder
					}
				}
			}
			else = {
				ordered_liege_or_above = {
					limit = {
						root = {
							is_character_interaction_potentially_accepted = {
							 	recipient = prev
							 	interaction = find_elder_interaction
							 	secondary_recipient = prev
							}
						}
					}
					save_scope_as = potential_elder
				}
			}
			try_create_important_action = {
				important_action_type = action_missing_elder
				actor = root
				recipient = scope:potential_elder
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = find_elder_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_can_make_elder_request = {
	priority = 350
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				OR = {
					any_relation = {
						type = elder
						type = disciple
					}
					top_participant_group:dynastic_cycle ?= {
						exists = var:movement_leader
					}
				}
			}
			every_relation = {
				type = elder
				type = disciple
				add_to_list = characters
			}
			top_participant_group:dynastic_cycle ?= {
				var:movement_leader ?= {
					add_to_list = characters
				}
			}
			every_in_list = {
				list = characters
				if = {
					limit = {
						root = {
							is_character_interaction_potentially_accepted = {
								recipient = prev
								interaction = celestial_request_elders_support_interaction
							}
						}
					}
					try_create_important_action = {
						important_action_type = action_can_make_elder_request
						actor = root
						recipient = this
					}
				}
			}
		}
	}
	effect = {
		open_interaction_window = {
			interaction = celestial_request_elders_support_interaction 
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_would_accept_mandala_embrace = {
	combine_into_one = yes
	type = action
	icon = action_pacify_tributary

	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				save_temporary_scope_as = temp_root_scope
				OR = {
					any_neighboring_and_across_water_top_liege_realm_owner = {
						NOR = {
							has_opinion_modifier = {
								modifier = tributary_request_denied_opinion
								target = scope:temp_root_scope
							}
						}
						trigger_if = {
							limit = { government_has_flag = government_is_celestial }
							highest_held_title_tier <= tier_duchy
						}
						trigger_else = { highest_held_title_tier < tier_hegemony }
					}
					any_neighboring_and_across_water_top_liege_realm_owner = {
						any_tributary = {
							NOR = {
								has_opinion_modifier = {
									modifier = tributary_request_denied_opinion
									target = scope:temp_root_scope
								}
							}
							trigger_if = {
								limit = { government_has_flag = government_is_celestial }
								highest_held_title_tier <= tier_duchy
							}
							trigger_else = { highest_held_title_tier < tier_hegemony }
							scope:temp_root_scope = {
								is_character_interaction_potentially_accepted = {
									recipient = prev
									interaction = offer_tributary_status_interaction
									ai_accept = 50
								}
							}
						}
					}
				}
			}
			every_neighboring_and_across_water_top_liege_realm_owner = {
				limit = {
					NOR = {
						has_opinion_modifier = {
							modifier = tributary_request_denied_opinion
							target = scope:temp_root_scope
						}
					}
					trigger_if = {
						limit = { government_has_flag = government_is_celestial }
						highest_held_title_tier <= tier_duchy
					}
					trigger_else = { highest_held_title_tier < tier_hegemony }
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = offer_tributary_status_interaction
							ai_accept = 50
						}
					}
				}
				save_scope_as = target_embrace
				try_create_important_action = {
					important_action_type = action_would_accept_mandala_embrace
					actor = root
					recipient = scope:target_embrace
				}
			}
			every_neighboring_and_across_water_top_liege_realm_owner = {
				every_tributary = {
					limit = {
						NOR = {
							has_opinion_modifier = {
								modifier = tributary_request_denied_opinion
								target = scope:temp_root_scope
							}
						}
						trigger_if = {
							limit = { government_has_flag = government_is_celestial }
							highest_held_title_tier <= tier_duchy
						}
						trigger_else = { highest_held_title_tier < tier_hegemony }
						root = {
							is_character_interaction_potentially_accepted = {
								recipient = prev
								interaction = offer_tributary_status_interaction
								ai_accept = 50
							}
						}
					}
					save_scope_as = target_embrace
					try_create_important_action = {
						important_action_type = action_would_accept_mandala_embrace
						actor = root
						recipient = scope:target_embrace
					}
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = offer_tributary_status_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

# Can request treasury from minister
action_can_request_treasury = {
	combine_into_one = yes
	check_create_action = {
		title:e_minister_of_revenue.holder ?= {
			if = {
				limit = {
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = celestial_request_treasury_interaction
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_can_request_treasury
					actor = root
					recipient = this
				}
			}
		}
		title:e_minister_of_war.holder ?= {
			if = {
				limit = {
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = celestial_request_treasury_interaction
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_can_request_treasury
					actor = root
					recipient = this
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = celestial_request_treasury_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

# Can request examination support from minister
action_can_request_examination_support = {
	combine_into_one = yes
	check_create_action = {
		title:e_minister_of_rites.holder ?= {
			if = {
				limit = {
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = celestial_request_examination_support_interaction
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_can_request_examination_support
					actor = root
					recipient = this
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = celestial_request_examination_support_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

# Can start a Great Project
action_start_great_project = { # Only non-important ones, Important GPs get their own alert
	type = action
	check_create_action = {
		if = {
			limit = {
				root = {
					OR = {
						can_plan_great_project = great_project_type:minister_project_culture
						can_plan_great_project = great_project_type:minister_project_development
						can_plan_great_project = great_project_type:minister_project_establish_control
						can_plan_great_project = great_project_type:construct_great_barracks
						can_plan_great_project = great_project_type:strengthen_capital
						can_plan_great_project = great_project_type:great_wall
						can_plan_great_project = great_project_type:great_wall_extend_to_shanhai_pass
						can_plan_great_project = great_project_type:great_wall_extend_to_liaodong
						can_plan_great_project = great_project_type:grand_canals
					}
				}
			}
			try_create_important_action = {
				important_action_type = action_start_great_project
				actor = root
				recipient = this
			}
		}
	}
	
	effect = {
		open_view_data = decisions
	}
}
						
action_can_send_to_childrens_examination = {
	priority = 300
	combine_into_one = yes
	
	check_create_action = {
		# only for close family members for now, might get too much for big families

		every_close_family_member = {
			limit = {
				root = {
					is_character_interaction_valid = {
						recipient = prev
						interaction = send_child_to_examination_interaction
					}
				}
			}
			try_create_important_action = {
				important_action_type = action_can_send_to_childrens_examination
				actor = root
				recipient = this
				secondary_recipient = this
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = send_child_to_examination_interaction
			actor = scope:actor
			recipient = scope:recipient
			secondary_recipient = scope:secondary_recipient
		}
	}
}

# you are jobless and chilled out, why don't you ruin that by studying?!
action_opportunity_to_study_classics = {
	type = action

	check_create_action = {
		if = {
			limit = {
				can_execute_decision = tgp_china_study_confucian_classics_decision
				is_governor = no
				stress_level < 1
			}
			try_create_important_action = {
				important_action_type = action_opportunity_to_study_classics
				actor = root
			}
		}
	}

	effect = {
		decision:tgp_china_study_confucian_classics_decision = { open_view_data = decision_detail }
	}
}


action_unaligned_join_movement = {
	type = action

	check_create_action = {
		if = {
			limit = {
				can_execute_decision = situation_dynastic_cycle_choose_movement_decision
				top_participant_group:dynastic_cycle ?= {
					participant_group_type = undecided_movement
				}
			}
			try_create_important_action = {
				important_action_type = action_unaligned_join_movement
				actor = root
			}
		}
	}

	effect = {
		decision:situation_dynastic_cycle_choose_movement_decision = { open_view_data = decision_detail }
	}
}

action_landless_admin_escape_to_realm = {
	type = alert
	icon = action_contract
	check_create_action = {
		if = {
			limit = {
				government_allows = administrative
				any_held_title = {
					count = all
					is_noble_family_title = yes
				}
				liege = {
					NOT = {
						has_same_government = root
					}
				}
				any_neighboring_and_across_water_top_liege_realm_owner = {
					has_same_government = root
					save_temporary_scope_as = same_gov_ruler
				}
			}
			try_create_important_action = {
				important_action_type = action_landless_admin_escape_to_realm
				actor = root
				recipient = scope:same_gov_ruler
			}
		}
	}
	effect = {
		open_interaction_window = {
			interaction = landless_admin_switch_non_admin_top_liege_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_minister_can_imprison = {
	priority = 350
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				has_title = title:e_minister_of_justice
				top_liege = {
					any_vassal_or_below = {
						liege = {
							has_imprisonment_reason = prev
						}
					}
				}
			}
			top_liege = {
				every_vassal_or_below = {
					limit = {
						liege = {
							has_imprisonment_reason = prev
						}
					}
					try_create_important_action = {
						important_action_type = action_minister_can_imprison
						actor = root
						recipient = this
					}
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = imprison_interaction 
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_minister_can_pardon = {
	priority = 350
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				has_title = title:e_minister_of_justice
				top_liege = {
					any_vassal_or_below = {
						liege = {
							has_imprisonment_reason = prev
						}
					}
				}
			}
			top_liege = {
				every_vassal_or_below = {
					limit = {
						liege = {
							has_imprisonment_reason = prev
						}
					}
					try_create_important_action = {
						important_action_type = action_minister_can_pardon
						actor = root
						recipient = this
					}
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = pardon_interaction 
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_can_be_pardoned_by_minister = {
	check_create_action = {
		title:e_minister_of_justice.holder ?= {
			if = {
				limit = {
					root = {
						is_character_interaction_valid = {
							recipient = prev
							interaction = ask_for_pardon_interaction
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_can_be_pardoned_by_minister
					actor = root
					recipient = this
				}
			}
		}
	}
	unimportant = {
		NOT = {
			is_character_interaction_potentially_accepted = {
				recipient = scope:recipient
				interaction = ask_for_pardon_interaction
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = ask_for_pardon_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_pay_governors_treasury_debt = {
	priority = 350
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				has_treasury = yes
				OR = {
					has_title = title:e_minister_of_revenue
					has_title = title:e_minister_of_war
				}
				top_liege = {
					any_vassal_or_below = {
						has_treasury = yes
						treasury < 0
						trigger_if = {
							limit = {
								title:e_minister_of_revenue.holder ?= root
							}
							NOT = { vassal_contract_has_flag = celestial_military_appointment }
						}
						trigger_else = {
							vassal_contract_has_flag = celestial_military_appointment
						}
						save_temporary_scope_as = governor
					}
				}
				treasury >= {
					value = scope:governor.treasury
					multiply = -1
				}
			}
			top_liege = {
				every_vassal_or_below = {
					limit = {
						has_treasury = yes
						treasury < 0
						trigger_if = {
							limit = {
								title:e_minister_of_revenue.holder ?= root
							}
							NOT = { vassal_contract_has_flag = celestial_military_appointment }
						}
						trigger_else = {
							vassal_contract_has_flag = celestial_military_appointment
						}
					}
					try_create_important_action = {
						important_action_type = action_pay_governors_treasury_debt
						actor = root
						recipient = this
					}
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = pay_treasury_debt_interaction 
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_minister_can_pay_treasury_debt = {
	priority = 350
	check_create_action = {
		if = {
			limit = {
				has_treasury = yes
				treasury < 0
				NOT = { vassal_contract_has_flag = celestial_military_appointment }
				title:e_minister_of_revenue.holder ?= {
					top_liege = root.top_liege
					has_treasury = yes
					treasury >= {
						value = root.treasury
						multiply = -1
					}
					save_temporary_scope_as = minister
				}
			}
			try_create_important_action = {
				important_action_type = action_minister_can_pay_treasury_debt
				actor = root
				recipient = scope:minister
			}
		}
		else_if = {
			limit = {
				has_treasury = yes
				treasury < 0
				vassal_contract_has_flag = celestial_military_appointment
				title:e_minister_of_war.holder ?= {
					top_liege = root.top_liege
					has_treasury = yes
					treasury >= {
						value = root.treasury
						multiply = -1
					}
					save_temporary_scope_as = minister
				}
			}
			try_create_important_action = {
				important_action_type = action_minister_can_pay_treasury_debt
				actor = root
				recipient = scope:minister
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = celestial_request_treasury_interaction 
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}

action_can_find_secrets = {
	priority = 350
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				OR = {
					AND = {
						has_title = title:e_minister_censor
						has_council_position = councillor_spymaster
					}
					AND = {
						has_title = title:e_minister_of_justice
						has_council_position = minister_justice
					}
				}
				top_liege = {
					tgp_has_access_to_ministry_trigger = yes
				}
			}
			liege ?= {
				every_vassal = {
					add_to_list = characters
				}
			}
			ordered_in_list = {
				list = characters
				max = 10
				order_by = tier
				if = {
					limit = {
						root = {
							is_character_interaction_potentially_accepted = {
								recipient = prev
								interaction = censor_find_secrets_interaction
							}
							can_start_scheme = {
								type = celestial_minister_find_secrets_scheme
								target_character = prev
							}
							NOT = {
								is_scheming_against = {
									type = celestial_minister_find_secrets_scheme
									target = prev
								}
							}
						}
					}
					try_create_important_action = {
						important_action_type = action_can_find_secrets
						actor = root
						recipient = this
					}
				}
			}
		}
	}
	effect = {
		open_interaction_window = {
			interaction = censor_find_secrets_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}
