﻿riseandfall_warlord_alliance_interaction = {
	category = interaction_riseandfall
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	icon = alliance

		send_name = riseandfall_warlord_alliance_interaction

	interface_priority = 60
	desc = riseandfall_warlord_alliance_interaction_desc

	greeting = positive
	notification_text = NEGOTIATE_ALLIANCE_NOTIFICATION

	is_shown = {
		scope:actor = {
			is_ruler = yes
			is_independent_ruler = no
			riseandfall_is_any_warlord_trigger = yes
			is_landed = yes
		}
		scope:recipient = {
			this != scope:actor
			NOT = { is_allied_to = scope:actor }
			is_ruler = yes
			is_independent_ruler = no
			riseandfall_is_any_warlord_trigger = yes
			is_landed = yes
		}
		# Require same direct liege for both parties
		scope:recipient = { liege = scope:actor.liege }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_ruler = yes
			is_independent_ruler = no
			riseandfall_is_any_warlord_trigger = yes
			is_landed = yes
		}
		scope:recipient = {
			is_ruler = yes
			is_independent_ruler = no
			riseandfall_is_any_warlord_trigger = yes
			is_landed = yes
		}
		# Require same direct liege for both parties
		scope:recipient = { liege = scope:actor.liege }
	}

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

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

	# Admin Gov can spend Influence to increase AI acceptance towards other same-realm admin characters
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_mechanic = administrative
			}
			scope:recipient = {
				top_liege = scope:actor.top_liege
				government_has_mechanic = administrative
			}
		}
		is_valid = {
			scope:actor = {
				influence >= major_influence_value
			}
			custom_tooltip = {
				text = ALREADY_USING_HOOK
				NOT = { scope:hook = yes }
			}
		}
		flag = influence
		localization = SPEND_INFLUENCE
	}

	send_options_exclusive = no

	on_accept = {
		scope:actor = {
			trigger_event = char_interaction.0235

			stress_impact = {
				shy = minor_stress_impact_gain
			}

			if = {
				limit = {
					scope:hook = yes
					has_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
			if = {
				limit = {
					scope:influence = yes
				}
				change_influence = major_influence_loss
			}
		}

		scope:recipient = {
			custom_tooltip = negotiate_alliance_effect_recipient_tooltip
		}

		#Set up alliance, depending on relation between rulers.
		hidden_effect = {
			#Prioritize marriage between rulers and/or direct blood relation between rulers first.
			if = {
				limit = {
					scope:actor = {
						OR = {
							is_spouse_of = scope:recipient
							is_child_of = scope:recipient
							is_parent_of = scope:recipient
							is_sibling_of = scope:recipient
							is_grandparent_of = scope:recipient
							is_great_grandparent_of = scope:recipient
							is_grandchild_of = scope:recipient
							is_great_grandchild_of = scope:recipient
							is_uncle_or_aunt_of = scope:recipient
							is_nibling_of = scope:recipient
						}
					}
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:actor
						allied_through_target = scope:recipient
					}
				}
			}
			#...Then marriage between close family members and either actor or recipient.
			else_if = {
				limit = {
					scope:recipient = {
						any_spouse = {
							OR = {
								is_close_family_of = scope:actor
								is_nibling_of = scope:actor
								is_uncle_or_aunt_of = scope:actor
							}
						}
					}
				}
				scope:recipient = {
					random_spouse = {
						limit = {
							OR = {
								is_close_family_of = scope:actor
								is_nibling_of = scope:actor
								is_uncle_or_aunt_of = scope:actor
							}
						}
						save_scope_as = recipient_spouse
					}
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:recipient_spouse
						allied_through_target = scope:recipient
					}
				}
			}
			else_if = {
				limit = {
					scope:actor = {
						any_spouse = {
							OR = {
								is_close_family_of = scope:recipient
								is_nibling_of = scope:recipient
								is_uncle_or_aunt_of = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					random_spouse = {
						limit = {
							OR = {
								is_close_family_of = scope:recipient
								is_nibling_of = scope:recipient
								is_uncle_or_aunt_of = scope:recipient
							}
						}
						save_scope_as = actor_spouse
					}
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:actor
						allied_through_target = scope:actor_spouse
					}
				}
			}
			#...And finally marriage between close relatives and close relatives.
			else_if = {
				limit = {
					scope:actor = {
						any_close_family_member = {
							OR = {
								is_child_of = scope:actor
								is_parent_of = scope:actor
								is_sibling_of = scope:actor
							}
							any_spouse = {
								OR = {
									is_child_of = scope:recipient
									is_parent_of = scope:recipient
									is_sibling_of = scope:recipient
								}
							}
						}
					}
				}
				scope:actor = {
					random_close_family_member = {
						limit = {
							OR = {
								is_child_of = scope:actor
								is_parent_of = scope:actor
								is_sibling_of = scope:actor
							}
							any_spouse = {
								OR = {
									is_child_of = scope:recipient
									is_parent_of = scope:recipient
									is_sibling_of = scope:recipient
								}
							}
						}
						save_scope_as = actor_spouse
						random_spouse = {
							limit = {
								OR = {
									is_child_of = scope:recipient
									is_parent_of = scope:recipient
									is_sibling_of = scope:recipient
								}
							}
							save_scope_as = recipient_spouse
						}
					}
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:actor_spouse
						allied_through_target = scope:recipient_spouse
					}
				}
			}
			else_if = {
				limit = {
					scope:actor = { has_perk = defensive_negotiations_perk }
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:actor
						allied_through_target = scope:recipient
					}
				}
				scope:recipient = { # This opinion modifier controls the interaction, and is removed when breaking the alliance in any way (though on_actions)
					add_opinion = {
						modifier = perk_negotiated_alliance_opinion
						target = scope:actor
					}
				}
			}
			else_if = {
				limit = {
					scope:actor = {
						hostage_oath_of_friendship_trigger = yes
					}
				}
				scope:actor = {
					create_alliance = {
						target = scope:recipient
						allied_through_owner = scope:actor
						allied_through_target = scope:recipient
					}
				}
			}
		}

		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_alliance.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0236
		}
		scope:actor = {
			add_opinion = {
				modifier = refused_alliance_opinion
				target = scope:recipient
			}
		}

		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_alliance_refusal.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}
	ai_accept = {
		modifier = {
			add = -1000
			OR = {
				AND = { scope:actor = { has_trait = loyalwarlord } scope:recipient = { has_trait = warlord } }
				AND = { scope:actor = { has_trait = warlord } scope:recipient = { has_trait = loyalwarlord } }
			}
		}
		modifier = {
			add = 75
			scope:actor = { has_trait = warlord }
			scope:recipient = { has_trait = warlord }
		}
		modifier = {
			add = 25
			scope:actor = { has_trait = loyalwarlord }
			scope:recipient = { has_trait = loyalwarlord }
		}
		base = 100

		# Tier Difference 	(+/-)
		# Inheritance 		(+)
		# Opinion 			(+/-)
		# Dynasty Prestige. (+)
		# Different Faith.	(-)
		# Liege is asking 	(+)
		# Dread 			(+)
		# Power difference 	(+/-)
		# Claimants (+/-)
		# Same House (+)
		# Declared war opinion
		# Actor is at war penalty

		modifier = {
			add = 20
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			desc = CLOSE_FAMILY_REASON
		}

		modifier = {
			add = 10
			scope:recipient = {
				NOT = { is_close_family_of = scope:actor }
				is_extended_family_of = scope:actor
			}
			desc = EXTENDED_FAMILY_REASON
		}

		modifier = {
			add = -20
			scope:recipient = {
				NOT = { is_close_or_extended_family_of = scope:actor }
				any_spouse = {
					NOT = { is_close_family_of = scope:actor }
					is_extended_family_of = scope:actor
				}
			}
			desc = DISTANT_FAMILY_CONNECTION_REASON
		}

		# Tier Differences
		modifier = {
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value >= 1
				}
			}
			add = {
				value = 30
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 2
						}
					}
					add = 30
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 3
						}
					}
					add = 60
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 4
						}
					}
					add = 90
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 5
						}
					}
					add = 120
				}
			}
			desc = RANK_DIFFERENCE_REASON
		}
		modifier = {
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value <= -1
				}
			}
			add = {
				value = -30
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -2
						}
					}
					add = -30
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -3
						}
					}
					add = -60
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -4
						}
					}
					add = -90
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -5
						}
					}
					add = -120
				}
			}
			desc = RANK_DIFFERENCE_REASON
		}
		modifier = {
			scope:recipient = {
				has_relation_lover = scope:actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_LOVERS
		}
		modifier = {
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_FRIENDS
		}
		modifier = {
			scope:recipient = {
				is_heir_of = scope:actor
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value > 0
				}
			}
			add = {
				value = 10
				if = {
					limit = {
						scope:actor = { player_heir = scope:recipient }
					}
					add = 10
				}
			}
			desc = IS_HEIR_REASON
		}
		opinion_modifier = { # More likely to accept if Recipient likes the Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.25
			min = 0
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Less likely to accept if Recipient dislikes the Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			max = 0
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = loyal
			}
			desc = INTERACTION_LOYAL
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = trusting
			}
			desc = INTERACTION_TRUSTING
		}

		modifier = {
			add = 5
			scope:recipient = {
				has_trait = craven
			}
			desc = INTERACTION_CRAVEN
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = paranoid
			}
			desc = INTERACTION_PARANOID
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = arrogant
			}
			desc = INTERACTION_ARROGANT
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = ambitious
			}
			desc = INTERACTION_AMBITIOUS
		}

		modifier = {
			add = -40
			scope:recipient = {
				has_trait = disloyal
			}
			desc = INTERACTION_DISLOYAL
		}

		modifier = {
			add = -10
			scope:recipient = {
				has_trait = fickle
			}
			desc = INTERACTION_FICKLE
		}

		# Rivalry
		modifier = { # Say no to rivals
			add = -100
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			desc = "ACTOR_RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to nemesis
			add = -300
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
			desc = "ACTOR_NEMESIS_TO_ME_REASON"
		}

		# Dynasty Prestige Levels
		modifier = {
			add = -5
			desc = AI_DYNASTY_PRESTIGE_REASON
			scope:actor = { has_dynasty = yes }
			scope:actor.dynasty != scope:recipient.dynasty
			scope:actor.dynasty = { dynasty_prestige_level = 0 }
		}
		modifier = {
			desc = AI_DYNASTY_PRESTIGE_REASON
			scope:actor = { has_dynasty = yes }
			scope:actor.dynasty != scope:recipient.dynasty
			scope:actor.dynasty = { dynasty_prestige_level >= 2 }
			add = {
				value = 10
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 3 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 4 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 5 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 6 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 7 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 8 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 9 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 10 }
					}
					add = 5
				}
			}
		}
		modifier = { #Faith compatibility
			scope:recipient.faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value > faith_fully_accepted_level
				}
			}
			NOT = {
				scope:recipient.ai_zeal <= -50
			}
			add = {
				value = -10
				if = {
					limit = {
						# Exempt certain struggle phases.
						NOT = { is_struggle_parameter_active_interfaith_marriages_available_between_involved_characters_trigger = yes }
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_astray_level
								}
							}
						}
						subtract = 20
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_hostile_level
								}
							}
						}
						subtract = 20
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_evil_level
								}
							}
						}
						subtract = 50
					}
					if = {
						limit = {
							scope:recipient.ai_zeal <= -25
						}
						divide = 2
					}
					else_if = {
						limit = {
							scope:recipient.ai_zeal >= 50
						}
						multiply = 2
					}
					if = {
						limit = {
							scope:recipient.faith = { has_doctrine = doctrine_pluralism_pluralistic }
						}
						divide = 2
					}
				}
			}
			desc = MARRY_DIFFERENT_FAITH_REASON
		}

		modifier = { # A Recipient is more likely to agree to an alliance requested by his liege.
			add = 20
			scope:recipient = {
				target_is_liege_or_above = scope:actor
			}
			desc = LIEGE_REASON
		}

		# Military power difference: apply -1 modifier per 1000 military_power difference (absolute)
		modifier = {
			scope:recipient = {
				military_power >= scope:actor.military_power
			}
			add = {
				value = 0
				add = {
					value = scope:actor.military_power
					divide = { value = 1000 min = 1 }
				}
				subtract = {
					value = scope:recipient.military_power
					divide = { value = 1000 min = 1 }
				}
				min = -1000
				max = 100
			}
			desc = AI_MILITARY_BALANCE_REASON
		}
		modifier = {
			scope:recipient = {
				military_power < scope:actor.military_power
			}
			add = {
				value = 0
				add = {
					value = scope:recipient.military_power
					divide = { value = 1000 min = 1 }
				}
				subtract = {
					value = scope:actor.military_power
					divide = { value = 1000 min = 1 }
				}
				min = -1000
				max = 100
			}
			desc = AI_MILITARY_BALANCE_REASON
		}
		# Recipient is a Claimant to Actor's titles.
		modifier = {
			scope:recipient = {
				any_claim = {
					holder = scope:actor
				}
				NOR = {
					is_heir_of = scope:actor
					ai_greed <= -25
				}
			}
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient.ai_greed >= 25
					}
					add = ai_greed
				}
				if = {
					limit = {
						scope:recipient.house != scope:actor.house
					}
					multiply = 2
				}
			}
			desc = IS_CLAIMANT_TO_ACTORS_TITLES
		}

		# If both actor and recipient are claimants against the liege, heavily penalize acceptance
		modifier = {
			scope:actor = {
				any_claim = {
					holder = scope:actor.liege
				}
			}
			scope:recipient = {
				any_claim = {
					holder = scope:recipient.liege
				}
			}
			add = -100
			desc = CLAIM_ON_LIEGE_PRIMARY_TITLE_REASON
		}
		#Actor has claims on recipient's titles.
		modifier = {
			scope:actor = {
				any_claim = {
					holder = scope:recipient
				}
			}
			add = 25
			desc = IS_CLAIMANT_TO_RECIPIENT_TITLES
		}
		modifier = {
			scope:recipient = {
				NOT = {
					any_claim = {
						holder = scope:actor
					}
				}
			}
			scope:recipient.house = scope:actor.house
			add = 15
			desc = IS_SAME_HOUSE_REASON
		}
		modifier = {
			scope:recipient = {
				has_opinion_modifier = {
					target = scope:actor
					modifier = declared_war
				}
			}
			add = -100
			desc = DECLARED_WAR_REASON
		}

		# Don't form new alliances with people already at war.
		modifier = {
			scope:actor = {
				is_at_war = yes

				# Since vassals and lieges can't call us into wars, this doesn't matter for us if we have that relationship.
				NOR = {
					target_is_liege_or_above = scope:recipient
					target_is_vassal_or_below = scope:recipient
				}
			}
			add = -50
			desc = IS_AT_WAR_REASON
		}

		#Bonus from Tradition Astute Diplomats
		modifier = {
			scope:actor.culture = { has_cultural_parameter = facilitate_alliance_acceptance }
			add = 50 #should be in a file 00_traditions_values
			desc = TRADITION_ASTUTE_DIPLOMATS_ACCEPTANCE_MODIFIER
		}

		# The AI doesn't want to form alliances with AI vassals within its capital duchy, so it can revoke them
		modifier = {
			scope:actor = {
				is_ai = yes
				is_vassal_or_below_of = scope:recipient
				any_held_title = {
					title_tier = county
					de_jure_liege = scope:actor.primary_title.title_capital_county.de_jure_liege
				}
			}
			scope:recipient = {
				is_ai = yes
			}
			add = -5000
		}

		# Feud
		modifier = {
			add = -25
			scope:recipient = {
				house_has_feud_relation_with_trigger = { TARGET = scope:actor }
			}
			desc = MARRY_FAMILY_FEUD_REASON
		}

		# Existing Alliances
		modifier = {
			add = {
				scope:actor = {
					every_ally = {
						add = -15
					}
				}
			}
			scope:actor = {
				any_ally = {
					count >= 2
				}
			}
			NOT = {
				scope:recipient = {
					government_has_flag = government_is_clan
					is_vassal_or_below_of = scope:actor
				}
			}
			desc = EXISTING_ALLIANCES_REASON
		}

		# Existing Alliances
		modifier = {
			add = {
				scope:recipient = {
					every_ally = {
						add = -15
					}
				}
			}
			scope:recipient = {
				any_ally = {
					count >= 2
				}
			}
			NOT = {
				scope:recipient = {
					government_has_flag = government_is_clan
					is_vassal_or_below_of = scope:actor
				}
			}
			desc = THEIR_EXISTING_ALLIANCES_REASON
		}

		modifier = {
			add = intimidated_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		modifier = {
			add = intimidated_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}

		fp3_struggle_resist_allied_wars_modifier = yes

		# LOW LEGITIMACY
		modifier = {
			desc = "LOW_LEGITIMACY_REASON"
			scope:actor = {
				OR = {
					has_legitimacy_flag = reduced_alliance_acceptance
					has_legitimacy_flag = very_reduced_alliance_acceptance
					has_legitimacy_flag = massively_reduced_alliance_acceptance
				}
			}
			add = {
				value = 0
				if = {
					limit = { scope:actor = { has_legitimacy_flag = reduced_alliance_acceptance } }
					add = -25
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = very_reduced_alliance_acceptance } }
					add = -50
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = massively_reduced_alliance_acceptance } }
					add = -100
				}
			}
		}

		# HIGH LEGITIMACY
		modifier = {
			desc = "HIGH_LEGITIMACY_REASON"
			scope:actor = {
				OR = {
					has_legitimacy_flag = increased_alliance_acceptance
					has_legitimacy_flag = very_increased_alliance_acceptance
					has_legitimacy_flag = extra_increased_alliance_acceptance
				}
			}
			add = {
				value = 0
				if = {
					limit = { scope:actor = { has_legitimacy_flag = increased_alliance_acceptance } }
					add = 10
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = very_increased_alliance_acceptance } }
					add = 25
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = extra_increased_alliance_acceptance } }
					add = 50
				}
			}
		}

		# INFLUENCE
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence = yes
			add = {
				value = 10
				multiply = scope:actor.influence_level
				min = 5
			}
		}

		# TGP ALLIANCE WITH NF HOUSE HEAD
		modifier = {
			add = 750
			scope:actor = {
				is_house_head = yes
				scope:recipient.house ?= this.house
				any_held_title = { is_noble_family_title = yes }
			}
			desc = JAPANESE_HOUSE_HEAD_ALLIANCE_REASON
		}
	}

        ai_potential = {
                is_at_war = no
        }

	ai_targets = {
		ai_recipients = neighboring_rulers
		max = 10
	}

	ai_targets = {
		ai_recipients = peer_vassals
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 12
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_will_do = {
		base = 100
		modifier = {
			add = -1000
			OR = {
				AND = { scope:actor = { has_trait = loyalwarlord } scope:recipient = { has_trait = warlord } }
				AND = { scope:actor = { has_trait = warlord } scope:recipient = { has_trait = loyalwarlord } }
			}
		}
		modifier = {
			add = 75
			scope:actor = { has_trait = warlord }
			scope:recipient = { has_trait = warlord }
		}
		modifier = {
			add = 25
			scope:actor = { has_trait = loyalwarlord }
			scope:recipient = { has_trait = loyalwarlord }
		}

		# Mirror ai_accept so AI proposals follow the same score model shown to players.
		# Tier Difference 	(+/-)
		# Inheritance 		(+)
		# Opinion 			(+/-)
		# Dynasty Prestige. (+)
		# Different Faith.	(-)
		# Liege is asking 	(+)
		# Dread 			(+)
		# Power difference 	(+/-)
		# Claimants (+/-)
		# Same House (+)
		# Declared war opinion
		# Actor is at war penalty

		modifier = {
			add = 20
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			desc = CLOSE_FAMILY_REASON
		}

		modifier = {
			add = 10
			scope:recipient = {
				NOT = { is_close_family_of = scope:actor }
				is_extended_family_of = scope:actor
			}
			desc = EXTENDED_FAMILY_REASON
		}

		modifier = {
			add = -20
			scope:recipient = {
				NOT = { is_close_or_extended_family_of = scope:actor }
				any_spouse = {
					NOT = { is_close_family_of = scope:actor }
					is_extended_family_of = scope:actor
				}
			}
			desc = DISTANT_FAMILY_CONNECTION_REASON
		}

		# Tier Differences
		modifier = {
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value >= 1
				}
			}
			add = {
				value = 30
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 2
						}
					}
					add = 30
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 3
						}
					}
					add = 60
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 4
						}
					}
					add = 90
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = 5
						}
					}
					add = 120
				}
			}
			desc = RANK_DIFFERENCE_REASON
		}
		modifier = {
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value <= -1
				}
			}
			add = {
				value = -30
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -2
						}
					}
					add = -30
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -3
						}
					}
					add = -60
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -4
						}
					}
					add = -90
				}
				if = {
					limit = {
						tier_difference = {
							target = scope:recipient
							value = -5
						}
					}
					add = -120
				}
			}
			desc = RANK_DIFFERENCE_REASON
		}
		modifier = {
			scope:recipient = {
				has_relation_lover = scope:actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_LOVERS
		}
		modifier = {
			scope:recipient = {
				has_relation_friend = scope:actor
			}
			add = {
				value = 25
			}
			desc = WE_ARE_FRIENDS
		}
		modifier = {
			scope:recipient = {
				is_heir_of = scope:actor
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value > 0
				}
			}
			add = {
				value = 10
				if = {
					limit = {
						scope:actor = { player_heir = scope:recipient }
					}
					add = 10
				}
			}
			desc = IS_HEIR_REASON
		}
		opinion_modifier = { # More likely to accept if Recipient likes the Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.25
			min = 0
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Less likely to accept if Recipient dislikes the Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			max = 0
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = loyal
			}
			desc = INTERACTION_LOYAL
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = trusting
			}
			desc = INTERACTION_TRUSTING
		}

		modifier = {
			add = 5
			scope:recipient = {
				has_trait = craven
			}
			desc = INTERACTION_CRAVEN
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = paranoid
			}
			desc = INTERACTION_PARANOID
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = arrogant
			}
			desc = INTERACTION_ARROGANT
		}

		modifier = {
			add = -20
			scope:recipient = {
				has_trait = ambitious
			}
			desc = INTERACTION_AMBITIOUS
		}

		modifier = {
			add = -40
			scope:recipient = {
				has_trait = disloyal
			}
			desc = INTERACTION_DISLOYAL
		}

		modifier = {
			add = -10
			scope:recipient = {
				has_trait = fickle
			}
			desc = INTERACTION_FICKLE
		}

		# Rivalry
		modifier = { # Say no to rivals
			add = -100
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			desc = "ACTOR_RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to nemesis
			add = -300
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
			desc = "ACTOR_NEMESIS_TO_ME_REASON"
		}

		# Dynasty Prestige Levels
		modifier = {
			add = -5
			desc = AI_DYNASTY_PRESTIGE_REASON
			scope:actor = { has_dynasty = yes }
			scope:actor.dynasty != scope:recipient.dynasty
			scope:actor.dynasty = { dynasty_prestige_level = 0 }
		}
		modifier = {
			desc = AI_DYNASTY_PRESTIGE_REASON
			scope:actor = { has_dynasty = yes }
			scope:actor.dynasty != scope:recipient.dynasty
			scope:actor.dynasty = { dynasty_prestige_level >= 2 }
			add = {
				value = 10
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 3 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 4 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 5 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 6 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 7 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 8 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 9 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 10 }
					}
					add = 5
				}
			}
		}
		modifier = { #Faith compatibility
			scope:recipient.faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value > faith_fully_accepted_level
				}
			}
			NOT = {
				scope:recipient.ai_zeal <= -50
			}
			add = {
				value = -10
				if = {
					limit = {
						# Exempt certain struggle phases.
						NOT = { is_struggle_parameter_active_interfaith_marriages_available_between_involved_characters_trigger = yes }
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_astray_level
								}
							}
						}
						subtract = 20
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_hostile_level
								}
							}
						}
						subtract = 20
					}
					if = {
						limit = {
							scope:recipient.faith = {
								faith_hostility_level = {
									target = scope:actor.faith
									value >= faith_evil_level
								}
							}
						}
						subtract = 50
					}
					if = {
						limit = {
							scope:recipient.ai_zeal <= -25
						}
						divide = 2
					}
					else_if = {
						limit = {
							scope:recipient.ai_zeal >= 50
						}
						multiply = 2
					}
					if = {
						limit = {
							scope:recipient.faith = { has_doctrine = doctrine_pluralism_pluralistic }
						}
						divide = 2
					}
				}
			}
			desc = MARRY_DIFFERENT_FAITH_REASON
		}

		modifier = { # A Recipient is more likely to agree to an alliance requested by his liege.
			add = 20
			scope:recipient = {
				target_is_liege_or_above = scope:actor
			}
			desc = LIEGE_REASON
		}

		# Military power difference: apply -1 modifier per 1000 military_power difference (absolute)
		modifier = {
			scope:recipient = {
				military_power >= scope:actor.military_power
			}
			add = {
				value = 0
				add = {
					value = scope:actor.military_power
					divide = { value = 1000 min = 1 }
				}
				subtract = {
					value = scope:recipient.military_power
					divide = { value = 1000 min = 1 }
				}
				min = -1000
				max = 100
			}
			desc = AI_MILITARY_BALANCE_REASON
		}
		modifier = {
			scope:recipient = {
				military_power < scope:actor.military_power
			}
			add = {
				value = 0
				add = {
					value = scope:recipient.military_power
					divide = { value = 1000 min = 1 }
				}
				subtract = {
					value = scope:actor.military_power
					divide = { value = 1000 min = 1 }
				}
				min = -1000
				max = 100
			}
			desc = AI_MILITARY_BALANCE_REASON
		}
		# Recipient is a Claimant to Actor's titles.
		modifier = {
			scope:recipient = {
				any_claim = {
					holder = scope:actor
				}
				NOR = {
					is_heir_of = scope:actor
					ai_greed <= -25
				}
			}
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient.ai_greed >= 25
					}
					add = ai_greed
				}
				if = {
					limit = {
						scope:recipient.house != scope:actor.house
					}
					multiply = 2
				}
			}
			desc = IS_CLAIMANT_TO_ACTORS_TITLES
		}

		# If both actor and recipient are claimants against the liege, heavily penalize acceptance
		modifier = {
			scope:actor = {
				any_claim = {
					holder = scope:actor.liege
				}
			}
			scope:recipient = {
				any_claim = {
					holder = scope:recipient.liege
				}
			}
			add = -100
			desc = CLAIM_ON_LIEGE_PRIMARY_TITLE_REASON
		}
		#Actor has claims on recipient's titles.
		modifier = {
			scope:actor = {
				any_claim = {
					holder = scope:recipient
				}
			}
			add = 25
			desc = IS_CLAIMANT_TO_RECIPIENT_TITLES
		}
		modifier = {
			scope:recipient = {
				NOT = {
					any_claim = {
						holder = scope:actor
					}
				}
			}
			scope:recipient.house = scope:actor.house
			add = 15
			desc = IS_SAME_HOUSE_REASON
		}
		modifier = {
			scope:recipient = {
				has_opinion_modifier = {
					target = scope:actor
					modifier = declared_war
				}
			}
			add = -100
			desc = DECLARED_WAR_REASON
		}

		# Don't form new alliances with people already at war.
		modifier = {
			scope:actor = {
				is_at_war = yes

				# Since vassals and lieges can't call us into wars, this doesn't matter for us if we have that relationship.
				NOR = {
					target_is_liege_or_above = scope:recipient
					target_is_vassal_or_below = scope:recipient
				}
			}
			add = -50
			desc = IS_AT_WAR_REASON
		}

		#Bonus from Tradition Astute Diplomats
		modifier = {
			scope:actor.culture = { has_cultural_parameter = facilitate_alliance_acceptance }
			add = 50 #should be in a file 00_traditions_values
			desc = TRADITION_ASTUTE_DIPLOMATS_ACCEPTANCE_MODIFIER
		}

		# The AI doesn't want to form alliances with AI vassals within its capital duchy, so it can revoke them
		modifier = {
			scope:actor = {
				is_ai = yes
				is_vassal_or_below_of = scope:recipient
				any_held_title = {
					title_tier = county
					de_jure_liege = scope:actor.primary_title.title_capital_county.de_jure_liege
				}
			}
			scope:recipient = {
				is_ai = yes
			}
			add = -5000
		}

		# Feud
		modifier = {
			add = -25
			scope:recipient = {
				house_has_feud_relation_with_trigger = { TARGET = scope:actor }
			}
			desc = MARRY_FAMILY_FEUD_REASON
		}

		# Existing Alliances
		modifier = {
			add = {
				scope:actor = {
					every_ally = {
						add = -15
					}
				}
			}
			scope:actor = {
				any_ally = {
					count >= 2
				}
			}
			NOT = {
				scope:recipient = {
					government_has_flag = government_is_clan
					is_vassal_or_below_of = scope:actor
				}
			}
			desc = EXISTING_ALLIANCES_REASON
		}

		# Existing Alliances
		modifier = {
			add = {
				scope:recipient = {
					every_ally = {
						add = -15
					}
				}
			}
			scope:recipient = {
				any_ally = {
					count >= 2
				}
			}
			NOT = {
				scope:recipient = {
					government_has_flag = government_is_clan
					is_vassal_or_below_of = scope:actor
				}
			}
			desc = THEIR_EXISTING_ALLIANCES_REASON
		}

		modifier = {
			add = intimidated_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		modifier = {
			add = intimidated_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}

		fp3_struggle_resist_allied_wars_modifier = yes

		# LOW LEGITIMACY
		modifier = {
			desc = "LOW_LEGITIMACY_REASON"
			scope:actor = {
				OR = {
					has_legitimacy_flag = reduced_alliance_acceptance
					has_legitimacy_flag = very_reduced_alliance_acceptance
					has_legitimacy_flag = massively_reduced_alliance_acceptance
				}
			}
			add = {
				value = 0
				if = {
					limit = { scope:actor = { has_legitimacy_flag = reduced_alliance_acceptance } }
					add = -25
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = very_reduced_alliance_acceptance } }
					add = -50
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = massively_reduced_alliance_acceptance } }
					add = -100
				}
			}
		}

		# HIGH LEGITIMACY
		modifier = {
			desc = "HIGH_LEGITIMACY_REASON"
			scope:actor = {
				OR = {
					has_legitimacy_flag = increased_alliance_acceptance
					has_legitimacy_flag = very_increased_alliance_acceptance
					has_legitimacy_flag = extra_increased_alliance_acceptance
				}
			}
			add = {
				value = 0
				if = {
					limit = { scope:actor = { has_legitimacy_flag = increased_alliance_acceptance } }
					add = 10
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = very_increased_alliance_acceptance } }
					add = 25
				}
				if = {
					limit = { scope:actor = { has_legitimacy_flag = extra_increased_alliance_acceptance } }
					add = 50
				}
			}
		}

		# INFLUENCE
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence = yes
			add = {
				value = 10
				multiply = scope:actor.influence_level
				min = 5
			}
		}

		# TGP ALLIANCE WITH NF HOUSE HEAD
		modifier = {
			add = 750
			scope:actor = {
				is_house_head = yes
				scope:recipient.house ?= this.house
				any_held_title = { is_noble_family_title = yes }
			}
			desc = JAPANESE_HOUSE_HEAD_ALLIANCE_REASON
		}
	}
}
