######################################
#
# Polygamy Events
#
# Event ID 89000 - 89249 reserved
#
######################################

### Wives fall in love with each other
character_event = {
	id = 89000
	desc = EVTDESC89000
	picture = GFX_evt_lovers

	is_triggered_only = yes # on_yearly_pulse

	has_dlc = "The Sword of Islam"
	religion_group = muslim
	only_women = yes
	is_married = yes
	min_age = 16
	only_capable = yes
	prisoner = no

	trigger = {
		trait = homosexual

		spouse = {
			any_spouse = {
				trait = homosexual
				NOT = { character = ROOT }
				at_location = ROOT

				opinion = {
					who = ROOT
					value >= 0
				}

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

		NOR = {
			has_character_flag = thelma
			has_character_flag = louise
		}
	}

	option = {
		name = EVTOPTA89000

		set_character_flag = thelma
		save_event_target_as = thelma

		spouse = {
			show_scope_change = no

			random_spouse = {
				show_scope_change = no

				limit = {
					trait = homosexual
					NOT = { character = ROOT }
					at_location = ROOT

					opinion = {
						who = ROOT
						value >= 0
					}

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

				set_character_flag = louise
				save_event_target_as = louise
				add_lover = ROOT
			}

			character_event = {
				id = 89001
				days = 14
			}
		}
	}
}

# Husband finds out
character_event = {
	id = 89001
	desc = EVTDESC89001
	picture = GFX_evt_lovers

	is_triggered_only = yes

	option = { # Accept it
		name = EVTOPTA89001

		prestige = -50

		any_spouse = {
			show_scope_change = no

			limit = {
				OR = {
					has_character_flag = thelma
					has_character_flag = louise
				}
			}

			clr_character_flag = thelma
			clr_character_flag = louise

			opinion = {
				name = opinion_grateful
				who = ROOT
				years = 1
			}
		}
	}

	option = { # Order them to stop
		name = EVTOPTB89001

		random = {
			chance = 50

			event_target:thelma = {
				show_scope_change = no

				remove_lover = event_target:louise
				clr_character_flag = thelma
			}

			event_target:louise = {
				clr_character_flag = louise
			}
		}

		if = {
			limit = {
				event_target:thelma = {
					is_lover = event_target:louise
				}
			}

			character_event = {
				id = 89002
				days = 30
			}
		}

		piety = 20
	}

	option = { # Execute them
		name = EVTOPTC89001

		any_spouse = {
			show_scope_change = no

			limit = {
				OR = {
					has_character_flag = thelma
					has_character_flag = louise
				}
			}

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}
}

# Husband finds out they've fled!
character_event = {
	id = 89002
	desc = EVTDESC89002
	picture = GFX_evt_bad_news

	is_triggered_only = yes

	option = {
		name = EVTOPTA89002

		character_event = {
			id = 89003
			tooltip = EVTTOOLTIP89003
		}
	}
}

# The wives drive their carriage over a cliff
character_event = {
	id = 89003
	desc = EVTDESC89003
	picture = GFX_evt_carriage

	is_triggered_only = yes

	option = {
		name = EVTOPTA89003

		any_spouse = {
			show_scope_change = no

			limit = {
				OR = {
					has_character_flag = thelma
					has_character_flag = louise
				}
			}

			death = { death_reason = death_suicide_fall }
		}
	}
}

### Secondary Wife schemes to become First Wife

# Secondary Wife thinks she should be First Wife - Setup
character_event = {
	id = 89004

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, polygamy_events
	hide_window = yes

	has_dlc = "The Sword of Islam"
	only_playable = yes
	is_married = yes
	only_capable = yes
	prisoner = no

	trigger = {
		has_polygamy = yes

		trigger_if = {
			limit = { is_female = yes }

			is_inaccessible_trigger = no
			is_main_spouse = no
			is_pregnant = no
			NOT = { trait = content }

			spouse = {
				is_incapable = no
				prisoner = no

					trigger_if = {
					limit = { has_character_flag = primary_wife_change }

					had_character_flag = {
						flag = primary_wife_change
						years >= 10
					}
				}
			}
		}
		trigger_else = {
			any_spouse = {
				is_playable = no
				is_inaccessible_or_incapable_trigger = no
				is_main_spouse = no
				is_pregnant = no
				NOT = { trait = content }
			}

			trigger_if = {
				limit = { has_character_flag = primary_wife_change }

				had_character_flag = {
					flag = primary_wife_change
					years >= 10
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = envious
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = envious
				}
			}
		}

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = ambitious
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = ambitious
				}
			}
		}

		mult_modifier = {
			factor = 1.33

			trigger_if = {
				limit = { is_female = yes }
				trait = deceitful
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = deceitful
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			trigger_if = {
				limit = { is_female = yes }
				trait = kind
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = kind
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			trigger_if = {
				limit = { is_female = yes }
				trait = shy
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = shy
				}
			}
		}

	#	mult_modifier = {
	#		factor = 0.25
	#
	#		trigger_if = {
	#			limit = { is_female = yes }
	#			trait = content
	#		}
	#		trigger_else = {
	#			any_spouse = {
	#				is_main_spouse = no
	#				trait = content
	#			}
	#		}
	#	}
	}

	immediate = {
		if = {
			limit = { is_female = yes }
			character_event = { id = 89005 }
		}
		else = {
			random_spouse = {
				limit = {
					is_playable = no
					is_inaccessible_or_incapable_trigger = no
					is_main_spouse = no
					is_pregnant = no
				}

				character_event = { id = 89005 }
			}
		}
	}
}

# Secondary Wife thinks she should be First Wife
character_event = {
	id = 89005
	desc = EVTDESC89005
	picture = GFX_evt_quarrel
	portrait = spouse

	is_triggered_only = yes

	option = { # Kill First Wife!
		name = EVTOPTA89005

		trigger = {
			OR = {
				trait = cruel
				trait = deceitful
				trait = lunatic
			}
		}

		set_character_flag = plotting_second_wife

		spouse = { # Husband
			show_scope_change = no

			random_list = {
				50 = {
					spouse = { # Primary spouse
						show_scope_change = no

						death = {
							death_reason = death_murder_poison
							killer = ROOT
						}
					}

					character_event = {
						id = 89006
						days = 4
						tooltip = EVTTOOLTIP89007
					}
				}

				50 = {
					spouse = {
						show_scope_change = no

						character_event = {
							id = 89007
							days = 4
							tooltip = EVTTOOLTIP89007
						}
					}
				}
			}
		}

		ai_chance = { factor = 10 }
	}

	option = { # Woo husband
		name = EVTOPTB89005

		set_character_flag = plotting_second_wife

		spouse = {
			show_scope_change = no

			character_event = {
				id = 89010
				days = 4
				tooltip = EVTTOOLTIP89010
			}
		}

		ai_chance = { factor = 60 }
	}

	option = { # Do nothing
		name = EVTOPTC89005

		trigger = {
			NOT = { trait = ambitious }
		}

		random = {
			chance = 50
			add_trait_content_effect = yes
		}

		piety = 20

		ai_chance = { factor = 30 }
	}
}

# First Wife is murdered by Second Wife
character_event = {
	id = 89006
	desc = EVTDESC89006
	picture = GFX_evt_death

	is_triggered_only = yes

	option = { # Accept it
		name = EVTOPTA89006

		prestige = -25
	}

	option = { # Send killer to prison
		name = EVTOPTB89006

		random_spouse = {
			show_scope_change = no

			limit = { has_character_flag = plotting_second_wife }

			imprison = yes
			clr_character_flag = plotting_second_wife
		}
	}

	option = { # Have killer executed
		name = EVTOPTC89006

		random_spouse = {
			show_scope_change = no

			limit = { has_character_flag = plotting_second_wife }

			clr_character_flag = plotting_second_wife

			death = {
				death_reason = death_execution_poison
				killer = ROOT
			}
		}
	}
}

# First Wife is informed of failed murder attempt
character_event = {
	id = 89007
	desc = EVTDESC89007
	picture = GFX_evt_shadow

	is_triggered_only = yes

	option = {
		name = EVTOPTA89007

		spouse = {
			show_scope_change = no

			character_event = {
				id = 89008
				days = 4
				tooltip = EVTTOOLTIP89008
			}
		}
	}
}

# Husband is informed of failed murder attempt
character_event = {
	id = 89008
	desc = EVTDESC89008
	picture = GFX_evt_shadow

	is_triggered_only = yes

	option = { # Execute wife
		name = EVTOPTA89008

		random_spouse = {
			show_scope_change = no

			limit = { has_character_flag = plotting_second_wife }

			clr_character_flag = plotting_second_wife

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = { # Imprison wife
		name = EVTOPTB89008

		random_spouse = {
			show_scope_change = no

			limit = { has_character_flag = plotting_second_wife }

			imprison = yes
			clr_character_flag = plotting_second_wife
		}
	}

	option = { # Tell wife to fight own battles
		name = EVTOPTC89008

		prestige = -25

		spouse = {
			show_scope_change = no

			character_event = {
				id = 89009
				days = 4
			}

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 2
			}
		}
	}
}

# First Wife told to fight her own battles.
character_event = {
	id = 89009
	desc = EVTDESC89009
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89009
	}
}

# Second Wife tries to manipulate Husband
character_event = {
	id = 89010
	desc = EVTDESC89010
	picture = GFX_evt_quarrel

	immediate = {
		set_character_flag = primary_wife_change
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTA89010

		spouse = {
			show_scope_change = no

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 4
			}

			character_event = {
				id = 89011
				days = 16
			}
		}

		FROM = {
			show_scope_change = no

			make_primary_spouse = yes

			opinion = {
				name = opinion_happy
				who = ROOT
				years = 2
			}
		}
	}

	option = {
		name = EVTOPTB89010

		reverse_opinion = {
			name = opinion_disappointed
			who = FROM
			years = 2
		}
	}
}

# Former First Wife schemes against new First Wife
character_event = {
	id = 89011
	desc = EVTDESC89011
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = {
		name = EVTOPTA89011

		trigger = {
			OR = {
				trait = cruel
				trait = deceitful
				trait = lunatic
			}
		}

		random = {
			chance = 30

			spouse = { # Husband
				show_scope_change = no

				spouse = { # Primary spouse
					show_scope_change = no

					death = {
						death_reason = death_murder_poison
						killer = ROOT
					}
				}

				character_event = { id = 89012 }
			}
		}

		ai_chance = { factor = 30 }
	}

	option = {
		name = EVTOPTB89011

		ai_chance = { factor = 70 }
	}
}

# Former First Wife murders new First Wife
character_event = {
	id = 89012
	desc = EVTDESC89012
	picture = GFX_evt_death

	is_triggered_only = yes

	option = {
		name = EVTOPTA89012

		prestige = -25
	}

	option = {
		name = EVTOPTB89012

		reverse_imprison = FROM
	}

	option = {
		name = EVTOPTC89012

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}
}

### First Wife thinks her son should get a county if he is not heir - Setup
character_event = {
	id = 89014

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, polygamy_events
	hide_window = yes

	has_dlc = "The Sword of Islam"
	only_playable = yes
	only_men = yes
	is_married = yes
	only_capable = yes
	prisoner = no

	trigger = {
		has_polygamy = yes
		demesne_size >= 5 # TODO: Use num_of_count_titles instead?

		spouse = {
			is_inaccessible_or_incapable_trigger = no
			is_main_spouse = yes
			is_pregnant = no

			any_child = {
				is_child_of = ROOT
				is_female = no
				practical_age >= 14
				is_primary_heir = no
				has_inheritance_blocker = no
			}

			NOR = {
				has_character_flag = envious_mother

				any_child = {
					is_primary_heir = yes
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4
			spouse = { trait = envious }
		}

		mult_modifier = {
			factor = 2
			spouse = { trait = ambitious }
		}

		mult_modifier = {
			factor = 0.5
			spouse = { trait = slothful }
		}

		mult_modifier = {
			factor = 0.25
			spouse = { trait = content }
		}
	}

	immediate = {
		spouse = {
			character_event = { id = 89015 }
		}
	}
}

### First Wife thinks her son should get a county if he is not heir
character_event = {
	id = 89015
	desc = EVTDESC89015
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Speak to husband
		name = EVTOPTA89015

		set_character_flag = envious_mother

		random_child = {
			show_scope_change = no

			limit = {
				is_female = no
				practical_age >= 14
				is_primary_heir = no
				has_inheritance_blocker = no

				father = {
					is_married = ROOT
				}
			}

			character_event = {
				id = 89016
				days = 2
				tooltip = EVTTOOLTIP89016
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTB89015

		ai_chance = { factor = 0 }
	}
}

# Son informed
character_event = {
	id = 89016
	desc = EVTDESC89016
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = {
		name = EVTOPTA89016

		father = {
			show_scope_change = no

			character_event = {
				id = 89017
				days = 2
				tooltip = EVTTOOLTIP89017
			}
		}
	}
}

# Husband informed
character_event = {
	id = 89017
	desc = EVTDESC89017
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Grant county
		name = EVTOPTA89017

		random_demesne_title = {
			show_scope_change = no

			limit = {
				lower_tier_than = DUKE

				location = {
					is_capital = no
				}
			}

			FROM = {
				show_scope_change = no

				grant_title = PREV
			}
		}
	}

	option = { # Say no
		name = EVTOPTB89017

		reverse_opinion = {
			name = opinion_very_disappointed
			who = FROMFROM
			years = 2
		}

		FROM = {
			show_scope_change = no

			opinion = {
				name = opinion_disappointed
				who = ROOT
				years = 2
			}

			character_event = {
				id = 89018
				days = 2
			}
		}
	}
}

# Son informed he is not getting county
character_event = {
	id = 89018
	desc = EVTDESC89018
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89018

		tooltip = {
			opinion = {
				name = opinion_disappointed
				who = FROM
				years = 2
			}
		}
	}
}

### Secondary Wife plots to kill heir - Setup
character_event = {
	id = 89019

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, polygamy_events
	hide_window = yes

	has_dlc = "The Sword of Islam"
	only_playable = yes
	is_married = yes
	only_capable = yes
	prisoner = no

	trigger = {
		has_polygamy = yes

		trigger_if = {
			limit = { is_female = yes }

			is_inaccessible_trigger = no
			is_main_spouse = no
			is_pregnant = no

			any_child = {
				is_pretender = yes
				is_female = no
				is_primary_heir = no
			}

			NOR = {
				has_character_flag = murdering_wife

				any_child = {
					is_primary_heir = yes
				}
			}

			spouse = {
				is_incapable = no
				prisoner = no

				any_child = {
					is_primary_heir = yes
					NOT = { is_child_of = ROOT }
					ai = yes
					is_adult = no
					at_location = ROOT
				}
			}
		}
		trigger_else = {
			any_spouse = {
				is_playable = no
				is_inaccessible_or_incapable_trigger = no
				is_main_spouse = no
				is_pregnant = no

				any_child = {
					is_pretender = yes
					is_female = no
					is_primary_heir = no
				}

				NOR = {
					has_character_flag = murdering_wife

					any_child = {
						is_primary_heir = yes
					}
				}

				ROOT = {
					any_child = {
						is_primary_heir = yes
						NOT = { is_child_of = PREVPREV }
						ai = yes
						is_adult = no
						at_location = PREVPREV
					}
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = envious
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = envious

					any_child = {
						is_pretender = yes
						is_female = no
						is_primary_heir = no
					}

					NOR = {
						has_character_flag = murdering_wife

						any_child = {
							is_primary_heir = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = ambitious
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = ambitious

					any_child = {
						is_pretender = yes
						is_female = no
						is_primary_heir = no
					}

					NOR = {
						has_character_flag = murdering_wife

						any_child = {
							is_primary_heir = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			trigger_if = {
				limit = { is_female = yes }
				trait = slothful
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = slothful

					any_child = {
						is_pretender = yes
						is_female = no
						is_primary_heir = no
					}

					NOR = {
						has_character_flag = murdering_wife

						any_child = {
							is_primary_heir = yes
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.25

			trigger_if = {
				limit = { is_female = yes }
				trait = content
			}
			trigger_else = {
				any_spouse = {
					is_main_spouse = no
					trait = content

					any_child = {
						is_pretender = yes
						is_female = no
						is_primary_heir = no
					}

					NOR = {
						has_character_flag = murdering_wife

						any_child = {
							is_primary_heir = yes
						}
					}
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { is_female = yes }
			character_event = { id = 89020 }
		}
		else = {
			random_spouse = {
				limit = {
					is_playable = no
					is_inaccessible_or_incapable_trigger = no
					is_main_spouse = no
					is_pregnant = no

					any_child = {
						is_pretender = yes
						is_female = no
						is_primary_heir = no
					}

					NOR = {
						has_character_flag = murdering_wife

						any_child = {
							is_primary_heir = yes
						}
					}

					ROOT = {
						any_child = {
							is_primary_heir = yes
							NOT = { is_child_of = PREVPREV }
							ai = yes
							is_adult = no
							at_location = PREVPREV
						}
					}
				}

				ROOT = {
					random_child = {
						limit = { is_primary_heir = yes }
						save_event_target_as = victim_son
					}
				}

				character_event = { id = 89020 }
			}
		}
	}
}

### Secondary Wife plots to kill heir
character_event = {
	id = 89020
	desc = EVTDESC89020
	picture = GFX_evt_quarrel
	portrait = event_target:victim_son

	is_triggered_only = yes

	option = { # Murder heir
		name = EVTOPTA89020

		set_character_flag = murdering_wife

		spouse = { # Husband
			show_scope_change = no

			random_list = {
				35 = { # Success
					event_target:victim_son = {
						show_scope_change = no

						character_event = {
							id = 89023
							days = 4
							tooltip = EVTTOOLTIP89023
						}
					}

					hidden_effect = {
						random_list = {
							50 = {
								event_target:victim_son = {
									death = {
										death_reason = death_murder_unknown_poison
										killer = ROOT
									}
								}

								character_event = { id = 89024 } # Inform husband, killer unknown
							}

							50 = {
								event_target:victim_son = {
									death = {
										death_reason = death_murder_poison
										killer = ROOT
									}
								}

								character_event = { id = 89025 } # Inform husband, killer known
							}
						}
					}
				}

				65 = { # Failure
					event_target:victim_son = {
						show_scope_change = no

						character_event = {
							id = 89021
							days = 4
							tooltip = EVTTOOLTIP89021
						}
					}

					character_event = { id = 89022 } # Inform husband
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTB89020

		ai_chance = { factor = 0 }
	}
}

# Heir is informed of failed attempt
character_event = {
	id = 89021
	desc = EVTDESC89021
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89021
	}
}

# Husband is informed of failed attempt
character_event = {
	id = 89022
	desc = EVTDESC89022
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Kill wife
		name = EVTOPTA89022

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = { # Imprison wife
		name = EVTOPTB89022

		reverse_imprison = FROM

		hidden_effect = {
			event_target:victim_son = {
				opinion = {
					name = attempted_murder
					who = FROM
					years = 30
				}

				mother = {
					opinion = {
						name = attempted_murder
						who = FROM
						years = 30
					}
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTC89022

		event_target:victim_son = {
			show_scope_change = no

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 2
			}

			mother = {
				show_scope_change = no

				opinion = {
					name = opinion_very_disappointed
					who = ROOT
					years = 2
				}
			}
		}

		hidden_effect = {
			event_target:victim_son = {
				opinion = {
					name = attempted_murder
					who = FROM
					years = 30
				}

				mother = {
					show_scope_change = no

					opinion = {
						name = attempted_murder
						who = FROM
						years = 30
					}
				}
			}
		}
	}
}

# Heir is killed
character_event = {
	id = 89023
	desc = EVTDESC89023
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89023
	}
}

# Husband informed heir is killed, killer is unknown
character_event = {
	id = 89024
	desc = EVTDESC89024
	picture = GFX_evt_quarrel

	hide_from = yes
	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89024
	}
}

# Husband informed heir is killed, killer is known
character_event = {
	id = 89025
	desc = EVTDESC89025
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Kill wife
		name = EVTOPTA89025

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = { # Imprison wife
		name = EVTOPTB89025

		reverse_imprison = FROM

		hidden_effect = {
			any_spouse = {
				limit = {
					NOT = { character = FROM }
				}

				opinion = {
					name = evil_murderer
					who = FROM
					years = 40
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTC89025

		any_spouse = {
			show_scope_change = no

			limit = {
				NOT = { character = FROM }
			}

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 8
			}

			opinion = {
				name = evil_murderer
				who = FROM
				years = 40
			}
		}
	}
}

### Evil wife plots to kill sons who aren't hers - Setup
character_event = {
	id = 89029

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, polygamy_events
	hide_window = yes

	has_dlc = "The Sword of Islam"
	only_playable = yes
	is_married = yes
	only_capable = yes
	prisoner = no

	trigger = {
		has_polygamy = yes

		trigger_if = {
			limit = { is_female = yes }

			is_inaccessible_trigger = no
			is_pregnant = no
			NOT = { trait = kind }

			any_child = {
				is_female = no
			}

			spouse = {
				any_child = {
					is_female = no
					NOT = { is_child_of = ROOT }
					is_adult = no
					is_primary_heir = no
					at_location = ROOT
					ai = yes
				}
			}
		}
		trigger_else = {
			any_spouse = {
				is_playable = no
				is_inaccessible_or_incapable_trigger = no
				is_pregnant = no
				NOT = { trait = kind }

				any_child = {
					is_female = no
				}

				ROOT = {
					any_child = {
						is_female = no
						NOT = { is_child_of = PREVPREV }
						is_adult = no
						is_primary_heir = no
						at_location = PREVPREV
						ai = yes
					}
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = envious
			}
			trigger_else = {
				any_spouse = {
					trait = envious

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = cruel
			}
			trigger_else = {
				any_spouse = {
					trait = cruel

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 2

			trigger_if = {
				limit = { is_female = yes }
				trait = ambitious
			}
			trigger_else = {
				any_spouse = {
					trait = ambitious
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 1.33

			trigger_if = {
				limit = { is_female = yes }
				trait = greedy
			}
			trigger_else = {
				any_spouse = {
					trait = greedy
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.2

			trigger_if = {
				limit = { is_female = yes }
				trait = honest
			}
			trigger_else = {
				any_spouse = {
					trait = honest
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.2

			trigger_if = {
				limit = { is_female = yes }
				trait = just
			}
			trigger_else = {
				any_spouse = {
					trait = just
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.2

			trigger_if = {
				limit = { is_female = yes }
				trait = content
			}
			trigger_else = {
				any_spouse = {
					trait = content
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_adult = no
							is_primary_heir = no
						}
					}
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { is_female = yes }

			spouse = {
				random_child = {
					limit = {
						is_female = no
						NOT = { is_child_of = ROOT }
						is_primary_heir = no
						at_location = ROOT
						is_adult = no
						ai = yes
					}

					save_event_target_as = victim_son
				}
			}

			character_event = { id = 89030 }
		}
		else = {
			random_spouse = {
				limit = {
					is_playable = no
					is_inaccessible_or_incapable_trigger = no
					is_pregnant = no
					NOT = { trait = kind }

					any_child = {
						is_female = no
					}

					ROOT = {
						any_child = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_primary_heir = no
							at_location = PREVPREV
							is_adult = no
							ai = yes
						}
					}
				}

				ROOT = {
					random_child = {
						limit = {
							is_female = no
							NOT = { is_child_of = PREVPREV }
							is_primary_heir = no
							at_location = PREVPREV
							is_adult = no
							ai = yes
						}

						save_event_target_as = victim_son
					}
				}

				character_event = { id = 89030 }
			}
		}
	}
}

### Evil wife plots to kill sons who aren't hers
character_event = {
	id = 89030
	desc = EVTDESC89030
	picture = GFX_evt_quarrel
	portrait = event_target:victim_son

	is_triggered_only = yes

	option = { # Murder son
		name = EVTOPTA89020

		random_list = {
			50 = { # Success
				spouse = {
					show_scope_change = no

					event_target:victim_son = {
						show_scope_change = no

						character_event = {
							id = 89033
							days = 4
							tooltip = EVTTOOLTIP89023
						}
					}

					hidden_effect = {
						random_list = {
							50 = {
								character_event = { id = 89034 }

								event_target:victim_son = {
									death = {
										death_reason = death_murder_unknown_poison
										killer = ROOT
									}
								}
							}

							50 = {
								character_event = { id = 89035 }

								event_target:victim_son = {
									death = {
										death_reason = death_murder_poison
										killer = ROOT
									}
								}
							}
						}
					}
				}
			}

			50 = {
				spouse = {
					show_scope_change = no

					event_target:victim_son = {
						show_scope_change = no

						character_event = {
							id = 89031
							days = 4
							tooltip = EVTTOOLTIP89021
						}
					}

					character_event = { id = 89032 }
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTB89020

		ai_chance = { factor = 0 }
	}
}

# Son is informed of failed attempt
character_event = {
	id = 89031
	desc = EVTDESC89021
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89021
	}
}

# Husband is informed of failed attempt
character_event = {
	id = 89032
	desc = EVTDESC89032
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Kill wife
		name = EVTOPTA89022

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = { # Imprison wife
		name = EVTOPTB89022

		reverse_imprison = FROM

		hidden_effect = {
			event_target:victim_son = {
				opinion = {
					name = attempted_murder
					who = FROM
					years = 30
				}

				mother = {
					opinion = {
						name = attempted_murder
						who = FROM
						years = 30
					}
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTC89022

		event_target:victim_son = {
			show_scope_change = no

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 2
			}

			mother = {
				show_scope_change = no

				opinion = {
					name = opinion_very_disappointed
					who = ROOT
					years = 2
				}
			}
		}

		hidden_effect = {
			event_target:victim_son = {
				opinion = {
					name = attempted_murder
					who = FROM
					years = 30
				}

				mother = {
					opinion = {
						name = attempted_murder
						who = FROM
						years = 30
					}
				}
			}
		}
	}
}

# Son is killed
character_event = {
	id = 89033
	desc = EVTDESC89023
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89023
	}
}

# Husband informed son is killed, killer is unknown
character_event = {
	id = 89034
	desc = EVTDESC89034
	picture = GFX_evt_quarrel

	hide_from = yes
	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA89024
	}
}

# Husband informed son is killed, killer is known
character_event = {
	id = 89035
	desc = EVTDESC89035
	picture = GFX_evt_quarrel

	is_triggered_only = yes

	option = { # Kill wife
		name = EVTOPTA89025

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = { # Imprison wife
		name = EVTOPTB89025

		reverse_imprison = FROM

		hidden_effect = {
			any_spouse = {
				limit = {
					NOT = { character = FROM }
				}

				opinion = {
					name = evil_murderer
					who = FROM
					years = 40
				}
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTC89025

		any_spouse = {
			limit = {
				NOT = { character = FROM }
			}

			opinion = {
				name = opinion_very_disappointed
				who = ROOT
				years = 8
			}

			opinion = {
				name = evil_murderer
				who = FROM
				years = 40
			}
		}
	}
}