﻿### EK EDIT: Removed references to unused Innovations
### EK TODO: Implement our custom tenets in increase_crown_authority_prestige_cost

##############
# 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
}

# Prowess: Base Dominance Cost Reduction
prowess_law_cost_modifier = {
	value = 0
	subtract = prowess
	add = 8
	divide = 75
	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: The modifier used to calculate the Warmonger modifier if the character's faith has Warmonger
warmonger_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

### EK TODO: Implement the effects of our custom tenets
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
		}
	}

	###EK DISABLED: All-Things is not in the mod
	# Apply All-Things cooldown breaker multiplier.
	# if = {
		# limit = {
			#OR = {
			#	has_variable = crown_authority_cooldown
			#	has_variable = imperial_bureaucracy_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
		}
	}
	
	###EK DISABLED: All-Things isn't in the mod
	# 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%
		}
	}
}

#Dominance / Nomadic Authority Change
increase_nomadic_authority_herd_cost_base = 500

increase_nomadic_authority_herd_cost = {
	add = {
		desc = "BASE_VALUE"
		value = increase_nomadic_authority_herd_cost_base
		format = "BASE_VALUE_FORMAT"
	}
	multiply = {
		desc = "era_law_cost_scale"
		value = domicile.herd_value_scale_by_era
	}
	multiply = {
		desc = "dominance_law_cost_scale"
		value = dominance_value
	}
}

increase_nomadic_authority_prestige_base = 300

increase_nomadic_authority_prestige_cost = {
	add = {
		desc = "BASE_VALUE"
		value = increase_nomadic_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
	}

	# Prowess Modifier (2% more expensive for each skill point below 8 Prowess)
	if = {
		limit = {
			prowess < 8
		}
		add = {
			desc = "poor_prowess_law_cost_tooltip"
			value = {
				add = increase_nomadic_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = prowess_law_cost_modifier
		}
	}
	else_if = { # (2% less expensive for each skill point above 8 Prowess)
		limit = {
			prowess > 8
		}
		add = {
			desc = "prowess_law_cost_tooltip"
			value = {
				add = increase_nomadic_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = prowess_law_cost_modifier
		}
	}

	# Tenet Modifiers
	if = {
		limit = {
			faith = {
				has_doctrine_parameter = warmonger
			}
		}
		add = {
			desc = "tenet_warmonger_law_cost_tooltip"
			value = {
				add = increase_crown_authority_prestige_base
				add = subrealm_size_modifier
			}
			multiply = warmonger_law_cost_modifier
		}
	}

	# Apply All-Things cooldown breaker multiplier.
	# if = {
	# 	limit = {
	# 		has_variable = nomadic_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
	# 		}
	# 	}
	# }
}

#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
		}
	}
}

### EK NOTE: The HRE doesn't exist, but we still use this value
@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%
		}
	}
}
