# Targeted decisions are possible vs _all_ other characters and shown are in the Diplomacy View, not the Intrigue View. The taker is in the FROM scope.
#
# filter = [self/court/home_court/vassals/sub_realm/realm/dynasty/all] ('self' MUST be set for decisions targetting only the taker, the other filter types can be set to lessen CPU load)
# ai_target_filter = [self/court/home_court/vassals/sub_realm/realm/dynasty/all] (which characters for which the AI evaluates the decision.)
#	court: all characters in the AI's host court, including prisoners, and characters currently away (wards, prisoners, etc)
#	home_court: all characters in the AI's home court, including prisoners, and characters currently away (wards, prisoners, etc)
#	vassals: direct vassal rulers of the AI's employer
#	sub_realm: all characters below the AI's employer
#	realm: all characters in the same top realm as the AI
#	dynasty: all members of the same dynasty
#	rivals: your rivals plus any character you have an opinion modifier with 'crime = yes' set (the same set of characters the 'is_foe' trigger evaluates)
#	all: all living characters (Avoid if possible. VERY CPU-HEAVY!)
#

targeted_decisions = {

	adopt_faith = {
		filter = realm
		ai_target_filter = realm
		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Horse Lords"
			is_nomadic = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			is_nomadic = yes
			is_playable = yes
			NOT = { religion = FROM }
			same_realm = FROM
		}

		allow = {
			FROM = {
				piety >= 50

				custom_tooltip = {
					text = recently_adopted_faith_tooltip
					NOT = { has_character_modifier = adopted_faith_timer }
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				religion = ROOT
				piety = -50

				add_character_modifier = {
					name = adopted_faith_timer
					years = 10
					hidden = yes
				}

				any_vassal = {
					limit = {
						ai = yes
						is_close_relative = FROM
						dynasty = FROM
						is_incapable = no

						trigger_if = {
							limit = { is_adult = yes }
							NOT = { trait = zealous }
						}
					}

					# Workaround for automatic usurption of theocratic characters
					ROOT = {
						religion_scope = {
							save_event_target_as = target_religion
						}
					}

					convert_religion_failsafe_effect = yes
				}

				any_courtier = {
					limit = {
						is_close_relative = FROM
						is_incapable = no

						trigger_if = {
							limit = { is_adult = yes }
							NOT = { trait = zealous }
						}
					}

					# Workaround for automatic usurption of theocratic characters
					ROOT = {
						religion_scope = {
							save_event_target_as = target_religion
						}
					}

					convert_religion_failsafe_effect = yes
				}
			}

			any_player = {
				limit = {
					same_realm = ROOT
					is_nomadic = yes
					NOT = { character = FROM }
				}

				if = {
					limit = { religion = ROOT }
					character_event = { id = HL.11 } # Notify
				}
				else = {
					character_event = { id = HL.9 } # Notify
				}
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				FROM = {
					NOR = {
						has_feud_with = ROOT
						trait = zealous
					}

					opinion = {
						who = ROOT
						value >= 25
					}

					clan_opinion = {
						who = ROOT
						value >= 25
					}

					# Don't convert away from organised religions
					trigger_if = {
						limit = {
							### ACR ###
							is_not_unreformed_pagan_trigger = yes
						}

						ROOT = {
							### ACR ###
							is_not_unreformed_pagan_trigger = yes
						}
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					religion_group = pagan_group
					is_reformed_religion = no
				}

				ROOT = {
					trigger_if = {
						limit = { religion_group = pagan_group }
						is_reformed_religion = yes
					}
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = { de_facto_liege = ROOT }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { has_blood_oath_with = ROOT }
			}

			mult_modifier = {
				factor = 1.5

				reverse_opinion = {
					who = FROM
					value >= 50
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_opinion = {
					who = FROM
					value >= 75
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_clan_opinion = {
					who = FROM
					value >= 50
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_clan_opinion = {
					who = FROM
					value >= 75
				}
			}

			mult_modifier = {
				factor = 1.5
				prestige >= 200
			}

			mult_modifier = {
				factor = 0.5
				prestige < 100
			}

			mult_modifier = {
				factor = 0.5

				relative_power = {
					who = FROM
					power < 0.5
				}
			}

			mult_modifier = {
				factor = 1.5

				relative_power = {
					who = FROM
					power >= 1.5
				}
			}
		}
	}

	declare_feud = {
		filter = realm
		ai_target_filter = realm
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Horse Lords"
			clan = yes
		}

		potential = {
			clan = yes
			is_playable = yes
			NOT = { has_feud_with = FROM }
		}

		allow = {
			NOT = { has_blood_oath_with = FROM }
		}

		effect = {
			clan_title = {
				show_scope_change = no

				FROM = {
					show_scope_change = no

					clan_title = {
						show_scope_change = no

						create_feud = PREVPREV
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				# Try not having more feuds than one (others can still add you to a feud however
				FROM = {
					trigger_if = {
						limit = { is_rival = ROOT }
						num_of_feuds < 3
					}
					trigger_else = {
						num_of_feuds < 1
					}
				}

				opinion = {
					who = ROOT
					value < 0
				}

				trigger_if = {
					limit = { NOT = { is_rival = FROM } }

					clan_opinion = {
						who = FROM
						value < -50
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_opinion = {
					who = FROM
					value < -50
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_opinion = {
					who = FROM
					value < -75
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_clan_opinion = {
					who = FROM
					value < -50
				}
			}

			mult_modifier = {
				factor = 1.5

				reverse_clan_opinion = {
					who = FROM
					value < -75
				}
			}

			mult_modifier = {
				factor = 0.5

				relative_power = {
					who = FROM
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 0.5

				relative_power = {
					who = FROM
					power < 0.5
				}
			}

			mult_modifier = {
				factor = 1.2

				FROM = {
					de_facto_liege = ROOT
					ai_ambition >= 0
				}
			}

			mult_modifier = {
				factor = 0.5

				FROM = {
					de_facto_liege = ROOT
					ai_honor >= 0
				}
			}

			mult_modifier = {
				factor = 1.2

				ROOT = {
					strongest_clan_vassal = {
						character = FROM
					}
				}
			}
		}
	}
}