﻿tier_unlanded = 0
tier_barony = 1
tier_county = 2
tier_duchy = 3
tier_kingdom = 4
tier_empire = 5

highest_held_title_tier_plus_one = {
	value = highest_held_title_tier
	add = 1
	max = tier_empire
}

highest_held_title_tier_minus_one = {
	value = highest_held_title_tier
	subtract = 1
	min = tier_unlanded
}

# Referenced in code, what % of a title's counties you need to own to create it
# Note: First item with 'desc' is considered the base and will be shown as 'neutral'
# root = creating character
# scope:title = the title
create_title_counties_percentage = {
	scope:title = {
		if = {
			limit = {
				OR = {
					tier = tier_duchy
					tier = tier_kingdom
				}
			}
			add = {
				value = 0.5
				desc = CREATE_TITLE_PERCENTAGE_BASE_DUCHY_KINGDOM
			}
			if = {
				limit = { # Do you have Legitimacy?
					root ?= {
						has_legitimacy = yes
					}
				}
				if = {
					limit = {
						root = {
							has_legitimacy_flag = extra_reduced_title_creation_cost
						}
					}
					add = {
						value = -0.25 #25%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_EXTRA_REDUCED
					}
				}
				else_if = {
					limit = {
						root = { has_legitimacy_flag = very_reduced_title_creation_cost }
					}
					add = {
						value = -0.20 #30%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_VERY_REDUCED
					}
				}
				else_if = {
					limit = {
						root = { has_legitimacy_flag = reduced_title_creation_cost }
					}
					add = {
						value = -0.15 #35%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_REDUCED
					}
				}
				else = {
					#If you're level 2/1/0 or don't have Legitimacy you get no discounts
					add = {
						value = 0.0
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_NONE
					}
				}
			}
			else = {
				#If you're level 2/1/0 or don't have Legitimacy you get no discounts
				add = {
					# We add 0 with a 'desc', so we show up in the GUI and people understand legitimacy is a way to improve this
					value = 0.0
					desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_NONE
				}
			}
		}
		else_if = { #Smaller discounts for Empires
			limit = {
				tier = tier_empire
			}
			add = {
				value = 0.8
				desc = CREATE_TITLE_PERCENTAGE_BASE_EMPIRE
			}
			if = {
				limit = { # Do you have Legitimacy?
					root = {
						has_legitimacy = yes
					}
				}
				if = {
					limit = {
						root = {
							has_legitimacy_flag = extra_reduced_title_creation_cost
						}
					}
					add = {
						value = -0.15 #65%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_EXTRA_REDUCED
					}
				}
				else_if = {
					limit = {
						root = { has_legitimacy_flag = very_reduced_title_creation_cost }
					}
					add = {
						value = -0.10 #70%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_VERY_REDUCED
					}
				}
				else_if = {
					limit = {
						root = { has_legitimacy_flag = reduced_title_creation_cost }
					}
					add = {
						value = -0.05 #75%
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_REDUCED
					}
				}
				else = {
					#If you're level 1/0 or don't have Legitimacy you get no discounts
					add = {
						value = 0.0
						desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_NONE
					}
				}
			}
			else = {
				#If you're level 1/0 or don't have Legitimacy you get no discounts
				add = {
					# We add 0 with a 'desc', so we show up in the GUI and people understand legitimacy is a way to improve this
					value = 0.0
					desc = CREATE_TITLE_PERCENTAGE_LEGITIMACY_DISCOUNT_NONE
				}
			}
		}
	}
}

# Referenced in code, what % of a title's counties you need to own to usurp it
# root = creating character
# scope:title = the title
usurp_title_counties_percentage = {
	scope:title = {
		if = {
			limit = {
				OR = {
					tier = tier_duchy
					tier = tier_kingdom
				}
			}
			add = 0.5
		}
		else_if = {
			limit = {
				tier = tier_empire
			}
			add = 0.8
		}
	}
}
