﻿# used in the heir events

heir_training_value = {
	value = 0
	add = {
		add = learning
		subtract = 5
		divide = 2
		max = 10
	}
	add = {
		add = scope:trainer.learning
		subtract = 5
		divide = 4
		max = 5
	}
	if = {
		limit = { is_adult = yes }
		add = -2
	}
	if = {
		limit = { age >= 25 }
		add = -2
	}
	if = {
		limit = { age >= 40 }
		add = -2
	}
	if = {
		limit = {
			OR = {
				is_diarch = yes
				is_councillor = yes
			}
		}
		add = 2
	}
	if = {
		limit = { has_court_position = seneschal_court_position }
		add = 1
	}
	if = {
		limit = { has_court_position = chief_qadi_court_position }
		add = 1
	}
	if = {
		limit = { has_trait = lazy }
		add = -1
	}
	if = {
		limit = { has_trait = content }
		add = -0.5
	}
	if = {
		limit = { has_trait = intellect_bad_1 }
		add = -1
	}
	if = {
		limit = { has_trait = intellect_bad_2 }
		add = -2
	}
	if = {
		limit = { has_trait = dull }
		add = -2
	}
	if = {
		limit = { has_trait = intellect_bad_3 }
		add = -3
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_bad_1 } }
		add = -0.5
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_bad_2 } }
		add = -1
	}
	if = {
		limit = { scope:trainer = { has_trait = dull } }
		add = -1
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_bad_3 } }
		add = -1.5
	}
	if = {
		limit = { scope:trainer = { has_trait = impatient } }
		add = -1
	}
	if = {
		limit = { scope:trainer = { has_trait = irritable } }
		add = -0.5
	}
	if = {
		limit = { scope:trainer = { has_trait = reclusive } }
		add = -0.5
	}
	if = {
		limit = { has_trait = diligent }
		add = 1
	}
	if = {
		limit = { has_trait = ambitious }
		add = 1
	}
	if = {
		limit = { has_trait = intellect_good_1 }
		add = 1
	}
	if = {
		limit = { has_trait = intellect_good_2 }
		add = 2
	}
	if = {
		limit = { has_trait = shrewd }
		add = 2
	}
	if = {
		limit = { has_trait = intellect_good_3 }
		add = 3
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_good_1 } }
		add = 0.5
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_good_2 } }
		add = 1
	}
	if = {
		limit = { scope:trainer = { has_trait = shrewd } }
		add = 1
	}
	if = {
		limit = { scope:trainer = { has_trait = intellect_good_3 } }
		add = 1.5
	}
	if = {
		limit = { scope:trainer = { has_trait = patient } }
		add = 1
	}
	if = {
		limit = { scope:trainer = { has_trait = architect } }
		add = 0.5
	}
	if = {
		limit = { scope:trainer = { has_trait = administrator } }
		add = 1
	}
	if = {
		limit = {
			# reduce advancement here because they can't give their heir a title anyhow
			host = {
				any_held_title = {
					title_tier = county
					count < 2
				}
			}
		}
		multiply = 0.5
	}
	round = yes
	min = 0
}

martial_educator_value = {
	value = 1
	add = {
		value = martial
		multiply = 3
	}
	add = {
		value = prowess
		multiply = 2
	}
	add = learning
	if = {
		limit = { has_trait = education_martial_3 }
		add = 50
	}
	else_if = {
		limit = { has_trait = education_martial_4 }
		add = 100
	}
	else_if = {
		limit = { has_trait = education_martial_5 }
		add = 150
	}
	if = {
		limit = { is_knight = yes }
		add = 10
	}
	if = {
		limit = { has_trait = lazy }
		add = -20
	}
	if = {
		limit = { has_trait = craven }
		add = -50
	}
	if = {
		limit = { has_trait = ambitious }
		add = 20
	}
	if = {
		limit = { has_trait = zealous }
		add = 20
	}
	if = {
		limit = { has_trait = wrathful }
		add = 20
	}
	if = {
		limit = { has_trait = brave }
		add = 50
	}
	if = {
		limit = { has_trait = patient }
		multiply = 1.25
	}
	if = {
		limit = { has_trait = impatient }
		multiply = 0.75
	}
	if = {
		limit = { NOT = { religion = root.religion } }
		multiply = 0.75
	}
	else_if = {
		limit = { NOT = { faith = root.faith } }
		multiply = 0.90
	}
	if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 10
				}
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 30
				}
			}
		}
		multiply = 0.8
	}
	if = {
		limit = {
			has_dynasty = yes
			dynasty = root.dynasty
		}
		multiply = 1.2
	}
	else_if = {
		limit = { is_lowborn = yes }
		multiply = 0.8
	}
	if = {
		limit = { is_close_or_extended_family_of = root }
		multiply = 1.2
	}
}

diplomacy_educator_value = {
	value = 1
	add = {
		value = diplomacy
		multiply = 3
	}
	add = learning
	if = {
		limit = { has_trait = education_diplomacy_3 }
		add = 50
	}
	else_if = {
		limit = { has_trait = education_diplomacy_4 }
		add = 100
	}
	else_if = {
		limit = { has_trait = education_diplomacy_5 }
		add = 150
	}
	if = {
		limit = { has_trait = lazy }
		add = -20
	}
	if = {
		limit = { has_trait = greedy }
		add = -20
	}
	if = {
		limit = { has_trait = deceitful }
		add = -20
	}
	if = {
		limit = { has_trait = callous }
		add = -20
	}
	if = {
		limit = { has_trait = eccentric }
		add = -20
	}
	if = {
		limit = { has_trait = vengeful }
		add = -20
	}
	if = {
		limit = { has_trait = shy }
		add = -20
	}
	if = {
		limit = { has_trait = trusting }
		add = 10
	}
	if = {
		limit = { has_trait = forgiving }
		add = 10
	}
	if = {
		limit = { has_trait = compassionate }
		add = 10
	}
	if = {
		limit = { has_trait = gregarious }
		add = 20
	}
	if = {
		limit = { has_trait = generous }
		add = 20
	}
	if = {
		limit = { has_trait = honest }
		add = 20
	}
	if = {
		limit = { has_trait = diligent }
		add = 30
	}
	if = {
		limit = { has_trait = patient }
		multiply = 1.25
	}
	if = {
		limit = { has_trait = impatient }
		multiply = 0.75
	}
	if = {
		limit = { NOT = { religion = root.religion } }
		multiply = 0.75
	}
	else_if = {
		limit = { NOT = { faith = root.faith } }
		multiply = 0.90
	}
	if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 10
				}
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 30
				}
			}
		}
		multiply = 0.8
	}
	if = {
		limit = {
			has_dynasty = yes
			dynasty = root.dynasty
		}
		multiply = 1.2
	}
	else_if = {
		limit = { is_lowborn = yes }
		multiply = 0.8
	}
	if = {
		limit = { is_close_or_extended_family_of = root }
		multiply = 1.2
	}
}

intrigue_educator_value = {
	value = 1
	add = {
		value = intrigue
		multiply = 3
	}
	add = learning
	if = {
		limit = { has_trait = education_intrigue_3 }
		add = 50
	}
	else_if = {
		limit = { has_trait = education_intrigue_4 }
		add = 100
	}
	else_if = {
		limit = { has_trait = education_intrigue_5 }
		add = 150
	}
	if = {
		limit = { has_trait = forgiving }
		add = -20
	}
	if = {
		limit = { has_trait = just }
		add = -20
	}
	if = {
		limit = { has_trait = lazy }
		add = -20
	}
	if = {
		limit = { has_trait = compassionate }
		add = -20
	}
	if = {
		limit = { has_trait = honest }
		add = -20
	}
	if = {
		limit = { has_trait = trusting }
		add = -20
	}
	if = {
		limit = { has_trait = lustful }
		add = 10
	}
	if = {
		limit = { has_trait = vengeful }
		add = 10
	}
	if = {
		limit = { has_trait = arbitrary }
		add = 20
	}
	if = {
		limit = { has_trait = cynical }
		add = 20
	}
	if = {
		limit = { has_trait = deceitful }
		add = 20
	}
	if = {
		limit = { has_trait = paranoid }
		add = 20
	}
	if = {
		limit = { has_trait = sadistic }
		add = 20
	}
	if = {
		limit = { has_trait = patient }
		multiply = 1.25
	}
	if = {
		limit = { has_trait = impatient }
		multiply = 0.75
	}
	if = {
		limit = { NOT = { religion = root.religion } }
		multiply = 0.75
	}
	else_if = {
		limit = { NOT = { faith = root.faith } }
		multiply = 0.90
	}
	if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 10
				}
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 30
				}
			}
		}
		multiply = 0.8
	}
	if = {
		limit = {
			has_dynasty = yes
			dynasty = root.dynasty
		}
		multiply = 1.2
	}
	else_if = {
		limit = { is_lowborn = yes }
		multiply = 0.8
	}
	if = {
		limit = { is_close_or_extended_family_of = root }
		multiply = 1.2
	}
}

learning_educator_value = {
	value = 1
	add = {
		value = learning
		multiply = 3
	}
	if = {
		limit = { has_trait = education_learning_3 }
		add = 50
	}
	else_if = {
		limit = { has_trait = education_learning_4 }
		add = 100
	}
	else_if = {
		limit = { has_trait = education_learning_5 }
		add = 150
	}
	if = {
		limit = { has_trait = lazy }
		add = -20
	}
	if = {
		limit = { has_trait = chaste }
		add = 10
	}
	if = {
		limit = { has_trait = content }
		add = 10
	}
	if = {
		limit = { has_trait = cynical }
		add = 20
	}
	if = {
		limit = { has_trait = diligent }
		add = 30
	}
	if = {
		limit = { has_trait = patient }
		multiply = 1.25
	}
	if = {
		limit = { has_trait = impatient }
		multiply = 0.75
	}
	if = {
		limit = { NOT = { religion = root.religion } }
		multiply = 0.75
	}
	else_if = {
		limit = { NOT = { faith = root.faith } }
		multiply = 0.90
	}
	if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 10
				}
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 30
				}
			}
		}
		multiply = 0.8
	}
	if = {
		limit = {
			has_dynasty = yes
			dynasty = root.dynasty
		}
		multiply = 1.2
	}
	else_if = {
		limit = { is_lowborn = yes }
		multiply = 0.8
	}
	if = {
		limit = { is_close_or_extended_family_of = root }
		multiply = 1.2
	}
}

stewardship_educator_value = {
	value = 1
	add = {
		value = stewardship
		multiply = 3
	}
	if = {
		limit = { has_trait = education_stewardship_3 }
		add = 50
	}
	else_if = {
		limit = { has_trait = education_stewardship_4 }
		add = 100
	}
	else_if = {
		limit = { has_trait = education_stewardship_5 }
		add = 150
	}
	if = {
		limit = { has_trait = arbitrary }
		add = -20
	}
	if = {
		limit = { has_trait = fickle }
		add = -20
	}
	if = {
		limit = { has_trait = lazy }
		add = -20
	}
	if = {
		limit = { has_trait = gluttonous }
		add = -20
	}
	if = {
		limit = { has_trait = just }
		add = 20
	}
	if = {
		limit = { has_trait = temperate }
		add = 20
	}
	if = {
		limit = { has_trait = diligent }
		add = 30
	}
	if = {
		limit = { has_trait = stubborn }
		add = 30
	}
	if = {
		limit = { has_trait = patient }
		multiply = 1.25
	}
	if = {
		limit = { has_trait = impatient }
		multiply = 0.75
	}
	if = {
		limit = { NOT = { religion = root.religion } }
		multiply = 0.75
	}
	else_if = {
		limit = { NOT = { faith = root.faith } }
		multiply = 0.90
	}
	if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 10
				}
			}
		}
		multiply = 0.75
	}
	else_if = {
		limit = {
			NOT = { culture = root.culture }
			culture = {
				cultural_acceptance = {
					target = root.culture
					value <= 30
				}
			}
		}
		multiply = 0.8
	}
	if = {
		limit = {
			has_dynasty = yes
			dynasty = root.dynasty
		}
		multiply = 1.2
	}
	else_if = {
		limit = { is_lowborn = yes }
		multiply = 0.8
	}
	if = {
		limit = { is_close_or_extended_family_of = root }
		multiply = 1.2
	}
}

martial_plus_two = {
	value = martial
	add = 2
}

martial_plus_four = {
	value = martial
	add = 4
}

martial_plus_five = {
	value = martial
	add = 5
}

diplomacy_plus_five = {
	value = diplomacy
	add = 5
}

stewardship_plus_five = {
	value = stewardship
	add = 5
}

intrigue_plus_five = {
	value = intrigue
	add = 5
}

learning_plus_five = {
	value = learning
	add = 5
}

heir_training_progress_value = {
	if = {
		limit = {
			is_alive = yes
			has_variable = heir_training_var
			var:heir_training_var > 0
		}
		add = var:heir_training_var
		divide = {
			add = 50
			if = {
				limit = { has_trait = education_heir_training_1 }
				add = 50
			}
			else_if = {
				limit = { has_trait = education_heir_training_2 }
				add = 100
			}
			else_if = {
				limit = { has_trait = education_heir_training_3 }
				add = 150
			}
		}
		multiply = 100
	}
	else = {
		value = 0
	}
	min = 0
	max = 100
}

num_expected_children = {
	value = 0

	if = {
		limit = {
			exists = host
			host.highest_held_title_tier >= tier_kingdom
			OR = {
				is_player_heir_of = host
				primary_spouse = { is_player_heir_of = host }
			}
		}
		add = 4
	}
	else_if = {
		limit = {
			OR = {
				any_heir_title = { tier >= tier_duchy }
				any_pretender_title = {
					tier >= tier_duchy
					place_in_line_of_succession = { target = prev value < 4 }
				}
				primary_spouse = {
					OR = {
						any_heir_title = { tier >= tier_duchy }
						any_pretender_title = {
							tier >= tier_duchy
							place_in_line_of_succession = { target = prev value < 4 }
						}
					}
				}
			}
		}
		add = 3
	}
	else_if = {
		limit = {
			OR = {
				any_heir_title = { tier >= tier_county }
				any_pretender_title = {
					tier >= tier_county
					place_in_line_of_succession = { target = prev value < 4 }
				}
				primary_spouse = {
					OR = {
						any_heir_title = { tier >= tier_county }
						any_pretender_title = {
							tier >= tier_county
							place_in_line_of_succession = { target = prev value < 4 }
						}
					}
				}
				any_claim = {
					pressed = yes
					tier >= tier_county
				}
				primary_spouse = {
					any_claim = {
						pressed = yes
						tier >= tier_county
					}
				}
			}
		}
		add = 2
	}
	else = {
		add = 1
	}
}

annual_chance_children = {
	value = fertility
	if = {
		limit = { fertility > primary_spouse.fertility }
		value = primary_spouse.fertility
	}
	if = {
		limit = {
			OR = {
				is_player_heir_of = host
				primary_spouse = { is_player_heir_of = host }
			}
		}
		multiply = 50
	}
	else = {
		multiply = 25
	}
	round = yes
}

language_tutor_value = {
	value = 0
	save_temporary_scope_as = potential_tutor
	if = {
		limit = {
			scope:current_pupil = {
				can_start_scheme = { type = learn_language target_character = scope:potential_tutor }
			}
		}
		scope:potential_tutor.culture = {
			if = {
				limit = { has_same_culture_language = scope:liege.culture }
				add = 2500
			}
			else_if = {
				limit = { is_in_list = realm_languages }
				add = 900
			}
			else_if = {
				limit = { is_in_list = vassal_languages }
				add = 250
			}
			else_if = {
				limit = { is_in_list = liege_languages }
				add = 100
			}
			else_if = {
				limit = { is_in_list = ally_languages }
				add = 30
			}
			else_if = {
				limit = { is_in_list = neighbour_languages }
				add = 10
			}
			else_if = {
				limit = {
					scope:current_pupil = {
						OR = {
							has_focus = education_learning
							has_trait = ambitious
							AND = {
								has_trait = intellect_good
								ai_energy >= 20
							}
						}
					}
				}
				if = {
					limit = { has_same_culture_heritage = scope:current_pupil.culture }
					add = 5
				}
				if = {
					limit = {
						scope:current_pupil = {
							has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:potential_tutor }
						}
					}
					add = 2
				}
				if = {
					limit = {
						scope:current_pupil.culture = {
							cultural_acceptance = {
								target = scope:potential_tutor.culture
								value > 0
							}
						}
					}
					add = 1
				}
			}
		}
	}
}

