﻿# 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 = {
	on_actions = {
		on_hide_genetic_traits
		on_intellect_rebalance
		on_ai_beautification
	}
}

on_hide_genetic_traits = {
	trigger = {
		NOT = { has_game_rule = child_development_disabled }
	}
	effect = {
		# remove_variables if they exist...
		while = {
			count = 10
			limit = {
				OR = {
					has_variable = qol_child_beauty
					has_variable = qol_child_intellect
					has_variable = qol_child_physique
					has_variable = qol_child_fecund
					has_variable = qol_child_pure_blooded
					has_variable = qol_child_lisping
					has_variable = qol_child_stuttering
					has_variable = qol_child_dwarf
					has_variable = qol_child_giant
					has_variable = qol_child_inbred
				}
			}
			switch = {
				trigger = has_variable
				qol_child_beauty = { remove_variable = qol_child_beauty }
				qol_child_intellect = { remove_variable = qol_child_intellect }
				qol_child_physique = { remove_variable = qol_child_physique }
				qol_child_fecund = { remove_variable = qol_child_fecund }
				qol_child_pure_blooded = { remove_variable = qol_child_pure_blooded }
				qol_child_lisping = { remove_variable = qol_child_lisping }
				qol_child_stuttering = { remove_variable = qol_child_stuttering }
				qol_child_dwarf = { remove_variable = qol_child_dwarf }
				qol_child_giant = { remove_variable = qol_child_giant }
				qol_child_inbred = { remove_variable = qol_child_inbred }
			}
		}
		# add_variables
		# beauty - shows around age 12-16
		set_qol_trait_group_variable = { TRAIT = beauty }

		# intellect - shows around age 2-16
		set_qol_trait_group_variable = { TRAIT = intellect }

		# physique - shows around age 6-16
		set_qol_trait_group_variable = { TRAIT = physique }

		# fecund - shows around age 12-16
		set_qol_trait_variable = { TRAIT = fecund }

		# pure blooded - shows around age 2-16
		set_qol_trait_variable = { TRAIT = pure_blooded }

		# lisping - shows around age 2-6
		set_qol_trait_variable = { TRAIT = lisping }

		# stuttering - shows around age 2-6
		set_qol_trait_variable = { TRAIT = stuttering }

		# dwarf - shows around age 6-14
		set_qol_trait_variable = { TRAIT = dwarf }

		# giant - shows around age 6-14
		set_qol_trait_variable = { TRAIT = giant }
		
		# inbred - shows around age 2-16
		set_qol_trait_variable = { TRAIT = inbred }
	}
}

on_intellect_rebalance = {
	trigger = {
		has_trait = intellect_good
		NOT = { has_game_rule = intellect_rebalance_disabled }
		trigger_if = {
			limit = { age < 2 } # new born toddler
			has_game_rule = child_development_disabled
		}
	}
	effect = {
		set_intellect_trait_xp = yes
	}
}

on_ai_beautification = {
	trigger = {
		NOR = {
			has_variable = qol_child_beauty
			has_trait = beauty_good
			trigger_if = {
				limit = { is_lowborn = no }
				any_ancestor = {
					is_ai = no
					house ?= root.house
				}
			}
		}
	}
	effect = {
		random = {
			chance = 10
			modifier = {
				any_ancestor = { is_ruler = yes }
				add = 10
			}
			modifier = {
				any_ancestor = { has_trait = beauty_good_3 }
				add = 40
			}
			modifier = {
				any_ancestor = { has_trait = beauty_good_2 }
				add = 20
			}
			modifier = {
				any_ancestor = { has_trait = beauty_good_1 }
				add = 10
			}
			modifier = {
				any_ancestor = { has_trait = beauty_bad_1 }
				add = -10
			}
			modifier = {
				any_ancestor = { has_trait = beauty_bad_2 }
				add = -20
			}
			modifier = {
				any_ancestor = { has_trait = beauty_bad_3 }
				add = -40
			}
			add_trait = beauty_good_3
			remove_trait = beauty_good_3
		}
	}
}

# 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 = {
	on_actions = {
		on_harder_ai_pregnancy
	}
}

on_harder_ai_pregnancy = {
	trigger = {
		NOT = { has_game_rule = no_extra_difficulty }
		is_ai = yes
		scope:real_father = { is_ai = yes }
		OR = {
			is_ruler = yes
			scope:real_father = { is_ruler = yes }
		}
	}
	effect = {
		if = {
			limit = {
				is_ruler = yes
				is_lowborn = no
				NOT = { any_player = { house = prev.house } }
			}
			house = {
				add_house_modifier = {
					modifier = harder_difficulty_bonus
					days = 270
				}
			}
		}
		else = {
			scope:real_father = {
				if = {
					limit = {
						is_lowborn = no
						NOT = { any_player = { house = prev.house } }
					}
					house = {
						add_house_modifier = {
							modifier = harder_difficulty_bonus
							days = 270
						}
					}
				}
			}
		}
	}
}