﻿call_ally_interaction = {
	common_interaction = yes
	interface_priority = 69
	category = interaction_category_diplomacy
	desc = call_ally_interaction_desc
	interface = call_ally
	special_interaction = call_ally_interaction
	icon = alliance
	notification_text = CALL_ALLY_NOTIFICATION
	ai_min_reply_days = 2
	ai_max_reply_days = 5
	greeting = positive
	popup_on_receive = yes
	pause_on_receive = yes
	is_shown = {
		scope:actor = {
			is_at_war = yes
			trigger_if = {
				# Avoid calling Adventurers without armies or landed rulers who have been devastated
				limit = {
					is_ai = yes
				}
				scope:recipient.current_military_strength >= 100
			}
			# max_military_strength > 200
			trigger_if = {
				limit = {
					liege = scope:recipient					# The recipient is actor's liege
					is_tributary_of = liege					# The recipient is actor's suzerain
				}
				subject_contract_has_flag = vassal_contract_liege_forced_war_override
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_tributary_of = scope:actor
						NOT = {
							is_allied_to = scope:actor
						}
					}
				}
				piety >= 50
				has_realm_law_flag = can_call_tributaries_for_piety
			}
		}
		scope:recipient = {
			OR = {
				is_allied_to = scope:actor
				AND = {
					this ?= scope:actor.diarch
					scope:actor = {
						any_character_war = {
							diarch_callable_in_internal_war_trigger = yes
						}
					}
				}
				scope:actor = {
					is_vassal_of = prev
					subject_contract_has_flag = vassal_contract_liege_forced_war_override
				}
				scope:actor = {
					is_tributary_of = prev
					subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
				}
				AND = {
					is_tributary_of = scope:actor
					scope:actor = {
						piety >= 50
						has_realm_law_flag = can_call_tributaries_for_piety
					}
				}
			}
			# max_military_strength > 200
		}
		#scope:actor = { #If you can call them as a House Member then do that
		#	NOT = {
		#		is_character_interaction_valid = {
		#			recipient = scope:recipient
		#			interaction = call_house_member_to_war_interaction
		#		}
		#	}
		#}
	}
	has_valid_target = {
		exists = scope:target
	}
	has_valid_target_showing_failures_only = {
		scope:target = {
			is_war_leader = scope:actor
		}
		scope:actor = {
			trigger_if = {
				limit = {
					# if you're invoking your suzerain's defensive guarantee, it has to be for a defensive war
					NOT = {
						is_allied_to = scope:recipient
					}
					suzerain = scope:recipient
					subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
				}
				scope:target = {
					primary_defender = scope:actor
				}
			}
			trigger_if = {
				limit = {
					scope:target = {
						OR = {
							using_cb = undirected_great_holy_war
							using_cb = directed_great_holy_war
						}
					}
				}
				trigger_if = {
					limit = {
						this = scope:target.casus_belli.primary_attacker
					}
					#if it's a religious war the recipient has to be of the same faith
					custom_description = {
						text = is_of_wrong_faith_for_holy_war
						subject = scope:actor
						object = scope:recipient
						faith = scope:recipient.faith
					}
				}
				trigger_else = {
					custom_description = {
						text = is_of_attacker_faith_in_holy_war
						subject = scope:actor
						object = scope:recipient
						scope:target = {
							NOT = {
								primary_attacker.faith = scope:recipient.faith
							}
						}
					}
				}
			}
		}
		# MIV change
		#joiner_not_already_in_another_war_with_any_target_war_participants_trigger = {
		#	WARRIOR = scope:actor
		#	JOINER = scope:recipient
		#}
	}
	is_valid_showing_failures_only = {
		scope:recipient = {
			is_ruler = yes
			# Only rulers of a high enough rank may call a hegemon into wars
			custom_tooltip = {
				text = too_low_rank_to_call_hegemon
				trigger_if = {
					limit = {
						highest_held_title_tier = tier_hegemony
					}
					scope:actor = {
						highest_held_title_tier >= tier_empire
					}
				}
			}
		}
		# Only War Leaders can call allies
		scope:actor = {
			custom_description = {
				text = must_be_war_leader
				any_character_war = {
					is_war_leader = scope:actor
				}
			}
		}
		# Cannot call the same character multiple times
		scope:actor = {
			custom_description = {
				text = cannot_call_same_character_multiple_times
				subject = scope:recipient
				any_character_war = {
					ALL_FALSE = {
						was_called = scope:recipient
						is_participant = scope:recipient
					}
				}
			}
		}
		can_potentially_call_ally_trigger = {
			WARRIOR = scope:actor
			JOINER = scope:recipient
		}
		# Cannot call a character of the "wrong" religion to a Great Holy War
		scope:actor = {
			trigger_if = {
				limit = {
					NOT = {
						faith = scope:recipient.faith
					}
				}
				custom_description = {
					text = is_of_wrong_faith_for_holy_war
					subject = scope:actor
					object = scope:recipient
					any_character_war = {
						NOR = {
							using_cb = undirected_great_holy_war
							using_cb = directed_great_holy_war
						}
					}
				}
			}
		}
	}
	can_be_picked = {
		OR = {
			has_game_rule = call_allied_vassals_enabled
			can_join_war_liege_vassal_check_trigger = {
				WARRIOR = scope:actor
				JOINER = scope:recipient
			}
		}
		OR = {
			has_game_rule = traitor_vassals_miv_enabled
			AND = {
				has_game_rule = traitor_vassals_miv_disabled
				NOT = {
					OR = {
						scope:target.casus_belli.primary_defender = {
							is_vassal_of = scope:recipient
						}
						scope:target.casus_belli.primary_attacker = {
							is_vassal_of = scope:recipient
						}
					}
				}
			}
		}
		scope:target = {
			is_war_leader = scope:actor
			# not already in target war
			custom_description = {
				text = join_war_interaction_already_in_target_war
				NOR = {
					any_war_attacker = {
						this = scope:recipient
					}
					any_war_defender = {
						this = scope:recipient
					}
				}
			}
			# Diarchs can only be called to internal wars.
			custom_tooltip = {
				text = call_ally_interaction.tt.diarchs_called_to_internal_wars
				trigger_if = {
					limit = {
						scope:recipient ?= scope:actor.diarch
					}
					primary_defender = scope:actor
					diarch_callable_in_internal_war_trigger = yes
				}
			}
		}
		# MIV: You cannot call someone who's already at war with the target (vanilla bug fix)
		custom_description = {
			text = "is_already_war_enemy_of_primary_enemy"
			subject = scope:recipient
			object = scope:target.casus_belli.primary_attacker
			NOT = {
				scope:target.casus_belli.primary_attacker = {
					is_at_war_with = scope:recipient
				}
			}
		}
		custom_description = {
			text = "is_already_war_enemy_of_primary_enemy"
			subject = scope:recipient
			object = scope:target.casus_belli.primary_defender
			NOT = {
				scope:target.casus_belli.primary_defender = {
					is_at_war_with = scope:recipient
				}
			}
		}
		# You cannot call a liege against their own vassal
		custom_description = {
			text = "basic_ally_can_join_because_liege_or_vassals"
			subject = scope:recipient
			NAND = {
				scope:target.casus_belli.primary_attacker = {
					is_vassal_of = scope:recipient
				}
				scope:target.casus_belli.primary_defender = {
					is_vassal_of = scope:recipient
				}
			}
		}
		# You cannot call a suzerain against their own tributary
		trigger_if = {
			limit = {
				scope:target.casus_belli.primary_defender = scope:actor
				scope:target.casus_belli.primary_attacker = {
					is_tributary_of_suzerain_or_above = scope:recipient
				}
			}
			NOT = {
				scope:target.casus_belli.primary_attacker = {
					is_tributary_of_suzerain_or_above = scope:recipient
				}
			}
		}
		trigger_else_if = {
			limit = {
				scope:target.casus_belli.primary_attacker = scope:actor
				scope:target.casus_belli.primary_defender = {
					is_tributary_of_suzerain_or_above = scope:recipient
				}
			}
			NOT = {
				scope:target.casus_belli.primary_defender = {
					is_tributary_of_suzerain_or_above = scope:recipient
				}
			}
		}
		trigger_else = {
		}
		# You cannot call a tributary against their suzerain
		trigger_if = {
			limit = {
				scope:target.casus_belli.primary_defender = scope:actor
				scope:recipient = {
					is_tributary_of_suzerain_or_above = scope:target.casus_belli.primary_attacker
				}
			}
			NOT = {
				scope:recipient = {
					is_tributary_of_suzerain_or_above = scope:target.casus_belli.primary_attacker
				}
			}
		}
		trigger_else_if = {
			limit = {
				scope:target.casus_belli.primary_attacker = scope:actor
				scope:recipient = {
					is_tributary_of_suzerain_or_above = scope:target.casus_belli.primary_defender
				}
			}
			NOT = {
				scope:recipient = {
					is_tributary_of_suzerain_or_above = scope:target.casus_belli.primary_defender
				}
			}
		}
		trigger_else = {
		}
		trigger_if = {
			limit = {
				NOT = {
					scope:target.primary_defender = scope:actor
				}
			}
			scope:actor = {
				prestige > 0
			}
		}
	}
	on_auto_accept = {
		scope:recipient = {
			trigger_event = call_ally.0001
		}
		scope:target = {
			if = {
				limit = {
					is_religious_war = yes
					scope:recipient = {
						any_active_accolade = {
							accolade_parameter = acclaimed_knight_piety_from_battle
						}
					}
				}
				scope:recipient = {
					add_piety = miniscule_piety_gain
				}
			}
			if = {
				limit = {
					is_religious_war = yes
					scope:recipient = {
						any_active_accolade = {
							accolade_parameter = acclaimed_knight_piety_from_battle_high
						}
					}
				}
				scope:recipient = {
					add_piety = minor_piety_gain
				}
			}
			# oathbreakers
			if = {
				limit = {
					has_game_rule = miv_oathbreakers_enabled
					OR = {
						AND = {
							scope:target.casus_belli.primary_defender = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_attacker
							}
						}
						AND = {
							scope:target.casus_belli.primary_attacker = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_defender
							}
						}
					}
				}
				if = {
					limit = {
						AND = {
							scope:target.casus_belli.primary_defender = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_attacker
							}
						}
					}
					scope:target.casus_belli.primary_attacker = {
						add_opinion = {
							target = scope:recipient
							modifier = miv_oathbreaker
						}
					}
					every_war_participant = {
						limit = {
							is_ai = no
						}
						hidden_effect = {
							scope:recipient = {
								save_scope_as = VASSAL
							}
							send_interface_toast = {
								type = msg_war_oathbreaker
								title = miv_oathbreaker_defects
								left_icon = scope:VASSAL
								custom_tooltip = interactive_oathbreaker_notification
							}
						}
					}
				}
				else_if = {
					limit = {
						AND = {
							scope:target.casus_belli.primary_attacker = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_defender
							}
						}
					}
					scope:target.casus_belli.primary_defender = {
						add_opinion = {
							target = scope:recipient
							modifier = miv_oathbreaker
						}
					}
					every_war_participant = {
						limit = {
							is_ai = no
						}
						hidden_effect = {
							scope:recipient = {
								save_scope_as = VASSAL
							}
							send_interface_toast = {
								type = msg_war_oathbreaker
								title = miv_oathbreaker_defects
								left_icon = scope:VASSAL
								custom_tooltip = interactive_oathbreaker_notification
							}
						}
					}
				}
			}
			# ally exhaustion
			if = {
				limit = {
					NOT = {
						has_game_rule = ally_exhaustion_miv_disabled
					}
					scope:actor = {
						is_ai = no
					}
				}
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = ally_exhaustion_opinion
						opinion = -10
					}
				}
			}
		}
	}
	on_accept = {
		call_ally_interaction_effect = yes
		save_scope_value_as = {
			name = call_ally_interaction
			value = yes
		}
		scope:actor = {
			hidden_effect = {
				#To nudge friendship
				if = {
					limit = {
						NOR = {
							has_relation_friend = scope:recipient
							has_relation_potential_friend = scope:recipient
						}
					}
					set_relation_potential_friend = scope:recipient
				}
			}
			trigger_event = call_ally.0100
		}
		scope:target = {
			if = {
				limit = {
					is_religious_war = yes
					scope:recipient = {
						any_active_accolade = {
							accolade_parameter = acclaimed_knight_piety_from_battle
						}
					}
				}
				scope:recipient = {
					add_piety = minor_piety_gain
				}
			}
			if = {
				limit = {
					is_religious_war = yes
					scope:recipient = {
						any_active_accolade = {
							accolade_parameter = acclaimed_knight_piety_from_battle_high
						}
					}
				}
				scope:recipient = {
					add_piety = medium_piety_gain
				}
			}
			# oathbreakers
			if = {
				limit = {
					has_game_rule = miv_oathbreakers_enabled
					OR = {
						AND = {
							scope:target.casus_belli.primary_defender = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_attacker
							}
						}
						AND = {
							scope:target.casus_belli.primary_attacker = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_defender
							}
						}
					}
				}
				if = {
					limit = {
						AND = {
							scope:target.casus_belli.primary_defender = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_attacker
							}
						}
					}
					scope:target.casus_belli.primary_attacker = {
						add_opinion = {
							target = scope:recipient
							modifier = miv_oathbreaker
						}
					}
					every_war_participant = {
						limit = {
							is_ai = no
						}
						hidden_effect = {
							scope:recipient = {
								save_scope_as = VASSAL
							}
							send_interface_toast = {
								type = msg_war_oathbreaker
								title = miv_oathbreaker_defects
								left_icon = scope:VASSAL
								custom_tooltip = interactive_oathbreaker_notification
							}
						}
					}
				}
				else_if = {
					limit = {
						AND = {
							scope:target.casus_belli.primary_attacker = scope:actor
							scope:recipient = {
								is_vassal_or_below_of = scope:target.casus_belli.primary_defender
							}
						}
					}
					scope:target.casus_belli.primary_defender = {
						add_opinion = {
							target = scope:recipient
							modifier = miv_oathbreaker
						}
					}
					every_war_participant = {
						limit = {
							is_ai = no
						}
						hidden_effect = {
							scope:recipient = {
								save_scope_as = VASSAL
							}
							send_interface_toast = {
								type = msg_war_oathbreaker
								title = miv_oathbreaker_defects
								left_icon = scope:VASSAL
								custom_tooltip = interactive_oathbreaker_notification
							}
						}
					}
				}
			}
			# ally exhaustion
			if = {
				limit = {
					NOT = {
						has_game_rule = ally_exhaustion_miv_disabled
					}
					scope:actor = {
						is_ai = no
					}
				}
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = ally_exhaustion_opinion
						opinion = -10
					}
				}
			}
		}
	}
	on_decline = {
		#The war could theoretically end on the day the decline is sent
		if = {
			limit = {
				exists = scope:target
			}
			scope:target = {
				if = {
					limit = {
						is_attacker = scope:actor
					}
					scope:actor = {
						add_opinion = {
							modifier = rejected_call_to_offensive_war
							target = scope:recipient
						}
					}
					scope:recipient = {
						#Why should Mandalas care about bickering tributaries in an offensive war
						if = {
							limit = {
								NOT = {
									government_has_flag = government_is_mandala
								}
							}
							add_prestige_experience = major_prestige_loss
						}
					}
				}
				else = {
					scope:actor = {
						add_opinion = {
							modifier = rejected_call_to_defensive_war
							target = scope:recipient
						}
					}
					scope:recipient = {
						if = {
							limit = {
								government_has_flag = government_is_mandala
							}
							add_prestige_experience = major_prestige_loss
							add_piety_level = -1
						}
						else = {
							add_prestige_experience = massive_prestige_loss
						}
					}
				}
				if = {
					limit = {
						scope:actor = {
							has_relation_blood_brother = scope:recipient
						}
					}
					scope:recipient = {
						add_piety_experience = massive_piety_loss
						add_character_modifier = {
							modifier = broke_blood_brotherhood_modifier
							desc = broke_blood_brotherhood_modifier_acceptance_tt
							years = 25
						}
						remove_relation_blood_brother = scope:actor
					}
					scope:actor = {
						set_relation_rival = {
							target = scope:recipient
							reason = rival_blood_brother_refused_call_reason
						}
					}
				}
				# Nomad Vassals and Tributaries stop being Obedient if they have the Liege War Support / Suzerain Defensive Guarantee contract right
				if = {
					limit = {
						scope:recipient = scope:actor.obedience_target
						scope:actor = {
							OR = {
								subject_contract_has_flag = vassal_contract_liege_forced_war_override
								subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
							}
						}
					}
					scope:actor = {
						set_variable = {
							name = not_obedient_declined_call
							value = scope:recipient
							years = 5
						}
					}
				}
				if = {
					limit = {
						scope:recipient = scope:actor.suzerain
						is_defender = scope:actor
						scope:actor = {
							subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
						}
					}
					scope:actor = {
						end_tributary = yes
					}
				}
				hidden_effect = {
					if = {
						limit = {
							NOT = {
								was_called = scope:recipient
							}
						}
						set_called_to = scope:recipient
					}
				}
			}
			scope:actor = {
				trigger_event = call_ally.0101
			}
			# If we're a clan this interaction affects unity
			refuse_call_to_arms_add_clan_unity_effect = yes
			scope:recipient = {
				if = {
					limit = {
						exists = house
						is_house_head = yes
						exists = scope:actor.house
					}
					house = {
						change_house_relation_effect = {
							HOUSE = scope:actor.house
							VALUE = house_relation_damage_medium_value
							REASON = ally_call_ignored
							CHAR = scope:recipient
							TARGET_CHAR = scope:actor
							TITLE = scope:dummy_gender
						}
					}
				}
			}
		}
	}
	auto_accept = {
		OR = {
			# Always accept a call from a Spouse
			custom_description = {
				text = "recipient_is_spouse"
				subject = scope:actor
				object = scope:recipient
				scope:recipient = {
					is_spouse_of = scope:actor
					is_ai = yes
				}
			}
			# Always accept a call from the Heir
			custom_description = {
				text = "is_recipients_player_heir"
				subject = scope:actor
				object = scope:recipient
				exists = scope:recipient.player_heir
				scope:recipient = {
					player_heir = scope:actor
					is_close_or_extended_family_of = scope:actor					# Only for family
					is_ai = yes
				}
			}
			# Always accept a call from the one you are heir of
			custom_description = {
				text = "is_player_heir"
				subject = scope:recipient
				object = scope:actor
				exists = scope:actor.player_heir
				scope:actor.player_heir = scope:recipient
				scope:actor = {
					# Shouldn't be able to force your liege to join just because you've not got any family...
					is_close_or_extended_family_of = scope:recipient
				}
				scope:recipient = {
					is_ai = yes
				}
			}
		}
	}
	ai_accept = {
		base = 20
		modifier = {
			# Conquerors do not help anyone but themselves
			add = -1000
			desc = NO_FRIVOLOUS_ACTIVITIES_REASON
			scope:recipient = {
				has_variable = conqueror
			}
		}
		modifier = {
			# Refuse call to conflicts of little benefit
			add = -1000
			desc = WONT_FIGHT_MEANINGLESS_REASON
			trigger_if = {
				limit = {
					exists = scope:target
				}
				scope:target = {
					using_cb = fp2_border_raid
				}
				scope:recipient = {
					# Unless they like going on raids
					NOR = {
						has_trait = viking
						has_trait = reaver
					}
				}
			}
			trigger_else = {
				always = no
			}
		}
		modifier = {
			# Refuse call against Heir
			add = -1000
			exists = scope:recipient.player_heir
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				scope:target.casus_belli.primary_attacker = scope:recipient.player_heir
			}
			trigger_else = {
				scope:target.casus_belli.primary_defender = scope:recipient.player_heir
			}
			desc = WONT_FIGHT_HEIR_REASON
		}
		modifier = {
			# Refuse call against Spouse
			add = -1000
			scope:recipient = {
				trigger_if = {
					limit = {
						scope:target.casus_belli.primary_defender = scope:actor
					}
					any_spouse = {
						this = scope:target.casus_belli.primary_attacker
					}
				}
				trigger_else = {
					any_spouse = {
						this = scope:target.casus_belli.primary_defender
					}
				}
			}
			desc = WONT_FIGHT_SPOUSE_REASON
		}
		modifier = {
			# Refuse call against Suzerain if Obedient
			add = -1000
			trigger_if = {
				limit = {
					exists = scope:recipient.suzerain
					trigger_if = {
						limit = {
							scope:target.casus_belli.primary_defender = scope:actor
						}
						scope:recipient.suzerain = scope:target.casus_belli.primary_attacker
					}
					trigger_else = {
						scope:recipient.suzerain = scope:target.casus_belli.primary_defender
					}
					scope:recipient = {
						exists = obedience_target
						is_obedient = yes
					}
				}
			}
			trigger_else = {
				always = no
			}
			desc = WONT_FIGHT_OBEDIENT_REASON
		}
		opinion_modifier = {
			# Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		# Honor factor
		ai_value_modifier = {
			ai_honor = 1
			min = -25			# MIV: from 0
			max = 25			# MIV: from 100
		}
		modifier = {
			# Tends to join defensive wars
			add = 25			# MIV: from 50
			scope:target.casus_belli.primary_defender = scope:actor
			desc = DEFENSIVE_WAR_REASON
		}
		modifier = {
			# Same language
			add = 5
			desc = speaks_same_language_interaction_reason
			trigger = {
				scope:actor = {
					knows_language_of_culture = scope:recipient.culture
				}
			}
		}
		modifier = {
			# Shared Court Language (non-spoken)
			add = 10
			desc = foreign_realm_court_language_non_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					has_dlc_feature = royal_court
					NOT = {
						knows_court_language_of = this
					}
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = {
							# You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
		modifier = {
			# Shared Court Language (spoken)
			add = 30
			desc = foreign_realm_court_language_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					has_dlc_feature = royal_court
					knows_court_language_of = this
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = {
							# You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = {
						# The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
		modifier = {
			# Serious diarchs wish to support their liege
			add = 50
			desc = ENTRENCHED_REGENT_WILL_SUPPORT_LIEGE
			trigger_if = {
				limit = {
					scope:recipient ?= scope:actor.diarch
				}
				scope:actor = {
					has_diarchy_parameter = diarchy_type_is_entrenched_regency
				}
			}
			trigger_else = {
				always = no
			}
		}
		compare_modifier = {
			# Likes fighting infidels
			trigger = {
				scope:recipient.faith = scope:actor.faith
				OR = {
					AND = {
						scope:target.casus_belli.primary_attacker = {
							this = scope:actor
							faith = {
								faith_hostility_level = {
									target = scope:target.casus_belli.primary_defender.faith
									value >= religious_cb_enabled_hostility_level
								}
							}
						}
					}
					AND = {
						scope:target.casus_belli.primary_defender = {
							this = scope:actor
							faith = {
								faith_hostility_level = {
									target = scope:target.casus_belli.primary_defender.faith
									value >= religious_cb_enabled_hostility_level
								}
							}
						}
					}
				}
			}
			target = scope:recipient
			value = ai_zeal
			desc = "ZEAL_AGAINST_INFIDELS"
			min = 0
			multiplier = 0.5
		}
		modifier = {
			# Reluctant to join against Liege (Oathbreakers)
			add = -40
			has_game_rule = miv_oathbreakers_enabled
			scope:target.casus_belli.primary_defender = scope:actor
			is_vassal_or_below_of = scope:target.casus_belli.primary_attacker
			desc = WILL_BECOME_OATHBREAKER
		}
		modifier = {
			# Reluctant to join against Liege (Oathbreakers)
			add = -40
			has_game_rule = miv_oathbreakers_enabled
			scope:target.casus_belli.primary_attacker = scope:actor
			is_vassal_or_below_of = scope:target.casus_belli.primary_defender
			desc = WILL_BECOME_OATHBREAKER
		}
		modifier = {
			# Reluctant to attack another ally
			add = -50
			scope:target.casus_belli.primary_attacker = scope:actor
			scope:recipient = {
				is_allied_to = scope:target.casus_belli.primary_defender
			}
			desc = ATTACK_ON_ALLY_REASON
		}
		modifier = {
			# Reluctant to defend against another ally
			add = -25
			scope:target.casus_belli.primary_defender = scope:actor
			scope:recipient = {
				is_allied_to = scope:target.casus_belli.primary_attacker
			}
			desc = WAR_WITH_ALLY_REASON
		}
		modifier = {
			# Reluctant to join wars against religious brethren.
			add = -50
			NOT = {
				scope:recipient.faith = scope:actor.faith
			}
			scope:target.casus_belli.primary_attacker = scope:actor
			scope:target.casus_belli.primary_defender.faith = scope:recipient.faith
			scope:target.casus_belli.war = {
				OR = {
					using_cb = minor_religious_war
					using_cb = religious_war
					using_cb = major_religious_war
					using_cb = undirected_great_holy_war
					using_cb = directed_great_holy_war
				}
			}
			desc = WONT_ATTACK_RELIGIOUS_BRETHREN_REASON
		}
		modifier = {
			# Reluctant to join against Friends
			add = -50
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				has_relation_friend = scope:target.casus_belli.primary_attacker
			}
			trigger_else = {
				has_relation_friend = scope:target.casus_belli.primary_defender
			}
			desc = WONT_FIGHT_FRIEND
		}
		modifier = {
			# Reluctant to join against Best Friends
			add = -100
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				has_relation_best_friend = scope:target.casus_belli.primary_attacker
			}
			trigger_else = {
				has_relation_best_friend = scope:target.casus_belli.primary_defender
			}
			desc = WONT_FIGHT_BEST_FRIEND
		}
		modifier = {
			# Reluctant to join against Lovers
			add = -100
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				has_relation_lover = scope:target.casus_belli.primary_attacker
			}
			trigger_else = {
				has_relation_lover = scope:target.casus_belli.primary_defender
			}
			desc = WONT_FIGHT_LOVER
		}
		modifier = {
			# Reluctant to join against Soulmate
			add = -200
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				has_relation_soulmate = scope:target.casus_belli.primary_attacker
			}
			trigger_else = {
				has_relation_soulmate = scope:target.casus_belli.primary_defender
			}
			desc = WONT_FIGHT_SOULMATE
		}
		modifier = {
			# Reluctant to join tributaries
			add = -200
			scope:actor = {
				is_tributary_of = scope:recipient
			}
			scope:recipient = {
				NOR = {
					has_relation_lover = scope:actor
					has_relation_friend = scope:actor
					is_allied_to = scope:actor
					#subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
					scope:actor = {
						subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
					}
				}
			}
			desc = WONT_FIGHT_MEANINGLESS_REASON
		}
		modifier = {
			# Refuse call for hostages' safety
			any_home_court_hostage = {
				warden = {
					OR = {
						is_at_war_with = scope:actor
						any_ally = {
							is_at_war_with = scope:actor
						}
					}
				}
			}
			add = {
				value = 0
				every_home_court_hostage = {
					limit = {
						warden = {
							OR = {
								is_at_war_with = scope:actor
								any_ally = {
									is_at_war_with = scope:actor
								}
							}
						}
					}
					subtract = call_to_arms_hostage_value
				}
				multiply = 0.25
			}
			desc = HOSTAGE_ENEMY_CALL_TO_ARMS_REASON
		}
		fp3_struggle_resist_allied_wars_modifier = yes
	}
	# Score above 0 means the AI will call this ally. Note that DESIRED_WAR_SIDE_STRENGTH still applies and can prevent calling the ally
	ai_will_do = {
		base = 100
		modifier = {
			# If the player is at war, do not bother them with offensive calls
			scope:target.casus_belli.primary_attacker = scope:actor
			scope:recipient = {
				is_ai = no
				any_character_war = {
					primary_defender = scope:recipient
				}
			}
			factor = 0
		}
		modifier = {
			# Don't call players in against their heirs (they wouldn't accept the reverse situation... don't be a hypocrite)
			exists = scope:recipient.player_heir
			scope:recipient = {
				is_ai = no
			}
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				scope:target.casus_belli.primary_attacker = scope:recipient.player_heir
			}
			trigger_else = {
				scope:target.casus_belli.primary_defender = scope:recipient.player_heir
			}
			factor = 0
		}
		modifier = {
			# Same with spouses
			scope:recipient = {
				is_ai = no
			}
			trigger_if = {
				limit = {
					scope:target.casus_belli.primary_defender = scope:actor
				}
				any_spouse = {
					this = scope:target.casus_belli.primary_attacker
				}
			}
			trigger_else = {
				any_spouse = {
					this = scope:target.casus_belli.primary_defender
				}
			}
			factor = 0
		}
		modifier = {
			# Don't call brand-new allies into old wars, at least until some time has elapsed.
			has_variable = delay_calling_recent_ally
			var:delay_calling_recent_ally = scope:recipient
			scope:target = {
				war_days >= 30
			}
			factor = 0
		}
		modifier = {
			# If the recipient is allied to both the attacker and the defender, the attacker shouldn't call
			scope:target.casus_belli.primary_attacker = scope:actor
			scope:target.casus_belli.primary_defender = {
				is_allied_to = scope:recipient
			}
			factor = 0
		}
		#You're a Mandala Suzerain; you don't get off the hook that easily
		modifier = {
			scope:actor = {
				subject_contract_has_flag = tributary_contract_suzerain_guarantee_override
			}
			scope:recipient = scope:actor.suzerain
			add = 500
		}
	}
}
