#Interactions relating to the head of the house

call_house_member_to_war_interaction = {
	category = interaction_category_diplomacy
	icon = alliance
	

	interface_priority = 60

	desc = call_house_member_to_war_interaction_desc
	
	interface = call_ally
	special_interaction = call_ally_interaction
	popup_on_receive = yes
	pause_on_receive = yes
	
	notification_text = CALL_HOUSE_MEMBER_NOTIFICATION
	
	is_shown = {
		scope:recipient != scope:actor

		scope:actor = {
			OR = {
				is_house_head = yes
				AND = {
					exists = dynasty
					# DLC checking
					has_fp2_dlc_trigger = yes
					# Standard check
					dynasty = { has_dynasty_perk = fp2_coterie_legacy_3 }
				}
			}
			religion = scope:recipient.religion
			house = scope:recipient.house
			any_character_war = {
				is_war_leader = scope:actor
			}
		}

		scope:recipient = {
			is_playable_character = yes
		}

		scope:recipient = {
			NOT = {
				target_is_liege_or_above = scope:actor
			}
		}
	}
	
	has_valid_target = {
		exists = scope:target
	}
	
	has_valid_target_showing_failures_only = {
		scope:target = {
			is_war_leader = scope:actor
		}
		joiner_not_already_in_another_war_with_any_target_war_participants_trigger = {
			WARRIOR = scope:actor
			JOINER = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = "is_already_in_all_wars"
			scope:actor = {
				any_character_war = {
					NOR = {
						is_participant = scope:recipient
						was_called = scope:recipient
					}
					OR = {
						primary_attacker = scope:actor
						primary_defender = scope:actor
					}
				}
			}
		}
	}

	can_be_picked = {
		can_join_war_liege_vassal_check_trigger = { WARRIOR = scope:actor JOINER = scope:recipient }
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = call_ally.0001
		}
	}
	
	on_accept = {
		call_house_member_to_war_interaction_effect = yes

		save_scope_value_as = {
			name = call_house_member_to_war_interaction
			value = yes
		}

		if = {
			limit = {
				exists = scope:target
			}

			scope:actor = {
				trigger_event = call_ally.0100
			}
		}

		scope:actor = {
			if = {
				limit = { NOT = {  is_house_head = yes } }
				add_prestige = medium_prestige_loss
			}
		}

		# If the Dynasty has the Unity Legacy perk, the recipient is rewarded with some Prestige
		if = {
			limit = { scope:actor.dynasty = { has_dynasty_perk = fp2_coterie_legacy_3 } }
			scope:recipient = {	add_prestige = medium_prestige_gain	}
		}
	}
	
	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
						}
					}
				}
				else = {
					scope:actor = {
						add_opinion = {
							modifier = rejected_call_to_defensive_war
							target = 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
		}
	}
	
	ai_accept = {
		base = 20

		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
		}

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}

		# Honor factor
		ai_value_modifier = {
			ai_honor = 1
			min = 0
		}

		modifier = {  # Tends to join defensive wars
			add = 50
			scope:target.casus_belli.primary_defender = scope:actor
			desc = DEFENSIVE_WAR_REASON
		}

		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 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
			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 = { # Happy to gain Prestige thanks to the Unity perk
			add = 50
			dynasty = { has_dynasty_perk = fp2_coterie_legacy_3 }
			desc = "UNITY_PERK_BONUS"
		}

		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 = { # Do not call the player if they are in debt
			scope:recipient = {
				is_ai = no
				gold <= -1
			}
			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
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	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
}


#Head legitimizes child or actor requests from head to legitimize
legitimize_bastard_interaction = {
	category = interaction_category_diplomacy
	special_interaction = legitimize_bastard
	icon = legitimized_bastard

	greeting = positive
	notification_text = ASK_TO_legitimize_bastard_interaction

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:actor.house.house_head = scope:actor }
				desc = legitimize_bastard_interaction_desc_house_head
			}
			desc = legitimize_bastard_interaction_desc_not_house_head
		}
	}

	is_shown = {
		scope:actor.house.house_head.faith = {
			has_doctrine_parameter = bastards_legitimize
		}
		scope:actor.faith = {
			has_doctrine_parameter = bastards_legitimize
		}
		scope:secondary_recipient = {
			faith = {
				has_doctrine_parameter = bastards_legitimize
			}
			this != scope:actor
			has_trait = bastard
			OR = {
				father = scope:actor
				mother = scope:actor
				scope:actor.house.house_head = scope:actor
			}
			OR = {
				house = scope:actor.house
				AND = {
					OR = {
						father.house = scope:actor.house
						mother.house = scope:actor.house
					}
					has_dynasty = no
				}
			}
		}
		scope:actor = {
			is_lowborn = no
			is_concubine = no
		}
	}

	is_valid_showing_failures_only = {
	}

	cost = {
		prestige = {
			value = bastard_legitimization_prestige_cost
		}
	}

	ai_accept = {
		base = -50

		modifier = {
			trigger = {
				scope:actor != scope:actor.house.house_head
			}
			add = {
				value = scope:actor.prestige_level
				multiply = 20
			}
			desc = PRESTIGOUS_IN_OUR_HOUSE
		}

		modifier = {
			trigger = {
				always = scope:hook
			}
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = {
			trigger = {
				scope:actor != scope:actor.house.house_head
			}
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
		}

		opinion_modifier = {
			trigger = {
				scope:actor != scope:actor.house.house_head
			}
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = 0.25
		}
		
		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_decreasing_house_unity = {
			VALUE = 100
		}
	}

	auto_accept = {
		OR = {
			scope:actor = scope:actor.house.house_head
			AND = {
				always = scope:hook
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				arrogant = minor_stress_impact_gain
			}

			legitimize_bastard_interaction_opinions_effect = {
				BASTARD = scope:secondary_recipient
				HOUSE_HEAD = scope:actor.house.house_head
				LEGITIMIZER = scope:actor
			}

			if = {
				limit = { always = scope:hook }
				scope:actor = {
					use_hook = scope:recipient
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = miniscule_unity_loss
			DESC = clan_unity_bastardry.desc
			REVERSE_NON_HOUSE_TARGET = no
		}	

		hidden_effect = {
			scope:actor = {
				if = {
					limit = {
						has_character_modifier = oath_of_children
					}
					hidden_effect = {
						remove_character_modifier = oath_of_children
						add_character_modifier = oath_of_children
					}
				}
			}
		}	
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = legitimize_bastard_interaction_decline_notification

				left_icon = scope:actor.house.house_head					
				right_icon = scope:secondary_recipient
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = miniscule_unity_gain
			DESC = clan_unity_bastardry_refusal.desc
			REVERSE_NON_HOUSE_TARGET = no
		}		
	}

	send_option = {
		is_shown = {
			scope:actor != scope:recipient
		}
		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
}

accuse_of_decandence_interaction = {
	icon = antagonistic
	category = interaction_category_hostile
	interface_priority = 60
	common_interaction = yes
	
	cooldown = { years = 3 }

	desc = accuse_of_decandence_interaction_desc
	
	is_shown = {
		scope:actor = { government_has_flag = government_is_clan }
		scope:recipient != scope:actor
		scope:actor.house.house_head ?= scope:actor
		scope:recipient.house ?= scope:actor.house
		scope:recipient = {
			NOT = {
				has_trait = decadent
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_adult = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:actor.diarch }
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0041
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				forgiving = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
			}
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = accuse_of_decandence_interaction_notification

				left_icon = scope:actor					
				right_icon = scope:recipient

				scope:recipient = {
					add_stress = major_stress_gain
					if = {
						limit = {
							has_trait = extolled
						}
						remove_trait = extolled
					}
					else = {
						add_trait = decadent
					}
					add_opinion = {
						modifier = accused_of_decadence_opinion
						target = scope:actor
					}
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = major_unity_loss
			DESC = clan_unity_decadence.desc
			REVERSE_NON_HOUSE_TARGET = no
		}		
	}

	cost = {
		piety = {
			value = {
				add = minor_piety_value
				if = {
					limit = {
						scope:recipient = {
							num_virtuous_traits > 0
						}
					}
					add = {
						value = minor_piety_value
						multiply = scope:recipient.num_virtuous_traits
					}
				}
				if = {
					limit = {
						scope:recipient = {
							num_sinful_traits > 0
						}
					}
					add = {
						value = minor_piety_value
						multiply = 0.5
						multiply = scope:recipient.num_sinful_traits
						min = 10
					}
				}
			}
		}
	}
	
	auto_accept = yes

	ai_potential = {
		is_at_war = no
		government_has_flag = government_is_clan
		house.house_head ?= this
		is_adult = yes
		NOT = {
			has_trait = forgiving
		}
	}
	
	ai_targets = {
		ai_recipients = dynasty
		max = 30
	}
	
	ai_targets = {
		ai_recipients = vassals
	}
	
	ai_frequency_by_tier = {
		barony = 0
		county = 96
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}
	
	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
				}
			}
		}
		
		modifier = {
			add = 50
			scope:actor = {
				ai_wants_low_unity = yes
				NOT = { house ?= { has_house_unity_stage = antagonistic } }
			}
			scope:recipient = {
				num_sinful_traits >= 1
			}
		}
		
		modifier = {
			add = 100
			scope:actor = {
				ai_wants_low_unity = yes
				NOT = { house ?= { has_house_unity_stage = antagonistic } }
			}
			scope:recipient = {
				num_sinful_traits >= 2
			}
		}
		
		modifier = {
			add = 20
			scope:actor = {
				ai_wants_low_unity = yes
				NOT = { house ?= { has_house_unity_stage = antagonistic } }
			}
			scope:recipient = {
				number_of_opposing_personality_traits = {
					target = scope:actor
					value >= 1
				}
			}
		}
		
		modifier = {
			add = 100
			scope:actor = {
				ai_wants_low_unity = yes
				NOT = { house ?= { has_house_unity_stage = antagonistic } }
			}
			scope:recipient = {
				number_of_opposing_personality_traits = {
					target = scope:actor
					value >= 2
				}
			}
		}
		
		modifier = {
			add = 50
			scope:actor = {
				ai_wants_low_unity = yes
				NOT = { house ?= { has_house_unity_stage = antagonistic } }
			}
			OR = {
				AND = {
					scope:recipient = {
						has_trait = incestuous
					}
					NOT = { is_incestuous_trigger = yes }
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:incestuous FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = kinslayer
					}
					NOT = { has_trait = kinslayer }
				}
				AND = {
					scope:recipient = {
						has_trait = adulterer
					}
					NOR = {
						has_trait = adulterer
						has_trait = fornicator
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:adulterer FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = fornicator
					}
					NOR = {
						has_trait = adulterer
						has_trait = fornicator
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = deviant
					}
					NOT = {
						is_deviant_trigger = yes
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:deviant FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = witch
					}
					NOT = {
						is_witch_trigger = yes
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:witch FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = sodomite
					}
					NOR = {
						has_trait = sodomite
						any_secret = {
							type = secret_homosexual
						}
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:sodomite FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
				AND = {
					scope:recipient = {
						has_trait = cannibal
					}
					NOT = {
						is_cannibal_trigger = yes
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:cannibal FAITH = scope:actor.faith GENDER_CHARACTER = scope:recipient }
				}
			}
		}
		
		modifier = {
			factor = 0.25
			scope:recipient = {
				is_powerful_vassal_of = scope:actor
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
				}
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				is_primary_heir_of = scope:actor
			}
		}
	}
}

extoll_virtuousness_interaction = {
	icon = unity_harmonious
	category = interaction_category_friendly
	interface_priority = 60
	common_interaction = yes
	
	cooldown = { years = 3 }

	desc = extoll_virtuousness_interaction_desc
	
	is_shown = {
		scope:actor = { government_has_flag = government_is_clan }
		scope:recipient != scope:actor
		scope:actor.house.house_head ?= scope:actor
		scope:recipient.house ?= scope:actor.house
		scope:recipient = {
			NOT = {
				has_trait = extolled
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_adult = yes }
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0042
		}
	}
	
	on_accept = {
		scope:actor = {
			stress_impact = {
				sadistic = minor_stress_impact_gain
				callous = minor_stress_impact_gain
			}
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = extoll_interaction_notification

				left_icon = scope:actor					
				right_icon = scope:recipient

				scope:recipient = {
					if = {
						limit = {
							has_trait = decadent
						}
						remove_trait = decadent
					}
					else = {
						add_trait = extolled
					}
					add_opinion = {
						modifier = extolled_virtue_opinion
						target = scope:actor
					}
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = major_unity_gain
			DESC = clan_unity_extolled.desc
			REVERSE_NON_HOUSE_TARGET = no
		}		
	}

	cost = {
		piety = {
			value = {
				add = medium_piety_value
				if = {
					limit = {
						scope:recipient = {
							num_sinful_traits > 0
						}
					}
					add = {
						value = medium_piety_value
						multiply = scope:recipient.num_sinful_traits
					}
				}
				if = {
					limit = {
						scope:recipient = {
							num_virtuous_traits > 0
						}
					}
					add = {
						value = medium_piety_value
						multiply = 0.5
						multiply = scope:recipient.num_virtuous_traits
						min = 10
					}
				}
			}
		}
	}
	
	auto_accept = yes

	ai_potential = {
		is_at_war = no
		government_has_flag = government_is_clan
		house.house_head ?= this
		is_adult = yes
		NOT = {
			has_trait = paranoid
		}
	}
	
	ai_targets = {
		ai_recipients = dynasty
		max = 30
	}
	
	ai_targets = {
		ai_recipients = vassals
	}
	
	ai_frequency_by_tier = {
		barony = 0
		county = 96
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}
	
	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			scope:actor = {
				NOT = { ai_wants_low_unity = yes }
			}
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					is_primary_heir_of = scope:actor
				}
			}
		}
		
		modifier = {
			add = 50
			scope:actor = {
				ai_wants_high_unity = yes
				NOT = { house ?= { has_house_unity_stage = harmonious } }
			}
			scope:recipient = {
				num_virtuous_traits >= 1
			}
		}
		
		modifier = {
			add = 100
			scope:actor = {
				ai_wants_high_unity = yes
				NOT = { house ?= { has_house_unity_stage = harmonious } }
			}
			scope:recipient = {
				num_virtuous_traits >= 2
			}
		}
		
		modifier = {
			add = 20
			scope:actor = {
				ai_wants_high_unity = yes
				NOT = { house ?= { has_house_unity_stage = harmonious } }
			}
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value >= 1
				}
			}
		}
		
		modifier = {
			add = 100
			scope:actor = {
				ai_wants_high_unity = yes
				NOT = { house ?= { has_house_unity_stage = harmonious } }
			}
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value >= 2
				}
			}
		}
		
		modifier = {
			factor = 1.5
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
				}
			}
		}
	}
}
