﻿accolade_creation_prestige_cost = {
	value = 0
	if = {
		limit = {
			scope:owner ?= {
				highest_held_title_tier >= tier_empire
			}
		}
		add = 200
	}
	else_if = {
		limit = {
			scope:owner ?= {
				highest_held_title_tier = tier_kingdom
			}
		}
		add = 150
	}
	else = {
		add = 100
	}
}

#######################################
# KNIGHTLY ACCOLADE VALUES
#######################################

accolade_low_value = 5
accolade_medium_value = 10
accolade_high_value = 20

accolade_prowess_requirement_value = 8
accolade_prowess_requirement_high_value = 15

accolade_opinion_multiplier_value = {
	value = 0
	## Below the minimum opinion, we don't want to factor them in at all.
	if = {
		limit = {
			reverse_opinion = {
				target = scope:owner
				value < -25
			}
		}
		# Here, we do nothing. Zero is the desired multiplier.
	}
	## Below the recommended opinion, we like them less.
	else_if = {
		limit = {
			reverse_opinion = {
				target = scope:owner
				value < 10
			}
		}
		add = 0.5
	}
	## Above the nepotistic opinion, we prioritise their wants more heavily.
	else_if = {
		limit = {
			reverse_opinion = {
				target = scope:owner
				value >= 90
			}
		}
		add = 2
	}
	## Or else they're in the default range, so x1 is good enough.
	else = { add = 1 }
}

accolade_uninteresting_base_value = 0
accolade_standard_base_value = 200
accolade_fascinating_base_value = 400
accolade_must_have_base_value = 800

accolade_weighted_up_in_earlier_eras_value = {
	value = 0
	culture ?= {
		# If we're in the TE, weight this attribute up a bit.
		if = {
			limit = {
				NOT = { has_cultural_era_or_later = culture_era_early_medieval }
			}
			add = 50
		}
		# If we're in the EME, weight this attribute up even further.
		if = {
			limit = {
				NOT = { has_cultural_era_or_later = culture_era_high_medieval }
			}
			add = 100
		}
	}
}

accolade_weighted_up_in_later_eras_value = {
	value = 0
	culture ?= {
		# If we're in the HME, weight this attribute up a bit.
		if = {
			limit = { has_cultural_era_or_later = culture_era_high_medieval }
			add = 100
		}
		# If we're in the LME, weight this attribute up even further.
		if = {
			limit = { has_cultural_era_or_later = culture_era_late_medieval }
			add = 200
		}
	}
}

maa_accolade_minimum_martial_value = medium_skill_rating

###############
# COMMON ATTRIBUTES
###############

accolade_agent_acceptance_chance_bonus = accolade_medium_value
accolade_agent_acceptance_chance_bonus_high = accolade_high_value
accolade_invite_courtiers_value = accolade_high_value
accolade_imprisonment_chance_value = 15
accolade_imprisonment_chance_value_high = 25
accolade_wise_educator_prestige = 100
accolade_wise_educator_prestige_high = 250
accolade_wise_educator_prowess = 1
accolade_wise_educator_prowess_high = 3
accolade_white_peace_prestige_value = major_prestige_value
accolade_seduction_vulnerability_value = 15
accolade_politicker_join_scheme_value = 25
accolade_charmer_fertility_value = 0.25
accolade_charmer_fertility_high_value = 0.5
accolade_charmer_attraction_opinion_value = accolade_medium_value
accolade_charmer_attraction_opinion_high_value = accolade_high_value
accolade_piety_reduction_value = 0.5
accolade_piety_reduction_value_high = 0.25

###############
# SKILLED ATTRIBUTES
###############

accolade_scales_of_power_value = -10
accolade_scales_of_power_value_high = -15

accolade_development_growth_on_tournament_completion_value = 50
accolade_development_level_on_tournament_completion_value = 1
accolade_county_control_gain_value = medium_county_control_gain

accolade_contender_trait_xp_low_value = 10
accolade_contender_trait_xp_medium_value = 15
accolade_contender_trait_xp_high_value = 20

accolade_all_knights_trait_xp_low_value = 5
accolade_all_knights_trait_xp_high_value = 10


###############
# MAA ATTRIBUTES
###############

accolade_hostile_knight_death_in_battle_low_value = 0.25
accolade_hostile_knight_death_in_battle_medium_value = 0.5
accolade_hostile_knight_death_in_battle_high_value = 0.75

accolade_hostile_knight_death_in_battle_actual_low_value = {
	value = accolade_hostile_knight_death_in_battle_low_value
	add = 1
}
accolade_hostile_knight_death_in_battle_actual_medium_value = {
	value = accolade_hostile_knight_death_in_battle_medium_value
	add = 1
}
accolade_hostile_knight_death_in_battle_actual_high_value = {
	value = accolade_hostile_knight_death_in_battle_high_value
	add = 1
}

###############
# EMINENT ATTRIBUTES
###############

acclaimed_knight_hunt_danger_value = -10 #Unop: Was 10 but this need to be reversed (since it's adding danger in hunt_melee_danger_value & hunt_bow_danger_value)
acclaimed_knight_hunt_danger_value_high = -15 #Unop: Was 15 but this need to be reversed (since it's adding danger in hunt_melee_danger_value & hunt_bow_danger_value)
accolade_tournament_invite_acceptance_value = 20
accolade_feast_wedding_invite_acceptance_value = 20
acclaimed_knight_prestige_from_victory_value = miniscule_prestige_value
acclaimed_knight_prestige_from_victory_value_high = minor_prestige_value

accolade_defends_family_low_value = -0.25
accolade_defends_family_medium_value = -0.5
accolade_defends_family_high_value = -0.75

accolade_defends_family_actual_low_value = {
	value = accolade_defends_family_low_value
	add = 1
}
accolade_defends_family_actual_medium_value = {
	value = accolade_defends_family_medium_value
	add = 1
}
accolade_defends_family_actual_high_value = {
	value = accolade_defends_family_high_value
	add = 1
}

num_accolades_multiplier = {
	value = 0
	every_accolade = {
		limit = {
			has_potential_accolade_successors = no
		}
		add = 1
		if = {
			limit = {
				accolade_rank = 3
			}
			add = 1
		}
		else_if = {
			limit = {
				accolade_rank > 3
			}
			add = 2
		}
	}
}

#The factors which determine the "Aptitude" of the Accolade's squires, and thus what bonuses or maluses will be applied to the Accolade's next knight
accolade_squires_quality_value = {
	#The Squires statistic ranges from 0-100, which is divided into 4 levels of quality/aptitude/whatever
	#0-19 - Pathetic
	#20-39 - Feckless
	#40-59 - Inexperienced
	#60-79 - Capable
	#80+ - Accomplished

	add = {
		value = 0
		desc = SQUIRES_BASE_VALUE
	}

	#Increase based on how much glory the knight has gained
	if = {
		limit = {
			exists = var:lifetime_glory
		}
		#This will factor HUGELY in accolades balancing
		add = {
			value = var:lifetime_glory
			divide = 12
			desc = SQUIRES_GLORY_VALUE
		}
	}

	#Modified by owner's martial
	if = {
		limit = {
			exists = accolade_owner
		}
		add = {
			value = accolade_owner.martial
			subtract = 10
			multiply = 0.5
			max = 30
			min = 0
			desc = SQUIRES_OWNER_MARTIAL_VALUE
		}
	}
	#Modified by Knight's prowess
	#Provides up to 40
	if = {
		limit = {
			exists = var:old_knight
		}
		add = {
			value = var:old_knight.prowess
			subtract = 10
			multiply = 1
			max = 40
			min = 1
			desc = SQUIRES_PROWESS_VALUE
		}
	}
	else = {
		if = {
			limit = {
				exists = acclaimed_knight
			}
			add = {
				value = acclaimed_knight.prowess
				subtract = 10
				multiply = 1
				max = 40
				min = 1
				desc = SQUIRES_PROWESS_VALUE
			}
		}
	}
	#Modified by Knight's martial
	if = {
		limit = {
			exists = var:old_knight
		}
		add = {
			value = var:old_knight.martial
			subtract = 10
			multiply = 0.33
			max = 20
			min = 0
			desc = SQUIRES_MARTIAL_VALUE
		}
	}
	else = {
		if = {
			limit = {
				exists = acclaimed_knight
			}
			add = {
				value = acclaimed_knight.martial
				subtract = 10
				multiply = 0.33
				max = 20
				min = 0
				desc = SQUIRES_MARTIAL_VALUE
			}
		}
	}
	if = {
		limit = {
			trigger_if = {
				limit = {
					exists = var:old_knight
				}
				var:old_knight = {
					has_trait = lifestyle_blademaster
				}
			}
			trigger_else = {
				acclaimed_knight ?= {
					has_trait = lifestyle_blademaster
				}
			}
		}
		add = {
			value = 0
			desc = SQUIRES_BLADEMASTER_VALUE
			if = {
				limit = {
					has_variable = old_knight
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = lifestyle_blademaster
								value >= 50
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = lifestyle_blademaster
								value >= 100
							}
						}
					}
					add = 5
				}
			}
			else = {
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = lifestyle_blademaster
								value >= 50
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = lifestyle_blademaster
								value >= 100
							}
						}
					}
					add = 5
				}
			}
		}
	}
	#Modified by Knight's tourney participant XP
	#Can gain 25 from each track, 105 in total
	if = {
		limit = {
			trigger_if = {
				limit = {
					exists = var:old_knight
				}
				var:old_knight = {
					has_trait = tourney_participant
				}
			}
			trigger_else = {
				acclaimed_knight ?= {
					has_trait = tourney_participant
				}
			}
		}
		add = {
			value = 5
			desc = SQUIRES_HASTILUDES_VALUE_BASE
		}
		#Painstakingly add amounts for each competency level...
		if = {
			limit = {
				exists = var:old_knight
			}
			add = {
				#Foot
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_FOOT
			}
			#Horse
			add = {
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_HORSE
			}
			#Wit
			add = {
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_WIT
			}
			add = {
				#Bow
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						var:old_knight = {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_BOW
			}
		}
		else = {
			#Foot
			add = {
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 100
							}
						}
					}
					add = 15
				}
				desc = SQUIRES_HASTILUDES_VALUE_FOOT
			}
			#Horse
			add = {
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_HORSE
			}
			#Wit
			add = {
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_WIT
			}
			#Bow
			add = {
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 30
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 65
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						acclaimed_knight ?= {
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 100
							}
						}
					}
					add = 10
				}
				desc = SQUIRES_HASTILUDES_VALUE_BOW
			}
		}
	}
	#A little extra from having "squires"
	if = {
		limit = {
			trigger_if = {
				limit = {
					exists = var:old_knight
				}
				save_temporary_scope_as = accolade
				var:old_knight = {
					any_child = {
						age >= 8
						exists = scope:accolade.accolade_owner
						is_courtier_of = scope:accolade.accolade_owner
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:accolade.accolade_owner }
					}
				}
			}
			trigger_else = {
				save_temporary_scope_as = accolade
				acclaimed_knight ?= {
					any_child = {
						age >= 8
						is_courtier_of = scope:accolade.accolade_owner
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:accolade.accolade_owner }
					}
				}
			}
		}
		add = {
			value = 5
			desc = SQUIRES_OWN_CHILD
		}
	}
	if = {
		limit = {
			trigger_if = {
				limit = {
					exists = var:old_knight
				}
				var:old_knight = { age >= 50 }
			}
			trigger_else = {
				acclaimed_knight ?= {
					age >= 50
				}
			}
		}
		add = {
			value = 5
			desc = SQUIRES_RESPECTED_ELDER
		}
	}
}

#MUST only change these alongside ACCOLADE_SQUIRE_LEVELS in the 00_defines file
accolade_squires_feckless_minimum_value = 20
accolade_squires_inexperienced_minimum_value = 40
accolade_squires_capable_minimum_value = 60
accolade_squires_accomplished_minimum_value = 80

squires_bonus_martial = {
	value = 0

	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_feckless_minimum_value }
			#Don't ruin root's children or heir
			NOR = {
				is_primary_heir_of = root
				is_child_of = root
			}
		}
		add = -1
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_feckless_minimum_value }
		}
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_inexperienced_minimum_value }
		}
		add = 1
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_capable_minimum_value }
		}
		add = 3
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_accomplished_minimum_value }
		}
		add = 5
	}
}
squires_bonus_trait_xp = {
	value = 0

	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_feckless_minimum_value }
		}
		add = { 1 2 } 
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_inexperienced_minimum_value }
		}
		add = { 3 5 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_capable_minimum_value }
		}
		add = { 5 10 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_accomplished_minimum_value }
		}
		add = { 8 15 }
	}
}
squires_bonus_trait_xp_high = {
	value = 0

	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_feckless_minimum_value }
		}
		add = { 3 5 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_inexperienced_minimum_value }
		}
		add = { 5 10 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_capable_minimum_value }
		}
		add = { 10 20 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_accomplished_minimum_value }
		}
		add = { 15 30 }
	}
}
#Meant to fulfill type req
squires_bonus_trait_xp_very_high = {
	value = 10

	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_feckless_minimum_value }
		}
		add = { 3 5 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_inexperienced_minimum_value }
		}
		add = { 5 10 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_capable_minimum_value }
		}
		add = { 10 20 }
	}
	if = {
		limit = {
			#Squires value, which should be using old knight stats instead of current one's
			scope:succeeding_accolade = { accolade_squires_quality_value >= accolade_squires_accomplished_minimum_value }
		}
		add = { 20 35 }
	}
}

skill_accolade_qualifying_value = high_skill_rating
skill_accolade_acceptable_value = decent_skill_rating

squire_quality_good_traits = {
	value = 0
	if = {
		limit = {
			scope:succeeding_accolade ?= { accolade_squires_quality_value >= accolade_squires_accomplished_minimum_value }
		}
		add = { 0 2 }
	}
	else_if = {
		limit = {
			scope:succeeding_accolade ?= { accolade_squires_quality_value >= accolade_squires_capable_minimum_value }
		}
		add = { 0 1 }
	}
}
squire_quality_bad_traits = {
	value = 0
	if = {
		limit = {
			scope:succeeding_accolade ?= { accolade_squires_quality_value < accolade_squires_feckless_minimum_value }
		}
		add = { 0 2 }
	}
	else_if = {
		limit = {
			scope:succeeding_accolade ?= { accolade_squires_quality_value < accolade_squires_inexperienced_minimum_value }
		}
		add = { 0 1 }
	}
	else_if = {
		limit = {
			scope:succeeding_accolade ?= { accolade_squires_quality_value < accolade_squires_capable_minimum_value }
		}
		add = { 0 1 }
		#To make it more likely you get 0
		subtract = { 0 1 }
	}
	min = 0
}
accolade_succession_glory_loss = {
	#50 as of right now
	value = medium_glory_value

	#50% more loss per level
	multiply = {
		add = scope:succeeding_accolade.accolade_rank
		divide = 2
		add = 1
	}

	min = minor_glory_value

	#To make it glory loss
	multiply = -1
}
