﻿# On actions for child birth and pregnancy notification events, triggered automatically by the game

# called for the mother
# scope:child is the new born character
# scope:mother is the pregnant mother
# scope:real_father is the biological father
# scope:father is the family father (not the biological)
on_birth_mother = {
	events = {
		birth.0001 #No one dies - hidden event that selects visible birth event based on bastard status and complication rolls
		birth.3011 #Mother dies
	}
}

# called for the father
# scope:child is the new born character
# scope:mother is the pregnant mother
# scope:real_father is the biological father
# scope:father is the family father (not the biological)
on_birth_father = {
	events = {

	}
}

# called for the biological father
# only called if father and real father are different
# scope:child is the new born character
# scope:mother is the pregnant mother
# scope:real_father is the biological father
# scope:father is the family father (not the biological)
on_birth_real_father = {
	events = {

	}
}

# called for the newborn child
# scope:child is the new born character
# scope:mother is the pregnant mother
# scope:father is the family father (not the biological)
# scope:real_father is the biological father
# scope:is_bastard, true if a known bastard
on_birth_child = {
	events = {
		middle_east_decisions.0012 #Saoshyant Descendants.
		major_decisions.0101 #Divine/Consecrated Blood Descendants.
		birth.8001 #Reincarnation
		birth.8011 #Born in the Purple
		trait_specific.0500 #To handle genetic traits not expressed until later in life
		debug.0010 # Disease data tracking
	}
	effect = {
		#Add bastardy traits and set correct House
		if = {
			limit = {
				OR = {
					scope:is_bastard = yes
					AND = {
						NOT = { scope:father = { this = scope:real_father } }
						has_game_rule = no_secret_bastards
					}
				}
			}
			add_bastard_trait_based_on_faith_effect = yes

			if = {
				limit = {
					OR = {
						scope:mother = {
							has_character_flag = pregnancy_real_father_of_bastard_is_known_flag
						}
						has_game_rule = no_secret_bastards
					}
				}
				#Set father and house
				set_father = scope:real_father
			}
			set_parent_house_effect = yes

			#Set conditions for any twins
			scope:mother = {
				every_child = {
					limit = {
						is_twin_of = scope:child
					}
					add_bastard_trait_based_on_faith_effect = yes
					if = {
						limit = {
							OR = {
								scope:mother = {
									has_character_flag = pregnancy_real_father_of_bastard_is_known_flag
								}
								has_game_rule = no_secret_bastards
							}
						}
						#Set father and house
						set_father = scope:real_father
					}
					set_parent_house_effect = yes
				}
			}
		}

		#To assign correct house to a child of consort
		if = {
			limit = {
				scope:is_bastard = no
				exists = father
				father = { is_lowborn = yes }
				mother = { is_ruler = yes }
				is_lowborn = yes
			}
			set_parent_house_effect = yes
		}

		#Add house hook
		if = {
			limit = {
				is_alive = yes
				exists = scope:child.house
				scope:child.house.house_head = { is_alive =yes }
				NOT = {
					scope:child = scope:child.house.house_head # If the house dies out, a posthumous child can revive it
				}
				#No need to check if the hook can be added, the kid was just born
			}
			scope:child.house.house_head = {
				add_hook_no_toast = {
					type = house_head_hook
					target = scope:child
				}
			}
		}

		if = {
			limit = {
				exists = scope:father
				OR = {
					scope:mother = {
						is_concubine_of = scope:father
					}
					scope:father = {
						is_concubine_of = scope:mother
					}
				}
			}
			add_trait = child_of_concubine
		}

		hidden_effect = {
			every_parent = {
				limit = {
					has_perk = sound_foundations_perk
				}
				sound_foundations_skill_gain_effect = yes
			}
		}

		# Blood legacy 4 extra genetic trait chance effect
		hidden_effect = {
			if = {
				limit = {
					exists = scope:child.dynasty
					scope:child.dynasty = { has_dynasty_perk = blood_legacy_4 }
					OR = { # The child must have a real parent of the Dynasty...
						scope:mother.dynasty = scope:child.dynasty
						scope:real_father.dynasty = scope:child.dynasty
					}
				}
				if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_beauty_good_1
						}
						NOR = {
							has_trait = beauty_good
							has_trait = beauty_bad
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = beauty_good_1
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_intellect_good_1
						}
						NOR = {
							has_trait = intellect_good
							has_trait = intellect_bad
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = intellect_good_1
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_physique_good_1
						}
						NOR = {
							has_trait = physique_good
							has_trait = physique_bad
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = physique_good_1
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_fecund
						}
						NOR = {
							has_trait = infertile
							has_trait = fecund
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = fecund
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_giant
						}
						NOR = {
							has_trait = giant
							has_trait = dwarf
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = giant
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_dwarf
						}
						NOR = {
							has_trait = giant
							has_trait = dwarf
						}
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = dwarf
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_albino
						}
						has_trait = albino
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = albino
					}
				}
				else_if = {
					limit = {
						scope:child.dynasty = {
							exists = var:blood_legacy_4_scaly
						}
						has_trait = scaly
					}
					random = {
						chance = blood_legacy_4_chance
						modifier = {
							add = blood_legacy_4_extra_player_chance
							any_parent = { is_ai = no }
						}
						add_trait = scaly
					}
				}
			}
		}
	}
}

# called for the mother when a pregnancy reaches the "revealed" status
# scope:mother is the pregnant mother
# scope:father is the assumed father
# scope:real_father is the biological father
on_pregnancy_mother = {
	events = {
		pregnancy.0001 # Universal hidden maintenance event
		pregnancy.1001 # Mother gives birth to current husband's child.
		pregnancy.1101 # Mother gives birth to ex-husband's child.
		pregnancy.2001 # Unwed mother gives birth to bastard child.
		pregnancy.2002 # Married mother gives birth to bastard child.
	}
}

# called for the father when a pregnancy reaches the "revealed" status
# scope:mother is the pregnant mother
# scope:father is the assumed father
# scope:real_father is the biological father
on_pregnancy_father = {
	events = {
	
	}
}

# called for the mother when a pregnancy ends prematurely
# scope:mother is the pregnant mother
# scope:father is the assumed father
# scope:real_father is the biological father
on_pregnancy_ended_mother = {
	events = {
	
	}
}
