﻿
declare_war_interaction = {
	category = interaction_category_diplomacy
	common_interaction = yes
	special_interaction = declare_war_interaction
	interface = declare_war
	interface_priority = 70
	popup_on_receive = yes
	pause_on_receive = no # this is handled by the interface instead

	desc = declare_war_desc

	is_shown = {
		NOT = {
			scope:recipient = scope:actor
		}
		scope:recipient = {
			is_playable_character = yes
		}
		scope:actor = {
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { has_trait = incapable }
			can_attack_in_hierarchy = scope:recipient
			NOT = {
				has_raised_armies = yes
			}
			has_any_display_cb_on = scope:recipient
			NOT = {
				is_allied_in_war = scope:recipient
			}
			custom_description = {
				text = "is_not_bankrupt"
				gold > 0
			}
			NOT = {
				custom_description = {
					text = "is_in_an_activity"
					exists = involved_activity
				}
			}
			trigger_if = {
				limit = {
					culture = { has_cultural_parameter = cannot_attack_allies }
				}
				NOT = {
					is_allied_to = scope:recipient
				}
			}
			trigger_if = {
				limit = {
					culture = { has_cultural_parameter = cannot_attack_truces }
				}
				NOT = {
					has_truce = scope:recipient
				}
			}
			is_imprisoned = no
			trigger_if = {
				limit = {
					has_variable_list = subjugation_offer_under_consideration
				}
				custom_description = {
					text = is_not_considering_offer_of_subjugation
					NOT = {
						is_target_in_variable_list = {
							name = subjugation_offer_under_consideration
							target = scope:recipient
						}
					}
				}
			}
		}
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:recipient = {
			trigger_if = {
				limit = { is_imprisoned = yes }
				NOT = {
					imprisoner = scope:actor
				}
			}
		}
		scope:actor = {
			trigger_if = {
				limit = { has_game_rule = admin_frontier_war_always_no_full }
				custom_tooltip = {
					text = admin_all_vassal_wars_banned_4
					always = no
				}
			}
			trigger_else_if = {
				limit = {
					NOT = { has_game_rule = admin_frontier_war_vanilla }
					liege ?= {
						OR = {
							has_realm_law = imperial_bureaucracy_1
							has_realm_law = imperial_bureaucracy_2
							has_realm_law = imperial_bureaucracy_3
							
							has_realm_law_flag = vassal_all_wars_banned_permanent
						}
						NOT = { this = scope:actor }
						#NOT = { vassal_contract_has_flag = admin_theme_frontier }
					}
				}
				custom_tooltip = {
					text = admin_all_vassal_wars_banned_2
					#always = no
					trigger_if ={
						limit = {
							has_game_rule = admin_frontier_war_direct_only
						}
						is_vassal_of = top_liege
						OR = {
							vassal_contract_has_flag = admin_theme_frontier
							vassal_contract_has_flag = admin_theme_naval
						}
					}
				}
				custom_tooltip = {
					text = admin_all_vassal_wars_banned
					#always = no
					trigger_if ={
						limit = {
							has_game_rule = admin_frontier_war_indirect_allowed
						}
						OR = {
							vassal_contract_has_flag = admin_theme_frontier
							vassal_contract_has_flag = admin_theme_naval
						}
					}
				}
				custom_tooltip = {
					text = admin_all_vassal_wars_banned_3
					#always = no
					trigger_if ={
						limit = {
							has_game_rule = admin_frontier_war_always_no
						}
						always = no
					}
				}
			}
			trigger_if = {
				limit = {
					government_allows = administrative
					top_liege = scope:recipient.top_liege
					scope:recipient = { government_allows = administrative }
					NOT = { top_liege = scope:recipient }
				}
				custom_tooltip = {
					text = admin_cannot_declare_internal_wars
					always = no
				}
			}
		}
		scope:actor = {
			trigger_if = {
				limit = { is_landless_adventurer = yes }
				custom_tooltip = {
					text = camp_located_in_defender_realm.tt
					domicile.domicile_location.county.holder = {
						NOR = {
							this = scope:recipient
							any_liege_or_above = { this = scope:recipient }
						}
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		custom_description = {
			text = "declare_war_hook_on_liege"
			OR = {
				war_declarer_needs_hook_on_liege = no
				always = scope:hook
			}
		}
		scope:actor = {
			NOR = {
				is_at_war_with = scope:recipient
				custom_description = { #A vassal cannot go to war against someone their Liege is already at war with
					text = liege_is_at_war_with_recipient
					object = scope:recipient
					liege = {
						is_at_war_with = scope:recipient
					}
				}
			}
		}
	}

	send_options_exclusive = no
	send_option = {
		is_shown = {
			war_declarer_needs_hook_on_liege = yes
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = liege
			}
		}
		flag = hook
		localization = WAR_LIEGE_HOOK
		can_invalidate_interaction = yes
	}
	should_use_extra_icon = {
		war_declarer_needs_hook_on_liege = yes
		scope:actor = { has_usable_hook = liege }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	
	on_accept = {
		scope:actor = {
			#Feedback!
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = declare_war_interaction_notification

					left_icon = scope:actor					
					right_icon = scope:recipient

					custom_tooltip = declare_war_interaction_notification_tooltip

					show_as_tooltip = {
						if = {
							limit = { always = scope:hook }
							use_hook = liege
						}
					}
				}
			}

			#Has the instigator promised a vassal a war (vassal.2601)?
			if = {
				limit = {
					exists = var:promised_war
					var:promised_war = {
						is_alive = yes
						NOT = { this = scope:recipient }
					}
				}
				trigger_event = {
					id = vassal.2610
					days = { 7 10 }
				}
			}

			if = {
				limit = { always = scope:hook }
				use_hook = liege
			}

			#Send break up event if they are your lover
			if = {
				limit = {
					has_relation_lover = scope:recipient
					NOT = { has_relation_rival = scope:recipient } #To enable really strange love stories
					any_character_war = {
						casus_belli = {
							primary_attacker = scope:actor
							primary_defender = scope:recipient
							any_target_title = { count >= 1 }
						}
					}
				}
				scope:recipient = {
					trigger_event = {
						id = lover.0103
						days = { 14 30 }
					}
				}
			}

			#Invalidate any wars your vassals have going against recipient atm
			scope:recipient = {
				if = {
					limit = {
						any_character_war = {
							primary_attacker = {
								is_vassal_or_below_of = scope:actor
								trigger_if = { #Ai should never invalidate a player's war!
									limit = {
										this = { is_ai = no }
									}
									scope:actor = {
										is_ai = no
									}
								}
							}
						}
					}
					every_character_war = {
						limit = {
							primary_attacker = {
								is_vassal_or_below_of = scope:actor
								trigger_if = { #Ai should never invalidate a player's war!
									limit = {
										this = { is_ai = no }
									}
									scope:actor = {
										is_ai = no
									}
								}
							}
						}
						show_as_tooltip = { end_war = invalidated } #Actually ended in the event
						primary_attacker = { trigger_event = war_event.1001 }
					}
				}
			}
			#Notify defender's vassals if the war is targeting one or more of their titles
			scope:recipient = {
				if = {
					limit = {
						any_vassal = {
							save_temporary_scope_as = attacked_vassal
							any_character_war = {
								casus_belli = {
									primary_attacker = scope:actor
									primary_defender = scope:recipient
									any_target_title = {
										holder = {
											OR = {
												this = scope:attacked_vassal
												is_vassal_or_below_of = scope:attacked_vassal
											}
										}
									}
								}
							}
						}
					}
					every_vassal = {
						save_temporary_scope_as = attacked_vassal
						limit = {
							any_character_war = {
								casus_belli = {
									primary_attacker = scope:actor
									primary_defender = scope:recipient
									any_target_title = {
										holder = {
											OR = {
												this = scope:attacked_vassal
												is_vassal_or_below_of = scope:attacked_vassal
											}
										}
									}
								}
							}
						}
						send_interface_toast = {
							type = msg_war_declared_on_liege
							title = declare_war_interaction_notification

							left_icon = scope:actor					
							right_icon = scope:recipient

							custom_tooltip = declare_war_interaction_notification_tooltip
						}
					}
				}
			}
		}
	}
	
	auto_accept = yes
}

start_dispute_border_interaction = {
	icon = icon_dispute_border
	interface_priority = 75
	category = interaction_category_admin 
	send_name = START_SCHEME 
	scheme = dispute_border
	ignores_pending_interaction_block = yes 
	ai_targets = { ai_recipients = peer_vassals } 
	ai_frequency = 60

	cooldown_against_recipient = { years = 5 }

	target_type = title
	target_filter = recipient_realm_titles

	can_be_picked_title = {
		scope:target = {
			ep3_boundary_dispute_county_trigger = {
				OWNER = scope:actor
				TARGET = scope:recipient
			}
		}
	}

	is_shown = {
		scope:actor = { is_governor = yes }
		scope:recipient = {
			this != scope:actor
			is_alive = yes
			top_liege = scope:actor.top_liege
			is_governor = yes
			in_diplomatic_range = scope:actor
		}
	}

	is_valid_showing_failures_only = {

		scope:actor = {
			custom_tooltip = {
				text = admin_border_dispute_authority_tooltip
				trigger_if ={
					limit = {
						has_game_rule = admin_border_dispute_authority
					}
					liege ?= {
						OR = {
							has_realm_law = imperial_bureaucracy_0
							has_realm_law = imperial_bureaucracy_1
						}
					}
				}
			}
			custom_tooltip = {
				text = admin_border_dispute_disabled_tooltip
				trigger_if ={
					limit = {
						has_game_rule = admin_border_dispute_disabled
					}
					always = no
				}
			}
		}
		scope:actor = {
			is_available_adult = yes
			trigger_if = {
				limit = { exists = scope:target }
				can_start_scheme = {
					type = dispute_border
					target_title = scope:target
				}
			}
			custom_tooltip = {
				text = dispute_border_county_neighbour_tt
				character_is_realm_neighbor = scope:recipient
			}
			is_in_civil_war = no
		}
		scope:recipient = {
			is_in_civil_war = no
		}
	}

	desc = start_dispute_border_interaction_desc

	cost = {
		influence = {
			add = scope:actor.massive_influence_gain
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_dispute_border_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_dispute_border_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_dispute_border_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_dispute_border_notification
						left_icon = scope:actor					
						right_icon = scope:target
						scope:actor = {
							# Success.
							if = {
								limit = { scope:agent_focus_success ?= yes }
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = dispute_border
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									AGENT_3 = agent_sycophant
									# Speed.
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_bureaucrat
								}
							}
							# Speed.
							else = {
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = dispute_border
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									# Speed.
									AGENT_3 = agent_political_socialite
									AGENT_4 = agent_bureaucrat
									AGENT_5 = agent_bureaucrat
								}
							}
						}
					}
				}
			}
			random_scheme = {
				limit = {
					scheme_type = dispute_border
					scheme_target_title = scope:target
				}
				set_variable = {
					name = target_character
					value = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = boundary_dispute_outcome_tt

			stress_impact = {
				content = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = attempted_dispute_border_opinion
				}
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_scheme_category = political }
		}
		is_governor = yes
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0
		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = content
			add = -15
		}
		# Land
		modifier = {
			scope:recipient = {
				any_sub_realm_county = {
					OR = {
						duchy.holder = scope:actor
						kingdom.holder = scope:actor
					}
				}
			}
		}
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:actor.house
		}
	}
}

start_subsume_province_interaction = {
	icon = icon_subsume_province
	common_interaction = yes
	interface_priority = 50
	category = interaction_category_admin 
	send_name = START_SCHEME 
	scheme = subsume_province
	ignores_pending_interaction_block = yes 
	ai_targets = { ai_recipients = peer_vassals } 
	ai_frequency = 60

	cooldown = { years = 5 }

	target_type = title
	target_filter = recipient_de_jure_titles

	can_be_picked_title = {
		scope:actor = {
			can_start_scheme = {
				type = subsume_province
				target_title = scope:target
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier = tier_duchy
			exists = holder
			holder = scope:recipient
		}
	}

	desc = start_subsume_province_interaction_desc

	is_shown = {
		scope:actor = { is_governor = yes }
		scope:recipient = {
			is_alive = yes
			top_liege = scope:actor.top_liege
			is_governor = yes
			NOR = { 
				this = scope:actor 
				scope:actor.house = scope:recipient.house
			}
			in_diplomatic_range = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_tooltip = {
				text = admin_border_dispute_authority_tooltip
				trigger_if ={
					limit = {
						has_game_rule = admin_border_dispute_authority
					}
					liege ?= {
						OR = {
							has_realm_law = imperial_bureaucracy_0
							has_realm_law = imperial_bureaucracy_1
						}
					}
				}
			}
			custom_tooltip = {
				text = admin_border_dispute_disabled_tooltip
				trigger_if ={
					limit = {
						has_game_rule = admin_border_dispute_disabled
					}
					always = no
				}
			}
		}	
		scope:actor = {
			is_available_adult = yes
			trigger_if = {
				limit = { exists = scope:target }
				can_start_scheme = {
					type = subsume_province
					target_title = scope:target
				}
			}
			#trigger_if = {
			#	limit = {
			#		top_liege ?= {
			#			NOT = { has_realm_law_flag = admin_vassal_border_limit }
			#		}
			#	}
			#	custom_tooltip = {
			#		text = interaction_must_be_powerful_or_dominant_family_tt
			#		house = {
			#			OR = {
			#				is_powerful_family = yes
			#				is_dominant_family = yes
			#			}
			#		}
			#	}
			#}
			is_in_civil_war = no
			#custom_tooltip = {
			#	text = admin_vassal_border_limit_desc
			#	top_liege ?= {
			#		NOT = { has_realm_law_flag = admin_vassal_border_limit }
			#	}
			#}
		}
		scope:recipient = {
			custom_tooltip = {
				text = subsume_province_neighboring_duchy_tt
				any_sub_realm_county = {
					any_neighboring_county = {
						county_held_or_vassal_to_target_trigger = { TARGET = scope:actor }
					}
				}
			}
			custom_tooltip = {
				text = subsume_province_recipient_scheming_against_you_tt
				NOT = {
					is_scheming_against = {
						type = subsume_province
						target = scope:actor
					}
				}
			}
			custom_tooltip = {
				text = subsume_province_recipient_house_power_or_gov_efficiency_tt
				OR = {
					governor_efficiency_presented <= -25
					AND = {
						trigger_if = {
							limit = { house = { is_powerful_family = yes } }
							scope:actor.house = { is_dominant_family = yes }
						}
						house = { is_dominant_family = no }
					}
				}
			}
			is_in_civil_war = no
			NOT = { is_diarch_of_target = liege }
		}
	}

	is_highlighted = { scope:recipient.governor_efficiency_presented <= -25 }
	should_use_extra_icon = { scope:recipient.governor_efficiency_presented <= -25 }
	extra_icon = "gfx/interface/icons/character_interactions/icon_damage_efficiency.dds"

	cost = {
		influence = {
			add = {
				value = scope:actor.massive_influence_gain
				multiply = 4
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_subsume_province_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_subsume_province_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_subsume_province_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_subsume_province_notification
						left_icon = scope:actor					
						right_icon = scope:target
						scope:actor = {
							# Success.
							if = {
								limit = { scope:agent_focus_success ?= yes }
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = subsume_province
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									AGENT_3 = agent_proponent
									# Speed.
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
							# Speed.
							else = {
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = subsume_province
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									# Speed.
									AGENT_3 = agent_political_socialite
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
						}
					}
				}
			}
			random_scheme = {
				limit = {
					scheme_type = subsume_province
					scheme_target_title = scope:target
				}
				set_variable = {
					name = target_character
					value = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes
			custom_tooltip = subsume_province_scheme_success_outcome_tt
			stress_impact = {
				content = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = attempted_subsume_province_opinion
				}
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_scheme_category = political }
		}
		is_governor = yes
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = content
			add = -15
		}
		# Land
		modifier = {
			scope:recipient = {
				any_sub_realm_county = {
					OR = {
						duchy.holder = scope:actor
						kingdom.holder = scope:actor
					}
				}
			}
		}
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:actor.house
		}
	}
}