﻿#INTERROGATE
#From the Ill-Advised event chain
action_can_interrogate = {
	priority = 500
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				any_courtier_or_guest = {
					is_target_in_variable_list = {
						name = valid_to_interrogate_var
						target = root
					}
				}
				# And Achmach is still around
				any_courtier_or_guest = {
					has_variable = achmach_loyalty
				}
			}
			every_courtier_or_guest = {
				limit = {
					is_target_in_variable_list = {
						name = valid_to_interrogate_var
						target = root
					}
				}
				root = {
					try_create_important_action = {
						important_action_type = action_can_interrogate
						actor = root
						recipient = prev
					}
				}
			}
		}
	}

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

#JOIN TRIBUTARY WAR
action_join_tributary_war = {
	priority = 400
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				any_tributary = {
					is_at_war = yes
					root = {
						is_character_interaction_valid = {
							recipient = prev
							interaction = join_war_interaction
						}
					}
					any_character_war = {
						NOR = {
							any_war_attacker = { this = root }
							any_war_defender = { this = root }
						}
						primary_defender = prev
						primary_attacker = {
							NOT = {
								is_vassal_or_below_of = root
							}
						}
					}
				}
			}
			every_tributary = {
				limit = {
					is_at_war = yes
					root = {
						is_character_interaction_valid = {
							recipient = prev
							interaction = join_war_interaction
						}
					}
					any_character_war = {
						NOR = {
							any_war_attacker = { this = root }
							any_war_defender = { this = root }
						}
						primary_defender = prev
						primary_attacker = {
							NOT = {
								is_vassal_or_below_of = root
							}
						}
					}
				}
				random_character_war = {
					limit = {
						primary_defender = prev
					}
					save_scope_as = tributary_war
					primary_attacker = { save_scope_as = tributary_war_attacker }
				}
				save_scope_as = tributary_to_help
				try_create_important_action = {
					important_action_type = action_join_tributary_war
					actor = root
					recipient = scope:tributary_to_help
				}
			}
		}
	}

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

#HIRE COURT ASTROLOGER
action_can_hire_court_astrologer = {
	priority = 250
	combine_into_one = yes
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_nomadic # Other governments don't care as much
				NOR = {
					employs_court_position = court_astrologer_court_position
					any_court_position_holder = {
						type = court_astrologer_court_position
					}
				}
				NOT = { has_global_variable = tutorial_current_situation_gradual_reveal_3 }
			}
			try_create_important_action = {
				important_action_type = action_can_hire_court_astrologer
				actor = root
			}
		}
	}

	effect = {
		open_appoint_court_position_window = court_astrologer_court_position
	}
}

### LOW FERTILITY ALERT
action_low_fertility = {
	type = alert
	icon = action_has_low_fertility
	check_create_action = {
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
				government_has_flag = government_is_nomadic
				is_migrating = no
				is_at_war = no
				current_domain_fertility < terrible_county_fertility_level
			}
			try_create_important_action = {
				important_action_type = action_low_fertility
				actor = root
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = migration_interaction
			actor = root
			recipient = root
		}
	}
}

action_demand_tributary = {
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = { can_have_tributaries_trigger = yes }
			every_land_neighboring_realm_with_tributaries_owner = {
				limit = {
					overlord != root
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = demand_tributary_interaction
							ai_accept = 20
						}
					}
				}
				save_scope_as = potential_tributary
				root = {
					try_create_important_action = {
						important_action_type = action_demand_tributary
						actor = root
						recipient = scope:potential_tributary
					}
				}
			}
		}
	}

	unimportant = {
		NOT = {
			scope:actor = {
				is_character_interaction_potentially_accepted = {
					recipient = scope:recipient
					interaction = demand_tributary_interaction
					ai_accept = 50
					# required_response = maybe
				}
			}
		}
	}

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

action_pacify_tributary = {
	combine_into_one = yes
	icon = action_pacify_tributary
	check_create_action = {
		if = {
			limit = { government_has_flag = government_is_nomadic }
			every_tributary = {
				limit = { 
					NOT = { government_has_flag = government_is_herder }
					NOT = { has_truce = root }
					subject_can_break_tributary = yes
					cease_tribute_payments_ai_chance > 10
				}
				save_scope_as = unreliable_tributary
				root = {
					try_create_important_action = {
						important_action_type = action_pacify_tributary
						actor = root
						recipient = scope:unreliable_tributary
					}
				}
			}
		}
	}

	effect = {
		if = {
			limit = {
				scope:recipient = {
					NOT = {
						is_obedient_to = scope:actor
					}
				}
			}
			open_interaction_window = {
				interaction = mpo_negotiate_obedience_interaction
				actor = scope:actor
				recipient = scope:recipient
			}
		}
		else = {
			open_interaction_window = {
				interaction = sway_interaction
				actor = scope:actor
				recipient = scope:recipient
			}
		}
	}
}

action_can_demand_herd = {
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			every_vassal = {
				limit = {
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = mpo_ask_for_herd_interaction
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_can_demand_herd
					actor = root
					recipient = this
				}
			}
		}
		
	}

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

action_upgrade_nomadic_holding_type = {
	combine_into_one = yes
	is_dangerous = yes
	
	check_create_action = {
		if = {
			limit = {
				NOT = { government_has_flag = government_is_nomadic }
				always = no #Unop: Splitted this decision in 2, 1 for nomadic > tribal & 1 for nomadic > feudal
			}
			every_held_title = {
				limit = {
					tier = tier_county
					title_province = {
						has_holding_type = nomad_holding
						barony = {
							is_leased_out = no
							has_wrong_holding_type = yes
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_upgrade_nomadic_holding_type
					actor = root
					landed_title = this
				}
			}
		}
	}

	effect = {
		scope:landed_title.title_province = {
			open_view_data = {
				view = holding_view
			}
		}
	}
}

action_upgrade_herder_holding_type = {
	combine_into_one = yes
	is_dangerous = yes
	
	check_create_action = {
		if = {
			limit = {
				NOT = { government_has_flag = government_is_nomadic }
				always = no #Unop: Splitted this decision in 2, 1 for herder > tribal & 1 for herder > feudal
			}
			every_held_title = {
				limit = {
					tier = tier_county
					title_province = {
						has_holding_type = herder_holding
						barony = {
							is_leased_out = no
							has_wrong_holding_type = yes
						}
					}
					holder = { NOT = { government_has_flag = government_is_nomadic } }
				}
				try_create_important_action = {
					important_action_type = action_upgrade_herder_holding_type
					actor = root
					landed_title = this
				}
			}
		}
	}

	effect = {
		scope:landed_title.title_province = {
			open_view_data = {
				view = holding_view
			}
		}
	}
}

### CHAOTIC SUCCESSION ALERT
action_chaotic_succession = {
	priority = 100
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
				government_has_flag = government_is_nomadic
				has_chaotic_succession_trigger = yes
			}
			try_create_important_action = {
				important_action_type = action_chaotic_succession
				actor = root
			}
		}
	}

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

### Losing Tributaries Alert
action_losing_tributaries = {
	priority = 100
	is_dangerous = yes
	check_create_action = {
		if = {
			limit = {
				is_landed = no
				is_migrating = no
				is_at_war = no
				number_of_tributaries > 0
				government_has_flag = government_is_nomadic
			}
			try_create_important_action = {
				important_action_type = action_losing_tributaries
				actor = root
			}
		}
	}

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

# You can switch from Vassal to Tributary
action_switch_to_tributary = {
	type = alert
	icon = action_migration
	check_create_action = {
		if = {
			limit = {
				is_ai = no
				has_mpo_dlc_trigger = yes
				government_has_flag = government_is_nomadic
				is_migrating = no
				is_at_war = no
				is_independent_ruler = no # Therefore a Vassal
				exists = liege
			}
			try_create_important_action = {
				important_action_type = action_switch_to_tributary
				actor = root
				recipient = liege
			}
		}
	}

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

### YOU CAN UPGRADE YOUR DOMINANCE ALERT
action_upgrade_dominance = {
	type = alert
	icon = action_upgrade_dominance
	check_create_action = {
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
				government_has_flag = government_is_nomadic
				OR = {
					NOT = { has_variable = nomadic_authority_cooldown }
					culture = { has_innovation = innovation_all_things }
				}
				OR = {
					AND = {
						has_realm_law = nomadic_authority_1
						domicile.herd >= nomadic_authority_level_2_requirement
						prestige >= increase_nomadic_authority_prestige_cost
					}
					AND = {
						has_realm_law = nomadic_authority_2
						domicile.herd >= nomadic_authority_level_3_requirement
						prestige >= increase_nomadic_authority_prestige_cost
					}
					AND = {
						has_realm_law = nomadic_authority_3
						domicile.herd >= nomadic_authority_level_4_requirement
						prestige >= increase_nomadic_authority_prestige_cost
					}
					AND = {
						has_realm_law = nomadic_authority_4
						domicile.herd >= nomadic_authority_level_5_requirement
						trigger_if = {
							limit = { exists = situation:the_great_steppe }
							root = situation:the_great_steppe.situation_top_herd
						}
						prestige >= {
							value = increase_nomadic_authority_prestige_cost
							multiply = 2
						}
					}
				}
			}
			try_create_important_action = {
				important_action_type = action_upgrade_dominance
				actor = root
			}
		}
	}

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

action_offer_submission_or_ruin = {
	priority = 900
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
				is_landed = yes
			}
			every_neighboring_top_liege_realm_owner = {
				limit = {
					is_landed = yes
					root = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = mpo_offer_submission_or_ruin
							required_response = maybe
						}
					}
				}
				try_create_important_action = {
					important_action_type = action_offer_submission_or_ruin
					actor = root
					recipient = this
				}
			}
		}
	}

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

action_offer_confederation = {
	priority = 900
	combine_into_one = yes
	check_create_action = {
		every_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				root = {
					is_character_interaction_potentially_accepted = {
						recipient = prev
						interaction = offer_confederation_interaction
					}
				}
			}
			add_to_list = potential_confeds
		}
		capital_county.empire ?= {
			every_de_jure_county = {
				limit = {
					holder = {
						root = {
							is_character_interaction_potentially_accepted = {
								recipient = prev
								interaction = offer_confederation_interaction
							}
						}
					}
				}
				holder = {
					add_to_list = potential_confeds
				}
			}
		}
		every_in_list = {
			list = potential_confeds
			try_create_important_action = {
				important_action_type = action_offer_confederation
				actor = root
				recipient = this
			}
		}
	}

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