# Targetted 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!)
#	

targetted_decisions = {

	commit_suicide = {
		filter = self
		ai_target_filter = self
		ai = no

		potential = {
			is_adult = yes

			OR = {
				trait = depressed
				AND = {
					trait = incapable
					has_dlc = "Reapers"
				}
			}
			immortal = no
		}
		allow = {
			custom_tooltip = {
				text = commit_suicide_allow_tooltip
				hidden_tooltip = {
					OR = {
						trait = depressed
						trait = incapable
					}
				}
			}
			prisoner = no
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = {
					# NOR  = { has_character_flag = do_not_disturb is_inaccessible_trigger = yes }
					# Line above outcommented to account for Seclusion (below)
					OR = {
						in_seclusion = yes
						NOR = {
							has_character_flag = do_not_disturb
							is_inaccessible_trigger = yes
						}
					}
				}
			}
			custom_tooltip = {
				NOT = { has_character_flag = attempting_suicide }
				text = attempting_suicide_tooltip
			}
		}
		effect = {
			if = {
				limit = { has_dlc = "Reapers" }

				set_character_flag = attempting_suicide

				if = {
					limit = { NOT = { trait = incapable } }
					character_event = { id = RIP.30200 }
				}
				if = {
					limit = { trait = incapable } 
					character_event = { id = RIP.30210 }
				}
			}
			if = {
				limit = { NOT = { has_dlc = "Reapers" } }

				prestige = -200

				add_character_modifier = {
					modifier = suicide
					duration = -1
				}
				death = { death_reason = death_suicide }
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

	legitimize_bastard = {
		only_playable = yes
		filter = close_relatives
		ai_target_filter = close_relatives
		ai_check_interval = 30
	
		from_potential = {
			ai = no
			is_playable = yes
			has_children = yes
			has_polygamy = no
		}
		
		potential = {
			trait = bastard
			is_child_of = FROM
			is_liege_or_above = FROM
		}
		allow = {
			conditional_tooltip = {
				trigger = {
					NOT = {
						any_owned_bloodline = {
							has_bloodline_flag = bloodline_legitimize
						}
					}
				}
				FROM = {
					piety = 20
				}
			}
		}
		effect = {
			dynasty = FROM
			remove_trait = bastard
			add_trait = legit_bastard
			recalc_succession = yes
			FROM = { 
				show_scope_change = no
				if = {
					limit = {
						NOT = {
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_legitimize
							}
						}
					}
					FROM = {
						piety = -20
					}
				}
			}
			if = {
				limit = {
					prisoner = yes
					host = { character = FROM }
				}
				imprison = no
			}
			
			if = {
				limit = { FROM = { is_female = no } }
				mother = {
					show_scope_change = no
					opinion = {
						who = FROM
						modifier = legitimized_child
						years = 10
					}
				}
			}
			FROM = {
				show_scope_change = no
				spouse = {
					show_scope_change = no
					if = {
						limit = {
							NOT = {
								any_child = {
									character = ROOT
								}	
							}
						}
						opinion = {
							who = ROOT_FROM
							modifier = legitimized_bastard
							years = 20
						}
					}
				}
				if = {
					limit = {
						any_child = {
							dynasty = ROOT_FROM
							NOT = { character = ROOT }
							NOT = { trait = bastard }
						}
					}
					custom_tooltip = {
						text = any_child_gets_angry_tt
						any_child = {
							show_scope_change = no
							limit = {
								NOT = { character = ROOT }
								dynasty = ROOT_FROM
								NOT = { trait = bastard }
							}
							opinion = {
								who = ROOT_FROM
								modifier = legitimized_bastard
								months = 12
							}
						}
					}
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	# Muslim ruler tries to convince a dynasty member to lose the 'Decadent' Trait
	convince_to_straighten_up = {
		only_playable = yes
		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
		
		from_potential = {
			is_playable = yes
			religion_group = muslim
			father_even_if_dead = {
				OR = {
					is_alive = no
					is_playable = no
				}
			}
		}
		
		potential = {
			is_female = no
			prisoner = no
			trait = decadent
			has_regent = no
			lower_tier_than = FROM
		}
		
		allow = {
			FROM = {
				piety = 100
				prisoner = no
				NOT = { trait = decadent }
			}
			custom_tooltip = {
				text = "NOT_ALREADY_NEGOTIATED"
				NOT = { has_character_flag = negotiated_to_drop_decadence }
			}
		}
		effect = {
			set_character_flag = negotiated_to_drop_decadence
			character_event = {
				id = 91350
			}
			
			FROM = { piety = -100 }
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				any_dynasty_member = {
					ai = no
					higher_tier_than = ROOT
					same_realm = ROOT
				}
			}
		}
	}

	# Unhardcoded decision.
	# Unhardcoded decision.
order_to_take_vows = {
	only_playable = yes
	filter = court
	ai_target_filter = court
	ai_check_interval = 120 #Check every 120 months
	
	from_potential = {
		is_playable = yes
		has_regent = no
		prisoner = no
		is_adult = yes
		has_dlc = "Sons of Abraham"
		OR = {
			AND = { 
				religion_group = christian
				is_alternate_start = no
			}
			AND = { 
				religion = hindu
				is_alternate_start = no
			}
			AND = { 
				religion = buddhist
				is_alternate_start = no
			}
			AND = { 
				religion = jain
				is_alternate_start = no
			}
			AND = { 
				religion = manichean
				is_alternate_start = no
			}
			has_religion_feature = religion_monastic
			has_religion_feature = religion_feature_west_african
		}
	}
	
	potential = {
		is_adult = yes
		is_ruler = no
		religion = FROM
		NOR = { 
			trait = incapable 
			trait = monk
			trait = nun
			trait = muni
			trait = aryika
			trait = bhikkhu
			trait = bhikkhuni
			trait = sanyasi
			trait = sanyasini
		}
		host = { character = FROM }
	}
	
	allow = {
		OR = { 
			AND = { 
				is_married = no
				custom_tooltip = {
					text = NOT_HEIR_TITLE_TT
					NOT = {
						any_heir_title = { 
							always = yes
						}
					}
				}
			}
			prisoner = yes
			conditional_tooltip = {
				trigger = { dynasty = FROM }
				custom_tooltip = { #Matilde's Bloodline
					text = BLOODLINE_EASIER_VOWS_TOOLTIP
					AND = {
						FROM = { 
							dynasty = ROOT
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_easy_monks
								bloodline_is_active_for = PREV
							}
						}
						ROOT = { 
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_easy_monks
								bloodline_is_active_for = PREV
							}
						}
					}
				}
			}
		}
		FROM = { piety = 50 }
	}

	effect = {
		FROM = { piety = -50 }

		add_ascetic_trait_effect = yes #Adds religion-based monk-traits.

		if = { #For pagans and Altstart
			limit = { 
				NOR = { 
					religion_group = christian 
					religion = hindu
					religion = buddhist
					religion = jain
				} 
				is_female = no
			}
			add_trait = monk
		}

		if = {
			limit = { 
				NOR = { 
					religion_group = christian 
					religion = hindu
					religion = buddhist
					religion = jain
				} 
				is_female = yes
			}
			add_trait = nun
		}

		if = {
			limit = { prisoner = yes }
			prisoner = no
		}

		if = {
			limit = { is_married = yes }
			any_spouse = { remove_spouse = ROOT }
		}

		if = { #Make them actually become monks/nuns if you have Societies.
			limit = { 
				has_dlc = "Mystics"	
				is_in_society = no		
				OR = {
					religion = catholic
					AND = {
						is_heretic = no
						OR = {
							religion = fraticelli
							religion = waldensian
							religion = lollard
							religion = cathar
						}
					}
				} 
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = {

				if = {
					limit = {
						religion = catholic
					}

					random_list = {

						# Catholic women normally enter the Order of the Sacred Magdalene.
						80 = {
							trigger = {
								is_female = yes
							}

							remove_trait = nun
							add_trait = lustful
							add_trait = nymphomaniac

							join_society = ggsm_order_sacred_magdalene
						}

						# Catholic men normally enter the Benedictines.
						80 = {
							trigger = {
								is_female = no
							}

							join_society = monastic_order_benedictine
						}

						# Either sex may enter the Dominicans.
						# Zealous and Cruel greatly increase the chance.
						20 = {
							modifier = {
								factor = 4
								trait = zealous
							}

							modifier = {
								factor = 4
								trait = cruel
							}

							join_society = monastic_order_dominican
						}
					}
				}

				else = {
					random_list = { 
						50 = { 
							trigger = { religion = catholic } 
							join_society = monastic_order_benedictine 
						} 
						50 = { 
							join_society = monastic_order_dominican 
						} 
					}
				}
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				OR = {
					religion = orthodox
					AND = {
						is_heretic = no
						OR = {
							religion = bogomilist
							religion = monothelite
							religion = iconoclast
							religion = paulician
						}
					}
				}
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_orthodox
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				OR = {
					religion = nestorian
					AND = {
						is_heretic = no
						religion = messalian
					}
				}
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_nestorian
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				OR = {
					religion = miaphysite
					AND = {
						is_heretic = no
						religion = monophysite
					}
				}
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_monophysite
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				religion = hindu 
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_hindu
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				religion = buddhist 
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_buddhist
			}
		}

		if = {
			limit = { 
				has_dlc = "Mystics" 
				is_in_society = no
				religion = jain
			}

			custom_tooltip = { text = tooltip_vows_monk_joins_society }

			hidden_tooltip = { 
				join_society = monastic_order_jain
			}
		}

		if = {
			limit = { 
				any_realm_lord = { 
					is_theocracy = yes 
					religion = ROOT 
				}
			}

			custom_tooltip = { text = tooltip_vows_monk_goes_to_theocracy }

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

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

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

					preferred_limit = { 
						same_society_as = ROOT #The one he just joined.
					} 

					preferred_limit = { 
						vassal_of = FROM
					} 

					ROOT = { 
						move_character = PREV
					} 
				}
			}
		}

		if = {
			limit = { 
				NOR = { 
					trait = zealous 
					dynasty = FROM 
				} 
			}

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

		if = {
			limit = { 
				NOT = { trait = zealous } 
				dynasty = FROM 
			}

			opinion = { 
				modifier = opinion_cloistered_me_family 
				who = FROM 
				years = 20 
			}
		}

		if = {
			limit = { 
				is_child_of = FROM 
			}

			hidden_tooltip = { 
				FROM = { 
					character_event = { id = HFP.23001 } 
				} 
			}
		}
	}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = { #Hate you too much to just send you off.
				factor = 0
				prisoner = yes
				NOT = { is_child_of = FROM }
				FROM = { is_benevolent_trigger = no }
				NOT = {
					reverse_opinion = {
						who = FROM
						value = -20
					}
				}
			}
			modifier = { #Like him too much to do it.
				factor = 0
				reverse_opinion = {
					who = FROM
					value = 50
				}
			}
			modifier = { #I'm a good ruler and he is a dynastic heir.
				factor = 0
				is_child_of = FROM
				dynasty = FROM
				FROM = { is_benevolent_trigger = yes }
				reverse_opinion = {
					who = FROM
					value = 0
				}
			}
			modifier = { #Must protect the line.
				factor = 5
				is_child_of = FROM
				NOT = { dynasty = FROM }
			}
			modifier = { #Hate you.
				factor = 5
				is_child_of = FROM
				is_rival = FROM
			}
			modifier = { #There are better spares.
				factor = 20
				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
						NOR = { 
							character = ROOT 
							has_negative_congenital_trigger = yes
							has_infertile_trait_trigger = yes
							has_severe_disability_trigger = yes
						}
					}
				}
			}
			modifier = { #Must preserve the realm from falling to evil.
				factor = 5
				is_evil_trigger = yes
				FROM = { 
					is_benevolent_trigger = yes 
					any_child = { 
						is_alive = yes
						NOR = { 
							character = ROOT 
							is_evil_trigger = yes
						}
					}
				}
			}
		}
	}
	send_child_into_hiding = {
		only_rulers = yes
		is_high_prio = yes
		
		filter = dynasty
		ai_target_filter = dynasty
		ai_check_interval = 12
	
		from_potential = {
			is_ruler = yes
			has_regent = no
			has_children = yes
			OR = {
				ai = no
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}
		
		potential = {
			NOT = { is_inaccessible_trigger = yes }
			is_ruler = no
			liege = { character = FROM }
			NOT = { is_plot_target_of = FROM }
			OR = {
				has_character_modifier = suspected_murder_plot
				FROM = {
					any_known_plotter = {
						target = PREV
						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}
				}
			}
			NOT = { any_spouse = { character = FROM } }
			OR = {
				father = { character = FROM }
				mother = { character = FROM }
			}
			OR = {
				father = { ai = no }
				mother = { ai = no }
				is_female = no
				is_primary_heir = yes
				AND = {
					is_female = yes
					FROM = { has_law = true_cognatic_succession }
				}
			}
			NOT = { has_character_modifier = went_out_of_hiding_timer }
		}
		
		allow = {
			in_command = no
			prisoner = no
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
			has_job_title = no
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip
				hidden_tooltip = {
					OR = {
						has_character_modifier = suspected_murder_plot
						FROM = {
							any_known_plotter = {
								target = PREV
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = recently_went_out_of_hiding_tooltip
				hidden_tooltip = {
					NOT = { has_character_modifier = went_out_of_hiding_timer }
				}
			}
		}
		effect = {
			custom_tooltip = { text = go_into_hiding_info_tooltip }
			add_trait = in_hiding
			set_character_flag = do_not_disturb
			hidden_tooltip = {
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							NOT = { has_character_flag = murder_in_motion }
							NOT = { character = FROM }
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6004 }
						any_backed_character = { 
							character_event = { id = CM.6004 }
						}
					}
					any_plotter = {
						target = ROOT
						limit = {
							has_character_flag = murder_in_motion
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6180 }
						any_backed_character = { 
							character_event = { id = CM.6004 }
						}
					}
				}
				father = {
					if = {
						limit = {
							NOT = { character = FROM }
							NOT = { plot_target_char = { character = ROOT } }
							NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
							NOT = { is_rival = ROOT }
						}
						character_event = { id = CM.6004 }
					}
				}
				mother = {
					if = {
						limit = {
							NOT = { character = FROM }
							NOT = { plot_target_char = { character = ROOT } }
							NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
							NOT = { is_rival = ROOT }
						}
						character_event = { id = CM.6004 }
					}
				}
				any_spouse = {
					limit = {
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
						NOT = { is_rival = ROOT }
					}
					character_event = { id = CM.6004 }
				}
				any_child = {
					limit = {
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
						NOT = { is_rival = ROOT }
					}
					character_event = { id = CM.6004 }
				}
				any_lover = {
					limit = {
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
						NOT = { is_rival = ROOT }
						NOT = { spouse = { character = ROOT } }
					}
					character_event = { id = CM.6004 }
				}
				any_sibling = {
					limit = {
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
						NOT = { is_rival = ROOT }
						NOT = { is_lover = ROOT }
					}
					character_event = { id = CM.6004 }
				}
				any_rival = {
					limit = {
						NOT = { character = FROM }
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
					}
					character_event = { id = CM.6004 }
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5
			}
			modifier = {
				factor = 0.5
				NOT = { 
					FROM = { 
						trait = in_hiding
					} 
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					reverse_opinion = {
						who = FROM
						value = -24
					}
				}
			}
			modifier = {
				factor = 1.5
				reverse_opinion = {
					who = FROM
					value = 25
				}
			}
			modifier = {
				factor = 5
				FROM = { trait = in_hiding }
			}
			modifier = {
				factor = 10
				FROM = { trait = paranoid }
			}					
		}
	}
	
	take_child_out_of_hiding = {
		only_rulers = yes
		is_high_prio = yes
		
		filter = dynasty
		ai_target_filter = dynasty
		ai_check_interval = 12
	
		from_potential = {
			is_ruler = yes
			has_regent = no
			has_children = yes
		}
		
		potential = {
			trait = in_hiding
			is_ruler = no
			liege = { character = FROM }
			is_child_of = FROM
			prisoner = no
			NOT = { any_spouse = { character = FROM } }
		}
		
		allow = {
			trait = in_hiding
		}
		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
				duration = 180
				hidden = yes
			}
			hidden_tooltip = {
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							NOT = { character = FROM }
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6005 }
					}
				}
				father = {
					if = {
						limit = {
							NOT = { character = FROM }
						}
						character_event = { id = CM.6005 }
					}
				}
				mother = {
					if = {
						limit = {
							NOT = { character = FROM }
						}
						character_event = { id = CM.6005 }
					}
				}
				any_sibling = {
					limit = {
						ROOT = {
							NOT = { is_plot_target_of = THIS }
						}
					}
					character_event = { id = CM.6005 }
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.3
				FROM = { trait = paranoid }
			}
			modifier = {
				factor = 0
				OR = {
					has_character_modifier = suspected_murder_plot
					FROM = {
						any_known_plotter = {
							target = PREV
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
					}
				}
			}		
		}
	}
	
	go_into_hiding = {
		only_playable = yes
		is_high_prio = yes
		
		filter = self
		ai_target_filter = self
		ai_check_interval = 12
		
		potential = {
			prisoner = no
			is_inaccessible_trigger = no
			OR = {
				ai = no
				trait = amateurish_plotter
				trait = flamboyant_schemer
				trait = intricate_webweaver
				trait = elusive_shadow
			}
		}
		allow = {
			in_command = no
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
			has_job_title = no
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip
				hidden_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
				hidden_tooltip = {
					NOT = { has_character_modifier = went_out_of_hiding_timer }
				}
			}
		}
		effect = {
			set_character_flag = do_not_disturb
			custom_tooltip = { text = go_into_hiding_info_tooltip }
			add_trait = in_hiding
			hidden_tooltip = {                    # Notify player and close family and plotters
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							NOT = { has_character_flag = murder_in_motion }
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6000 }
						any_backed_character = { 
							character_event = { id = CM.6000 }
						}
					}
					any_plotter = {
						target = ROOT
						limit = {
							has_character_flag = murder_in_motion
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6180 }
						any_backed_character = { 
							character_event = { id = CM.6000 }
						}
					}
				}
				any_spouse = {
					limit = {
						NOT = { plot_target_char = { character = ROOT } }
						NOT = { any_backed_character = { plot_target_char = { character = ROOT } } }
						NOT = { is_rival = ROOT }
					}
					character_event = { id = CM.6000 }
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1 
			
			modifier = {
				factor = 0
				ROOT = {
					any_plotter = {
						target = ROOT
						is_primary_heir = yes
						ai = no
					}
				}
			}
			modifier = {
				factor = 0.5
			}
			modifier = {
				factor = 0.1
				age = 65
			}
			modifier = {
				factor = 0.1
				trait = brave
			}
			modifier = {
				factor = 2
				trait = depressed
			}
			modifier = {
				factor = 5
				trait = craven
			}
			modifier = {
				factor = 10
				trait = paranoid
			}
		}
	}
	
	come_out_of_hiding = {
		only_rulers = yes
		is_high_prio = yes
		
		filter = self
		ai_target_filter = self
		ai_check_interval = 12
		
		potential = {
			is_ruler = yes
			trait = in_hiding
			NOT = { has_character_flag = in_religious_seclusion }
		}
		allow = {
			OR = {
				OR = {
					age = 16
					NOT = {	trait = incapable }
				}
				regent = {
					NOT = { trait = deceitful }
					NOT = { trait = ambitious }
					NOT = { is_rival = ROOT }
				}
			}
		}
		effect = {
			add_character_modifier = {
				name = went_out_of_hiding_timer
				duration = 180
				hidden = yes
			}
			clr_character_flag = do_not_disturb
			custom_tooltip = { text = come_out_of_hiding_info_tooltip }
			remove_trait = in_hiding
			hidden_tooltip = {                    # Notify player and close family and plotters
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6001 }
					}
				}
				any_spouse = {
					limit = {
						ROOT = {
							NOT = { is_plot_target_of = THIS }
						}
					}
					character_event = { id = CM.6001 }
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.3
				trait = paranoid
			}
			modifier = {
				factor = 0
				NOT = {
					ROOT = {
						any_plotter = {
							target = ROOT
							is_primary_heir = yes
							ai = no
						}
					}
				}
				OR = {
					has_character_modifier = suspected_murder_plot
					any_known_plotter = {
						target = ROOT
						OR = {
							has_plot = plot_kill_character
							has_plot = plot_kill_spouse
						}
					}
				}
			}
		}
	}

	send_spouse_into_hiding = {
		only_rulers = yes
		is_high_prio = yes
		
		filter = spouse
		ai_target_filter = spouse
		ai_check_interval = 12
		
		from_potential = {
			is_ruler = yes
			has_regent = no
			OR = {
				ai = no
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}
		
		potential = {
			NOT = { is_inaccessible_trigger = yes }
			is_ruler = no
			is_married = FROM
			liege = { character = FROM }
			NAND = { 
				is_plot_target_of = FROM 
				FROM = {
					OR = {
						has_plot = plot_kill_character
						has_plot = plot_kill_spouse
					}
				}
			}
			NOT = { has_character_modifier = went_out_of_hiding_timer }
		}
		
		allow = {
			in_command = no
			prisoner = no
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
			has_job_title = no
			NOT = { is_ruler = yes }
			custom_tooltip = {
				text = is_target_of_murder_plot_tooltip
				hidden_tooltip = {
					OR = {
						has_character_modifier = suspected_murder_plot
						FROM = {
							any_known_plotter = {
								target = PREV
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = recently_went_out_of_hiding_tooltip
				hidden_tooltip = {
					NOT = { has_character_modifier = went_out_of_hiding_timer }
				}
			}
		}
		
		effect = {
			set_character_flag = do_not_disturb
			custom_tooltip = { text = go_into_hiding_info_tooltip }
			add_trait = in_hiding
			hidden_tooltip = {                    # Notify player and close family and plotters
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							NOT = { has_character_flag = murder_in_motion }
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6002 }
						any_backed_character = { 
							character_event = { id = CM.6002 }
						}
					}
					any_plotter = {
						target = ROOT
						limit = {
							has_character_flag = murder_in_motion
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6180 }
						any_backed_character = { 
							character_event = { id = CM.6002 }
						}
					}
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1 
			
			modifier = {
				factor = 0.5
			}
			modifier = {
				factor = 0.1
				spouse = {
					age = 65
				}
			}
			modifier = {
				factor = 0.1
				spouse = { 
					trait = pregnant 
					NOT = {
						father_of_unborn = {
							character = ROOT
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				NOT = { 
					FROM = { 
						trait = in_hiding
					} 
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					opinion = {
						who = spouse
						value = -24
					}
				}
			}
			modifier = {
				factor = 1.5
				opinion = {
					who = spouse
					value = 25
				}
			}
			modifier = {
				factor = 5
				trait = in_hiding
			}
			modifier = {
				factor = 10
				trait = paranoid
			}
			modifier = {
				factor = 10
				spouse = { 
					trait = pregnant 
					father_of_unborn = {
						character = ROOT
					}
				}
			}
		}
	}

	take_spouse_out_of_hiding = {
		only_rulers = yes
		is_high_prio = yes
		
		filter = spouse
		ai_target_filter = spouse
		ai_check_interval = 12
		
		from_potential = {
			is_ruler = yes
			has_regent = no
		}
		
		potential = {
			trait = in_hiding
			is_ruler = no
			is_married = FROM
			liege = { character = FROM }
			prisoner = no
		}
		
		allow = {
			trait = in_hiding
		}
		
		effect = {
			add_character_modifier = {
				name = went_out_of_hiding_timer
				duration = 180
				hidden = yes
			}
			clr_character_flag = do_not_disturb
			custom_tooltip = { text = come_out_of_hiding_info_tooltip }
			remove_trait = in_hiding
			hidden_tooltip = {                    # Notify player and close family and plotters
				ROOT = {
					any_plotter = {
						target = ROOT
						limit = {
							spouse = { NOT = { character = PREV } }
							OR = {
								has_plot = plot_kill_character
								has_plot = plot_kill_spouse
							}
						}
						character_event = { id = CM.6003 }
					}
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.3
				trait = paranoid
			}
			modifier = {
				factor = 0
				spouse = {
					OR = {
						has_character_modifier = suspected_murder_plot
						FROM = {
							any_known_plotter = {
								target = PREV
								OR = {
									has_plot = plot_kill_character
									has_plot = plot_kill_spouse
								}
							}
						}
					}
				}
			}			
		}
	}
}
