﻿### Configuration parameters

authority_gain_per_prestige 							= 0.05
authority_gain_per_dread 								= 0.05

# Vassal parameters
authority_gain_per_vassal_multiplier 					= 0.1
authority_gain_per_vassal_duchy_bonus   				= 0.5
authority_gain_per_vassal_kingdom_bonus 				= 1

authority_loss_per_waged_vassal_war_multiplier			= -0.2
authority_loss_per_waged_vassal_war						= 0.4

authority_loss_infidel_multiplier						= 0.5
#authority_loss_per_infidel								= -0.5

# Territory parameters
authority_gain_per_territory_multiplier					= 0.002
authority_loss_per_unheld_heartlands_multiplier			= -0.2
authority_loss_per_unheld_heartlands					= -0.07

HRT_authority_change_value = {
	value = 0
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				is_alive = yes
			}
		}
		# Total Gain
		add = {
			value = HRT_authority_total_gain_value
			# 3.1 centralization
			multiply = HRT_authority_centralization_modifier
		}
		# Total Loss
		add = HRT_authority_total_loss_value

		min = HRT_authority_min
		max = HRT_authority_max
	}
}

HRT_authority_total_gain_value = {
	value = 0
	add = HRT_authority_prestige_bonus
	add = HRT_authority_dread_bonus
	add = HRT_authority_gain_years_reigned_bonus
	add = HRT_authority_vassal_bonus
	#add = HRT_authority_held_castle_bonus
	add = HRT_authority_territory_bonus
	add = HRT_authority_ally_bonus
	add = HRT_authority_artifact_bonus
	add = HRT_authority_grand_tour_bonus
	add = HRT_authority_cardinals_bonus
	# 2.5 Reichsstadt
	add = HRT_authority_reichsstadt_bonus
	#TCT Compat
	multiply = HRT_authority_free_investiture_bonus
	multiply = HRT_authority_papal_investiture_malus
	#/TCT Compat
	multiply = HRT_authority_constrained_reach
	multiply = HRT_authority_uncrowned_malus
	multiply = HRT_authority_imprisoned_malus
	multiply = HRT_authority_child_malus
	# Multiplicators
	#Legitimacy
	multiply = HRT_authority_legitimacy_modifier
	# 2.2 Unity
	if = { limit = { exists = title:c_aachen.var:HRT_emperor.var:HRT_authority_unity } multiply = HRT_authority_unity_bonus }
	#Edicts
	multiply = HRT_authority_edict_modifier
	#Game Rule
	multiply = HRT_authority_game_rule_bonus_one_and_a_half
	multiply = HRT_authority_game_rule_bonus_twice
}

HRT_authority_total_gain_value_gui = {
	value = HRT_authority_total_gain_value
	multiply = HRT_authority_centralization_modifier
}

HRT_authority_total_loss_value = {
	value = 0
	add = HRT_authority_absent_sovereign_malus
	add = HRT_authority_loss_waged_vassal_wars_malus
	add = HRT_authority_infidel_malus
	#add = HRT_authority_unheld_heartlands_malus
	add = HRT_authority_excommunicated_malus
	add = HRT_authority_criminal_malus
	add = HRT_authority_serious_disease_malus
}

HRT_authority_constrained_reach = {
	value = 1
	if = {
		limit = {
			NOT = { exists = title:e_hre.holder }
		}
		subtract = 0.3
	}
}

HRT_authority_prestige_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_prestige
		divide = 10000
		max = 2
		#if =		{ limit = { prestige_level >= 5 } add = 2 }
		#else_if =	{ limit = { prestige_level >= 3 } add = 1 }
	}
}
HRT_authority_dread_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_dread
		divide = 100
		if =		{ limit = { var:HRT_authority_dread >= 70 } add = 1 }
		else_if =	{ limit = { var:HRT_authority_dread >= 40 } add = 0.5 }
		max = 2
	}
}
HRT_authority_gain_years_reigned_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_years_reigned
		divide = 100
		#if =		{ limit = { var:HRT_authority_years_reigned >= 40 } add = 1 }
		#else_if =	{ limit = { var:HRT_authority_years_reigned >= 20 } add = 0.5 }
	}
}

HRT_authority_vassal_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_vassals_bonus_var
		multiply = authority_gain_per_vassal_multiplier
		if = {
			limit = { has_title = title:e_hre }
			multiply = 0.3
		}
	}
}
HRT_authority_loss_waged_vassal_wars_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_vassals_war_var
		multiply = authority_loss_per_waged_vassal_war_multiplier
		min = -3
	}
}
HRT_authority_infidel_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = HRT_authority_infidels_share
		divide = 10
		multiply = -0.5
		min = -3
	}
}
HRT_authority_infidels_share = {
	title:c_aachen.var:HRT_emperor ?= {
		value = var:HRT_authority_infidels_var
		divide = {
			value = var:HRT_authority_vassals_var
			min = 1
		}
		multiply = 100
	}
}

HRT_authority_territory_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		value = var:HRT_authority_territory
		multiply = authority_gain_per_territory_multiplier
		max = 3
	}
}

HRT_authority_unheld_heartlands_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = HRT_authority_unheld_heartlands_share
		divide = 20
		multiply = authority_loss_per_unheld_heartlands_multiplier
		if = {
			limit = { NOT = { has_title = title:e_hre } }
			multiply = 0
		}
	}
}
HRT_authority_unheld_heartlands_share = {
	title:c_aachen.var:HRT_emperor ?= {
		value = var:HRT_authority_unheld_heartlands
		divide = {
			value = title:c_aachen.var:HRT_core_territory
			min = 1
		}
		multiply = 100
	}
}

#HRT_authority_held_castle_bonus = {
#	value = -2
#	every_directly_owned_province = {
#		limit = { has_holding_type = castle_holding }
#		add = 0.5
#	}
#	max = 1
#}

HRT_authority_ally_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_ally_military_strength
		divide = {
			value = var:HRT_authority_military_strength
			min = 1
		}
		max = 2
	}
}

HRT_authority_artifact_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		add = var:HRT_authority_artifacts
		max = 1.5
	}
}
HRT_authority_missing_reichskrone_malus = {
	value = 1
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				AND = {
					exists = title:e_hre.holder
					NOT = {
						any_character_artifact = {
							has_variable = reichskrone
						}
					}
				}
			}
			subtract = 0.2
		}
	}
}

##TCT##
#Majority of cardinals in college
HRT_authority_cardinals_bonus = {
	value = 0
	if = {
		limit = {
			exists = global_var:Trinity_is_loaded
			title:c_aachen.var:HRT_emperor ?= { faith = faith:catholic }
		}
		title:c_aachen.var:HRT_emperor ?= {
			add = var:HRT_authority_cardinals
			divide = 21
		}
	}
	max = 0.5
}
HRT_authority_papal_investiture_malus = {
	value = 1
	if = {
		limit = {
			exists = global_var:Trinity_is_loaded
			title:c_aachen.var:HRT_emperor ?= {
				faith = faith:catholic
				has_realm_law_flag = papal_enacted
			}
		}
		subtract = 0.1
	}
}
HRT_authority_free_investiture_bonus = {
	value = 1
	if = {
		limit = {
			exists = global_var:Trinity_is_loaded
			title:c_aachen.var:HRT_emperor ?= {
				faith = faith:catholic
				has_realm_law_flag = free_enacted
			}
		}
		add = 0.05
	}
}
HRT_authority_excommunicated_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				faith = faith:catholic
				has_trait = excommunicated
			}
			add = -2
			if = {
				limit = {
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = free_enacted
				}
				add = 1
			}
		}
	}
}
#2.5 Reichsstadt
HRT_authority_reichsstadt_bonus = {
	value = 0
	title:c_aachen = {
		if = {
			limit = { has_variable_list = HRT_reichsstaedte }
			every_in_list = {
				variable = HRT_reichsstaedte
				limit = { has_variable = HRT_reichsstadt_development }
				add = var:HRT_reichsstadt_development
			}
			divide = 200
		}
	}
}
#2.2 Unity
HRT_authority_unity_bonus = {
	value = 0
	if = {
		limit = {
			title:e_hre.holder ?= { has_variable = HRT_authority_unity }
		}
		add = title:e_hre.holder.var:HRT_authority_unity
		divide = 50
	}
}
HRT_authority_criminal_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				faith = faith:catholic
				OR = {
					has_trait = murderer
					has_trait = incestuous
					has_trait = sodomite
					has_trait = cannibal
					has_trait = kinslayer
				}
			}
			add = -1
		}
	}
}
HRT_authority_serious_disease_malus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				OR = {
					has_serious_disease_trigger = yes
					has_contagious_deadly_disease_trigger = yes
					has_epidemic_disease_trigger = yes
					has_trait = infirm
					has_trait = incapable
				}
			}
			add = -1
		}
	}
}

HRT_authority_grand_tour_bonus = {
	value = 0
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				involved_activity ?= {
					has_activity_type = activity_tour
				}
			}
			add = 2
		}
		else_if = {
			limit = {
				OR = {
					has_character_modifier = mega_itinerant_liege_modifier
					has_character_modifier = itinerant_liege_modifier
				}
			}
			add = 1
		}
	}
}

HRT_authority_absent_sovereign_malus = {
	value = 0
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				is_ai = no
				has_variable = HRT_authority_years_without_tour
			}
		}
		if = {
			limit = { title:c_aachen.var:HRT_emperor.var:HRT_authority_years_without_tour > 5 }
			add = title:c_aachen.var:HRT_emperor.var:HRT_authority_years_without_tour
			subtract = 5
			multiply = -0.1
			if =		{ limit = { HRT_has_centralization_1_trigger = yes } multiply = 0.8 }
			else_if =	{ limit = { HRT_has_centralization_2_trigger = yes } multiply = 0.6 }
			else_if =	{ limit = { HRT_has_centralization_3_trigger = yes } multiply = 0.4 }
			else_if =	{ limit = { HRT_has_centralization_4_trigger = yes } multiply = 0.2 }
		}
	}
	min = -3
}

HRT_authority_uncrowned_malus = {
	value = 1
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				OR = {
					is_ai = yes
					AND = {
						has_dlc_feature = tours_and_tournaments
						has_dlc_feature = advanced_activities
					}
				}
				faith = faith:catholic
				NOR = {
					has_trait = HRT_emperor
					has_trait = COR_crowned_by_myself
				}
			}
			subtract = 0.5
		}
	}
}

HRT_authority_imprisoned_malus = {
	value = 1
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				is_imprisoned = yes
			}
			subtract = 1
		}
	}
}
HRT_authority_child_malus = {
	value = 1
	title:c_aachen.var:HRT_emperor ?= {
		if = {
			limit = {
				is_adult = no
			}
			subtract = 1
		}
	}
}

HRT_authority_legitimacy_modifier = {
	value = 1
	if = { limit = { title:c_aachen.var:HRT_emperor ?= { highest_held_title_tier = tier_empire } }
		if =		{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 0 } }		multiply = 0.1 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 1 } }		multiply = 0.2 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 2 } }		multiply = 0.4 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 3 } }		multiply = 0.8 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 4 } }		multiply = 1 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 5 } }		multiply = 1.2 }
	}
	else = {
		if =		{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 0 } }		multiply = 0.2 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 1 } }		multiply = 0.4 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 2 } }		multiply = 0.8 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 3 } }		multiply = 1 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 4 } }		multiply = 1.2 }
		else_if =	{ limit = { title:c_aachen.var:HRT_emperor ?= { legitimacy_level ?= 5 } }		multiply = 1.6 }
	}
}

HRT_authority_edict_modifier = {
	value = 1
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_legal_unification_var } }			multiply = 1.2 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_consular_taxation_var } }			multiply = 0.5 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_urban_rights_var } } 				multiply = 0.5 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_scholastic_advancement_var } }		multiply = 0.5 }
}

# 3.1 centralization
HRT_authority_centralization_modifier = {
	value = 1
	if = {
		limit = { HRT_is_centralizing_trigger = yes }
	if = 		{ limit = {title:c_aachen.var:HRT_emperor.var:HRT_centralization_effort_value ?= 0}	multiply = 0.75	}
	else_if =	{ limit = {title:c_aachen.var:HRT_emperor.var:HRT_centralization_effort_value ?= 1}	multiply = 0.5 	}
	else_if = 	{ limit = {title:c_aachen.var:HRT_emperor.var:HRT_centralization_effort_value ?= 2}	multiply = 0.25	}
	}
}

HRT_authority_min = {
	value = -5
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_consular_taxation_var } }			add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_urban_rights_var } } 				add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_scholastic_advancement_var } }		add = -1 }
}
HRT_authority_max = {
	value = 5
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_legal_unification_var } }			add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_chivalric_excellence_var } }		add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_diplomatic_corps_var } }			add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_consular_taxation_var } }			add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_levy_conscription_var } }			add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_urban_rights_var } }				add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_border_defense_var } }				add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_scholastic_advancement_var } }		add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_imperial_works_var } }				add = -1 }
	if = { limit = { title:c_aachen = { has_variable = HRT_edict_ecclesiastical_patronage_var } }	add = -1 }
	min = 0
}

#War Values
HRT_authority_on_war_won_attacker_value = {
	value = 0
	add = scope:defender.max_military_strength
	divide = {
		value = max_military_strength
		min = 1
	}
	multiply = 10
	max = 10
}
HRT_authority_on_war_won_defender_value = {
	value = 0
	add = scope:attacker.max_military_strength
	divide = {
		value = max_military_strength
		min = 1
	}
	multiply = 20
	max = 20
}

#Game Rules
HRT_authority_game_rule_bonus_one_and_a_half = {
	value = 1
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				is_ai = no
			}
			has_game_rule = HRT_authority_one_and_a_half
		}
		multiply = 1.5
	}
}
HRT_authority_game_rule_bonus_twice = {
	value = 1
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				is_ai = no
			}
			has_game_rule = HRT_authority_twice
		}
		multiply = 2
	}
}

#Limiter
HRT_authority_limiter_value = {
	value = var:HRT_authority
	add = HRT_authority_change_value
}

#GUI
HRT_authority_progressbar_value = {
	value = 0
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				exists = this
				is_alive = yes
				has_variable = HRT_authority
			}
		}
		add = title:c_aachen.var:HRT_emperor.var:HRT_authority
	}
}
HRT_authority_change_value_gui = {
	value = 0
	if = {
		limit = {
			title:c_aachen.var:HRT_emperor ?= {
				exists = this
				is_alive = yes
			}
		}
		title:c_aachen.var:HRT_emperor ?= {
			add = HRT_authority_change_value
		}
	}
}