# 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 = {

	commit_suicide = {
		filter = self

		ai = no

		potential = {
			OR = {
				trait = depressed

				trigger_if = {
					limit = { has_dlc = "Reapers" }
					is_incapable = yes
				}
			}

			is_adult = yes
			immortal = no
			prisoner = no
			NOT = { has_character_flag = attempting_suicide }
		}

		allow = {
			custom_tooltip = { text = commit_suicide_allow_tooltip }

			custom_tooltip = {
				text = is_not_busy_trigger_tooltip

				trigger_if = {
					limit = { in_seclusion = no }
					is_inaccessible_trigger = no
				}
			}
		}

		effect = {
			if = {
				limit = { has_dlc = "Reapers" }
				set_character_flag = attempting_suicide

				if = {
					limit = { is_incapable = yes }
					character_event = { id = RIP.30210 }
				}
				else = {
					character_event = { id = RIP.30200 }
				}
			}
			else = {
				prestige = -200

				add_character_modifier = {
					name = suicide
					duration = -1
				}

				death = { death_reason = death_suicide }
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	legitimize_bastard = {
		filter = close_relatives

		ai = no

		from_potential = {
			has_living_children = yes
			# has_polygamy = no # CleanSlate: There is no reason to restrict this to non-polygamists.
			any_child = {
				trait = bastard
				is_alive = yes
			}
		}

		potential = {
			trait = bastard
			is_child_of = FROM
			is_vassal_or_below_of = FROM
		}

		allow = {
			FROM = {
				show_scope_change = no

				trigger_if = {
					limit = {
						NOR = {
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_legitimize
								bloodline_is_active_for = PREV
							}
							### ACR ###
							trait = dryad
							trait = bad_dryad
						}
					}

					piety >= 20
				}
			}
		}

		effect = {
			dynasty = FROM
			remove_trait = bastard
			### ACR ###
			if = {
				limit = { 
					FROM = {
						NAND = {
							religion = britannic_pagan
							is_celtic_clergy_trigger = yes
						}
					}
				}
				add_trait = legit_bastard
			}
			recalc_succession = yes

			# Take the piety price from the legitimizer
			FROM = {
				show_scope_change = no

				if = {
					limit = {
						NOR = {
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_legitimize
								bloodline_is_active_for = PREV
							}
							### ACR ###
							trait = dryad
							trait = bad_dryad
						}
					}

					piety = -20
				}
			}

			# Release Bastard if imprisoned
			if = {
				limit = {
					prisoner = yes
					host = { character = FROM }
				}

				imprison = no
			}

			# Bastard's other parent is pleased
			if = {
				limit = {
					FROM = { is_female = yes }
				}

				father = {
					show_scope_change = no

					opinion = {
						name = legitimized_child
						who = FROM
						years = 10
					}
				}
			}
			else = {
				mother = {
					show_scope_change = no

					opinion = {
						name = legitimized_child
						who = FROM
						years = 10
					}
				}
			}

			FROM = {
				show_scope_change = no

				# Spouses are angry
				any_spouse = {
					show_scope_change = no

					limit = { NOT = { is_parent_of = ROOT } }

					opinion = {
						name = legitimized_bastard
						who = ROOT_FROM
						years = 20
					}
				}

				# Non-bastard children are angry
				if = {
					limit = {
						any_child = {
							dynasty = ROOT_FROM

							NOR = {
								character = ROOT
								trait = legit_bastard
							}
						}
					}

					custom_tooltip = {
						text = any_child_gets_angry_tt

						any_child = {
							show_scope_change = no

							limit = {
								dynasty = ROOT_FROM

								NOR = {
									character = ROOT
									trait = legit_bastard
								}
							}

							opinion = {
								name = legitimized_bastard
								who = ROOT_FROM
								years = 1
							}
						}
					}
				}
			}
		}

		ai_will_do = {
			### ACR ###
			factor = 1
			modifier = {
				factor = 0 # only dryads should be doing this
				NOR = {
					religion = britannic_pagan
					is_celtic_clergy_trigger = yes
					any_owned_bloodline = {
						has_bloodline_flag = bloodline_legitimize
						bloodline_is_active_for = PREV
					}
				}
			}
		}
	}

	# Muslim ruler tries to convince a dynasty member to lose the 'Decadent' Trait
	convince_to_straighten_up = {
		filter = dynasty
		ai_target_filter = dynasty
		ai_check_interval = 6

		hide_in_decisions_list = yes # This decision is shown in the Religion View for each decadent character

		only_playable = yes

		from_potential = {
			uses_decadence = yes

			father_even_if_dead = {
				OR = {
					is_alive = no
					is_playable = no
				}
			}
		}

		potential = {
			trait = decadent
			lower_real_tier_than = FROM
			has_regent = no
		}

		allow = {
			FROM = {
				piety >= 100
				NOT = { trait = decadent }
				has_regent = no

				custom_tooltip = {
					text = NOT_ALREADY_NEGOTIATED

					ROOT = {
						NOT = { has_character_flag = negotiated_to_drop_decadence }
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				piety = -100
			}

			set_character_flag = negotiated_to_drop_decadence
			character_event = { id = 91350 } # Try to convince to lose 'Decadent' trait
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Not if there's a higher ranking player in the same realm as the target (CleanSlate: Why though?)
				FROM = {
					NOT = {
						any_player = {
							dynasty = ROOT
							higher_tier_than = ROOT
							same_realm = ROOT
						}
					}
				}
			}
		}
	}

	# Unhardcoded decision
	order_to_take_vows = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 120

		only_playable = yes

		from_potential = {
			has_dlc = "Sons of Abraham"
			is_adult = yes
			prisoner = no
			has_regent = no

			OR = {
				trigger_if = {
					limit = { is_alternate_start = no }

					OR = {
						religion_group = christian
						has_dharmic_religion_trigger = yes
						religion = manichaean
					}
				}

				has_religion_feature = religion_monastic
				has_religion_feature = religion_feature_west_african
				### ACR ###
				has_religion_feature = religion_feature_celtic
			}
		}

		potential = {
			host = { character = FROM }
			religion = FROM
			is_ruler = no
			is_adult = yes
			is_incapable = no
			is_not_ascetic_trigger = yes
		}

		allow = {
			trigger_if = {
				limit = {
					dynasty = FROM

					any_owned_bloodline = {
						has_bloodline_flag = bloodline_easy_monks
						bloodline_is_active_for = FROM
						bloodline_is_active_for = ROOT
					}
				}

				# Matilde's Bloodline
				custom_tooltip = {
					text = BLOODLINE_EASIER_VOWS_TOOLTIP
				}
			}
			trigger_else = {
				OR = {
					prisoner = yes

					AND = {
						is_heir = no
						is_married = no
					}
				}
			}

			FROM = {
				piety >= 50
			}
		}

		effect = {
			FROM = {
				show_scope_change = no
				piety = -50
			}

			add_ascetic_trait_effect = yes # Adds religion-based monk-traits

			# Prisoners are freed upon taking the vows
			if = {
				limit = { prisoner = yes }
				imprison = no
			}

			# The vows mean no marriage
			if = {
				limit = { is_married = yes }

				any_spouse = {
					show_scope_change = no

					remove_spouse = ROOT
				}
			}

			# And no consorts
			if = {
				limit = { is_senior_consort_party = yes }

				any_consort = {
					show_scope_change = no

					remove_consort = ROOT
				}
			}

			# Monks and Mystics actually join societies
			if = {
				limit = {
					has_dlc = "Mystics"
					is_in_society = no
					is_heretic = no
				}

				if = {
					limit = { is_catholic_branch = yes }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society

						random_list = {
							50 = {
								trigger = { religion = catholic }
								join_society = monastic_order_benedictine
							}
							50 = { join_society = monastic_order_dominican }
						}
					}
				}
				else_if = {
					limit = { is_orthodox_branch = yes }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_orthodox
					}
				}
				else_if = {
					limit = { is_nestorian_branch = yes }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_nestorian
					}
				}
				else_if = {
					limit = { is_miaphysite_branch = yes }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_monophysite
					}
				}
				else_if = {
					limit = { religion = hindu }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_hindu
					}
				}
				else_if = {
					limit = { religion = buddhist }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_buddhist
					}
				}
				else_if = {
					limit = { religion = jain }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_jain
					}
				}
				### ACR ###
				else_if = {
					limit = { religion_openly_egyptian_or_reformed_trigger = yes }

					custom_tooltip = {
						text = tooltip_vows_monk_joins_society
						join_society = monastic_order_isis
					}
				}
			}

			# Moves to Theocracy
			if = {
				limit = {
					any_realm_lord = {
						is_theocracy = yes
						religion = ROOT
					}
				}

				custom_tooltip = {
					text = tooltip_vows_monk_goes_to_theocracy

					random_realm_lord = {
						limit = {
							is_theocracy = yes
							religion = ROOT
						}

						preferred_limit = {
							reverse_opinion = {
								who = FROM
								value >= 20
							}
							vassal_of = FROM
							# The one they just joined
							same_society_as = ROOT
						}

						preferred_limit = {
							vassal_of = FROM
							# The one they just joined
							same_society_as = ROOT
						}

						preferred_limit = {
							# The one they just joined
							same_society_as = ROOT
						}

						preferred_limit = {
							vassal_of = FROM
						}

						ROOT = { move_character = PREV }
					}
				}
			}

			# People have opinions
			if = {
				limit = {
					dynasty = FROM
					NOR = {
						trait = zealous
						### ACR ###
						trait = druid
					}
				}

				opinion = {
					name = opinion_cloistered_me_family
					who = FROM
					years = 20
				}
			}
			else_if = {
				limit = {
					NOR = {
						dynasty = FROM
						trait = zealous
						### ACR ###
						trait = druid
					}
				}

				opinion = {
					name = opinion_cloistered_me
					who = FROM
					years = 20
				}
			}

			# Child reacts
			if = {
				limit = { is_child_of = FROM }

				FROM = {
					character_event = { id = HFP.23001 }
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				FROM = {
					opinion = {
						who = ROOT
						value < 50
					}

					# I'm not a good ruler or they are not a dynastic heir
					trigger_if = {
						limit = { is_benevolent_trigger = yes }

						opinion = {
							who = ROOT
							value < 0
						}
					}
					trigger_else_if = {
						limit = { is_parent_of = ROOT }
						NOT = { dynasty = ROOT }
					}

					# Don't hate you enough to send you off
					trigger_if = {
						limit = { is_benevolent_trigger = yes }

						ROOT = {
							OR = {
								is_child_of = FROM
								prisoner = no

								reverse_opinion = {
									who = FROM
									value >= -20
								}
							}
						}
					}
				}
			}

			# Must protect the line
			mult_modifier = {
				factor = 5

				ROOT = {
					is_child_of = FROM
					NOT = { dynasty = FROM }
				}
			}

			# Hate you
			mult_modifier = {
				factor = 5

				ROOT = {
					is_child_of = FROM
					is_rival = FROM
				}
			}

			# There are better spares
			mult_modifier = {
				factor = 20

				ROOT = {
					is_child_of = FROM

					OR = {
						has_negative_congenital_trigger = yes
						has_infertile_trait_trigger = yes
						has_severe_disability_trigger = yes
					}
				}

				FROM = {
					any_child = {
						is_alive = yes
						has_negative_congenital_trigger = no
						has_infertile_trait_trigger = no
						has_severe_disability_trigger = no
					}
				}
			}

			# Must keep the realm from falling to evil
			mult_modifier = {
				factor = 5

				ROOT = { is_evil_trigger = yes }

				FROM = {
					is_benevolent_trigger = yes

					any_child = {
						is_alive = yes
						is_evil_trigger = no
					}
				}
			}
		}
	}

	send_child_into_hiding = {
		filter = close_relatives
		ai_target_filter = close_relatives
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		from_potential = {
			has_living_children = yes
			has_regent = no

			trigger_if = {
				limit = { ai = yes }
				has_education_intrigue_trigger = yes
			}
		}

		potential = {
			is_child_of = FROM
			host = { character = FROM }
			is_ruler = no
			prisoner = no

			NOR = {
				is_married = FROM
				has_character_modifier = went_out_of_hiding_timer

				# CleanSlate: Not if you're plotting against your own child (you monster)
				trigger_if = {
					limit = { is_plot_target_of = FROM }

					FROM = {
						has_plot = plot_kill_character
					}
				}
			}
		}

		allow = {
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip

				OR = {
					has_character_modifier = suspected_murder_plot

					FROM = {
						any_known_plotter = {
							target = ROOT

							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
					}
				}
			}

			custom_tooltip = {
				text = recently_went_out_of_hiding_tooltip

				NOT = { has_character_modifier = went_out_of_hiding_timer }
			}

			is_inaccessible_trigger = no
			has_job_title = no
			in_command = no
		}

		effect = {
			custom_tooltip = {
				text = go_into_hiding_info_tooltip

				add_trait = in_hiding
				set_character_flag = do_not_disturb
			}

			hidden_effect = {
				any_plotter = {
					target = ROOT

					limit = {
						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}

					if = {
						# CleanSlate: Prevent the AI from firing unneeded notification events
						limit = { ai = yes }
						# CleanSlate: Deactivate the plot directly instead of firing the event that deactivates it
						activate_plot = no
					}
					else = {
						# CleanSlate: Players can have notification events
						if = {
							limit = { is_plot_active = yes }
							character_event = { id = CM.6180 } # Notify, deactivate plot
						}
						else = {
							character_event = { id = CM.6004 } # Notify
						}
					}

					any_backed_character = {
						limit = { ai = no }
						character_event = { id = CM.6004 } # Notify
					}
				}

				any_player = {
					limit = {
						OR = {
							is_close_relative = ROOT
							is_friend = ROOT
							is_lover = ROOT
							is_rival = ROOT
						}

						NOR = {
							character = FROM

							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}

							any_backed_character = {
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}

								plot_target_char = {
									character = ROOT
								}
							}
						}
					}

					character_event = { id = CM.6004 } # Notify
				}
			}
		}

		ai_will_do = {
			factor = 0.25

			trigger = {
				trigger_if = {
					limit = {
						NOT = { is_primary_heir = FROM }
					}

					trigger_if = {
						limit = { is_female = yes }

						OR = {
							has_law = true_cognatic_succession
							has_law = enatic_cognatic_succession
							has_law = enatic_succession
						}
					}
					trigger_else = {
						OR = {
							has_law = true_cognatic_succession
							has_law = cognatic_succession
							has_law = agnatic_succession
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				FROM = {
					opinion = {
						who = ROOT
						value < -25
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					opinion = {
						who = ROOT
						value >= 25
					}
				}
			}

			mult_modifier = {
				factor = 5
				FROM = { trait = in_hiding }
			}

			mult_modifier = {
				factor = 10
				FROM = { trait = paranoid }
			}
		}
	}

	take_child_out_of_hiding = {
		filter = close_relatives
		ai_target_filter = close_relatives
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		from_potential = {
			has_living_children = yes
			has_regent = no
		}

		potential = {
			is_child_of = FROM
			trait = in_hiding
			host = { character = FROM }
			is_ruler = no
			prisoner = no
			NOT = { is_married = FROM }
		}

		allow = {
			trait = in_hiding
		}

		effect = {
			custom_tooltip = {
				text = come_out_of_hiding_info_tooltip

				clr_character_flag = do_not_disturb
				remove_trait = in_hiding

				add_character_modifier = {
					name = went_out_of_hiding_timer
					months = 6
					hidden = yes
				}

				# Notify player close family and plotters
				any_player = {
					limit = {
						OR = {
							is_close_relative = ROOT
							is_friend = ROOT
							is_lover = ROOT
							is_rival = ROOT

							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}
							trigger_else = {
								any_backed_character = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}

									plot_target_char = {
										character = ROOT
									}
								}
							}
						}

						NOT = { character = FROM }
					}

					character_event = { id = CM.6005 } # Notify
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Don't take plot targets out of hiding
				NOR = {
					has_character_modifier = suspected_murder_plot

					FROM = {
						any_known_plotter = {
							target = ROOT

							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.3
				FROM = { trait = paranoid }
			}
		}
	}

	go_into_hiding = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		potential = {
			prisoner = no
		}

		allow = {
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip

				OR = {
					has_character_modifier = suspected_murder_plot

					any_known_plotter = {
						target = ROOT

						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}
				}
			}

			custom_tooltip = {
				text = recently_went_out_of_hiding_tooltip

				NOT = { has_character_modifier = went_out_of_hiding_timer }
			}

			is_inaccessible_trigger = no
			has_job_title = no
			in_command = no
		}

		effect = {
			custom_tooltip = {
				text = go_into_hiding_info_tooltip

				add_trait = in_hiding
				set_character_flag = do_not_disturb

				# Notify close family and plotters
				any_plotter = {
					target = ROOT

					limit = {
						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}

					# CleanSlate: AI doesn't need notification events
					if = {
						limit = { ai = yes }
						# CleanSlate: Deactivate the plot directly instead of firing the event that deactivates it
						activate_plot = no
					}
					# CleanSlate: Players do
					else = {
						if = {
							limit = { is_plot_active = yes }
							character_event = { id = CM.6180 }
						}
						else = {
							character_event = { id = CM.6000 }
						}
					}

					any_backed_character = {
						limit = { ai = no }
						character_event = { id = CM.6000 }
					}
				}

				any_player = {
					limit = {
						OR = {
							is_close_relative = ROOT
							is_friend = ROOT
							is_lover = ROOT
							is_rival = ROOT
						}

						NOR = {
							character = ROOT

							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}

							any_backed_character = {
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}

								plot_target_char = {
									character = ROOT
								}
							}
						}
					}

					character_event = { id = CM.6000 }
				}
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				has_education_intrigue_trigger = yes

				# NOT = {
				# 	any_player = {
				# 		is_primary_heir = ROOT
				#
				# 		plot_target_char = {
				# 			character = ROOT
				# 		}
				#
				# 		OR = {
				# 			has_plot = plot_kill_character
				# 			has_plot = plot_kill_spouse
				# 		}
				# 	}
				# }
			}

			mult_modifier = {
				factor = 0.1
				practical_age >= 65
			}

			mult_modifier = {
				factor = 0.1
				trait = brave
			}

			mult_modifier = {
				factor = 2
				trait = depressed
			}

			mult_modifier = {
				factor = 5
				trait = craven
			}

			mult_modifier = {
				factor = 10
				trait = paranoid
			}
		}
	}

	come_out_of_hiding = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		potential = {
			trait = in_hiding
			NOT = { has_character_flag = in_religious_seclusion }
		}

		allow = {
			trigger_if = {
				limit = {
					OR = {
						is_adult = no
						is_incapable = yes
					}
				}

				regent = {
					NOR = {
						trait = deceitful
						trait = ambitious
						is_rival = ROOT
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = come_out_of_hiding_info_tooltip

				clr_character_flag = do_not_disturb
				remove_trait = in_hiding

				add_character_modifier = {
					name = went_out_of_hiding_timer
					months = 6
					hidden = yes
				}

				# Notify player close family and plotters
				any_player = {
					limit = {
						trigger_if = {
							limit = {
								OR = {
									is_close_relative = ROOT
									is_friend = ROOT
									is_lover = ROOT
									is_rival = ROOT
								}
							}

							NOR = {
								character = ROOT

								trigger_if = {
									limit = {
										OR = {
											has_plot = plot_kill_character
											has_plot = plot_kill_spouse
										}
									}

									plot_target_char = {
										character = ROOT
									}
								}

								any_backed_character = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}

									plot_target_char = {
										character = ROOT
									}
								}
							}
						}
						trigger_else = {
							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}
							trigger_else = {
								any_backed_character = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}

									plot_target_char = {
										character = ROOT
									}
								}
							}
						}
					}

					character_event = { id = CM.6001 }
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Stay in hiding if still a (suspected) target of a plot
				NOR = {
					has_character_modifier = suspected_murder_plot

					any_known_plotter = {
						target = ROOT

						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}

				# 	any_player = {
				# 		is_primary_heir = ROOT
				#
				# 		plot_target_char = {
				# 			character = ROOT
				# 		}
				#
				# 		OR = {
				# 			has_plot = plot_kill_character
				# 			has_plot = plot_kill_spouse
				# 		}
				# 	}
				 }
			}

			mult_modifier = {
				factor = 0.3
				trait = paranoid
			}
		}
	}

	send_spouse_into_hiding = {
		filter = spouse
		ai_target_filter = spouse
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		from_potential = {
			is_married = yes
			has_regent = no

			trigger_if = {
				limit = { ai = yes }
				has_education_intrigue_trigger = yes
			}
		}

		potential = {
			host = { character = FROM }
			is_ruler = no
			is_inaccessible_trigger = no

			# CleanSlate: Not if you're plotting against your spouse yourself (you monster)
			trigger_if = {
				limit = { is_plot_target_of = FROM }

				FROM = {
					NOT = { has_plot = plot_kill_spouse }
				}
			}
		}

		allow = {
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip

				OR = {
					has_character_modifier = suspected_murder_plot

					FROM = {
						any_known_plotter = {
							target = ROOT

							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
					}
				}
			}

			custom_tooltip = {
				text = recently_went_out_of_hiding_tooltip

				NOT = { has_character_modifier = went_out_of_hiding_timer }
			}

			has_job_title = no
			in_command = no
			prisoner = no
		}

		effect = {
			custom_tooltip = {
				text = go_into_hiding_info_tooltip

				add_trait = in_hiding
				set_character_flag = do_not_disturb

				# Notify player and close family and plotters
				any_plotter = {
					target = ROOT

					limit = {
						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}

					# CleanSlate: AI don't need notification events
					if = {
						limit = { ai = yes }
						# CleanSlate: Deactivate the plot directly instead of firing the event that deactivates it
						activate_plot = no
					}
					# CleanSlate: Players do
					else = {
						if = {
							limit = { is_plot_active = yes }
							character_event = { id = CM.6180 }
						}
						else = {
							character_event = { id = CM.6002 }
						}
					}

					any_backed_character = {
						limit = { ai = no }
						character_event = { id = CM.6002 }
					}
				}

				any_player = {
					limit = {
						OR = {
							is_close_relative = ROOT
							is_friend = ROOT
							is_lover = ROOT
							is_rival = ROOT
						}

						NOR = {
							character = FROM

							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}

							any_backed_character = {
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}

								plot_target_char = {
									character = ROOT
								}
							}
						}
					}

					character_event = { id = CM.6002 }
				}
			}
		}

		ai_will_do = {
			factor = 0.25

			mult_modifier = {
				factor = 0.1
				practical_age >= 65
			}

			mult_modifier = {
				factor = 0.1

				OR = {
					FROM = {
						trait = pregnant
						father_of_unborn_known = yes
						father_of_unborn = { NOT = { character = ROOT } }
					}

					ROOT = {
						trait = pregnant
						father_of_unborn_known = yes
						father_of_unborn = { NOT = { character = FROM } }
					}
				}
			}

			mult_modifier = {
				factor = 10

				OR = {
					FROM = {
						trait = pregnant
						father_of_unborn_known = yes
						father_of_unborn = { character = ROOT }
					}

					ROOT = {
						trait = pregnant
						father_of_unborn_known = yes
						father_of_unborn = { character = FROM }
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				FROM = {
					opinion = {
						who = ROOT
						value < -25
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					opinion = {
						who = ROOT
						value >= 25
					}
				}
			}

			mult_modifier = {
				factor = 5
				FROM = { trait = in_hiding }
			}

			mult_modifier = {
				factor = 10
				FROM = { trait = paranoid }
			}
		}
	}

	take_spouse_out_of_hiding = {
		filter = spouse
		ai_target_filter = spouse
		ai_check_interval = 12

		is_high_prio = yes

		only_rulers = yes

		from_potential = {
			is_married = yes
			has_regent = no
		}

		potential = {
			trait = in_hiding
			host = { character = FROM }
			is_ruler = no
			prisoner = no
		}

		effect = {
			custom_tooltip = {
				text = come_out_of_hiding_info_tooltip

				remove_trait = in_hiding
				clr_character_flag = do_not_disturb

				add_character_modifier = {
					name = went_out_of_hiding_timer
					months = 6
					hidden = yes
				}

				# Notify player close family and plotters
				any_player = {
					limit = {
						trigger_if = {
							limit = {
								OR = {
									is_close_relative = ROOT
									is_friend = ROOT
									is_lover = ROOT
									is_rival = ROOT
								}
							}

							NOR = {
								character = FROM

								trigger_if = {
									limit = {
										OR = {
											has_plot = plot_kill_character
											has_plot = plot_kill_spouse
										}
									}

									plot_target_char = {
										character = ROOT
									}
								}

								any_backed_character = {
									plot_target_char = {
										character = ROOT
									}
								}
							}
						}
						trigger_else = {
							trigger_if = {
								limit = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}
								}

								plot_target_char = {
									character = ROOT
								}
							}
							trigger_else = {
								any_backed_character = {
									OR = {
										has_plot = plot_kill_character
										has_plot = plot_kill_spouse
									}

									plot_target_char = {
										character = ROOT
									}
								}
							}
						}
					}

					character_event = { id = CM.6003 }
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Only if no longer a (suspected) plot target
				NOR = {
					has_character_modifier = suspected_murder_plot

					FROM = {
						any_known_plotter = {
							target = ROOT

							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.3
				FROM = { trait = paranoid }
			}
		}
	}
}