﻿early_age_max_chance = {
	value = age
	divide = {
		value = 6
		if = {
			limit = { has_game_rule = child_development_harsh }
			multiply = {
				value = 6
				if = {
					limit = {
						is_ai = no
						any_ancestor = { is_ai = no }
					}
					add = 2
				}
				else = {
					add = -2
				}
			}
		}
	}
	multiply = 100
	max = 100
}

adolescent_max_chance = {
	value = age
	divide = {
		value = 14
		if = {
			limit = { has_game_rule = child_development_harsh }
			multiply = {
				value = 6
				if = {
					limit = {
						is_ai = no
						any_ancestor = { is_ai = no }
					}
					add = 2
				}
				else = {
					add = -2
				}
			}
		}
	}
	multiply = 100
	max = 100
}

adult_age_max_chance = {
	value = age
	divide = {
		value = 16
		if = {
			limit = { has_game_rule = child_development_harsh }
			multiply = {
				value = 6
				if = {
					limit = {
						is_ai = no
						any_ancestor = { is_ai = no }
					}
					add = 2
				}
				else = {
					add = -2
				}
			}
		}
	}
	multiply = 100
	max = 100
}

adult_age_max_chance_health_considered = {
	value = age
	if = {
		limit = { fine_health > health }
		add = {
			value = fine_health
			subtract = health
			save_temporary_value_as = difference
			multiply = scope:difference
		}
	}
	divide = {
		value = 16
		if = {
			limit = { has_game_rule = child_development_harsh }
			multiply = {
				value = 6
				if = {
					limit = {
						is_ai = no
						any_ancestor = { is_ai = no }
					}
					add = 2
				}
				else = {
					add = -2
				}
			}
		}
	}
	multiply = 100
	max = 100
}

parabola = {
	# paste into desmos: \max\left(50-2\left(x-16\right)^{2},\ \frac{x}{2}\right)
	switch = {
		trigger = has_game_rule
		child_development_harsh = { value = 50 }
		fallback = { value = 100 }
	}
	subtract = {
		# 2(difference^2)
		value = {
			value = age
			if = {
				limit = {
					has_variable = health_considered
					fine_health > health
				}
				add = {
					value = fine_health
					subtract = health
					save_temporary_value_as = difference
					multiply = scope:difference
				}
				max = 16 # to prevent decrease in chance: maximize chance when needed
			}
			save_temporary_value_as = adjusted_age
		}
		add = -16
		save_temporary_value_as = difference
		multiply = scope:difference
		switch = {
			trigger = has_game_rule
			child_development_harsh = { multiply = 2 }
			fallback = { multiply = 10 }
		}
	}
	min = {
		value = scope:adjusted_age
		if = {
			limit = { has_game_rule = child_development_harsh }
			divide = 2
		}
	}
	max = 100
}