targeted_decisions = {

	prisoner_torture = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			num_of_prisoners > 0
			is_not_in_regency_trigger = yes
		}

		potential = {
			host = { character = FROM }
			prisoner = yes
			practical_age >= 13
			NOT = { has_character_modifier = tortured }
		}

		allow = {
			prisoner = yes
			diplomatic_immunity = no
		}

		effect = {
			hidden_effect = {
				FROM = {
					if = {
						limit = {
							has_nickname = no
							is_adult = yes
							is_incapable = no
						}

						random_list = {
							5 = { give_nickname = nick_the_cruel }
							5 = { give_nickname = nick_the_evil }
							5 = { give_nickname = nick_the_tormentor }
							5 = { give_nickname = nick_the_depraved }
							100 = { }
						}
					}

					clear_prison_reasons = ROOT
				}

				random_list = {
					# Normal torture options
					10 = {
						random_list = {
							10 = {
								# Racks
								FROM = { character_event = { id = RIP.20001 } }
								character_event = { id = RIP.20002 }
							}

							10 = {
								# Whipping
								FROM = { character_event = { id = RIP.20003 } }
								character_event = { id = RIP.20004 }
							}

							10 = {
								# Rats
								FROM = { character_event = { id = RIP.20005 } }
								character_event = { id = RIP.20006 }
							}

							20 = {
								# Heat exposure
								trigger = {
									month >= 3
									month <= 8

									FROM = {
										capital_scope = {
											OR = {
												region = world_africa
												region = world_middle_east
												region = world_persia
												region = world_india_rajastan
											}
										}
									}
								}

								FROM = { character_event = { id = RIP.20009 } }
								character_event = { id = RIP.20010 }
							}

							20 = {
								# Cold exposure
								trigger = {
									OR = {
										month >= 11
										month <= 1
									}

									FROM = {
										capital_scope = {
											OR = {
												region = world_europe_north
												region = world_steppe_west
												region = world_steppe_east
											}
										}
									}
								}

								FROM = { character_event = { id = RIP.20011 } }
								character_event = { id = RIP.20012 }
							}
						}

						hidden_effect = {
							opinion = {
								name = opinion_tortured_me
								who = FROM
							}

							mother = {
								opinion = {
									name = opinion_tortured_close_kin
									who = FROM
								}
							}

							father = {
								opinion = {
									name = opinion_tortured_close_kin
									who = FROM
								}
							}

							any_spouse = {
								opinion = {
									name = opinion_tortured_close_kin
									who = FROM
								}
							}

							any_child = {
								opinion = {
									name = opinion_tortured_close_kin
									who = FROM
								}
							}

							if = {
								limit = {
									NOR = {
										dynasty = FROM
										sibling = FROM
									}
								}

								any_sibling = {
									opinion = {
										name = opinion_tortured_close_kin
										who = FROM
									}
								}

								any_dynasty_member = {
									opinion = {
										name = opinion_tortured_family
										who = FROM
									}
								}
							}
						}
					}

					20 = {
						# Lunatic option
						trigger = {
							FROM = { trait = lunatic }
						}

						FROM = { character_event = { id = RIP.20007 } }
						character_event = { id = RIP.20008 }
					}

					70 = {
						# Phalaris option
						trigger = {
							FROM = {
								has_dlc = "Holy Fury"
								independent = yes
								culture = greek

								primary_title = {
									title = k_sicily
								}

								capital_scope = {
									de_jure_liege = d_sicily
								}

								completely_controls = d_sicily

								OR = {
									trait = lunatic
									trait = possessed
									trait = impaler
									trait = cruel
								}

								OR = {
									learning >= 15
									has_character_modifier = brazen_bull # Already has it from Impaler event
								}

								is_female = no
								is_alternate_start = no

								NOR = {
									has_dynasty_flag = flag_phalaris_event
									has_global_flag = flag_phalaris_bloodline
								}
							}
						}

						FROM = { character_event = { id = HF.24002 } }
						character_event = { id = HF.24003 }
					}
				}
			}

			tooltip = {
				add_character_modifier = {
					name = tortured
					years = 2
				}

				opinion = {
					name = opinion_tortured_me
					who = FROM
				}
			}

			if = {
				limit = {
					has_game_rule = {
						name = punishment_release_prisoner
						value = on
					}
				}

				imprison  = no
			}

			FROM = {
				show_scope_change = no

				piety = -20

				random = {
					chance = 25
					add_trait_cruel_effect = yes
				}

				if = {
					limit = { trait = kind }

					random = {
						chance = 50
						remove_trait_kind_effect = yes
					}

					hidden_effect = {
						random_list = {
							30 = { add_trait_stressed_effect = yes }
							10 = { add_trait_depressed_effect = yes }
							60 = { } # Nothing
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					piety > 100

					opinion = {
						who = ROOT
						value < 40
					}

					liege = {
						NOT = { dynasty = ROOT }
					}

					OR = {
						is_rival = ROOT
						trait = cruel
						trait = impaler
						trait = wroth
						trait = arbitrary
						trait = paranoid
						trait = deceitful
						trait = proud
						trait = lunatic
						trait = possessed
					}

					NOR = {
						trait = kind
						trait = just
						trait = patient
						trait = shy
						trait = greedy
					}
				}
			}

			mult_modifier = {
				factor = 10

				FROM = {
					OR = {
						is_rival = ROOT
						trait = cruel
						trait = impaler
						trait = wroth
						trait = arbitrary
					}
				}
			}
		}
	}

	prisoner_mutilate = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 3

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			num_of_prisoners > 0
			is_adult = yes
			prisoner = no
			is_incapable = no

			OR = {
				trait = cruel
				trait = impaler
				trait = wroth
				trait = arbitrary

				AND = {
					trait = envious
					trait = ugly
				}
			}

			NOT = { trait = kind }
		}

		potential = {
			host = { character = FROM }
			prisoner = yes
			practical_age >= 13

			NAND = {
				trait = one_legged
				trait = one_handed
				trait = disfigured

				OR = {
					trait = one_eyed
					trait = blinded
				}

				trigger_if = {
					limit = { is_female = no }
					trait = eunuch
				}
			}

			trigger_if = {
				limit = { has_character_flag = recently_mutilated }

				had_character_flag = {
					flag = recently_mutilated
					years >= 2
				}
			}
		}

		allow = {
			prisoner = yes
			diplomatic_immunity = no
		}

		effect = {
			hidden_effect = {
				set_character_flag = recently_mutilated

				FROM = {
					if = {
						limit = {
							has_nickname = no
							is_adult = yes
							is_incapable = no
						}
					}

					random_list = {
						5 = { give_nickname = nick_the_evil }
						5 = { give_nickname = nick_the_tormentor }
						5 = { give_nickname = nick_the_butcher }
						5 = { give_nickname = nick_the_mutilator }
						5 = { give_nickname = nick_the_monster }
						5 = { give_nickname = nick_son_of_evilgod }
						100 = { }
					}

					clear_prison_reasons = ROOT
				}

				random_list = {
					20 = {
						# One-legged
						trigger = {
							NOT = { trait = one_legged }
						}

						FROM = { character_event = { id = RIP.20013 } }
						character_event = { id = RIP.20014 }
					}

					20 = {
						# One-handed
						trigger = {
							NOT = { trait = one_handed }
						}

						FROM = { character_event = { id = RIP.20015 } }
						character_event = { id = RIP.20016 }
					}

					20 = {
						# One-eyed
						trigger = {
							NOR = {
								trait = one_eyed
								trait = blinded
							}
						}

						FROM = { character_event = { id = RIP.20017 } }
						character_event = { id = RIP.20018 }
					}

					20 = {
						# Disfigured
						trigger = {
							NOT = { trait = disfigured }
						}

						FROM = { character_event = { id = RIP.20019 } }
						character_event = { id = RIP.20020 }
					}

					20 = {
						# Castrate
						trigger = {
							is_female = no
							NOT = { trait = eunuch }
						}

						FROM = { character_event = { id = RIP.20021 } }
						character_event = { id = RIP.20022 }
					}
				}
			}

			if = {
				limit = {
					has_game_rule = {
						name = punishment_release_prisoner
						value = on
					}
				}

				imprison = no
			}

			opinion = {
				name = opinion_mutilated_me
				who = FROM
			}

			FROM = {
				show_scope_change = no

				piety = -50

				random = {
					chance = 25
					add_trait_cruel_effect = yes
				}
			}

			hidden_effect = {
				mother = {
					opinion = {
						name = opinion_mutilated_close_kin
						who = FROM
					}
				}

				father = {
					opinion = {
						name = opinion_mutilated_close_kin
						who = FROM
					}
				}

				any_spouse = {
					opinion = {
						name = opinion_mutilated_close_kin
						who = FROM
					}
				}

				any_child = {
					opinion = {
						name = opinion_mutilated_close_kin
						who = FROM
					}
				}

				if = {
					limit = {
						NOR = {
							dynasty = FROM
							sibling = FROM
						}
					}

					any_sibling = {
						opinion = {
							name = opinion_mutilated_close_kin
							who = FROM
						}
					}

					any_dynasty_member = {
						opinion = {
							name = opinion_mutilated_family
							who = FROM
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.66

			trigger = {
				FROM = {
					piety > 100

					opinion = {
						who = ROOT
						value < 40
					}

					liege = {
						NOT = { dynasty = ROOT }
					}

					OR = {
						is_rival = ROOT
						trait = cruel
						trait = impaler
						trait = wroth
						trait = arbitrary
					}
				}
			}

			mult_modifier = {
				factor = 0.5

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

	prisoner_read_poetry = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			trait = poet
			num_of_prisoners > 0
			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			host = { character = FROM }
			prisoner = yes
			age >= 13

			trigger_if = {
				limit = {
					has_character_flag = read_poem_1
					has_character_flag = read_poem_2
					has_character_flag = read_poem_3
				}

				had_character_flag = {
					flag = read_poem_1
					days >= 45
				}

				had_character_flag = {
					flag = read_poem_2
					days >= 45
				}

				had_character_flag = {
					flag = read_poem_3
					days >= 45
				}
			}
		}

		allow = {
			prisoner = yes
			diplomatic_immunity = no
		}

		effect = {
			hidden_effect = {
				FROM = {
					# TODO: Sort out weird flag checking logic below
					random_list = {
						33 = {
							trigger = {
								ROOT = {
									NOR = {
										has_character_flag = read_poem_1
										has_character_flag = read_poem_2
									}
								}
							}

							# Poem 1
							character_event = { id = RIP.20023 }

							ROOT = {
								set_character_flag = read_poem_1
								character_event = { id = RIP.20024 }
								clr_character_flag = read_poem_3
							}
						}

						33 = {
							trigger = {
								ROOT = {
									OR = {
										has_character_flag = read_poem_1
										has_character_flag = read_poem_2
										has_character_flag = read_poem_3
									}

									NOR = {
										has_character_flag = read_poem_2
										has_character_flag = read_poem_3
									}
								}
							}

							# Poem 2
							character_event = { id = RIP.20025 }

							ROOT = {
								set_character_flag = read_poem_2
								character_event = { id = RIP.20026 }
								clr_character_flag = read_poem_1
							}
						}

						33 = {
							trigger = {
								ROOT = {
									OR = {
										has_character_flag = read_poem_1
										has_character_flag = read_poem_2
										has_character_flag = read_poem_3
									}

									NOR = {
										has_character_flag = read_poem_1
										has_character_flag = read_poem_3
									}
								}
							}

							# Poem 3
							character_event = { id = RIP.20027 }

							ROOT = {
								set_character_flag = read_poem_3
								character_event = { id = RIP.20028 }
								clr_character_flag = read_poem_2
							}
						}
					}

					clear_prison_reasons = ROOT
				}
			}

			if = {
				limit = {
					has_game_rule = {
						name = punishment_release_prisoner
						value = on
					}
				}

				imprison = no
			}

			opinion = {
				name = opinion_bad_poetry
				who = FROM
			}
		}

		ai_will_do = {
			factor = 0.02

			trigger = {
				reverse_opinion = {
					who = FROM
					value < 40
				}
			}

			mult_modifier = {
				factor = 5

				FROM = {
					OR = {
						is_rival = ROOT
						trait = cruel
						trait = envious
						trait = arbitrary
					}
				}
			}
		}
	}

	# Humiliate
	prisoner_humiliation = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			num_of_prisoners > 0
			is_adult = yes
			prisoner = no
			is_incapable = no
		}

		potential = {
			host = { character = FROM }
			prisoner = yes
			practical_age >= 13
			NOT = { has_character_modifier = publicly_humiliated }
		}

		allow = {
			prisoner = yes
			diplomatic_immunity = no
		}

		effect = {
			hidden_effect = {
				FROM = {
					# Walk of shame
					if = {
						limit = {
							ROOT = {
								OR = {
									has_character_modifier = incestuous_adulterer
									has_character_modifier = incestuous_adulteress
									has_character_modifier = adulterer
									has_character_modifier = adulteress
									has_character_modifier = known_sodomite
									has_character_modifier = cradle_robber
									has_character_modifier = adulterous_priest
								}
							}
						}

						character_event = { id = RIP.15005 }
						ROOT = { character_event = { id = RIP.15006 } }
					}
					else = {
						random_list = {
							# Tar 'n' feathers
							33 = {
								trigger = {
									is_nomadic = no
									is_tribal = no
								}

								character_event = { id = RIP.15001 }
								ROOT = { character_event = { id = RIP.15002 } }
							}

							# Tar 'n' feathers NOMAD
							33 = {
								trigger = { is_nomadic = yes }

								character_event = { id = RIP.15007 }
								ROOT = { character_event = { id = RIP.15008 } }
							}

							# the Stocks
							33 = {
								trigger = {
									is_nomadic = no
									is_tribal = no
								}

								character_event = { id = RIP.15003 }
								ROOT = { character_event = { id = RIP.15004 } }
							}
						}
					}

					clear_prison_reasons = ROOT
				}
			}

			if = {
				limit = {
					has_game_rule = {
						name = punishment_release_prisoner
						value = on
					}
				}

				imprison = no
			}

			add_character_modifier = {
				name = publicly_humiliated
				years = 10
			}

			opinion = {
				name = opinion_humiliated_me
				who = FROM
			}

			hidden_effect = {
				mother = {
					opinion = {
						name = opinion_humiliated_close_kin
						who = FROM
					}
				}

				father = {
					opinion = {
						name = opinion_humiliated_close_kin
						who = FROM
					}
				}

				any_spouse = {
					opinion = {
						name = opinion_humiliated_close_kin
						who = FROM
					}
				}

				any_child = {
					opinion = {
						name = opinion_humiliated_close_kin
						who = FROM
					}
				}

				if = {
					limit = {
						NOR = {
							dynasty = FROM
							sibling = FROM
						}
					}

					any_sibling = {
						opinion = {
							name = opinion_humiliated_close_kin
							who = FROM
						}
					}

					any_dynasty_member = {
						opinion = {
							name = opinion_humiliated_family
							who = FROM
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					NOT = { trait = greedy }

					opinion = {
						who = ROOT
						value < 40
					}
				}
			}

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

			mult_modifier = {
				factor = 10

				is_pretender = yes
				is_rival = ROOT

				FROM = {
					OR = {
						is_pretender = yes
						is_primary_heir = yes
					}
				}
			}
		}
	}

	execute_eat = {
		filter = court
		ai_target_filter = court
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			num_of_prisoners > 0
			is_adult = yes
			prisoner = no
			is_incapable = no

			OR = {
				trait = cannibal
				graphical_culture = beargfx
				graphical_culture = dragongfx
			}

			OR = {
				trait = possessed
				trait = lunatic
				graphical_culture = beargfx
				graphical_culture = dragongfx
			}
		}

		potential = {
			host = { character = FROM }
			prisoner = yes
			age >= 12
		}

		allow = {
			prisoner = yes
			diplomatic_immunity = no
		}

		effect = {
			hidden_effect = {
				any_dynasty_member = {
					limit = {
						is_offmap_ruler = no
						is_close_relative = ROOT
						NOT = { character = FROM }
					}

					character_event = {
						id = RIP.11511
						days = 1
					}
				}

				FROM = {
					add_blood_splatter_effect = yes

					random_list = {
						50 = { # Nothing happens
							trigger = {
								ROOT = {
									immortal = no

									trigger_if = {
										limit = { controls_religion = yes }
										religion_group = FROM
									}
								}
							}
						}

						40 = { # Get sick
							trigger = {
								immortal = no
								NOT = { has_character_flag = demon_child }

								ROOT = {
									immortal = no

									trigger_if = {
										limit = { controls_religion = yes }
										religion_group = FROM
									}
								}
							}

							random_list = {
								50 = { # Food Poisoning
									if = {
										limit = {
											num_of_symptoms < 1
											is_ill = no

											NOR = {
												has_character_flag = developing_illness
												has_character_flag = disease_not_serious
											}
										}

										set_character_flag = got_food_poisoning
										set_character_flag = developing_illness

										character_event = {
											id = RIP.5023
											days = 5
										}
									}
								}

								25 = { # Diarrhea - Not Serious
									if = {
										limit = {
											num_of_symptoms < 1
											is_ill = no

											NOR = {
												has_character_flag = developing_illness
												has_character_flag = disease_not_serious
											}
										}

										set_character_flag = disease_not_serious

										character_event = {
											id = RIP.5002
											days = 5
										}

										character_event = {
											id = RIP.11004
											days = 10
											random = 50
										}
									}
								}

								25 = { # Vomiting - Not Serious
									if = {
										limit = {
											num_of_symptoms < 1
											is_ill = no

											NOR = {
												has_character_flag = developing_illness
												has_character_flag = disease_not_serious
											}
										}

										set_character_flag = disease_not_serious

										character_event = {
											id = RIP.5003
											days = 5
										}

										character_event = {
											id = RIP.11005
											days = 10
											random = 50
										}
									}
								}
							}
						}

						10 = { # Gain power!
							trigger = {
								has_game_rule = {
									name = supernatural_events
									value = on
								}
							}

							ROOT = {
								if = {
									limit = {
										controls_religion = yes
										NOT = { religion_group = FROM }
									}

									trigger_switch = {
										on_trigger = religion_group

										christian         = { FROM = { set_character_flag = pope_eater } }
										muslim            = { FROM = { set_character_flag = caliph_eater } }
										pagan_group       = { FROM = { set_character_flag = fylkir_eater } }
										zoroastrian_group = { FROM = { set_character_flag = fire_eater } }
										jewish_group      = { FROM = { set_character_flag = non_kosher } }
										indian_group      = { FROM = { set_character_flag = dont_even_exist } }
									}
								}
							}

							character_event = { id = RIP.11510 }
						}
					}

					if = {
						limit = { has_nickname = no }

						random_list = {
							20 = { give_nickname = nick_the_cannibal }
							15 = { give_nickname = nick_the_dragon }
							15 = { give_nickname = nick_the_abomination }
							10 = { give_nickname = nick_the_monster }
							40 = { } # No nickname
						}
					}
				}
			}

			death = {
				death_reason = death_execution_eaten
				killer = FROM
			}

			save_event_target_as = kinslayer_target

			FROM = {
				add_kinslayer_trait_effect = yes

				if = {
					limit = {
						NOR = {
							trait = lunatic
							graphical_culture = beargfx
							graphical_culture = dragongfx
						}
					}

					add_trait = lunatic
				}

				if = {
					limit = {
						NOR = {
							has_character_modifier = crazy_cannibal
							graphical_culture = beargfx
							graphical_culture = dragongfx
						}
					}

					add_character_modifier = {
						name = crazy_cannibal
						duration = -1
					}
				}
			}

			if = {
				limit = {
					religion_openly_bon_or_reformed_trigger = yes

					FROM = {
						ai = no
						is_ironman = yes
					}
				}

				FROM = {
					set_character_flag = achievement_bon_appetit
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

}