﻿#Events for pregnancy on actions

namespace = pregnancy



# This event is always called on pregnancy start. Determines if the pregnancy will continue smoothly, if it will continue with complications, or be terminated prematurely.
#If either the birth goes smoothly, the mother grows sick, or the child grows sick, it will trigger the ordinary birth event (birth.0001). Otherwise a custom event will be triggered.

# by Linnéa Thimrén
pregnancy.0001 = {
	hidden = yes
	immediate = {
		# Check first if pregnancy should be invalid
		if = {
			limit = { should_disallow_pregnancy_trigger = yes }
			# End the pregnancy
			end_pregnancy = yes
			pregnancy_cleanup_effect = yes
			# only check for genetic infertility if the pregnancy was otherwise valid
			if = {
				limit = {
					NOR = {
						has_game_rule = lmf_no_birth_fertility_modifiers
						has_character_flag = lmf_no_children
						scope:real_father = { has_character_flag = lmf_no_children }
						has_relation_unfruitful_marriage = scope:real_father
						realistic_pregnancy_system_prevents_pregnancy = yes
					}
				}
				inactive_infertility_check_effect = yes
			}
		}
		# Failing that, proceed
		else = {
			#PREGNANCY COMPLICATION CALCULATIONS & FLAG-SETTING
			random_list = {
				200 = { #All goes smoothly!
					#Less likely if health is bad
					modifier = {
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						health >= excellent_health
						add = 10
					}
					modifier = {
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						health >= good_health
						add = 5
					}
					modifier = {
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						health <= fine_health
						add = -15
					}
					modifier = {
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						health <= poor_health
						add = -20
					}
					modifier = {
						has_game_rule = lmf_no_birth_fertility_modifiers
						health <= fine_health
						add = -10
					}
					modifier = {
						has_game_rule = lmf_no_birth_fertility_modifiers
						health <= poor_health
						add = -15
					}

					#More kids means less risk of complications!
					modifier = {
						add = 5
						any_child = {
							even_if_dead = yes
							count >= 2
						}
					}
					modifier = {
						add = 5
						any_child = {
							even_if_dead = yes
							count >= 4
						}
					}
					
					#First pregnancy is the riskiest
					modifier = {
						add = -20
						NOR = {
							has_game_rule = lmf_no_birth_fertility_modifiers
							any_child = {
								even_if_dead = yes
							}
						}
					}
					
					#Less likely the older the mother is
					modifier = {
						add = -5
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						age >= 30
					}
					modifier = {
						add = -5
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						age >= 35
					}
					modifier = {
						add = -10
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						age >= 40
					}
					
					#Less likely when underweight
					modifier = {
						add = -10
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						current_weight < -50
					}
					modifier = {
						add = 10
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						current_weight > 50
					}
					
					#More likely if fecund
					modifier = {
						add = 25
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
						has_trait = fecund
					}

					#More likely if you have sacred childbirth
					modifier = {
						factor = 2 # Religious doctrine focusing on providing a sanitary birthing chamber and supplies should have a substantial impact on birth complications.
						faith = {
							has_doctrine_parameter = safer_childbirths_active
						}
					}
					#More likely if the Dynasty has the Kin legacy
					modifier = {
						factor = 1.5 # So too should constant care of pregnant/birthing mothers.
						has_dynasty = yes
						dynasty = {
							has_dynasty_perk = kin_legacy_3
						}
					}

					add_character_flag = {
						flag = birth_will_go_smoothly
						days = 270
					}
				}
				25 = { #Pregnancy ends prematurely
					modifier = {
						add = -15
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					trigger_event = {
						id = pregnancy.2101
						days = { 80 120 }
					}
				}
				15 = { #Child dies during delivery (this triggers when the birth "should" have gone down, since we dont want to create the baby)
					modifier = {
						add = -12
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					trigger_event = {
						id = birth.3001
						days = { 180 200 }
					}
				}
				3 = { #Mother dies
					modifier = { #to keep players from dying excessively
						add = -2
						is_ai = no
					}
					modifier = {
						add = -1
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					add_character_flag = { #Flags blocks other birth events
						flag = birth_mother_will_die
						days = 270
					}
				}
				3 = { #Mother and child dies (this triggers when the birth "should" have gone down, since we dont want to create the baby)
					modifier = { #to keep players from dying excessively
						add = -2
						is_ai = no
					}
					modifier = {
						add = -1
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					trigger_event = {
						id = birth.3021
						days = { 180 200 }
					}
				}
				20 = { #Sickly child (all other events happen as usual)
					modifier = {
						add = -10
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					modifier = {
						factor = 0.5 # Religious doctrine focusing on providing a sanitary birthing chamber and supplies should have a substantial impact on birth complications.
						faith = {
							has_doctrine_parameter = healthier_children_active
						}
					}
					add_character_flag = { #Flags blocks other birth events
						flag = birth_child_will_become_sickly
						days = 270
					}
				}
				15 = { #Ill mother (all other events happen as usual)
					modifier = { #to keep players from dying excessively
						add = -5
						is_ai = no
						NOT = { has_game_rule = lmf_no_birth_fertility_modifiers }
					}
					modifier = { #to keep players from dying excessively
						add = -4
						is_ai = no
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					modifier = {
						add = -10
						has_game_rule = lmf_no_birth_fertility_modifiers
					}
					add_character_flag = { #Flags blocks other birth events
						flag = birth_mother_will_become_ill
						days = 270
					}
				}
			}
		}
	}
}



#####################################
# Ordinary "I'm pregnant" events!
####################################

# for the mother
pregnancy.1001 = {
	title = pregnancy.1001.t
	desc = pregnancy.1001.d
	theme = pregnancy
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:real_father
		triggered_animation = {
			trigger = { has_any_bad_relationship_with_character_trigger = { CHARACTER = root } }
			animation = stress
		}
		animation = happiness
	}

	trigger = {
		NOT = { has_variable = borte_first_child_var }
		any_consort = {
			this = scope:real_father
		}
		should_disallow_pregnancy_trigger = no
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		add_trait = pregnant
		scope:real_father = {
			if = {
				limit = { accepts_adultery_without_penalty_trigger = no }
				pregnancy_spouse_suspicion_chance_effect = yes
			}
		}
	}
	
	option = {
		name = pregnancy.1001.a
	}
}

#for the father if it's the first child or the first dynastic heir (assumed biological father)
pregnancy.1002 = {
	title = pregnancy.1002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					this = character:125501 # You are Temüjin
					scope:mother = { has_variable = borte_first_child_var }
				}
				desc = pregnancy.1002.d.borte
			}
			desc = pregnancy.1002.d
		}
	}
	theme = pregnancy
	override_background = { reference = bedchamber }
	left_portrait = {
		character = scope:mother
		triggered_animation = {
			trigger = {
				scope:mother = { has_variable = borte_first_child_var }
			}
			animation = worry
		}
		animation = love
	}
	right_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					AND = {
						scope:mother = { has_variable = borte_first_child_var }
						this = character:125501
					}
				}
			}
			animation = stress
		}
		animation = happiness
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
	}

	option = {
		name = {
			trigger = {
				scope:mother = { has_variable = borte_first_child_var }
			}
			text = pregnancy.1002.a.borte
		}
		name = {
			trigger = {
				NOT = {
					scope:mother = { has_variable = borte_first_child_var }
				}
			}
			text = pregnancy.1002.a
		}
		show_as_tooltip = {
			scope:mother = {
				add_trait_force_tooltip = pregnant
			}
		}
	}
}

# Pregnant with late husband or ex-husband's child
# by Sean Hughes
pregnancy.1101 = {
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:ex_spouse = {
						is_alive = no
					}
				}
				desc = pregnancy.1101.t.dead
			}
			desc = pregnancy.1101.t.divorced
		}
	}
	desc = {
		desc = pregnancy.1101.desc.start
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:ex_spouse = {
						is_alive = no
					}
				}
				desc = pregnancy.1101.desc.dead
			}
			desc = pregnancy.1101.desc.divorced
			
		}
		desc = pregnancy.1101.desc.end
	}
	theme = pregnancy
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
	}
	right_portrait = scope:ex_spouse

	trigger = {
		# Event is only valid if our former spouse (dead or divorced) is both the real and assumed father (e.g., it was a legitimate pregnancy when the child was conceived).
		former_consort_was_father = yes
		should_disallow_pregnancy_trigger = no
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		add_trait = pregnant
		scope:father = {
			save_scope_as = ex_spouse
		}
	}

	option = {
		name = {
			trigger = {
				scope:ex_spouse = {
					is_alive = yes
				}
			}
			text = pregnancy.1101.a.divorced
		}
		name = {
			trigger = {
				scope:ex_spouse = {
					is_alive = no
				}
			}
			text = pregnancy.1101.a.dead
		}

		# Notify spouses about the pregnancy.
		every_spouse = {
			trigger_event = pregnancy.1102
		}
		# Notify the father if alive.
		scope:ex_spouse = {
			if = {
				limit = {
					is_alive = yes
				}
				trigger_event = pregnancy.1103
			}
		}
	}
}

# For the mother's husband (not father) to explain why their spouse is pregnant and that it is okay.
pregnancy.1102 = {
	title = pregnancy.1102.t
	desc = pregnancy.1102.desc
	theme = pregnancy
	override_background = { reference = bedchamber }
	left_portrait = {
		character = scope:mother
	}
	right_portrait = {
		character = scope:ex_spouse
		triggered_animation = {
			trigger = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:mother } }
			animation = stress
		}
		animation = happiness
	}
	

	option = {
		name = pregnancy.1102.a
		show_as_tooltip = {
			scope:mother = {
				add_trait_force_tooltip = pregnant
			}
		}
	}
}


# For the father, explaining that their ex-wife will bear them a new child soon.
pregnancy.1103 = {
	type = letter_event
	opening = {
		first_valid = {
			triggered_desc = {
			    trigger = {
					OR = {
						any_former_concubine = { this = scope:mother }
						any_former_concubinist = { this = scope:mother }
					}
			    }
			    desc = pregnancy.1103.opening_concubine
			}
			desc = pregnancy.1103.opening
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
			    trigger = {
					OR = {
						any_former_concubine = { this = scope:mother }
						any_former_concubinist = { this = scope:mother }
					}
			    }
			    desc = pregnancy.1103.desc_concubine
			}
			desc = pregnancy.1103.desc
		}
	}
	sender = scope:mother

	option = {
		name = pregnancy.1103.a
		show_as_tooltip = {
			scope:mother = {
				add_trait_force_tooltip = pregnant
			}
		}
	}
}

###########################
# Bastard pregnancies
###########################

#Unmarried mother pregnant with child
pregnancy.2001 = {
	title = pregnancy.2001.t
	desc = {
		desc = pregnancy.2001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:real_father = { is_married = yes }
				}
				desc = pregnancy.2001.father_is_married
			}
			desc = pregnancy.2001.father_is_unmarried
		}
	}
	theme = pregnancy
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
	}
	right_portrait = {
		character = scope:real_father
		triggered_animation = {
			trigger = { has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:mother } }
			animation = stress
		}
		animation = happiness
	}

	trigger = {
		is_pregnant = yes # Fix to prevent pipeline failures on account of set_num_pregnancy_children being used on an unpregnant character
		should_disallow_pregnancy_trigger = no
		NOR = {
			# If we are married or have concubines (or are a concubine) this event is not valid, as there is a (assumed) father.
			any_consort = { }
			AND = {
				is_ruler = no
				NOR = {
					has_trait = fornicator
					has_character_flag = liege_refused_seclusion
				}
				exists = liege
				trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = trait:fornicator GENDER_CHARACTER = scope:mother }
				scope:mother.liege = {
					is_landed = yes
					is_close_family_of = scope:mother
					NOT = { scope:real_father = this }
					exists = cp:councillor_spymaster
					cp:councillor_spymaster.intrigue > scope:mother.intrigue
				}
			}
		}
		pregnancy_is_bastard = yes
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		remove_character_flag = liege_refused_seclusion
		hidden_effect = {
			set_num_pregnancy_children = 1
			add_character_flag = {
				flag = unmarried_bastard_pregnancy
				months = 9
			}
		}
		# LMF added: will remove devoted trait if required
		lmf_check_pregnant_devoted_status = yes
	}

	option = { #Publicly name the father!
		name = pregnancy.2001.a
		unmarried_mother_pregnancy_effect = yes
		bastardy_pregnancy_announcement_effect = yes
		hidden_effect = {
			expose_lover_secret_or_run_consequence_effect = {
				TARGET = scope:real_father
				EXPOSER = scope:mother
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = 0.5
				ai_compassion = 0.25
			}
			compare_modifier = {
				value = ai_vengefulness
				trigger = {
					opinion = {
						target = scope:real_father
						value < 0
					}
					ai_vengefulness > 0
				}
			}
		}
	}

	option = { #Only tell the real_father
		name = pregnancy.2001.b
		trigger = {
			scope:real_father = { is_alive = yes }
		}
		add_trait_force_tooltip = pregnant
		hidden_effect = {
			set_known_bastard_on_pregnancy = yes #The bastard status is already known since the mother is unmarried.
			add_character_flag = { #Add flag to determine what should happen in adultery.1101
				flag = planning_to_confess_to_real_father
				days = 22
			}
			if = {
				limit = {
					NOT = {
						any_owned_story = {
							type = story_peasant_affair
							var:peasant_character = scope:mother.pregnancy_real_father
						}
					}
				}
				trigger_event = { #This parses whether the mother is planning to confess to a real_father, and checks if there are characters out there who should suspect that they might be the real father
					id = adultery.1101
					days = 20
				}
				trigger_event = { #In case the real father is dead by the time the event fires
					id = pregnancy.3005
					days = 21
				}
			}
		}
		if = {
			limit = {
				any_owned_story = {
					type = story_peasant_affair
					var:peasant_character = {
						this = scope:real_father
					}
				}
			}
			add_fornicator_trait_or_nothing_effect = yes
			add_character_flag = is_looking_for_peasant #To take the story_peasant_affair to the next step
			add_character_flag = peasant_affair_already_looking
			custom_tooltip = search_for_real_father_tt
		}
		else = {
			custom_tooltip = reveal_illegitimate_pregnancy_to_real_father_tt
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 200
				is_ai = yes
				can_marry_character_trigger = { CHARACTER = scope:real_father }
				NOT = { would_need_elopement_to_marry_target = { TARGET = scope:real_father } }
				scope:real_father = {
					is_ai = yes
					might_agree_to_marriage = yes
				}
			}
			modifier = {
				add = 500
				is_ai = yes
				OR = {
					has_trait = will_not_wed
					scope:real_father = { has_trait = will_not_wed }
				}
				can_be_introduced_character_trigger = { CHARACTER = scope:real_father }
				NOT = { would_need_elopement_to_marry_target = { TARGET = scope:real_father } }
			}
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = 1
				ai_rationality = 0.5
			}
			modifier = { # Never hide the truth in faiths with the Polyamory tenet.
				factor = 0
				accepts_adultery_without_penalty_trigger = yes
			}
		}
	}

	option = { #Keep it secret!
		name = pregnancy.2001.c
		unmarried_mother_pregnancy_effect = yes
		flavor = pregnancy.2001.c.tt
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = { # Never hide the truth in faiths with the Polyamory tenet.
				factor = 0
				accepts_adultery_without_penalty_trigger = yes
			}
		}
	}

	option = { #Attempt to terminate the pregnancy
		name = pregnancy.2001.d
		unmarried_mother_pregnancy_effect = yes
		pregnancy_termination_attempt_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = { # Never hide the truth in faiths with the Polyamory tenet.
				factor = 0
				accepts_adultery_without_penalty_trigger = yes
			}
		}
	}
}

#Married woman pregnant with a bastard child
pregnancy.2002 = {
	type = character_event
	title = pregnancy.2002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { accepts_adultery_without_penalty_trigger = yes }
				desc = pregnancy.2002.desc.polyamorous
			}
			desc = pregnancy.2002.desc
		}
	}
	theme = pregnancy
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = scope:father
	lower_center_portrait = scope:real_father
	
	trigger = {
		# If we are married and/or have concubines, but the real father is not one of them, it's a bastard!
		any_consort = {
			is_male = yes
		}

		pregnancy_is_bastard = yes
		should_disallow_pregnancy_trigger = no
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		# If we got pregnant before our marriage, there will be no assumed father set. However, we need one for the event logic to work correctly.
		# Since this is a pretty rare edge case, we just go ahead and set the assumed father to a current living spouse.
		if = {
			limit = {
				NOT = { exists = pregnancy_assumed_father }
			}
			random_consort = {
				save_scope_as = assumed_father
			}
			hidden_effect = {
				set_pregnancy_assumed_father = scope:assumed_father
			}
		}

		save_scope_as = mother
		hidden_effect = {	
			set_num_pregnancy_children = 1
			if = {
				limit = {
					exists = primary_partner
				}
				primary_partner = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					save_scope_as = spouse
				}
			}
			add_character_flag = {
				flag = bastard_pregnancy
				months = 9
			}
		}
	
		# LMF added: will remove devoted trait if required
		lmf_check_pregnant_devoted_status = yes	
	}

	option = { #Confess
		name = {
			trigger = { accepts_adultery_without_penalty_trigger = no }
			text = pregnancy.2002.a
		}
		name = {
			trigger = { accepts_adultery_without_penalty_trigger = yes }
			text = pregnancy.2001.a
		}

		married_mother_pregnancy_effect = yes
		add_fornicator_trait_or_nothing_effect = yes
		bastardy_pregnancy_announcement_effect = yes
		if = {
			limit = { accepts_adultery_without_penalty_trigger = no }
			expose_lover_secret_or_run_consequence_effect = {
				TARGET = scope:real_father
				EXPOSER = scope:mother
			}
		}
		ai_chance = {
			base = 0
			modifier = { # Never hide the truth in faiths with the Polyamory tenet.
				add = 100
				accepts_adultery_without_penalty_trigger = yes
			}
			modifier = {
				add = 50
				accepts_adultery_without_penalty_trigger = yes
				scope:father = { is_lowborn = yes }
				scope:real_father = { is_lowborn = no }
			}
			modifier = {
				accepts_adultery_without_penalty_trigger = yes
				add = {
					value = scope:real_father.highest_held_title_tier
					multiply = 10
				}
			}
			modifier = {
				accepts_adultery_without_penalty_trigger = yes
				add = {
					value = scope:father.highest_held_title_tier
					multiply = -10
				}
			}
		}
	}

	option = { #Tell the real father
		name = pregnancy.2002.b
		trigger = {
			NOT = {
				exists = primary_partner
			}
		}
		if = {
			limit = {
				any_owned_story = {
					type = story_peasant_affair
					var:peasant_character = {
						this = scope:real_father
					}
				}
			}
			add_character_flag = is_looking_for_peasant #To take the story_peasant_affair to the next step
			add_character_flag = peasant_affair_already_looking
			custom_tooltip = search_for_real_father_tt
		}
		else = {
			custom_tooltip = reveal_illegitimate_pregnancy_to_real_father_tt
		}
		add_character_flag = { #Add flag to determine what should happen in adultery.1101
			flag = planning_to_confess_to_real_father
			days = 22
		}
		married_mother_pregnancy_effect = yes
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = 1
				ai_rationality = 0.5
			}
			modifier = {
				add = 50
				scope:father = { is_lowborn = no }
				scope:real_father = { is_lowborn = yes }
			}
			modifier = {
				add = {
					value = scope:real_father.highest_held_title_tier
					multiply = 10
				}
			}
			modifier = {
				add = {
					value = scope:father.highest_held_title_tier
					multiply = -10
				}
			}
			modifier = { # Less likely to hide the truth in faiths with the Polyamory tenet.
				add = 100
				accepts_adultery_without_penalty_trigger = yes
			}
		}
	}

	option = { #Keep it secret!
		name = pregnancy.2002.c
		custom_tooltip = pregnancy.2002.c.tt
		married_mother_pregnancy_effect = yes
		stress_impact = {
			honest = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				add = 50
				scope:father = { is_lowborn = no }
				scope:real_father = { is_lowborn = yes }
			}
			modifier = {
				add = {
					value = scope:father.highest_held_title_tier
					multiply = 10
				}
			}
			modifier = {
				add = {
					value = scope:real_father.highest_held_title_tier
					multiply = -10
				}
			}
			modifier = { # Less likely to hide the truth in faiths with the Polyamory tenet.
				add = -100
				accepts_adultery_without_penalty_trigger = yes
			}
		}
	}

	option = { #Attempt to get rid of the child
		name = pregnancy.2002.d
		pregnancy_termination_attempt_effect = yes

		ai_chance = {
			base = 0
		}
	}
}


################
# Attempted Termination Chain
# 2003 - 2007
###############
#Successful attempt, no side effects
pregnancy.2003 = {
	type = character_event
	title = pregnancy.2003.t
	desc = {
		random_valid = {
			desc = pregnancy.2003.desc_no_notice
			desc = pregnancy.2003.desc_pain
		}
	}
	theme = pregnancy
	left_portrait = {
		character = root
		animation = happiness
	}

	immediate = {
		end_pregnancy = yes
		pregnancy_cleanup_effect = yes
	}

	option = { #It is for the best
		name = pregnancy.2003.a
	}
}

#Successful attempt, fall ill
pregnancy.2004 = {
	type = character_event
	title = pregnancy.2004.t
	desc = pregnancy.2004.desc
	theme = pregnancy
	left_portrait = {
		character = root
		animation = personality_cynical
	}

	immediate = {
		end_pregnancy = yes
		add_trait_force_tooltip = ill
		pregnancy_cleanup_effect = yes
	}

	option = { #It was what had to be done
		name = pregnancy.2004.a
	}
}

#Failed attempt, no side effects
pregnancy.2005 = {
	type = character_event
	title = pregnancy.2005.t
	desc = pregnancy.2005.desc
	theme = pregnancy
	left_portrait = {
		character = root
		animation = sadness
	}

	immediate = {	
		if = {
			limit = {
				is_married = no
			}
			#unmarried_mother_pregnancy_effect = yes
		}
		else = {
			married_mother_pregnancy_effect = yes
		}
	}

	option = { #I had to try
		name = pregnancy.2005.a
	}
}

#Die
pregnancy.2007 = {
	type = character_event
	title = pregnancy.2007.t
	desc = pregnancy.2007.desc
	theme = pregnancy
	left_portrait = {
		character = root
		animation = grief
	}

	immediate = {
		play_music_cue = "mx_cue_murder"
	}

	option = { #It was what had to be done
		name = pregnancy.2007.a
		death = {
			death_reason = death_attempted_treatment
		}
	}
}


################
# Same-sex
# 250 - 2059
###############

# Pregnant while all mother's consorts are women
# by Linnéa Thimrén
pregnancy.2050 = {
	title = pregnancy.2050.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { accepts_adultery_without_penalty_trigger = yes }
				desc = pregnancy.2050.desc.polyamorous
			}
			desc = pregnancy.2050.desc
		}
	}
	theme = pregnancy
	left_portrait = scope:real_father
	right_portrait = scope:spouse

	trigger = {
		# If we are married and/or have concubines, but all of them are women as well, it's a bastard!
		any_consort = { } # count = all returns true if list is empty!
		any_consort = {
			is_female = yes
			count = all
		}

		pregnancy_is_bastard = yes
		should_disallow_pregnancy_trigger = no
	}

	immediate = {
		play_music_cue = "mx_cue_succession"

		save_scope_as = mother
		hidden_effect = {	
			set_num_pregnancy_children = 1
			if = {
				limit = {
					exists = primary_partner
				}
				primary_partner = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					save_scope_as = spouse
				}
			}
			add_character_flag = {
				flag = bastard_pregnancy
				months = 9
			}
		}

		# People will know you've been unfaithful, obviously
		add_fornicator_trait_or_nothing_effect = yes
		
		# LMF added: will remove devoted trait if required
		lmf_check_pregnant_devoted_status = yes
	}

	option = { #Confess (for now this is the only option since you cannot deny that youve slept with someone else)
		name = {
			trigger = { accepts_adultery_without_penalty_trigger = no }
			text = pregnancy.2002.a
		}
		name = {
			trigger = { accepts_adultery_without_penalty_trigger = yes }
			text = pregnancy.2001.a
		}

		married_mother_pregnancy_effect = yes
		bastardy_pregnancy_announcement_effect = yes
		expose_lover_secret_or_run_consequence_effect = {
			TARGET = scope:real_father
			EXPOSER = scope:mother
		}
		ai_chance = {
			base = 100
		}
	}
}



####################
# Pregnancy ended prematurely (naturally)
# by Linnéa Thimrén
###################
pregnancy.2101 = {
	type = character_event
	title = pregnancy.2101.t
	desc = {
		random_valid = {
			first_valid = {
				triggered_desc = {
					trigger = {
						any_child = {
							even_if_dead = yes
							count >= 1
						}
					}
					desc = pregnancy.2101.desc_other_children
				}
				desc = pregnancy.2101.desc_pain
			}
			desc = pregnancy.2101.desc
		}
	}
	theme = pregnancy
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	
	trigger = {
		is_pregnant = yes
	}

	immediate = {
		if = {
			limit = {
				exists = primary_partner
			}
			primary_partner = {
				save_scope_as = spouse
			}
		}
		create_character_memory = {
			type = child_premature
			participants = { mother = root }
		}
		hidden_effect = {
			end_pregnancy = yes
			pregnancy_cleanup_effect = yes
		}
	}

	option = {
		name = pregnancy.2101.a

		#To tell spouse
		if = {
			limit = {
				exists = scope:spouse
			}
			scope:spouse = { trigger_event = pregnancy.2102 }
		}

		#To tell real_father if they're not your spouse and they know of the pregnancy
		if = {
			limit = {
				exists = scope:spouse
				NOT = {
					scope:spouse = scope:real_father
					has_character_flag = pregnancy_real_father_knows
				}
			}
			scope:real_father = { trigger_event = pregnancy.2102 }
		}
	}
	
	after = {
		save_scope_value_as = {
			name = pregnancy_ended
			value = yes
		}
		trigger_event = {
			id = lmf_birth.1100
			days = { 3 7 }
		}
	}
}

#Pregnancy ended prematurely - for father
pregnancy.2102 = {
	type = character_event
	title = pregnancy.2101.t
	desc = pregnancy.2102.desc
	theme = pregnancy
	right_portrait = {
		character = scope:mother
		animation = personality_cynical
	}
	
	immediate = {
		create_character_memory = {
			type = child_premature
			participants = { mother = scope:mother }
		}
	}

	option = {
		name = pregnancy.2102.a
	}
}


###############
#3000: Events for the real father
######################

#real_father suspects they are the father
#Can be triggered if the mother tries to keep fatherhood hidden from real_father in pregnancy.2002 or 2003
pregnancy.3001 = {
	type = character_event
	title = pregnancy.3001.t
	desc = {
		desc = pregnancy.3001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:mother = { any_relation = { type = lover this = root } }
					has_opinion_modifier = {
						modifier = love_opinion
						target = scope:mother
					}
				}
				desc = pregnancy.3001.lovers_love
			}
			triggered_desc = {
				trigger = {
					scope:mother = { any_relation = { type = lover this = root } }
				}
				desc = pregnancy.3001.lovers_not_love
			}
			desc = pregnancy.3001.not_lovers
		}
	}
	theme = pregnancy
	left_portrait = scope:mother
	
	trigger = {
		scope:mother = {
			is_pregnant = yes
			NOR = {
				any_owned_story = {
					exists = var:peasant_character
					var:peasant_character = { this = root }
				}
				has_character_flag = pregnancy_real_father_knows
			}
		}

		#Safety block for spouses that are also lovers, since this event is for bastard fathers
		NOT = { is_consort_of = scope:mother }
	}


	option = { #I must confront her about it!
		name = pregnancy.3001.a
		custom_tooltip = pregnancy.3001.a.tt
		hidden_effect = {
			save_scope_as = real_father_inquirer
			scope:mother = {
				trigger_event = {
					id = pregnancy.5001
					days = { 3 5 }
				}
			}
		}
	}

	option = { #Could it be...
		name = pregnancy.3001.b
		custom_tooltip = pregnancy.3001.b.tt
	}
}


#Mother chooses to tell the real father in pregnancy.2002
pregnancy.3002 = {
	type = character_event
	title = pregnancy.3002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { any_relation = { type = lover this = scope:mother }}
				desc = pregnancy.3002.lovers
			}
			desc = pregnancy.3002.not_lovers
		}
		triggered_desc = {
			trigger = { exists = scope:spouse }
		}
	}
	theme = pregnancy
	left_portrait = scope:mother

	trigger = {
		scope:mother = {
			is_pregnant = yes
		}
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
	}

	option = { #What will become of the child
		name = pregnancy.3002.a
		trigger = {
			has_opinion_modifier = {
				modifier = love_opinion
				target = scope:mother
			}
		}
		exclusive = yes
		custom_tooltip = pregnancy.3002.a.tt
		scope:mother = {
			add_character_flag = {
				flag = pregnancy_real_father_knows
				months = 9
			}
		}
	}

	option = { #What will become of the child
		name = {
			trigger = {
				OR = {
					any_child = {
						OR = {
							has_trait = bastard
							has_trait = legitimized_bastard
							has_trait = wild_oat
						}
					}
					any_known_secret = {
						OR = {
							secret_type = secret_disputed_heritage
							secret_type = secret_unmarried_illegitimate_child
						}
						exists = secret_target
						exists = secret_target.real_father
						secret_target = {
							real_father = root
						}
					}
				}
			}
			text = pregnancy.3002.b.not_again
		}
		name = {
			text = pregnancy.3002.b
		}
		custom_tooltip = pregnancy.3002.a.tt
		scope:mother = {
			add_character_flag = {
				flag = pregnancy_real_father_knows
				months = 9
			}
		}
	}

	option = { #The whole world must know the truth
		name = pregnancy.3002.c
		trigger = {
			is_married = no
		}
		save_scope_value_as = {
			name = real_father_revealing
			value = yes
		}
		bastardy_pregnancy_announcement_effect = yes
	}
}



#Unmarried mother comes to unmarried father
pregnancy.3003 = {
	type = character_event
	title = pregnancy.3003.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					faith = {
						has_doctrine_parameter = bastards_none
					}
				}
				desc = pregnancy.3003.desc_no_bastards
			}
			desc = pregnancy.3003.desc
		}
	}
	theme = pregnancy
	left_portrait = scope:mother

	trigger = {
		scope:mother = {
			is_pregnant = yes
		}
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		scope:mother = {
			add_character_flag = {
				flag = pregnancy_real_father_knows
				months = 9
			}
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = tutorial_reactive_advice_bastards
			}
		}
	}

	option = { #This must be kept secret!
		name = pregnancy.3003.a
		scope:mother = { add_fornicator_trait_or_nothing_effect = yes }
		custom_tooltip = pregnancy.3003.a.tt
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				factor = 0.5
				is_ai = yes
				might_agree_to_marriage = yes
				can_marry_character_trigger = { CHARACTER = scope:mother }
				NOT = { would_need_elopement_to_marry_target = { TARGET = scope:mother } }
				scope:mother = { is_ai = yes }
			}
			min = 1
		}
	}

	option = { #The whole world must know!
		name = pregnancy.3003.b
		scope:mother = { add_fornicator_trait_or_nothing_effect = yes }
		bastardy_pregnancy_announcement_effect = yes
		ai_chance = {
			base = 25
			modifier = {
				add = -15
				NOT = { has_trait = fornicator }
				OR = {
					AND = {
						faith = { save_temporary_scope_as = check_faith }
						trait_is_shunned_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:check_faith GENDER_CHARACTER = root }
					}
					AND = { #Liege's faith doesn't approve
						exists = liege
						liege = { faith = { save_temporary_scope_as = check_faith } }
						trait_is_shunned_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:check_faith GENDER_CHARACTER = root }
					}
				}
			}
			modifier = {
				factor = 0
				NOT = { has_trait = fornicator }
				OR = {
					AND = {
						faith = { save_temporary_scope_as = check_faith }
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:check_faith GENDER_CHARACTER = root }
					}
					AND = { #Liege's faith doesn't approve
						exists = liege
						liege = { faith = { save_temporary_scope_as = check_faith } }
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:check_faith GENDER_CHARACTER = root }
					}
				}
			}
		}
	}

	option = { #Then we must marry!
		trigger = {
			is_ai = yes
			scope:mother = { is_ai = yes }
			might_agree_to_marriage = yes
			NOT = { would_need_elopement_to_marry_target = { TARGET = scope:mother } }
			can_be_introduced_character_trigger = { CHARACTER = scope:mother }
		}
		name = pregnancy.3003.c
		
		if = {
			limit = {
				NOT = { has_relation_lover = scope:mother }
			}
			save_scope_value_as = {
				name = is_non_lover_proposal
				value = flag:yes
			}
		}
		save_scope_value_as = {
			name = is_pregnancy_proposal
			value = flag:yes
		}
		root = { save_scope_as = owner }
		scope:mother = { save_scope_as = target }
		
		if = {
			limit = {
				needs_permission_to_marry_trigger = { CHARACTER1 = scope:owner CHARACTER2 = scope:target }
			}
			find_proposer_and_lieges_effect = yes
			if = {
				limit = { exists = scope:proposer_liege }
				scope:proposer_liege = { trigger_event = lmf_scheme.1031 }
			}
			else = {
				scope:proposer_target_liege = { trigger_event = lmf_scheme.1032 }
			}
		}
		else = {
			find_proposer_and_lieges_effect = yes
			scope:proposer = {
				if = {
					limit = { should_marry_matrilineally_trigger = { PROPOSER = scope:proposer TARGET = scope:proposer_target } }
					marry_matrilineal = scope:proposer_target
				}
				else = {
					marry = scope:proposer_target
				}
			}
		}
		
		ai_chance = {
			base = 200
			modifier = {
				add = 300
				OR = {
					AND = {
						has_trait = will_not_wed
						any_owned_story = { type = lmf_will_not_wed_story_cycle }
					}
					scope:mother = {
						has_trait = will_not_wed
						any_owned_story = { type = lmf_will_not_wed_story_cycle }
					}
				}
			}
			modifier = {
				has_relation_soulmate = scope:mother
				factor = 3
			}
			ai_value_modifier = {
				ai_honor = 1
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:mother
				multiplier = 1
			}
			modifier = {
				NOT = { has_relation_lover = scope:mother }
				factor = 0.5
			}
		}
	}
}


#Unmarried mother comes to married father
pregnancy.3004 = {
	type = character_event
	title = pregnancy.3004.t
	desc = pregnancy.3004.desc
	theme = pregnancy
	left_portrait = scope:mother
	lower_right_portrait = scope:spouse

	trigger = {
		scope:mother = {
			is_pregnant = yes
		}
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		#The real father knows now
		scope:mother = {
			add_fornicator_trait_or_nothing_effect = yes
			add_character_flag = {
				flag = pregnancy_real_father_knows
				months = 9
			}
		}
		#For portrait and desc purposes
		primary_spouse = {
			save_scope_as = spouse
		}
		show_as_tooltip = {
			scope:mother = { add_trait_force_tooltip = pregnant }
		}
	}

	option = { #This must be kept secret!
		name = pregnancy.3004.a
	}	
}

#In case the father is dead
pregnancy.3005 = {
	hidden = yes
	
	trigger = {
		is_pregnant = yes
		scope:real_father = { is_alive = no }
	}
	
	immediate = {
		add_fornicator_trait_or_nothing_effect = yes
	}
}


#5000: Follow-ups
#The child's real_father suspects, confronts mother about it.
#Fired by the real_father choosing to press the mother in pregnancy.3001
pregnancy.5001 = {
	type = character_event
	title = pregnancy.5001.t
	desc = {
		desc = pregnancy.5001.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:real_father = scope:real_father_inquirer }
				desc = pregnancy.5001.real_father
			}
			desc = pregnancy.5001.not_father
		}
	}
	theme = pregnancy
	left_portrait = {
		character = scope:real_father_inquirer
		animation = worry
	}
	right_portrait = {
		trigger = {
			scope:spouse != scope:real_father_inquirer
		}
		character = scope:spouse
	}

	trigger = {
		scope:mother = {
			is_pregnant = yes
		}
	}

	option = { #It is true!
		name = pregnancy.5001.a
		trigger = {
			scope:real_father_inquirer = scope:real_father
		}
		custom_tooltip = reveal_illegitimate_pregnancy_to_real_father_tt
		ai_chance = {
			base = 100
		}
		scope:real_father = {
			trigger_event = {
				id = pregnancy.5002 #The truth is revealed to them
				days = { 3 5 }
			}
		}
	}

	option = { #Insist real_father is wrong
		name = pregnancy.5001.b
		trigger = { scope:real_father_inquirer != scope:real_father }
		fallback = yes # Only show if they are not the father
		ai_chance = {
			base = 100
		}
		scope:real_father = {
			trigger_event = {
				id = pregnancy.5003 #Denial
				days = { 3 5 }
			}
		}
	}
}


#Mother confesses that root is the real_father, sharing the secret with them
pregnancy.5002 = {
	type = character_event
	title = pregnancy.5002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_opinion_modifier = {
						modifier = love_opinion
						target = scope:mother
					}
				}
				desc = pregnancy.5002.love
			}
			desc = pregnancy.5002.not_love
		}
	}
	theme = pregnancy
	left_portrait = scope:mother

	trigger = {
		scope:mother = {
			is_pregnant = yes
		}
	}

	immediate = {
		hidden_effect = {
			scope:mother = {
				add_character_flag = {
					flag = pregnancy_real_father_knows
					months = 9
				}
			}
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = tutorial_reactive_advice_bastards
			}
		}
	}

	option = { #Ah, what will become of our child?
		name = pregnancy.5002.a
		custom_tooltip = pregnancy.3003.a.tt
	}

	option = {
		name = pregnancy.5002.b
		expose_lover_secret_or_run_consequence_effect = {
			TARGET = scope:mother
			EXPOSER = root
		}
		bastardy_pregnancy_announcement_effect = yes
	}
}


#Mother keeps insisting the child is not root's
pregnancy.5003 = {
	type = character_event
	title = pregnancy.5003.t
	desc = pregnancy.5003.desc
	theme = pregnancy
	left_portrait = {
		character = scope:mother
		animation = personality_callous
	}
	
	option = { #Are they really telling the truth?
		name = pregnancy.5003.a
	}	
}



########################
# Someone publicly announces the child is theirs
# 6000
########################

### 6000 - 6099: Mother announces
#Mother announces the child - and the real father
pregnancy.6001 = {
	type = character_event
	title = pregnancy.6001.t
	desc = pregnancy.6001.desc
	theme = pregnancy
	left_portrait = {
		character = scope:mother
		animation = personality_callous
	}
	right_portrait = {
		character = scope:real_father
		animation = war_over_win
	}
	lower_center_portrait = {
		character = scope:father
		trigger = {
			NOT = { this = scope:real_father }
		}
	}

	option = {
		name = pregnancy.6001.a
		custom_tooltip = pregnancy_announcement_my_child_will_be_a_bastard
	}
}


#Mother announces child father - event for real father
pregnancy.6002 = {
	type = character_event
	title = pregnancy.6002.t
	desc = {
		desc = pregnancy.6002.desc
		triggered_desc = {
			trigger = {
				exists = scope:spouse
				scope:spouse = { accepts_adultery_without_penalty_trigger = no }
			}
			desc = pregnancy.6002.married
		}
		triggered_desc = {
			trigger = {
				is_married = no
				opinion = {
					target = scope:mother
					value <= 0
				}
			}
			desc = pregnancy.6002.unmarried_unsympathetic
		}
		triggered_desc = {
			trigger = {
				is_married = no
				opinion = {
					target = scope:mother
					value > 0
				}
			}
			desc = pregnancy.6002.unmarried_sympathetic
		}
	}

	theme = pregnancy
	left_portrait = scope:mother
	right_portrait = {
		character = scope:spouse
		animation = disapproval
	}

	immediate = {
		if = {
			limit = {
				primary_partner ?= { accepts_adultery_without_penalty_trigger = no }
			}
			primary_partner = {
				save_scope_as = spouse
			}
		}
		else = {
			random_consort = {
				limit = { accepts_adultery_without_penalty_trigger = no }
				save_scope_as = spouse
			}
		}
	}

	option = {
		name = pregnancy.6002.a
		trigger = { is_married = no }
	}

	after = {
		custom_tooltip = pregnancy_announcement_the_child_will_be_a_bastard_real_father
	}
}


#Mother announces child father - event for spouse of mother
pregnancy.6003 = {
	type = character_event
	title = pregnancy.6003.t
	desc = pregnancy.6003.desc
	theme = pregnancy
	left_portrait = scope:mother
	lower_left_portrait = scope:real_father

	immediate = {
		play_music_cue = "mx_cue_prison"
	}

	option = {
		name = pregnancy.6003.a
		custom_tooltip = pregnancy_announcement_the_child_will_be_a_bastard
	}
}


#Mother announces child father - event for family of mother
pregnancy.6004 = {
	type = character_event
	title = pregnancy.6004.t
	desc = {
		desc = pregnancy.6004.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:mother = {
						is_close_family_trigger = {
							CHARACTER = scope:real_father
						}
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:incestuous FAITH = root.faith GENDER_CHARACTER = scope:mother }
				}
				desc = pregnancy.6004.incest
			}
			triggered_desc = {
				trigger = {
					exists = scope:spouse
				}
				desc = pregnancy.6004.mother_married
			}
			desc = pregnancy.6004.mother_unmarried
		}
	}
	theme = pregnancy
	left_portrait = scope:mother
	lower_left_portrait = scope:real_father

	immediate = {
		play_music_cue = "mx_cue_prison"
		scope:mother = {
			if = {
				limit = { exists = primary_partner }
				primary_partner = {
					save_scope_as = spouse
				}
			}
		}
	}

	option = {
		name = pregnancy.6004.a
		custom_tooltip = pregnancy_announcement_the_child_will_be_a_bastard
	}
}



#Mother announces child father - event for spouse of real_father
pregnancy.6005 = {
	type = character_event
	title = pregnancy.6005.t
	desc = pregnancy.6005.desc
	theme = pregnancy
	left_portrait = scope:real_father
	right_portrait = scope:mother

	immediate = {
		play_music_cue = "mx_cue_prison"
	}

	option = {
		name = pregnancy.6005.a
		custom_tooltip = pregnancy_announcement_the_child_will_be_a_bastard
	}
}



#Mother announces child father - event for family of real_father
pregnancy.6006 = {
	type = character_event
	title = pregnancy.6006.t
	desc = {
		desc = pregnancy.6006.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:spouse
				}
				desc = pregnancy.6006.real_father_married
			}
			desc = pregnancy.6006.real_father_unmarried
		}
	}
	theme = pregnancy
	left_portrait = scope:mother
	lower_left_portrait = scope:real_father
	lower_center_portrait = scope:spouse
	override_background = {
		reference = dungeon
		trigger = {
			scope:mother = { is_imprisoned = yes }
		}
	}

	immediate = {
		play_music_cue = "mx_cue_prison"
		scope:real_father = {
			if = {
				limit = { exists = primary_partner }
				primary_partner = {
					save_scope_as = spouse
				}
			}
		}
	}

	option = {
		name = pregnancy.6006.a
	}
}


#Mother announces child father - event for real_father
pregnancy.6999 = {
	type = character_event
	title = pregnancy.6999.t
	desc = pregnancy.6999.desc
	theme = pregnancy
	left_portrait = scope:mother
	right_portrait = scope:real_father

	option = {
		name = pregnancy.6999.a
		custom_tooltip = pregnancy_announcement_the_child_will_be_a_bastard
	}
}

