##############
# LAW VALUES #
##############

# Scaling value used to calculate realm law cost changes.
subrealm_size_modifier = {
	every_sub_realm_county = {
		add = 10
	}
	max = 900
	
	if = {
		limit = {
			culture = { has_cultural_parameter = cheaper_to_change_laws }
		}
		multiply = 0.5
	}
}

# Learning: Base Law Cost Reduction
learning_law_cost_modifier = {
	value = 0
	subtract = learning
	add = 8
	divide = 50
	min = -0.5
}

#Faith: The modifier used to calculate the Legalism modifier if the character's faith has Legalism
legalism_law_cost_modifier = {
	value = 0
	add = num_sinful_traits
	subtract = num_virtuous_traits
	divide = 10
	min = -0.3
}

#Faith: Religious Law
religious_legal_pronouncements_modifier = -0.1

#Faith: Natural Primitivism
natural_primitivism_modifier = 1.5

#Crown Authority Change
increase_crown_authority_prestige_base = 100

increase_crown_authority_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = increase_crown_authority_prestige_base
		format = "BASE_VALUE_FORMAT"
	}

	# Realm Size Penalty: +10 Prestige cost per county controlled by you(r vassals)
	if = {
		limit = {
			NOT = {
				culture = { has_cultural_parameter = cheaper_to_change_laws }
			}
		}
		add = {
			desc = "realm_size"
			format = "BREAKDOWN_FORMAT_REALM_SIZE_PRESTIGE_COST"
			value = subrealm_size_modifier
		}
	}
	if = { #Reduced penalty from Tradition (for tooltip)
		limit = {
			culture = { has_cultural_parameter = cheaper_to_change_laws }
		}
		add = {
			desc = "realm_size"
			format = "TRADITION_BREAKDOWN_LAW_REALM_SIZE_COST"
			value = subrealm_size_modifier
		}
	}

	# Learning Modifier (2% more expensive for each skill point below 8 Learning)
	if = {
		limit = {
			learning < 8
		}
		add = {
			desc = "poor_learning_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = learning_law_cost_modifier
		}
	}
	else_if = { # (2% less expensive for each skill point below 8 Learning)
		limit = {
			learning > 8
		}
		add = {
			desc = "learning_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = learning_law_cost_modifier
		}
	}

	# Tenet Modifiers
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = legalism_law_cost_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		multiply = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			is_independent_ruler = no
			vassal_contract_has_flag = locked_to_partition
		}
		multiply = {
			desc = "succession_rights_forced_partition"
			value = 1.25 # succession_rights_contract_law_cost = 0.25
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}

	# Apply All-Things cooldown breaker multiplier.
	if = {
		limit = {
			has_variable = crown_authority_cooldown
			culture = { has_innovation = innovation_all_things }
		}
		# If the tally exists, multiply by that.
		if = {
			limit = { has_variable = authority_cooldown_break_tally }
			multiply = {
				desc = "breaking_authority_cooldown"
				value = var:authority_cooldown_break_tally
			}
		}
		# Otherwise, multiply by the stock tally base.
		else = {
			multiply = {
				desc = "breaking_authority_cooldown"
				value = authority_cooldown_breaker_value
			}
		}
	}

	# Character Modifier Bonuses
	if = {
		limit = { has_character_modifier = yearly_benevolent_forgiveness_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 0.9 # yearly_benevolent_forgiveness_modifier = -10%
		}
	}

	# Character Modifier Maluses
	if = {
		limit = { has_character_modifier = vassal_distrust_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 1.1 # vassal_distrust_modifier = +10%
		}
	}	
}

#Tribal Authority Change
increase_tribal_authority_prestige_base = 200

increase_tribal_authority_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = increase_tribal_authority_prestige_base
		format = "BASE_VALUE_FORMAT"
	}
	# +10 Prestige cost per county controlled by you(r vassals)
	add = {
		desc = "realm_size"
		format = "BREAKDOWN_FORMAT_REALM_SIZE_PRESTIGE_COST"
		value = subrealm_size_modifier
	}

	# Learning Modifier (2% more expensive for each skill point below 8 Learning)
	if = {
		limit = {
			learning < 8
		}
		add = {
			desc = "poor_learning_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = learning_law_cost_modifier
		}
	}
	else_if = { # (2% less expensive for each skill point below 8 Learning)
		limit = {
			learning > 8
		}
		add = {
			desc = "learning_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = learning_law_cost_modifier
		}
	}

	# Tenet Modifiers
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = legalism_law_cost_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		add = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}

	# Apply All-Things cooldown breaker multiplier.
	if = {
		limit = {
			has_variable = tribal_authority_cooldown
			culture = { has_innovation = innovation_all_things }
		 }
		# If the tally exists, multiply by that.
		if = {
			limit = { has_variable = authority_cooldown_break_tally }
			multiply = {
				desc = "breaking_authority_cooldown"
				value = var:authority_cooldown_break_tally
			}
		}
		# Otherwise, multiply by the stock tally base.
		else = {
			multiply = {
				desc = "breaking_authority_cooldown"
				value = authority_cooldown_breaker_value
			}
		}
	}

	# Character Modifier Bonuses
	if = {
		limit = { has_character_modifier = yearly_benevolent_forgiveness_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 0.9 # yearly_benevolent_forgiveness_modifier = -10%
		}
	}

	# Character Modifier Maluses
	if = {
		limit = { has_character_modifier = vassal_distrust_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 1.1 # vassal_distrust_modifier = +10%
		}
	}
}

#Succession Law Change
change_succession_law_prestige_base = 500
@title_succession_law_mult = 3 #How many times more expensive is it to add custom title succession than change your realm succession?

change_succession_law_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = change_succession_law_prestige_base
		format = "BASE_VALUE_FORMAT"
	}
	#Clans pay more
	if = {
		limit = {
			government_has_flag = government_is_clan
		}
		add = {
			desc = "clan_government_cost_tooltip"
			value = change_succession_law_prestige_base
			multiply = 4
		}
	}
	#Calculate the Legalism modifier if relevant
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = change_succession_law_prestige_base
			multiply = legalism_law_cost_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		add = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			is_independent_ruler = no
			vassal_contract_has_flag = locked_to_partition
		}
		multiply = {
			desc = "succession_rights_forced_partition"
			value = 1.25 # succession_rights_contract_law_cost = 0.25
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}
}

change_title_succession_law_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = change_succession_law_prestige_base
		multiply = @title_succession_law_mult
	}
	#Calculate the Legalism modifier if relevant
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = change_succession_law_prestige_base
			multiply = legalism_law_cost_modifier
			multiply = @title_succession_law_mult
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		add = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			is_independent_ruler = no
			vassal_contract_has_flag = locked_to_partition
		}
		multiply = {
			desc = "succession_rights_forced_partition"
			value = 1.25 # succession_rights_contract_law_cost = 0.25
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}
}

@hre_title_succession_law_mult = 20
change_hre_title_succession_law_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = change_succession_law_prestige_base
		multiply = @hre_title_succession_law_mult
	}
	#Calculate the Legalism modifier if relevant
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = change_succession_law_prestige_base
			multiply = legalism_law_cost_modifier
			multiply = @hre_title_succession_law_mult
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		add = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}
}

admin_law_prestige_base_cost = 200
admin_law_realm_size_cost = {
	value = realm_size
	max = admin_law_prestige_base_cost # Realm size can double the cost
	if = {
		limit = {
			culture = { has_cultural_parameter = cheaper_to_change_laws }
		}
		multiply = 0.5
	}
}
admin_law_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = admin_law_prestige_base_cost
		format = "BASE_VALUE_FORMAT"
	}

	# Realm Size Penalty: +10 Prestige cost per county controlled by you(r vassals)
	if = {
		limit = {
			NOT = {
				culture = { has_cultural_parameter = cheaper_to_change_laws }
			}
		}
		add = {
			desc = "realm_size"
			format = "BREAKDOWN_FORMAT_REALM_SIZE_PRESTIGE_COST"
			value = admin_law_realm_size_cost
		}
	}
	if = { #Reduced penalty from Tradition (for tooltip)
		limit = {
			culture = { has_cultural_parameter = cheaper_to_change_laws }
		}
		add = {
			desc = "realm_size"
			format = "TRADITION_BREAKDOWN_LAW_REALM_SIZE_COST"
			value = admin_law_realm_size_cost
		}
	}

	# Learning Modifier (2% more expensive for each skill point below 8 Learning)
	if = {
		limit = {
			learning < 8
		}
		add = {
			desc = "poor_learning_law_cost_tooltip"
			value = {
				add = admin_law_prestige_base_cost
				add = admin_law_realm_size_cost
			}
			multiply = learning_law_cost_modifier
		}
	}
	else_if = { # (2% less expensive for each skill point below 8 Learning)
		limit = {
			learning > 8
		}
		add = {
			desc = "learning_law_cost_tooltip"
			value = {
				add = admin_law_prestige_base_cost
				add = admin_law_realm_size_cost
			}
			multiply = learning_law_cost_modifier
		}
	}

	# Tenet Modifiers
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = legalism_modified_law_costs
			}
		}
		add = {
			desc = "rite_legalism_law_cost_tooltip"
			value = {
				add = admin_law_prestige_base_cost
				add = admin_law_realm_size_cost
			}
			multiply = legalism_law_cost_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = natural_primitivism_law_cost_increase
			}
		}
		multiply = {
			desc = "rite_primitivism_law_cost_tooltip"
			value = natural_primitivism_modifier
		}
	}
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = religious_legal_pronouncements_law_cost_reduction
			}
		}
		multiply = {
			desc = "rite_pronouncements_law_cost_tooltip"
			value = 0.9 # religious_legal_pronouncements_modifier = -0.1
		}
	}

	# Character Modifier Bonuses
	if = {
		limit = { has_character_modifier = yearly_benevolent_forgiveness_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 0.9 # yearly_benevolent_forgiveness_modifier = -10%
		}
	}

	# Character Modifier Maluses
	if = {
		limit = { has_character_modifier = vassal_distrust_modifier }
		multiply = {
			desc = "character_modifiers_law_cost_tooltip"
			value = 1.1 # vassal_distrust_modifier = +10%
		}
	}
}
