﻿
designate_military_heir_interaction = {

	category = interaction_category_diplomacy

	desc = designate_heir_interaction_desc

	is_shown = {
		scope:actor = { has_government = military_command }
		scope:recipient = {
			OR = {
				is_close_family_of = scope:actor			
				house = scope:actor.house
			}						
			has_unelectable_trait_trigger = no
			has_unelectable_government_trigger = no
		}
		NOT = {
			scope:recipient = scope:actor.designated_heir
		}
	}

	is_valid = {
		scope:recipient = { 
			is_diplomatically_available = yes 
			custom_description = {
				text = eligible_for_military_appointment_trigger_BASE
				subject = scope:recipient
				OR = {
					has_martial_lifestyle_trait_trigger = yes
					#martial > medium_skill_rating
					has_education_martial_trigger = yes
					has_character_modifier = imperial_military_rank_gained
				}
			}
			eligible_for_military_appointment_trigger = { APPOINTEE = scope:actor.liege }
			trigger_if = {
				limit = { is_ruler = yes }
				liege = scope:actor
			}
			custom_description = {
				text = TOOLTIPdesignate_military_heir_REALM
				#Candidate is within top liege realm
				exists = top_liege
				top_liege = {
					OR = {
						this = scope:actor
						is_liege_or_above_of = scope:actor
					}	
				}
			}
			custom_description = {
				text = TOOLTIPdesignate_military_heir_INVALID_HEIR
				#Landless characters should not be heirs to Theocracies/Republics.
				NOT = { 
					any_heir_title = {
						exists = holder
						holder = {
							has_unelectable_government_trigger = yes
						}
					}
				}
			}
		}
		scope:actor = { 
			prestige >= 100
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0120
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				title = designate_heir_interaction_notification

				left_icon = scope:actor					
				right_icon = scope:recipient

				set_designated_heir = scope:recipient
				add_prestige = { subtract = 100 }
			}
		}
	}

	auto_accept = yes
	
	ai_potential = {
		always = no #decision seems to cause CTD, disabled for AI until a fix can be found
		#has_government = military_command
	}
	# # AI
	# ai_targets = {
		# ai_recipients = dynasty
	# }
	# ai_frequency = 12

	# ai_will_do = {
		# base = 0
		
		# modifier = { # Designated heir is my child
			# add = -1000
			# exists = scope:actor.designated_heir
			# scope:actor.designated_heir = {
				# eligible_for_military_appointment_trigger = { APPOINTEE = scope:actor.liege }
				# is_child_of = scope:actor
			# }		
		# }
		# modifier = { # Already has a designated heir
			# add = -25
			# exists = scope:actor.designated_heir		
		# }
		# modifier = { 
			# add = 25
			# scope:recipient = { is_child_of = scope:actor }	
		# }
		# modifier = { 
			# add = 10
			# scope:recipient.house = scope:recipient.house
		# }
		# modifier = { 
			# add = 10
			# scope:recipient = { is_grandchild_of = scope:actor }	
		# }
		# modifier = { 
			# add = 5
			# scope:recipient = { is_sibling_of = scope:actor }	
		# }
		# modifier = { 
			# add = 5
			# scope:actor = { is_sibling_of = scope:actor }	
		# }
		# opinion_modifier = { # Opinion Factor
			# who = scope:recipient
			# opinion_target = scope:actor
			# multiplier = 0.25
		# }
		# modifier = { 
			# add = {
				# value = -20
				# add = scope:recipient.martial
				# add = scope:recipient.stewardship
				# add = scope:recipient.diplomacy
				# add = scope:recipient.intrigue
				# multiply = 0.5
			# }
		# }
	# }
}
request_new_command_interaction = {

	category = interaction_category_diplomacy
	common_interaction = yes

	desc = request_new_command_interaction_desc
	
	#notification_text = REVOKE_TITLE_PROPOSAL
	notification_text = REQUEST_NEW_COMMAND_PROPOSAL
	
	#special_interaction = grant_titles_interaction
	#interface = revoke_title
	target_type = title
	target_filter = recipient_domain_titles
	ai_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes
	
	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	
	# actor character giving the titles
	# recipient character receiving the titles

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			OR = {
				has_government = military_command
				has_government = patrician_government
			}	
			is_landed = yes
			liege = scope:recipient
		}
	}
	
	is_valid_showing_failures_only = {
		scope:actor = { 
			is_at_war = no 
			is_imprisoned = no
			eligible_for_military_appointment_trigger = { APPOINTEE = scope:recipient }
			NOT = { has_opinion_modifier = { target = scope:recipient modifier = denied_new_command } }
			NOT = { has_opinion_modifier = { target = scope:recipient modifier = received_new_command } }
		}
		scope:recipient = { is_at_war = no }
		trigger_if = { # Can't request on titles you already have a claim on
			limit = { exists = scope:target }
			
		}
		trigger_else = {
			always = yes
		}
	}
	
	cost = {											
		prestige = major_prestige_value
	}
	
	can_be_picked_title = {
		scope:target = {
			is_leased_out = no
			tier >= tier_county
			custom_description = {
				text = request_new_command_PRIMARY
				NOR = {
					this = scope:recipient.primary_title
					tier = scope:recipient.primary_title.tier
				}	
			}
			custom_description = {
				text = request_new_command_NOT_CAPITAL
				scope:recipient.capital_barony = {
					NOR = {
						this = scope:target
						county = scope:target
						duchy = scope:target
						kingdom = scope:target
					}
				}
			}
			custom_description = {
				text = request_new_command_HAS_AVAILABLE_LAND
				scope:target = {
					OR = {
						tier = tier_county
						any_in_de_jure_hierarchy = {
							continue = { NOT = { tier = tier_county } }
							tier = tier_county
							OR = {
								holder = scope:recipient
								holder = scope:actor
							}	
						}
					}
				}	
			}			
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_send = {
		scope:actor = {
			stress_impact = {	
				lazy = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				
				content = medium_stress_impact_gain
				ambitious = medium_stress_impact_loss	
			}
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = imperial.0031
		}
	}

	on_accept = {
		if = { #Is a promotion
			limit = { scope:target.tier > scope:actor.primary_title.tier }
			if = {
				limit = {
					scope:target.tier = tier_county
				}
				scope:actor = {
					add_opinion = {
						target = scope:recipient
						modifier = received_title_county
					}
				}	
			}	
			else_if = {
				limit = {
					scope:target.tier = tier_duchy
				}
				scope:actor = {
					add_opinion = {
						target = scope:recipient
						modifier = received_title_duchy
					}
				}	
			}
			else_if = {
				limit = {
					scope:target.tier = tier_kingdom
				}
				scope:actor = {
					add_opinion = {
						target = scope:recipient
						modifier = received_title_kingdom
					}
				}	
			}
		}
		else = {
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = received_new_command
				}
			}
		}
		scope:actor = { custom_tooltip = request_new_command_TOOLTIP }
		hidden_effect = {
			scope:actor = {
				primary_title = { save_scope_as = old_command }
			}
			hidden_effect = { #Inform relevent characters
				every_player = {
					limit = {
						NOT = { this = scope:actor }
						NOT = { this = scope:recipient }
						OR = {
							is_vassal_or_below_of = scope:actor						
							dynasty = scope:actor
							liege = scope:recipient					
						}
					}
					send_interface_message = {
						title = request_new_command_TITLE
						desc = request_new_command_DESC
						left_icon = scope:actor						
					}
				}
			}
			
			create_title_and_vassal_change = change
			scope:change = {
				set_title_and_vassal_change_type = granted
			}
						
			scope:actor = { #Return titles
				every_held_title = {
					limit = { 
						NOT = { 
							is_landless_patrician_title_trigger = yes
						} 
						NOR = {
							county = scope:target
							duchy = scope:target
							kingdom = scope:target
						}
						NAND = { 
							holder = { highest_held_title_tier > tier_barony }
							this = scope:actor.capital_barony 
						}
					}
					change_title_holder = {
						holder = scope:recipient
						change = scope:change
					}
					every_in_de_jure_hierarchy = {
						limit = { 
							holder.liege = scope:actor				
						}
						holder = {
							change_liege = {
								liege = scope:recipient
								change = scope:change
							}
						}	
					}
				}
			}	
			scope:target = { #acquire new titles
				change_title_holder = {
					holder = scope:actor
					change = scope:change
				}
				every_in_de_jure_hierarchy = {
					limit = { 
						holder = scope:recipient 
						NAND = { 
							holder = { highest_held_title_tier > tier_barony }
							this = scope:recipient.capital_barony 
						}
					}
					change_title_holder = {
						holder = scope:actor
						change = scope:change
					}
				}
				every_in_de_jure_hierarchy = {
					limit = { 
						holder = { 
							primary_title.tier < scope:target.tier 
							liege = scope:recipient
						}						
					}
					holder = {
						change_liege = {
							liege = scope:actor
							change = scope:change
						}
					}	
				}
			}
			
			resolve_title_and_vassal_change = scope:change
		}
		
		scope:actor = {
			if = {
				limit = {
					joined_faction = { faction_is_type = military_faction }
				}
				add_joined_faction_discontent = -10
			}
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
		}
		
		save_scope_value_as = {
			name = request_new_command_interaction
			value = yes
		}
		
		scope:actor = {
			trigger_event = imperial.0032
		}
	}

	on_decline = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = denied_new_command
			}
			if = {
				limit = {
					joined_faction = { faction_is_type = military_faction }
				}
				add_joined_faction_discontent = 10
			}
		}
		scope:actor = {
			primary_title = { save_scope_as = old_command }
			trigger_event = imperial.0033
		}
	}

	auto_accept = {
		OR = {
			scope:recipient = {
				is_imprisoned_by = scope:actor
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}
	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			desc = AI_OPINION_REASON
		}
			
		modifier = { #Comparative military strength.
			desc = offer_vassalization_interaction_aibehavior_power_tt
	  	  	add = {
				value = scope:actor.max_military_strength
				divide = { value = scope:recipient.max_military_strength min = 1 }
				multiply = 50
				min = 0
				max = 50
				# value = 1
				# subtract = {
					# value = scope:recipient.max_military_strength
					# divide = { value = scope:actor.max_military_strength min = 1 }
				# }
				# multiply = 50
	  		}
		}
		modifier = {
			scope:actor = {
				is_powerful_vassal = yes
			}
			add = 10
			desc = request_new_command_POWERFUL_VASSAL
		}
		
		modifier = { # Acceptance boon for lovers, friends, etc
			add = {
				value = 25
				if = {
					limit = { 
						OR = {
							has_relation_soulmate = scope:actor
							has_relation_best_friend = scope:actor
							is_parent_of = scope:actor
						}
					}
					add = 25
				}
			}
			scope:recipient = {
				OR = {
					is_spouse_of = scope:actor
					is_close_or_extended_family_of = scope:actor
					has_relation_lover = scope:actor
					has_relation_friend = scope:actor
					has_secret_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
					has_relation_best_friend = scope:actor
					is_parent_of = scope:actor
				}
				
			}
			desc = "DEAR_TO_ME_REASON"
		}
		modifier = {
			add = 10
			scope:recipient = {
				NOR = {
					this = scope:secondary_recipient
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_soulmate = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
				NOR = {
					has_relation_rival = scope:secondary_recipient
					has_relation_nemesis = scope:secondary_recipient
				}
			}
			scope:recipient.dynasty = scope:secondary_recipient.dynasty
			desc = "MY_DYNASTY_REASON"
		}
		
		modifier = {
			scope:actor = {
				joined_faction = { 
					faction_is_type = military_faction 
					faction_discontent < 80
				}
			}
			add = 10
			desc = request_new_command_MILITARY_FACTION
		}
		modifier = {
			scope:actor = {
				joined_faction = { 
					faction_is_type = military_faction 
					faction_discontent >= 80
				}
			}
			add = 30
			desc = request_new_command_FACTION_IS_UNHAPPY
		}
		modifier = {
			# scope:target = { #is richer
				# any_in_de_jure_hierarchy = {
					# continue = { NOT = { tier = tier_county } }
					# holder = scope:recipient
					# tier = tier_county
					# title_province = { monthly_income > scope:actor.capital_province }	
				# }
			# }
			add = {
				if = {
					limit = { scope:target.tier = tier_county }
					value = scope:target.title_province.monthly_income
					subtract = scope:actor.capital_province.monthly_income
				}	
				else = {
					value = 0
					scope:target = {
						every_in_de_jure_hierarchy = {
							continue = { NOT = { tier = tier_county } }
							limit = {
								holder = scope:recipient
								tier = tier_county
							}
							add = this.title_province.monthly_income	
						}
					}	
					scope:actor = {
						every_held_title = {
							limit = {
								tier = tier_county
							}
							subtract = this.title_province.monthly_income						
						}
					}
					
				}
				multiply = -15
				multiply = {
					value = scope:recipient.ai_greed
					multiply = 0.01
					add = 1
					min = 0.5
				}
				max = 0
				min = -50
			}
			desc = request_new_command_RICHER_PROVINCE
		}
		modifier = {
			scope:target.tier > scope:actor.primary_title.tier
			add = {
				value = scope:target.tier
				subtract = scope:actor.primary_title.tier
				multiply = -15
			}
			desc = request_new_command_PROMOTION
		}
	}

	# AI
	ai_targets = {
		ai_recipients = liege
	}
	ai_frequency = 60 # This is handled via code instead; see REVOKE_TITLE_TICK in the AI defines. All the logic for *if* to send a revoke though is scripted below

	ai_potential = {
		
	}

	ai_will_do = {
		base = -1000
		
		#AI motives
		modifier = {
			add = 1010
			OR = {
				scope:target.tier > scope:actor.primary_title.tier #is a promotion
				scope:target = { #is richer
					tier = scope:actor.primary_title.tier
					any_in_de_jure_hierarchy = {
						continue = { NOT = { tier = tier_county } }
						holder = scope:recipient
						tier = tier_county
						title_province = { monthly_income > scope:actor.capital_province }	
					}
				}
			}	
		}
			
		# This is a current dejure title
		modifier = {
			add = 10
			scope:target = {
				any_in_de_jure_hierarchy = {
					continue = { NOT = { tier = tier_county } }
					tier = tier_county
					holder = scope:actor
				}
			}
		}
			
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		
		#AI personality
		modifier = { 
			add = { 
				value = scope:actor.ai_greed
				min = -75
				max = 75
			}
		}
		modifier = { 
			add = { 
				value = scope:actor.ai_energy
				multiply = 0.5
				min = -35
				max = 35
			}
		}
	}
}

confiscate_estates_interaction = {

	category = interaction_category_vassal
	common_interaction = yes
	highlighted_reason = HIGHLIGHTED_HAS_REVOKE_TITLE_REASON
	notification_text = REVOKE_ESTATE_PROPOSAL

	desc = confiscate_estates_interaction_desc

	# special_interaction = revoke_title_interaction
	# interface = revoke_title
	# target_type = title
	# target_filter = recipient_domain_titles
	ai_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	on_decline_summary = general_rebellion_decline_summary

	# actor character giving the titles
	# recipient character receiving the titles

	is_shown = {
		scope:recipient = {
			#is_ruler = yes
			# should be shown but be disabled for indirect vassals
			target_is_liege_or_above = scope:actor
			# is_vassal_of = scope:actor
			
			has_estates_trigger = yes
		}
	}
	
	is_valid_showing_failures_only = {
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
		scope:actor = {
			custom_description = {
				text = "character_interactions_revoke_title_from_ally_without_reason"
				object = scope:recipient
				OR = {
					NOT = {
						is_allied_to = scope:recipient
					}
					has_revoke_title_reason = scope:recipient
				}
			}
			trigger_if = {
				limit = { has_government = tribal_government }
				custom_description = {
					text = "has_law_allowing_title_revocation_tribal"
					has_realm_law_flag = title_revocation_allowed
				}
			}
			trigger_if = {
				limit = {
					NOT = { has_government = tribal_government }
				}
				custom_description = {
					text = "has_law_allowing_title_revocation_crown"
					has_realm_law_flag = title_revocation_allowed
				}
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						vassal_contract_has_flag = vassal_contract_cannot_revoke_titles
					}
				}
				custom_description = {
					text = vassal_contract_forbids_revocation
					scope:recipient = {
						NOT = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
					}
				}
			}
		}
		scope:recipient = {
			liege = scope:actor
			is_diplomatically_available = yes
			NOT = { has_strong_hook = scope:actor }
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}
	
	# Highlighted in the interaction menu when right-clicking a character
	is_highlighted = {
		scope:actor = {
			has_revoke_title_reason = scope:recipient
		}
	}
	
	# whether a character can be picked for the interaction, interface only (e.g. picking the first character in the marriage interaction)
	# in character scope, actor and recipient event tagets can be used, but not the secondary characters
	can_be_picked = {
		AND =  {
			NOT = {
				scope:actor = scope:recipient	
			}
 			scope:recipient = {
				liege = scope:actor
			}
		}
	}
	
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = imperial.0072
		}
	}

	on_accept = {
		scope:actor = {
			add_gold = estate_sell_value		
		}
		scope:recipient = {
			if = { #game over!
				limit = {
					has_character_modifier = patrician_estate_modifier_1
					is_ruler = yes
					primary_title = { 
						is_landless_patrician_title_trigger = yes					
					}
					NOT = { 
						any_held_title = {
							NOT = { 
								is_landless_patrician_title_trigger = yes 
							}
							tier >= tier_duchy
						}
					}
				}
				custom_description = {
					text = TOOLTIP_PATRICIAN_GAME_OVER
					trigger_event = { id = imperial.0073 days = 2 }
				}	
			}
			lose_one_estate_level_effect = yes
		}
		if = {
			limit = {
				scope:recipient = {
					faith = scope:actor.faith
					has_government = theocracy_government
				}
			}
			scope:actor = {
				add_piety = major_piety_loss
			}
			if = {
				limit = {
					exists = scope:actor.faith.religious_head
				}
				scope:actor.faith.religious_head = {
					add_opinion = {
						target = scope:actor
						modifier = impious_opinion
						opinion = -20
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:actor.faith.religious_head
				scope:recipient = scope:actor.faith.religious_head
			}
			scope:actor = {
				add_piety_level = -2
			}
		}
		scope:actor = {
			if = {
				limit = {
					NOT = { has_revoke_title_reason = scope:recipient }
				}
				add_tyranny = revoke_title_tyranny_gain
			}
			else = {
				custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_DESC
			}
			if = {
				limit = {
					NOT = { has_revoke_title_reason = scope:recipient }
				}
				stress_impact = {
					generous = medium_stress_impact_gain
					just = medium_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					generous = medium_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			consume_revoke_title_reason = scope:recipient
		}
		scope:recipient = {
			if = {
				limit = {
					is_a_faction_member = yes
				}
				add_joined_faction_discontent = 15
			}
		}
		
		scope:actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = revoked_estate
			}
			if = { #If they recently imprisoned you, or asked for your excommunication, they become your rival
				limit = {
					OR = {
						has_opinion_modifier = {
							target = scope:actor
							modifier = released_from_prison
						}
						AND = {
							exists = var:requested_my_excommunication
							var:requested_my_excommunication = scope:actor
						}
					}
					NOT = {
						has_relation_rival = scope:actor
					}
				}
				if = {
					limit = {
						has_relation_potential_rival = scope:actor
					}
					remove_relation_potential_rival = scope:actor
				}
				set_relation_rival = scope:actor
			}
			else = {
				progress_towards_rival_effect = {
					CHARACTER = scope:actor
					OPINION = no
				}
			}
		}
		
		save_scope_value_as = {
			name = revoke_estate_interaction
			value = yes
		}
		
		scope:actor = {
			trigger_event = imperial.0074
		}
		###

		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

	on_decline = {
		war_for_revoke_effect = yes
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = revoked_estate
			}
		}
		if = {
			limit = {
				scope:actor = { has_realm_law_flag = vassal_refusal_is_treason }
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_revoke_refusal
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

	auto_accept = {
		OR = {
			scope:recipient = {
				is_imprisoned_by = scope:actor
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			scope:recipient = {
				max_military_strength < 50
			}
			scope:recipient = {
				is_ruler = no
			}
		}
	}
	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.8
			desc = AI_OPINION_REASON
		}
		
		modifier = {
			add = 40
			scope:actor = {
				has_realm_law_flag = vassal_refusal_is_treason
			}
			desc = AI_REFUSAL_IS_TREASON
		}

		ai_value_modifier = {
			who = scope:recipient
			ai_greed = -0.75
	  	  	trigger = {
	  	  		scope:recipient = { NOT = { ai_greed = 0 } }
	  		}
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_honor = 0.5
			trigger = {
				scope:recipient = { #If AI is honorable and the law compels to obey the liege, AI will be more likely to obey.
					ai_honor > 0
				}
				scope:actor = {
					has_realm_law_flag = vassal_refusal_is_treason
				}
			}
		}
		# modifier = { #I am a King!
			# desc = offer_vassalization_interaction_aibehavior_amkingtier_tt
			# trigger = {
				# scope:recipient = { highest_held_title_tier = tier_kingdom }
			# }
			# add = -20
		# }
		modifier = {
			add = 30
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 60
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = { #Comparative military strength.
			desc = offer_vassalization_interaction_aibehavior_power_tt
	  	  	add = {
				value = 1
					subtract = {
					value = scope:recipient.max_military_strength
					divide = { value = scope:actor.max_military_strength min = 1 }
					}
				multiply = 50
	  		}
		}
	}

	# AI
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = courtiers
	}
	ai_frequency = 12

	ai_potential = {
		has_realm_law_flag = title_revocation_allowed
		OR = {
			has_government = imperial_government
			top_liege = { has_government = imperial_government }
		}
	}

	ai_will_do = {
		base = -1000

		# We want to avoid tyranny unless we've got a good reason
		# And even if we can avoid tyranny we don't want to revoke just because we can, so this only gets us to -10
		# Certain characters will revoke despite tyranny, if their rationality is sufficiently low
		modifier = {
			scope:actor = {
				OR = {
					has_revoke_title_reason = scope:recipient
					AND = {
						ai_rationality <= very_high_negative_ai_value
						OR = {
							has_trait = lunatic
							has_trait = possessed
							has_trait = arbitrary
							has_trait = greedy
						}
					}
				}
			}

			add = 1005
		}
		
		ai_value_modifier = { #Greedy for cash
			who = scope:actor
			ai_greed = -0.75
	  	  	trigger = {
	  	  		scope:actor = { NOT = { ai_greed = 0 } }
	  		}
		}
		# Need the cash
		modifier = {
			scope:actor = {
				OR = {
					AND = {
						is_at_war = yes
						gold < 50
						monthly_character_balance < 0
					}	
					time_in_prison = { years >= 2 }
					gold < -50
				}
			}
			add = 50
		}
		
		# Revoke from characters you dislike if you can do it without tyranny
		modifier = {
			scope:actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
			add = 100
		}

		# Do not revoke titles from certain characters
		modifier = {
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_soulmate = scope:recipient
					is_heir_of = scope:recipient
				}
			}
			add = -2000
		}
		
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}

		modifier = { # Avoid triggering Tyranny wars mid-war
			factor = 0
			scope:actor = {
				is_at_war = yes
			}
			scope:recipient = {
				NOT = {
					is_imprisoned_by = scope:actor
				}
			}
		}
	}
}
