# 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/spouse/liege/religious_head/rivals/society/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/spouse/liege/religious_head/rivals/society/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 (but not yourself)
#	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)
# society: the other members of your society (but not yourself)
#	all: all living characters (Avoid if possible. VERY CPU-HEAVY!)
#	

targeted_decisions = {

	break_up_with_lover = {
		ai_target_filter = court
		ai_check_interval = 12
		from_potential = {
			has_dlc = "Way of Life"
			has_lover = yes
		}
		potential = {
			is_lover = FROM
			NOT = { any_spouse = { character = FROM } }
			NOT = { any_consort = { character = FROM } }
		}
		allow = {
			always = yes
		}
		effect = {
			FROM = { character_event = { id = WoL.1109 tooltip = EVTTOOLTIP64046 } }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
				always = yes
			}
			modifier = {
				factor = 0.1
				FROM = {
					OR = {
						trait = lustful
						trait = hedonist
					}
				}
			}
			modifier = {
				factor = 0.5
				reverse_opinion = { who = FROM value = 0 }
			}
			modifier = {
				factor = 0
				reverse_opinion = { who = FROM value = 25 }
				NOT = { age = 40 }
			}
			modifier = {
				factor = 0
				reverse_opinion = { who = FROM value = 50 }
			}
		}
	}

	seduce_decision = {
		ai_target_filter = realm
		ai_check_interval = 12
	
		from_potential = {
			OR = {
				has_focus = focus_seduction
				AND = {
					has_dlc = "Way of Life"
					NOT = { num_of_lovers = 1 }
					OR = {
						trait = lustful
						trait = seducer
						trait = seductress
					}
					at_location = ROOT
				}
			}
			is_marriage_adult = yes
			NOT = {
				is_pregnant = yes
				trait = incapable
				trait = eunuch
				trait = infirm
				trait = inbred
				trait = imbecile
				has_any_opinion_modifier = opinion_seducing
				has_character_modifier = seduction_timer
				has_character_modifier = messalian_prayer
			}
			OR = {
				ai = no
				AND = {
					OR = {
						is_female = no
						trait = lustful
						trait = hedonist
						trait = homosexual
						AND = {
							any_spouse = { trait = homosexual }
							NOT = { any_spouse = { NOT = { trait = homosexual } } }
						}
						AND = {
							any_consort = { trait = homosexual }
							is_ruler = no
						}
					}
					NOT = {
						trait = chaste
						trait = shy
						num_of_lovers = 5
					}
				}
			}
			prisoner = no
		}
		potential = {
			is_marriage_adult = yes
			prisoner = no
			
			OR = {
				AND = {
					FROM = { NOT = { trait = homosexual } }
					is_opposite_sex = FROM
				}
				AND = {
					FROM = { trait = homosexual }
					same_sex = FROM
				}
			}
			OR = {
				AND = {
					NOT = { is_child_of = FROM }
					NOT = { mother_even_if_dead = { is_child_of = FROM } }
					NOT = { father_even_if_dead = { is_child_of = FROM } }
					FROM = {
						NOT = { is_child_of = ROOT }
						NOT = { mother_even_if_dead = { is_child_of = ROOT } }
						NOT = { father_even_if_dead = { is_child_of = ROOT } }
					}
				}
				AND = {
					is_pc_marriage_religion_trigger = yes
					FROM = { is_pc_marriage_religion_trigger = yes }
				}
				AND = {
					trait = lunatic
					trait = syphilitic
				}
				AND = {
					trait = possessed
					trait = syphilitic
				}
			}
			NOR = {
				character = FROM
				trait = incapable
				trait = eunuch
				trait = infirm
				is_lover = FROM
				is_former_lover = FROM
				is_consort = FROM
				is_married = FROM
			}
		}
		allow = {
			religion_group = FROM
			custom_tooltip = {
				text = SEDUCTION_TARGET_TIMER_RECENT
				hidden_tooltip = {
					NOT = { has_character_modifier = seduction_target_timer }
				}
			}
			custom_tooltip = {
				text = SEDUCTION_DISTANCE_OKAY
				hidden_tooltip = {
					OR = {
						location = { FROM = { location = { NOT = { distance = { where = PREVPREV value = 150 } } } } }
						same_realm = FROM
					}
				}
			}
			is_ill = no
			is_pregnant = no
			NOT = { trait = celibate }
			FROM = {
				is_ill = no
				NOT = { trait = celibate }
			}
		}
		effect = {
			hidden_tooltip = {
				if = {
					limit = { ai = no }
					add_character_modifier = {
						name = seduction_target_timer
						duration = 730
						hidden = yes
					}
				}
				if = {
					limit = { ai = yes }
					add_character_modifier = {
						name = seduction_target_timer
						duration = 90
						hidden = yes
					}
				}
				FROM = {
					hidden_tooltip = { change_variable = { which = "lifestyle_hedonist" value = 1 } }
					if = {
						limit = { ai = yes }
						add_character_modifier = {
							name = seduction_timer
							duration = 365
							hidden = yes
						}
					}
					opinion = {
						who = ROOT
						modifier = opinion_seducing
						years = 1000
					}
					if = {
						limit = {
							is_close_relative = ROOT
							is_bs_marriage_religion_trigger = no
						}
						character_event = { id = WoL.102 days = 1 } # Warning - Incest scandal risk
						break = yes
					}
					if = {
						limit = {
							same_sex = ROOT
						}
						character_event = { id = WoL.104 days = 1 } # Warning - Homosexual scandal risk
						break = yes
					}
					if = {
						limit = {
							religion_group = christian
							OR = {
								is_priest = yes
								is_ascetic_trigger = yes
								ROOT = { is_priest = yes }
								ROOT = { is_ascetic_trigger = yes }
							}
						}
						character_event = { id = WoL.103 days = 1 } # Warning - Priest scandal risk
						break = yes
					}
					if = {
						limit = { 
							age_diff = {
								who = ROOT
								years = 25
							}
						}
						character_event = { id = WoL.101 days = 1 } # Warning - Age scandal risk
						break = yes
					}
					character_event = { id = WoL.100 days = 1 } # No warning - Let the chase begin!
				}
			}
		}
		ai_will_do = {
			factor = 1 		# 1 = 100% chance every month (for each allowed target!)
			modifier = {
				factor = 0.5
				always = yes
			}
			modifier = {
				factor = 0
				has_game_rule = {
					name = ai_seduction
					value = off
				}
			}
			modifier = {
				factor = 0
				is_female = yes
				has_character_modifier = lustful_affair_timer
			}
			modifier = {
				factor = 0
				is_female = yes
				age = 40
			}
			modifier = {
				factor = 0
				is_female = no
				age = 60
			}
			#Target Traits (negative)
			modifier = {
				factor = 0
				OR = {
					trait = chaste
					
					trait = imbecile
					has_unattractive_trait_trigger = yes
				}
			}
			modifier = {
				factor = 0
				is_close_relative = FROM
				FROM = {
					NOT = {
						trait = lustful
						trait = hedonist
						trait = divine_blood
						is_bs_marriage_religion_trigger = yes
					}
				}
			}
			#don't target faithful spouses/concubines
			modifier = {
				factor = 0
				is_married = yes
				spouse = { reverse_opinion = { who = FROM value = 25 } }
			}
			modifier = {
				factor = 0
				is_consort = yes
				liege = { reverse_opinion = { who = FROM value = 50 } }
			}
			#don't target liege's spouse or kids unless you're brave or reckless or hate them
			modifier = {
				factor = 0
				FROM = {
					liege = {
						NOT = { character = FROM }
						OR = {
							any_child = { character = ROOT }
							any_spouse = { character = ROOT }
						}
					}
					NOT = {
						trait = brave
						trait = seducer
						trait = seductress
						opinion = { who = liege value = -25 }
					}
				}
			}
			#same for the top liege
			modifier = {
				factor = 0
				FROM = {
					top_liege = {
						NOT = { character = FROM }
						OR = {
							any_child = { character = ROOT }
							any_spouse = { character = ROOT }
						}
					}
					NOT = {
						trait = brave
						trait = seducer
						trait = seductress
						opinion = { who = top_liege value = -25 }
					}
				}
			}
			modifier = {
				factor = 0
				location = { FROM = { location = { NOT = { distance = { where = PREVPREV value = 150 } } } } }
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.1
				OR = {
					ai = no
					any_spouse = { ai = no }
					any_consort = { ai = no }
				}
			}
			#"Dude, don't you have enough kids already?" factors
			modifier = {
				factor = 0.5
				FROM = {
					is_female = no
					num_of_children = 3
				}
			}
			modifier = {
				factor = 0.1
				FROM = {
					is_female = no
					num_of_children = 6
				}
			}
			modifier = {
				factor = 0.5
				FROM = {
					is_female = no
					num_of_children = 8
				}
			}

			modifier = {
				factor = 2
				NOT = { age = 20 }
			}
			modifier = {
				factor = 0.5
				age = 25
			}
			modifier = {
				factor = 0.5
				age = 30
			}
			modifier = {
				factor = 0.25
				age = 35
			}
						
			
			
			#enough lovers already
			modifier = {
				factor = 0
				FROM = {
					num_of_lovers = 1
					NOT = {
						trait = lustful
						trait = hedonist
						trait = seducer
						trait = seductress
					}
				}
			}
			modifier = {
				factor = 0.25
				FROM = { num_of_lovers = 2 }
			}
			modifier = {
				factor = 0.25
				FROM = { num_of_lovers = 3 }
			}
			modifier = {
				factor = 0.25
				FROM = { num_of_lovers = 4 }
			}
			modifier = {
				factor = 10
				FROM = {
					OR = {
						trait = lustful
						trait = hedonist
						trait = seducer
						trait = seductress
					}
					has_focus = focus_seduction
				}
			}
			modifier = {
				factor = 0.25
				is_close_relative = FROM
				FROM = {
					OR = {
						trait = lustful
						trait = hedonist
						trait = divine_blood
						is_bs_marriage_religion_trigger = yes
					}
				}
			}
			modifier = {
				factor = 2
				OR = {
					trait = lustful
					trait = hedonist
				}
			}
			modifier = {
				factor = 2
				trait = gregarious
			}
			modifier = {
				factor = 10
				trait = fair
			}
			modifier = {
				factor = 0.5
				NOT = { diplomacy = 4 }
			}
			modifier = {
				factor = 0.5
				NOT = { diplomacy = 8 }
			}
			modifier = {
				factor = 1.5
				diplomacy = 10
			}
			modifier = {
				factor = 1.5
				diplomacy = 12
			}
			modifier = {
				factor = 1.5
				diplomacy = 14
			}
			modifier = {
				factor = 1.5
				diplomacy = 16
			}
			modifier = {
				factor = 1.5
				diplomacy = 18
			}
			modifier = {
				factor = 1.5
				diplomacy = 20
			}
			modifier = {
				factor = 5 # A more interesting quarry
				OR = {
					is_playable = yes
					is_married = yes
				}
			}
			modifier = {
				factor = 0.5
				NOR = { 
					has_focus = focus_seduction
					has_ambition = obj_find_lover 
				}
			}
			modifier = {
				factor = 0.1
				FROM = { 
					NOR = { 
						has_focus = focus_seduction 
						has_ambition = obj_find_lover
					} 
				}
			}
		}
	}
	
	stop_seduce_decision = {
		filter = self
		ai_target_filter = self
	
		potential = {
			ai = no
			is_marriage_adult = yes
			OR = {
				has_focus = focus_seduction
				AND = {
					has_dlc = "Way of Life"
					OR = {
						trait = lustful
						trait = seducer
						trait = seductress
					}
				}
			}
			OR = {
				has_character_flag = seduction_confirmed
				has_any_opinion_modifier = opinion_seducing
			}
		}
		
		effect = {
			random_opinion_modifier_target = {
				limit = {
					ROOT = {
						has_opinion_modifier = {
							who = PREV
							modifier = opinion_seducing
						}
					}
				}
				save_event_target_as = target_seduced
				ROOT = { character_event = { id = WoL.118 tooltip = stop_seduce_decision_tt } }
			}
		}
		
		
		ai_will_do = {
			factor = 0
		}
	}
	
	stop_seduce_decision_target = {
		ai_target_filter = realm
	
		from_potential = {
			ai = no
			is_marriage_adult = yes
			OR = {
				has_focus = focus_seduction
				AND = {
					has_dlc = "Way of Life"
					OR = {
						trait = lustful
						trait = seducer
						trait = seductress
					}
				}
			}
			OR = {
				has_character_flag = seduction_confirmed
				has_any_opinion_modifier = opinion_seducing
			}
		}
		
		potential = {
			FROM = {
				has_opinion_modifier = {
					who = ROOT
					modifier = opinion_seducing
				}
			}
		}
		
		effect = {
			save_event_target_as = target_seduced
			hidden_tooltip = {
				FROM = { character_event = { id = WoL.118 } }
			}
		}
		
		
		ai_will_do = {
			factor = 0
		}
	}
	
	decision_spy_on = {
		filter = realm
		ai_target_filter = realm
		ai_check_interval = 12
		from_potential = {
			OR = {
				has_focus = focus_intrigue
				AND = {
					has_dlc = "Way of Life"
					trait = schemer
				}
			}			
			has_regent = no
			NOT = { has_any_opinion_modifier = opinion_spying_on }
			NOT = { has_any_opinion_modifier = opinion_breaking_out }
			prisoner = no
		}
		potential = {
			is_adult = yes
			same_realm = FROM
			NOT = { character = FROM }
		}
		allow = {
			NOT = { trait = incapable }
			prisoner = no
			is_within_diplo_range = FROM
			custom_tooltip = {
				text = NOT_RECENTLY_SPIED_UPON
				hidden_tooltip = {
					NOT = { has_character_modifier = spying_target_timer }
				}
			}
			FROM = {
				custom_tooltip = {
					text = NOT_RECENTLY_SPIED
					hidden_tooltip = {
						NOT = { has_character_modifier = spying_timer }
					}
				}
			}
		}
		effect = {
			hidden_tooltip = {
				if = {
					limit = { ai = no }
					add_character_modifier = {
						name = spying_target_timer
						duration = 365
						hidden = yes
					}
				}
				if = {
					limit = { ai = yes }
					add_character_modifier = {
						name = spying_target_timer
						duration = 60
						hidden = yes
					}
				}
				FROM = {
					hidden_tooltip = { change_variable = { which = "lifestyle_intrigue" value = 1 } }
					any_opinion_modifier_target = {
						limit = {
							reverse_has_opinion_modifier = {
								who = PREV
								modifier = opinion_spying_on
							}
						}
						reverse_remove_opinion = {
							who = PREV
							modifier = opinion_spying_on
						}
					}
					opinion = {
						who = ROOT
						modifier = opinion_spying_on
						months = 12000
					}
					character_event = { id = WoL.2050 days = 1 }
				}
			}
		}
		
		ai_will_do = {
			factor = 1 		# 1 = 100% chance every month (for each allowed target!)
			modifier = {
				factor = 0
				NOR = {
					is_plot_target_of = FROM
					is_rival = FROM
					is_married = FROM
					vassal_of = FROM
					is_liege_of = FROM
					AND = {
						is_ruler = yes
						same_liege = FROM
					}
				}
			}
			modifier = {
				factor = 0
				reverse_opinion = { who = FROM value = 0 }
			}
			modifier = {
				factor = 2.0
				has_plot = yes
			}
			modifier = {
				factor = 5.0
				FROM = { trait = paranoid }
			}
			modifier = {
				factor = 0.5
				FROM = { trait = trusting }
			}
		}
	}

	stop_spy_on_decision = {
		filter = self
		ai_target_filter = self
	
		potential = {
			ai = no
			OR = {
				has_focus = focus_intrigue
				AND = {
					has_dlc = "Way of Life"
					trait = schemer
				}
			}	
			has_any_opinion_modifier = opinion_spying_on
		}
		
		effect = {
			random_opinion_modifier_target = {
				limit = {
					ROOT = {
						has_opinion_modifier = {
							who = PREV
							modifier = opinion_spying_on
						}
					}
				}
				save_event_target_as = target_spy_on
				ROOT = { character_event = { id = WoL.2069 tooltip = stop_spy_on_decision_tt } }
			}
		}
		
		
		ai_will_do = {
			factor = 0
		}
	}
	
	stop_spy_on_decision_target = {
		ai_target_filter = realm
	
		from_potential = {
			ai = no
			OR = {
				has_focus = focus_intrigue
				AND = {
					has_dlc = "Way of Life"
					trait = schemer
				}
			}	
			has_any_opinion_modifier = opinion_spying_on
		}
		
		potential = {
			FROM = {
				has_opinion_modifier = {
					who = ROOT
					modifier = opinion_spying_on
				}
			}
		}
		
		effect = {
			save_event_target_as = target_spy_on
			hidden_tooltip = {
				FROM = { character_event = { id = WoL.2069 } }
			}
		}
		
		
		ai_will_do = {
			factor = 0
		}
	}
	
	decision_break_free = {
		is_high_prio = yes
		ai_check_interval = 12
		filter = sub_realm
		ai_target_filter = dynasty
		
		from_potential = {
			OR = {
				has_focus = focus_intrigue
				AND = {
					has_dlc = "Way of Life"
					trait = schemer
				}
			}	
			NOT = { trait = incapable }
			prisoner = no
			NOT = { has_any_opinion_modifier = opinion_breaking_out }
			NOT = { has_any_opinion_modifier = opinion_spying_on }
		}
		
		potential = {
			NOT = { character = FROM }
			OR = {
				AND = {
					prisoner = yes
					liege = { character = FROM }
					host = { NOT = { character = FROM } }
				}
				AND = {
					is_female = yes
					is_consort = yes
					prisoner = no
					consort = {
						NOT = { character = FROM }
						reverse_has_opinion_modifier = {
							who = ROOT
							modifier = opinion_forced_consort
						}
					}
					is_close_relative = FROM
				}
			}
		}
		
		allow = {
			NOT = { trait = incapable }
			NOT = { has_character_modifier = failed_escape }
		}
		
		effect = {
			hidden_tooltip = {
				FROM = {
					hidden_tooltip = { change_variable = { which = "lifestyle_intrigue" value = 1 } }
					opinion = {
						who = ROOT
						modifier = opinion_breaking_out
						months = 12000
					}
					if = {
						limit = { ROOT = { prisoner = yes } }
						character_event = { id = WoL.2200 days = 1 }
					}
					if = {
						limit = { ROOT = { prisoner = no } }
						character_event = { id = WoL.2201 days = 1 }
					}
				}
			}
		}
		
		
		ai_will_do = {
			factor = 1 		# 1 = 100% chance every month (for each allowed target!)
			modifier = {
				factor = 10
				is_primary_heir = FROM
			}
			modifier = {
				factor = 2
				OR = {
					is_married = FROM
					AND = {
						is_child_of = FROM
						NOT = { trait = bastard }
					}
				}
			}
			modifier = {
				factor = 0
				is_rival = FROM
			}
			modifier = {
				factor = 0.5
				NOT = { reverse_opinion = { who = FROM value = 50 } }
			}
			modifier = {
				factor = 0.5
				NOT = { reverse_opinion = { who = FROM value = 0 } }
			}
			modifier = {
				factor = 0
				trait = decadent
				religion_group = muslim
			}
		}
	}

	invite_to_party = {
		is_high_prio = yes
		ai_target_filter = realm
		only_playable = yes
		ai_check_interval = 4
		from_potential = {
			is_playable = yes
			OR = {
				has_focus = focus_carousing
				trait = hedonist
				trait = socializer
			}
			has_regent = no
			OR = {
				is_not_busy_trigger = yes
				has_character_modifier = organizing_party
			}
			NOT = { had_character_flag = { flag = inviting_guests_to_party_timer days = 90 } }
			NOT = { has_character_flag = party_host }
			prisoner = no
		}
		potential = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			is_within_diplo_range = FROM
			NOT = { has_character_flag = carousing_invite }
			NOT = { character = FROM }                            # Can't do this decision on yourself...
			is_abroad_trigger = no
		}
		allow = {
			NOT = { has_character_modifier = i_hate_carousing }
			is_ill = no
			is_pregnant = no
			same_realm = FROM   # Can only invite characters in same realm!
			is_not_busy_trigger = yes
			NOT = { has_character_modifier = organizing_party }
			NOT = { has_character_modifier = party_carousing }
			war = no
			NOT = {
				reverse_has_opinion_modifier = {
					modifier = opinion_declined_party
					who = FROM
				}
			}
			FROM = {
				war = no
				NOT = { has_character_modifier = party_timer }
				OR = {
					NOT = { religion_group = muslim }
					trait = decadent
					trait = hedonist
					trait = drunkard
				}
			}
		}
		effect = {
			FROM = {
				if = {
					limit = {
						NOT = { has_character_modifier = organizing_party }
					}
					add_character_modifier = {
						name = organizing_party
						duration = 120
					}
					hidden_tooltip = { character_event = { id = WoL.4010 days = 120 } } # Party to be held in four months
					set_character_flag = inviting_guests_to_party_timer
				}
				add_character_modifier = {
					name = do_not_disturb
					duration = 165
					hidden = yes
				}
			}
			hidden_tooltip = {
				letter_event = { id = WoL.4000 days = 7 } # Invitee receives event - any number of invitees possible
			}
			set_character_flag = carousing_invite
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				reverse_opinion = { who = FROM value = 0 }
			}
			modifier = {
				factor = 0
				is_rival = FROM
			}
			modifier = {
				factor = 0
				NOT = {
					is_ruler = yes
					has_job_title = yes
					is_close_relative = FROM
				}
			}
			modifier = {
				factor = 0
				lower_tier_than = COUNT
				NOT = { vassal_of = FROM }
			}
			modifier = {
				factor = 0
				lower_tier_than = DUKE
				NOT = {
					vassal_of = FROM
					capital_scope = {
						any_neighbor_province = {
							OR = {
								owner = { character = ROOT }
								owner = { vassal_of = ROOT }
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				FROM = { has_character_modifier = organizing_party } # AI will only invite one person
			}
		}
	}

	duel_decision = {
		is_high_prio = yes
		
		#filter = rivals
		ai_target_filter = rivals
		ai_check_interval = 12
		from_potential = {
			is_adult = yes
			prisoner = no
			has_dlc = "Way of Life"
			OR = {
				has_focus = focus_war
				trait = duelist
			}			
			has_regent = no
			is_inaccessible_trigger = no

			OR = {
				ai = no
				
				is_female = no

				AND = {
					is_female = yes
					OR = {
						trait = brave
						is_pagan_religion = yes
						is_nomadic = yes
						religion = buddhist
						religion = bogomilist
						religion = mazdaki
						religion = tondrakian
						gender_equality_trigger = yes
					}
				}
			}
		}
		
		potential = {
			is_adult = yes
			prisoner = no
			NOT = { character = FROM }
			is_inaccessible_trigger = no

			OR = {
				AND = {
					OR = {
						is_rival = FROM
						is_foe = FROM
						AND = {
							FROM = { trait = zealous }
							OR = {	
								AND = {
									religion = FROM
									trait = excommunicated
								}
								AND = {
									FROM = { religion_group = muslim }
									trait = decadent
								}
							}
						}
						has_game_rule = {
							name = dueling
							value = restricted
						}
					}
					OR = {
						is_female = no

						#Both FROM and ROOT have gender equality
						AND = {
							OR = {
								trait = brave
								gender_equality_trigger = yes
								is_pagan_religion = yes
								is_nomadic = yes
								religion = buddhist
								religion = bogomilist
								religion = tondrakian
								religion = mazdaki
								religion = messalian
								religion = cathar
							}
							FROM = {
								OR = {
									gender_equality_trigger = yes
									is_pagan_religion = yes
									is_nomadic = yes
									religion = buddhist
									religion = bogomilist
									religion = tondrakian
									religion = mazdaki
									religion = messalian
									religion = cathar
								}
							}
						}
					}
				}
				has_game_rule = {
					name = dueling
					value = unrestricted
				}
			}
		}
		
		allow = {
			OR = {
				AND = {
					#Valid reasons for duel
					OR = {
						custom_tooltip = {
							text = duel_tooltip_rivals
							is_rival = FROM
						}
						custom_tooltip = {
							text = duel_tooltip_foes
							is_foe = FROM
						}
						custom_tooltip = {
							text = duel_tooltip_excommunicated
							religion = FROM
							FROM = { trait = zealous }
							trait = excommunicated
						}
						custom_tooltip = {
							text = duel_tooltip_decadent
							FROM = { religion_group = muslim }
							FROM = { trait = zealous }
							trait = decadent
						}
						has_game_rule = {
							name = dueling
							value = restricted
						}
					}

					#Both are healthy
					custom_tooltip = {
						text = duel_tooltip_sickness
						FROM = {
							NOR = {
								trait = incapable
								trait = infirm
								trait = has_aztec_disease
								trait = has_small_pox
								trait = has_measles
								trait = has_bubonic_plague
								trait = has_typhus
								trait = has_typhoid_fever
								trait = has_tuberculosis
								trait = leper
								trait = pneumonic
							}
						}
						ROOT = {
							NOR = {
								trait = incapable
								trait = infirm
								trait = has_aztec_disease
								trait = has_small_pox
								trait = has_measles
								trait = has_bubonic_plague
								trait = has_typhus
								trait = has_typhoid_fever
								trait = has_tuberculosis
								trait = leper
								trait = pneumonic
								age = 70
							}
						}
					}
					
					#Checks gender and some religious stuff
					custom_tooltip = {
						text = duel_tooltip_valid_target
						hidden_tooltip = { ### Not female or challenger religion accepts female warriors
							 OR = {
								is_female = no

								#Both FROM and ROOT have gender equality
								AND = {
									OR = {
										trait = brave
										gender_equality_trigger = yes
										is_pagan_religion = yes
										is_nomadic = yes
										religion = buddhist
										religion = bogomilist
										religion = tondrakian
										religion = mazdaki
										religion = messalian
										religion = cathar
									}
									FROM = {
										OR = {
											gender_equality_trigger = yes
											is_pagan_religion = yes
											is_nomadic = yes
											religion = buddhist
											religion = bogomilist
											religion = tondrakian
											religion = mazdaki
											religion = messalian
											religion = cathar
										}
									}
								}
							}
							### Not priest or challenger religion is pagan
							OR = {
								is_priest = no
								FROM = { is_pagan_religion = yes }
							}
							
						}
					}
				}
				has_game_rule = {
					name = dueling
					value = unrestricted
				}
			}
			custom_tooltip = {
				text = duel_tooltip_challenged_before
				hidden_tooltip = {
					NOT = {
						has_opinion_modifier = { who = FROM modifier = opinion_fought_duel }
					}
					FROM = { 
						NOT = { has_opinion_modifier = { who = ROOT modifier = opinion_fought_duel } }
						NOT = { has_opinion_modifier = { who = ROOT modifier = opinion_fled_duel } } 
					}
				}
			}
			custom_tooltip = {
				text = duel_tooltip_recent_duel
				hidden_tooltip = {
					FROM = { NOT = { has_character_modifier = recent_duel_timer } }
					NOT = { has_character_modifier = recent_duel_timer }
				}
			}
			custom_tooltip = {
				text = duel_tooltip_busy
				hidden_tooltip = {
					FROM = {
						is_not_busy_trigger = yes
						NOT = { war = yes }
					}
					is_not_busy_trigger = yes
					NOT = { war = yes }
				}
			}
			is_within_diplo_range = ROOT # CPU HEAVY!
		}
		
		effect = {
			if = { 
				limit = {
					OR = {
						age = 50
						trait = wounded
						is_maimed_trigger = yes
					}
				}
				custom_tooltip = { 
					text = dishonorable_duel_tooltip
					hidden_tooltip = {
						FROM = {
							any_realm_character = {
								limit = {
									NOT = { character = FROM }
									OR = {
										trait = honest
										trait = kind
										trait = just
									}
								}
								opinion = {
									modifier = opinion_dishonorable_duel
									who = PREV
									months = 36
								}
							}
						}
					}
				}
			}
			FROM = {
				hidden_tooltip = { change_variable = { which = "lifestyle_martial" value = 1 } }
				if = {
					limit = { religion = jain }
					piety = -20
					custom_tooltip = { text = jain_ahimsa_tooltip }
				}
				if = {
					limit = { religion = cathar }
					piety = -20
				}
				add_character_modifier = {
					name = recent_duel_timer
					duration = 365
					hidden = yes
				}
			}
			hidden_tooltip = {
				character_event = { id = WoL.11000 }
			}
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				has_character_modifier = declined_prestige_duel_timer
			}
			modifier = {
				factor = 0
				FROM = { religion = cathar }
			}
			modifier = {
				factor = 0
				FROM = { religion = jain }
			}
			modifier = {
				factor = 0.1
			}
		}
	}
}

##################################
# OLD STYLE REGULAR DECISIONS
##################################

decisions = {
	
	# Build an observatory (learning focus)
	build_observatory = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			is_playable = yes
			has_focus = focus_scholarship
			NOT = { trait = incapable }
			NOT = { trait = scholar }
			NOT = { trait = mystic }
			NOT = { has_character_flag = building_observatory }
			NOT = { has_character_flag = built_observatory }
			NOT = { has_character_modifier = studying_the_stars }
			NOT = { has_character_modifier = heliocentrist_scholar }
			NOT = { has_character_modifier = weird_scholar }
			prisoner = no
		}
		allow = {
			prisoner = no
			wealth = 25
			is_adult = yes
			is_not_busy_trigger = yes
		}
		effect = {
			wealth = -25
			set_character_flag = building_observatory
			hidden_tooltip = { character_event = { id = WoL.6000 } }
		}
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0
				NOT = { wealth = 50 }
			}
			modifier = {
				factor = 0.25
				trait = zealous
			}
			modifier = {
				factor = 2
				trait = cynical
			}
			modifier = {
				factor = 0.1
				NOT = { age = 30 }
			}
		}
	}
}