###################################
#
# TDH Amazon Pregnancy and Birth Events 
#
###################################

namespace = AMAZON

# Amazons may become pregnant via Parthenogenesis or Normally
character_event = {
	id = AMAZON.0100
	hide_window = yes

	# Pre-triggers
	only_women = yes
	min_age = 16
	max_age = 45

	trigger = {
##		is_female = yes
		trait = amazon
		is_pregnant = no
##		age = 16
##		NOT = { age = 45 }
		NOR = { 
			trait = incapable
			trait = infirm
			trait = eunuch			# [eunuch] trait can be applied to females
		}
		NOT = { any_courtier = { trait = amazon count = 30 } }	# Limit Amazon numbers

	}
	mean_time_to_happen = {
		months = 60

		# Fertility higher in youth; decreases with age
		modifier = { factor = 0.75 NOT = { age = 20 } }
		modifier = { factor = 0.85 NOT = { age = 25 } }
		modifier = { factor = 1.05 age = 30 }
		modifier = { factor = 1.25 age = 35 }
		modifier = { factor = 1.50 age = 40 }
##		modifier = { factor = 99.0 age = 45 }		# No "event" children after 45

		# The more Amazons in a court, the less likely they are to have more children
		modifier = { factor = 0.70 
			NOT = { any_courtier = { trait = amazon count = 5 } }
		}
		modifier = { factor = 0.95 
			NOT = { any_courtier = { trait = amazon count = 10 } }
		}
		modifier = { factor = 1.05 
			any_courtier = { trait = amazon count = 15 } 
		}
		modifier = { factor = 1.20 
			any_courtier = { trait = amazon count = 20 } 
		}
		modifier = { factor = 1.50 
			any_courtier = { trait = amazon count = 25 } 
		}

		# Being married, etc, increases liklihhod of conception
		modifier = { factor = 0.75 is_married = yes }
		modifier = { factor = 0.85 is_consort = yes }
		modifier = { factor = 0.95 has_lover = yes }
		modifier = { factor = 0.90 is_ruler = yes }

		modifier = { factor = 0.85 has_character_flag = obj_have_child_1 }# wants daughter
		modifier = { factor = 0.90 SPOUSE = { trait = amazon } }# increase Parthenogenesis 

		# The more children an Amazon already has, the less likely she is to have more
		modifier = { factor = 0.30 has_living_children = no }
		modifier = { factor = 0.70 NOT = { num_of_children = 1 } }
		modifier = { factor = 0.75 NOT = { num_of_children = 2 } }
		modifier = { factor = 0.85 num_of_children = 2 }
		modifier = { factor = 1.05 num_of_children = 3 }
		modifier = { factor = 1.20 num_of_children = 4 }
		modifier = { factor = 1.35 num_of_children = 5 }
		modifier = { factor = 1.50 num_of_children = 6 }
		modifier = { factor = 1.75 num_of_children = 7 }
		modifier = { factor = 2.00 num_of_children = 8 }
	}

	immediate = {
		# IF (unmarried and has no lover) OR celibate: Parthenogenesis indeed
		if = {
			limit = {
				is_pregnant = no
				OR = {
					AND = {
						is_married = no
						has_lover = no
					}
					trait = celibate
				}
			}
			character_event = { id = AMAZON.0110 days = 0 }	# 100% via Parthenogenesis
		}
		# IF [has_lover] who is not spouse: 15% impregnated by Lover
		else_if = {
			limit = {
				is_pregnant = no
				has_lover = yes
				any_lover = {
					SPOUSE = { NOT = { character = ROOT } }	# NOT Lover={SPOUSE)
				}
			}
			random_list = {					# 15% impregnated by Lover
				15 = { 
					character_event = { id = AMAZON.0130 days = 0 } 
##					##break				# END IMMEDIATE == messes up script
				}
				85 = { }					# No conception here; try below
			}
		}

		## If no conception above ##
		# IF ruler OR matri-married: Parthenogenesis probable
		if = {
			limit = {
				is_pregnant = no
				OR = {
					is_ruler = yes
					is_married_matrilineally = yes
				}
			}
			random_list = {					# 80% via Parthenogenesis
				80 = { character_event = { id = AMAZON.0110 days = 0 } }
				20 = { character_event = { id = AMAZON.0120 days = 0 } }
			}
		}
		# IF not ruler AND married: Parthenogenesis likely
		else_if = {
			limit = {
				is_pregnant = no
				is_ruler = no
				is_married = yes
				is_married_matrilineally = no
			}
			random_list = {					# 70% via Parthenogenesis
				70 = { character_event = { id = AMAZON.0110 days = 0 } }
				30 = { character_event = { id = AMAZON.0120 days = 0 } }
			}
		}
		# (this is a fail-safe, in case the intended conditions don't obtain)
		else = {
			character_event = { id = AMAZON.0110 days = 0 }	# 100% via Parthenogenesis
		}
	}
	option = { name = OK }
}

# Amazon conceives parthenogenetically
character_event = {
	id = AMAZON.0110
	hide_window = yes

	# Pre-triggers
	only_women = yes
	##prisoner = no					# [prisoner] doesn't stop parthenogenesis

	is_triggered_only = yes
	trigger = {
##		is_female = yes
		trait = amazon
		is_pregnant = no
##		##prisoner = no				# [prisoner] doesn't stop parthenogenesis
		NOR = { 
			trait = infirm
			trait = incapable
			##trait = celibate		# [celibate] doesn't stop parthenogenesis
			trait = eunuch			# [eunuch] trait can be applied to females
			##trait = in_hiding		# [in_hiding] doesn't stop parthenogenesis
		}
	}
	
	immediate = {
##		#unsafe_impregnate = 0			# Let's not chance Amazon twins
		impregnate = 0

		character_event = { id = AMAZON.0111 days = 60 }	# Notify the Amazon
	}
	option = { name = OK }
}

# Amazon Parthenogenesis -> Notify the Amazon
character_event = {
	id = AMAZON.0111
	desc = AMAZON_EVTDESC_0111
	picture = GFX_evt_pregnancy
	border = GFX_event_normal_frame_religion

	# Pre-triggers
	only_women = yes

	is_triggered_only = yes
	trigger = {
##		is_female = yes
		trait = amazon
		NOT = { trait = pregnant }
	}

	immediate = {
		add_trait = pregnant
		SPOUSE = {
			character_event = { id = AMAZON.0112 days = 0 }	# Notify the Amazon's husband
		}
	}
	option = { 
		name = EXCELLENT
		tooltip = { add_trait = pregnant }
		prestige = 10
		piety = 10
	}
}

# Amazon Parthenogenesis -> Notify the Amazon's husband (if any)
character_event = {
	id = AMAZON.0112
	desc = AMAZON_EVTDESC_0112
	picture = GFX_evt_pregnancy
	border = GFX_event_normal_frame_religion

	# Pre-triggers
	only_men = yes

	is_triggered_only = yes
	trigger = {
		SPOUSE = { 
			trait = amazon 
			trait = pregnant
		}
	}

	option = { 
##		name = "Well, I knew this day would come."
		name = AMAZON_EVTRESP_0112
		tooltip = { add_trait = pregnant }
		prestige = -5
		piety = -5
	}
}

# Amazon may be impregnated by Spouse -> Let normal mechanics do notifications/updates
# Failure here helps reduce Amazon births
character_event = {
	id = AMAZON.0120
	hide_window = yes

	# Pre-triggers
	only_women = yes
	prisoner = no

	is_triggered_only = yes
	trigger = {
		SPOUSE = { 					# Can SPOUSE impregnate her?
			is_female = no			# D'uh!
			prisoner = no
			NOR = { 
				trait = amazon		# Amazon men are sterile
				trait = incapable
				trait = infirm
				trait = celibate
				trait = eunuch
				trait = in_hiding
			}
		}
##		is_female = yes
		trait = amazon
		is_pregnant = no
##		prisoner = no
		NOR = { 
			trait = infirm
			trait = incapable
			trait = celibate
			trait = eunuch			# [eunuch] trait can be applied to females
			trait = in_hiding
		}
	}
	
	immediate = {
		SPOUSE = {
			THIS = { impregnate = ROOT }	# Initiate a normal pregnancy
		}
	}
	option = { name = OK }
}

# Amazon may be impregnated by Lover -> Let normal mechanics do notifications/updates
# Failure here helps reduce Amazon births
character_event = {
	id = AMAZON.0130
	hide_window = yes

	# Pre-triggers
	only_women = yes
	prisoner = no

	is_triggered_only = yes
	trigger = {
		any_lover = {				# Can Lover impregnate her?
			is_female = no			# D'uh!
			prisoner = no
			NOR = { 
				SPOUSE = { character = ROOT }	# NOT Lover={SPOUSE)
				trait = amazon		# Amazon men are sterile
				trait = incapable
				trait = infirm
				trait = celibate
				trait = eunuch
				trait = in_hiding
			}
		}
##		is_female = yes
		trait = amazon
		is_pregnant = no
##		prisoner = no
		NOR = { 
			trait = infirm
			trait = incapable
			trait = celibate
			trait = eunuch			# [eunuch] trait can be applied to females
			trait = in_hiding
		}
	}
	
	immediate = {
		random_lover = {
			limit = {
				is_female = no		# D'uh!
				prisoner = no
				NOR = { 
					SPOUSE = { character = ROOT }	# NOT Lover={SPOUSE)
					trait = amazon	# Amazon men are sterile
					trait = incapable
					trait = infirm
					trait = celibate
					trait = eunuch
					trait = in_hiding
				}
			}
			THIS = { impregnate = ROOT }	# Initiate a normal pregnancy
		}
	}
	option = { name = OK }
}

# A child is born to an Amazon 
character_event = {
	id = AMAZON.0200
	hide_window = yes

	is_triggered_only = yes
	trigger = {
		MOTHER = { trait = amazon }
	}

	immediate = {
		add_trait = strong			# Surely, all Amazons are strong
		if = {
			limit = { 
				NOR = { 
					trait = genius 
					trait = quick 
				}
			}
			random_list = {
				25 = { add_trait = quick }
				10 = { add_trait = genius }
				65 = { }
			}
		}
		random_list = {
			10 = { add_trait = shrewd }
			90 = { }
		}
		random_list = {
			45 = { add_trait = fair }
			55 = { }
		}

		# Ensure parthenogenetically-born child is female and of mother's dynasty
		if = {
			limit = { trait = bastard }	# Assigned only via Amazon Parthenogenesis
			character_event = { id = AMAZON.0201 days = 0 }	# Ensure mother's dynasty
			character_event = { id = AMAZON.0202 days = 0 }	# Make males "stillborn"
		}
		# Non-parthenogenetically-born males may lose [amazon] trait
		else
		{
			character_event = { id = AMAZON.0203 days = 0 }
		}
	}
	option = { name = OK }
}

# A child is born to an Amazon -> 
#	Ensure parthenogenetically-born child is female and of mother's dynasty
character_event = {
	id = AMAZON.0201
	hide_window = yes

	is_triggered_only = yes
	trigger = {
		MOTHER = { trait = amazon }
		trait = bastard				# Assigned only via Amazon Parthenogenesis
	}

	immediate = {
		remove_trait = bastard
## place-holder to remove the "bstd=yes" line from the child ##
		dynasty = MOTHER 				# Ensure that the child has mother's dynasty
		add_trait = amazon			# (just to be sure)

		# IF child is female: 1% chance to start a new dynasty
		if = {
			limit = { is_female = yes }
			random_list = {
				01 = { dynasty = mother_bastard }	# these two seem to have
##				01 = { dynasty = father_bastard }	# the same effect
				99 = { }
			}
		}
	}
	option = { name = OK }
}

# A child is born to an Amazon -> 
#	Ensure parthenogenetically-born males are "stillborn"
# 	ALSO, this here helps reduce Amazon births
character_event = {
	id = AMAZON.0202
	hide_window = yes

	# Pre-triggers
	only_men = yes

	is_triggered_only = yes
	trigger = {
##		is_female = no
		trait = amazon
	}

	immediate = {
		set_father = 0
		set_mother = 0
		dynasty = none
		death = { }
	}
	option = { name = OK }
}


# A child is born to an Amazon -> 
#	5% chance non-parthenogenetically-born males lose [amazon] trait
character_event = {
	id = AMAZON.0203
	hide_window = yes

	# Pre-triggers
	only_men = yes

	is_triggered_only = yes
	trigger = {
##		is_female = no
		trait = amazon
	}

	immediate = {
		random_list = {
			05 = { remove_trait = amazon }
			95 = { }
		}
	}
	option = { name = OK }
}