﻿### Caliphal Authority
cal_authority_target = {
	value = 10

	every_realm_province = {
		limit = {
			barony = { is_holy_site_of = faith }
		}
		add = 2
	}

	if = {
		limit = {
			NOT = { any_realm_province = { barony = { is_holy_site_of = faith } } } 
		}
		subtract = 2
	}

	if = {
		limit = {
			piety_level = max_piety_level
		}
		add = 10
	}
	if = {
		limit = {
			piety_level = very_high_piety_level
		}
		add = 5
	}
	if = {
		limit = {
			piety_level = high_piety_level
		}
		add = 3
	}
	if = {
		limit = {
			piety_level = low_piety_level
		}
		subtract = 2
	}

	if = {
		limit = {
			has_character_flag = islam_prophet
			
		}
		add = 200
	}

	if = {
		limit = {
			has_title = title:e_rashidun
			
		}
		add = 100
	}

	max = 100
	min = 0
}

### Trade
trade_node_strength = {
	value = 1

	kingdom = {
		every_in_de_jure_hierarchy = {
			limit = {
				tier = tier_county
			}
			every_county_province = {
				if = {
					limit = {
						OR = {
							has_building_or_higher = resources_market_01
							has_building_or_higher = resources_market_03
							has_building_or_higher = resources_market_04
							has_building_or_higher = resources_market_05
							has_building_or_higher = resources_market_14
						}
					}
					if = {
						limit = {
							OR = {
								has_building = resources_market_01
								has_building = resources_market_03
								has_building = resources_market_04
								has_building = resources_market_05
								has_building = resources_market_14
							}
						}
						add = 2
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus_01
								has_building = resources_market_plus_03
								has_building = resources_market_plus_04
								has_building = resources_market_plus_05
								has_building = resources_market_plus_14
							}
						}
						add = 4
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus2_01
								has_building = resources_market_plus2_03
								has_building = resources_market_plus2_04
								has_building = resources_market_plus2_05
								has_building = resources_market_plus2_14
							}
						}
						add = 6
					}
				}
				if = {
					limit = {
						OR = {
							has_building_or_higher = resources_market_02
							has_building_or_higher = resources_market_10
							has_building_or_higher = resources_market_11
							has_building_or_higher = resources_market_12
							has_building_or_higher = resources_market_13
							has_building_or_higher = resources_market_15
							has_building_or_higher = resources_market_16
						}
					}
					if = {
						limit = {
							OR = {
								has_building = resources_market_02
								has_building = resources_market_10
								has_building = resources_market_11
								has_building = resources_market_12
								has_building = resources_market_13
								has_building = resources_market_15
								has_building = resources_market_16
							}
						}
						add = 3
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus_02
								has_building = resources_market_plus_10
								has_building = resources_market_plus_11
								has_building = resources_market_plus_12
								has_building = resources_market_plus_13
								has_building = resources_market_plus_15
								has_building = resources_market_plus_16
							}
						}
						add = 5
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus2_02
								has_building = resources_market_plus2_10
								has_building = resources_market_plus2_11
								has_building = resources_market_plus2_12
								has_building = resources_market_plus2_13
								has_building = resources_market_plus2_15
								has_building = resources_market_plus2_16
							}
						}
						add = 7
					}
				}
				if = {
					limit = {
						OR = {
							has_building_or_higher = resources_market_06
							has_building_or_higher = resources_market_07
							has_building_or_higher = resources_market_08
							has_building_or_higher = resources_market_09
						}
					}
					if = {
						limit = {
							OR = {
								has_building = resources_market_06
								has_building = resources_market_07
								has_building = resources_market_08
								has_building = resources_market_09
							}
						}
						add = 1
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus_06
								has_building = resources_market_plus_07
								has_building = resources_market_plus_08
								has_building = resources_market_plus_09
							}
						}
						add = 2
					}
					else_if = {
						limit = {
							OR = {
								has_building = resources_market_plus2_06
								has_building = resources_market_plus2_07
								has_building = resources_market_plus2_08
								has_building = resources_market_plus2_09
							}
						}
						add = 4
					}
				}
				
			}
		}
	}
	if = {
		limit = {
			has_building = trade_center_01
		}
		multiply = 1.1
	}
	else_if = {
		limit = {
			has_building = trade_center_02
		}
		multiply = 1.2
	}
	else_if = {
		limit = {
			has_building = trade_center_03
		}
		multiply = 1.3
	}
	else_if = {
		limit = {
			has_building = trade_center_04
		}
		multiply = 1.4
	}

	max = var:trade_node_cap
	min = 0
}

### Imperial Competence
imp_policy_1_requirement = 2000
imp_policy_2_requirement = 3000
imp_policy_3_requirement = 4000
## Military Competence
mil_competence_net = {
	value = 0

	### General, shared in some forms by all competences
	add = {
		value = mil_competence_martial
		desc = "MIL_COMP_MARTIAL"
	}
	add = {
		value = mil_competence_martial_marshal
		desc = "MIL_COMP_MARTIAL_MARSHAL"
	}
	add = {
		value = mil_competence_martial_court
		desc = "MIL_COMP_MARTIAL_COURT"
	}
	
	### More specific
	add = {
		value = mil_competence_empire_size
		desc = "MIL_COMP_EMPIRE_SIZE"
	}
	add = {
		value = mil_competence_unprotected_borders
		desc = "MIL_COMP_UNPROTECTED_BORDERS"
	}
	add = {
		value = mil_competence_allies
		desc = "MIL_COMP_ALLIES"
	}
	add = {
		value = mil_competence_empire
		desc = "MIL_COMP_EMPIRE"
	}
	add = {
		value = mil_competence_legions
		desc = "MIL_COMP_LEGIONS"
	}
	add = {
		value = mil_competence_army_size
		desc = "MIL_COMP_ARMY_SIZE"
	}
	add = {
		value = mil_competence_knights_prowess
		desc = "MIL_COMP_KNIGHTS_PROWESS"
	}
	add = {
		value = mil_competence_maa_regiments
		desc = "MIL_COMP_MAA_REGIMENTS"
	}
	# add = {
		# value = mil_competence_sub_value_3
		# desc = "MIL_COMP_ARMYQUALITY"
	# }
	if = {
		limit = {
			AND = {
				is_ai = yes
				has_title = title:e_roman_empire
				current_date <= 400.1.1
			}
		}
		multiply = 0.9 #slow down competence
	}
}
mil_competence_total = {
	value = 0

	add = {
		value = mil_competence_net
		desc = "MIL_COMP_TOTAL"
	}
}

# An Emperor with a high martial is GOOD
mil_competence_martial = {
	add = martial
}

# A Marshal with a high martial is GOOD
mil_competence_martial_marshal = {
	value = 0
	
	every_martial_councillor = {
		add = martial
	}
}

# A Martial court is GOOD
mil_competence_martial_court_grandeur_bonus = 10
mil_competence_martial_court = {
	value = 0
	
	if = {
		limit = {
			has_royal_court = yes
			has_court_type = court_warlike
		}
		add = court_grandeur_current_level
		multiply = mil_competence_martial_court_grandeur_bonus
	}
}

# A large empire is BAD (well, harder to defend)
mil_competence_empire_size_penalty = 0.5
mil_competence_empire_size = {
	value = 0
	
	subtract = {
		value = {
			every_realm_county = {
				add = mil_competence_empire_size_penalty
			}
		}
	}
}

# Every county whose neighbour is potentially hostile to you is dangerous
mil_competence_unprotected_borders_penalty = -5
mil_competence_unprotected_borders = {
	value = 0
	
	# Every county bordering a realm will penalize you, unless the border is secure enough (fort level >= 5)
	every_realm_county = {
		limit = {
			holder.top_liege = { save_temporary_scope_as = emperor }
			any_neighboring_county = {
				holder.top_liege = {
					save_temporary_scope_as = current_ruler
					
					NOR = {
						this = scope:emperor # Can't be you, obviously
						is_allied_to = scope:emperor # Allies will probably make your border secure
						has_truce = scope:emperor # They won't attack you through a truce
						AND = {
							exists = var:my_suzerain
							var:my_suzerain = scope:emperor
							var:my_suzerain = {
								OR = {
									is_target_in_variable_list = { name = non_permanent_tributaries target = prev }  #tributaries are gud
									is_target_in_variable_list = { name = permanent_tributaries target = prev }
								}
							}
						}
						
						AND = {
							trigger_if = { # If they can raid, defeat their armies
								limit = { can_raid_trigger = yes }
								has_raid_immunity_against = scope:emperor
							}
							trigger_else = { always = yes }
							
							# If you have a strong hook, they can't DoW you
							scope:emperor = { has_strong_hook = scope:current_ruler }
						}
					}
				}
			}
		}
		add = {
			value = mil_competence_unprotected_borders_penalty
			add = total_county_fort_level
			max = 0
		}
	}
}

# Having allies is GOOD
mil_competence_allies_ratio = 500
mil_competence_allies = {
	value = 0
	
	every_ally = {
		limit = { NOT = { top_liege = prev } }
		add = max_military_strength

		divide = mil_competence_allies_ratio
	}
}

# Having lots of soldiers is GOOD
mil_competence_army_size_ratio = 100
mil_competence_army_size = {
	value = 0
	add = max_military_strength
	divide = mil_competence_army_size_ratio
}

# Having next to no soldiers is BAD

mil_competence_empire_sub_value = {
	value = max_military_strength
	if = {
		limit = {
			has_variable_list = legion_counties
		}
		every_in_list = {
			variable = legion_counties
			add = 1000
		}
	}
	
}
mil_competence_empire = {
	value = 0
	if = {
		limit = {
			OR = {
				has_title = title:e_byzantium
				has_title = title:e_western_roman_empire
				has_title = title:e_roman_empire
			}
			AND = {
				mil_competence_empire_sub_value < 3000
				NOT = {
					mil_competence_empire_sub_value = 0 #pdx pls fix your engine
				}
			}
			NOT = {
				has_realm_law = mil_law_2_2
			}
			NOT = {
				OR = {
					AND = {
						has_title = title:e_western_roman_empire
						exists = global_var:wre_partial_collapsed
					}
					AND = {
						has_title = title:e_byzantium
						exists = global_var:ere_partial_collapsed
					}
				}
			}
		}
		add = mil_competence_empire_sub_value
		subtract = 3000

		multiply = 50
	}
}

# Having legions is GOOD
mil_competence_legion = 15
mil_competence_prae_guard = 15 # Added to mil_competence_legion
mil_competence_legions = {
	value = 0
	if = {
		limit = {
			has_variable_list = legion_counties
		}
		every_in_list = {
			variable = legion_counties
			add = mil_competence_legion
			if = {
				limit = { has_variable = prae_guard }
				add = mil_competence_prae_guard
			}
		}
	}
}

# Having good knights is GOOD
mil_competence_knights_prowess_min = 8
mil_competence_knights_prowess_point = 2
mil_competence_knights_prowess = {
	value = 0
	every_knight = {
		add = {
			value = prowess
			subtract = mil_competence_knights_prowess_min
		
			multiply = mil_competence_knights_prowess_point
		}
	}
}

# Having lots of MaA regiments is GOOD
mil_competence_maa_regiments_skirmishers_points = 5
mil_competence_maa_regiments_archers_points = 10
mil_competence_maa_regiments_pikemen_points = 10
mil_competence_maa_regiments_light_cavalry_points = 15
mil_competence_maa_regiments_heavy_infantry_points = 20
mil_competence_maa_regiments_heavy_cavalry_points = 25
# Special
mil_competence_maa_regiments_archer_cavalry_points = 20
mil_competence_maa_regiments_camel_cavalry_points = 20
mil_competence_maa_regiments_elephant_cavalry_points = 25

mil_competence_maa_regiments = {
	value = 0
	
	# # Skirmishers (light infantry)
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 1 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 2 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 3 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 4 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 5 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 6 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 7 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 8 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value = 9 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = skirmishers value >= 10 } }
		# add = { value = mil_competence_maa_regiments_skirmishers_points multiply = 10 }
	# }
	
	# # Archers
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 1 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 2 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 3 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 4 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 5 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 6 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 7 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 8 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value = 9 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archers value >= 10 } }
		# add = { value = mil_competence_maa_regiments_archers_points multiply = 10 }
	# }
	
	# # Pikemen
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 1 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 2 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 3 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 4 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 5 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 6 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 7 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 8 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value = 9 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = pikemen value >= 10 } }
		# add = { value = mil_competence_maa_regiments_pikemen_points multiply = 10 }
	# }
	
	# # Light Cavalry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 1 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 2 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 3 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 4 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 5 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 6 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 7 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 8 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value = 9 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = light_cavalry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_light_cavalry_points multiply = 10 }
	# }
	
	# # Heavy Infantry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 1 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 2 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 3 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 4 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 5 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 6 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 7 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 8 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value = 9 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_infantry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_heavy_infantry_points multiply = 10 }
	# }
	
	# # Heavy Cavalry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 1 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 2 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 3 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 4 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 5 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 6 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 7 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 8 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value = 9 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = heavy_cavalry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_heavy_cavalry_points multiply = 10 }
	# }
	
	# # Archer Cavalry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 1 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 2 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 3 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 4 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 5 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 6 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 7 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 8 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value = 9 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = archer_cavalry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_archer_cavalry_points multiply = 10 }
	# }
	
	# # Camel Cavalry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 1 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 2 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 3 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 4 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 5 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 6 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 7 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 8 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value = 9 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = camel_cavalry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_camel_cavalry_points multiply = 10 }
	# }
	
	# # Elephant Cavalry
	# if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 1 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 1 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 2 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 2 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 3 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 3 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 4 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 4 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 5 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 5 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 6 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 6 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 7 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 7 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 8 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 8 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value = 9 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 9 }
	# }
	# else_if = {
		# limit = { number_maa_regiments_of_base_type = { type = elephant_cavalry value >= 10 } }
		# add = { value = mil_competence_maa_regiments_elephant_cavalry_points multiply = 10 }
	# }
}

# Nb of max soldiers / 1000
mil_competence_sub_value_2 = {
	value = max_military_strength

	divide = 1000
}

mil_competence_sub_value_3 = {
	value = number_of_maa_regiments

	if = {
		limit = {
			mil_competence_sub_value_2 > 0
		}
		divide = mil_competence_sub_value_2
	}

	if = {
		limit = {
			government_has_flag = government_is_autocratic
		}
		subtract = 0.4
	}
	else = {
		subtract = 0.6
	}

	if = {
		limit = {
			# Very low nb of regiments per 1k soldiers, and very low nb of regiments in general
			AND = {
				mil_competence_sub_value_4 < 0
				number_of_maa_regiments < 5
			}
		}
		multiply = 700
	}
	else_if = {
		limit = {
			# Somewhat good nb of regiments per 1k soldiers
			OR = {
				mil_competence_sub_value_4 > 0
				number_of_maa_regiments = 5
			}
		}
		multiply = 100
	}
	else_if = {
		limit = {
			OR = {
				number_of_maa_regiments > 5
			}
		}
		multiply = 50
	}
}

# Nb of maa regiments / ( Nb of max soldiers / 1000)
# How many regiments per 1k soldiers?
mil_competence_sub_value_4 = {
	value = number_of_maa_regiments

	if = {
		limit = {
			mil_competence_sub_value_2 > 0
		}
		divide = mil_competence_sub_value_2
	}

	if = {
		limit = {
			government_has_flag = government_is_autocratic
		}
		subtract = 0.4
	}
	else = {
		subtract = 0.6
	}
}

## Civic Competence
civic_competence_net = {
	value = 0

	### General, shared in some forms by all competences
	add = {
		value = civic_competence_stewardship
		desc = "CIVIC_COMP_STEWARDSHIP"
	}
	add = {
		value = civic_competence_stewardship_steward
		desc = "CIVIC_COMP_STEWARDSHIP_STEWARD"
	}
	add = {
		value = civic_comp_administrative_court
		desc = "CIVIC_COMP_ADMINISTRATIVE_COURT"
	}
	
	### More specific
	add = {
		value = civic_competence_empire_size
		desc = "CIVIC_COMP_EMPIRE_SIZE"
	}
	add = {
		value = civic_competence_empire_size_unintegrated
		desc = "CIVIC_COMP_EMPIRE_SIZE_UNINTEGRATED"
	}
	add = {
		value = civic_competence_domain_size
		desc = "CIVIC_COMP_DOMAIN_SIZE"
	}
	# add = {
		# value = civic_competence_empire_county_opinion
		# desc = "CIVIC_COMP_EMPIRE_COUNTY_OPINION"
	# }
	add = {
		value = civic_competence_trade_nodes
		desc = "CIVIC_COMP_TRADE_NODES"
	}
	add = {
		value = civic_competence_income
		desc = "CIVIC_COMP_INCOME"
	}
	add = {
		value = civic_competence_gold_reserve
		desc = "CIVIC_COMP_GOLD_RESERVE"
	}
	add = {
		value = civic_competence_development
		desc = "CIVIC_COMP_DEVELOPMENT"
	}
	add = {
		value = civic_competence_buildings
		desc = "CIVIC_COMP_BUILDINGS"
	}
	
	# add = {
		# value = {
			# every_vassal = {
				# limit = {
					# has_realm_law = centeral_law_policy_4
				# }
				# add = 15
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = centeral_law_policy_3
				# }
				# add = 10
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = centeral_law_policy_2
				# }
				# add = 5
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = centeral_law_policy_1
				# }
				# add = 1
			# }
		
			# every_vassal = {
				# limit = {
					# has_realm_law = de_centeral_law_policy_4
				# }
				# subtract = 20
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = de_centeral_law_policy_3
				# }
				# subtract = 15
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = de_centeral_law_policy_2
				# }
				# subtract = 5
			# }
			# every_vassal = {
				# limit = {
					# has_realm_law = de_centeral_law_policy_1
				# }
				# subtract = 1
			# }
		# }

		# desc = "CIVIC_COMP_CENTRAL"
	# }

	# add = {
		# value = {
			# every_realm_county = {
				# limit = {
					# county_control < 10
				# }
				# subtract = 2
			# }
		# }
		# desc = "CIVIC_COMP_CONTROL"
	# }
	if = {
		limit = {
			AND = {
				is_ai = yes
				has_title = title:e_roman_empire
				current_date <= 400.1.1
			}
		}
		multiply = 0.7 #slow down competence
	}
}
civic_competence_total = {
	value = 0

	add = {
		value = civic_competence_net
		desc = "CIVIC_COMP_TOTAL"
	}
}

# An Emperor with a high stewardship is GOOD
civic_competence_stewardship = {
	add = stewardship
}

# A Steward with a high stewardship is GOOD
civic_competence_stewardship_steward = {
	value = 0
	
	every_stewardship_councillor = {
		add = stewardship
	}
}

# An Administrative court is GOOD
civic_competence_administrative_court_grandeur_bonus = 10
civic_competence_administrative_court = {
	value = 0
	
	if = {
		limit = {
			has_royal_court = yes
			has_court_type = court_administrative
		}
		add = court_grandeur_current_level
		multiply = civic_competence_administrative_court_grandeur_bonus
	}
}

# More integrated territory (i.e you're their de Jure liege) = more bureaucratic upkeep, so BAD
civic_competence_empire_size_penalty_base = 1
civic_competence_empire_size_penalty_county_opinion_modifier = { # Counties that don't like us weigh more, those that do like us weigh less
	value = 0
	
	add = { # If county opinion = -20, we get a modifier (-20 * (-1) / 100) = 0.2, so it weighs 20% more
		value = county_opinion
		multiply = -1
		divide = 100
	}
}
civic_competence_empire_size_penalty_control_modifier = { # Counties that are almost independent weigh more, those that we have a tight control over weigh less
	value = 0
	
	add = { # If control = 50, we get a modifier (100 - 50 )/ 100 = 0.5, so it weighs 50% more
		value = 100
		subtract = county_control
		divide = 100
	}
	
	# Absolute Control, makes counties weigh 25% less
	if = {
		limit = {
			holder = { has_perk = absolute_control_perk }
			county_control >= 100
		}
		subtract = 0.25
	}
}
civic_competence_empire_size_penalty_modifiers = { # Allows a rather smooth transition
	value = 1
	
	add = civic_competence_empire_size_penalty_county_opinion_modifier
	add = civic_competence_empire_size_penalty_control_modifier
}
civic_competence_empire_size_penalty = { # Base * sum of various modifiers
	value = civic_competence_empire_size_penalty_base
	
	multiply = civic_competence_empire_size_penalty_modifiers
}
civic_competence_empire_size = {
	value = 0
	
	subtract = {
		value = {
			every_realm_county = {
				limit = {
					holder.top_liege = { save_temporary_scope_as = emperor } # Technically not always an Emperor, for Autocracies it can be lower
					trigger_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_empire }
						empire.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_kingdom }
						kingdom.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_duchy }
						duchy.holder = scope:emperor
					}
					trigger_else = { always = yes }
				}
				add = civic_competence_empire_size_penalty
			}
		}
	}
}

# More unintegrated territory (i.e you're NOT their de Jure liege) = even more bureaucratic upkeep, so BAD (worse)
civic_competence_empire_size_unintegrated_penalty = 2
civic_competence_empire_size_unintegrated = {
	value = 0
	
	subtract = {
		value = {
			every_realm_county = {
				limit = {
					holder.top_liege = { save_temporary_scope_as = emperor } # Technically not always an Emperor, for Autocracies it can be lower
					trigger_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_empire }
						NOT = { empire.holder = scope:emperor }
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_kingdom }
						NOT = { kingdom.holder = scope:emperor }
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_duchy }
						NOT = { duchy.holder = scope:emperor }
					}
					trigger_else = { always = no }
				}
				add = civic_competence_empire_size_unintegrated_penalty
			}
		}
	}
}

# A vast personal domain is GOOD
civic_competence_domain_size_value = 5
civic_competence_domain_size = {
	value = 0
	
	add = {
		value = {
			add = domain_size
			multiply = civic_competence_domain_size_value
		}
	}
}

# The people not being in open rebellion is GOOD, them not liking your rule is BAD
# Note: We only check integrated counties
civic_competence_empire_county_opinion = {
	value = 0
	
	add = {
		value = {
			every_realm_county = {
				limit = {
					holder.top_liege = { save_temporary_scope_as = emperor } # Technically not always an Emperor, for Autocracies it can be lower
					trigger_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_empire }
						empire.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_kingdom }
						kingdom.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_duchy }
						duchy.holder = scope:emperor
					}
					trigger_else = { always = yes }
				}
				add = county_opinion
			}
		}
	}
}

# Having trade nodes is GOOD
civic_competence_trade_nodes_value = 5
civic_competence_trade_nodes = {
	value = 0
	
	add = {
		value = {
			every_realm_province = {
				limit = {
					exists = var:node
					trigger_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_empire }
						empire.holder = province_owner.top_liege
					}
					trigger_else_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_kingdom }
						kingdom.holder = province_owner.top_liege
					}
					trigger_else_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_duchy }
						duchy.holder = province_owner.top_liege
					}
					trigger_else = { always = yes }
				}
				add = civic_competence_trade_nodes_value
			}
		}
	}
}

# Gaining lots of cash is GOOD
civic_competence_income = {
	value = 0
	
	add = yearly_character_balance
	if = {
		limit = {
			is_ai = yes
		}
		divide = 4 #dumb AI lol
	}
}

# Having a lot of gold in reserve is GOOD (and debt bad, accordingly)
civic_competence_gold_reserve = {
	value = 0
	
	add = gold
	divide = 20
}

# High development is GOOD
civic_competence_development_breakpoint = 6
civic_competence_development_breakpoint_after_450 = 10
civic_competence_development_breakpoint_after_550 = 15
civic_competence_development_breakpoint_after_650 = 20
civic_competence_development_point = 1
civic_competence_development = {
	value = 0

	add = {
		value = {
			every_realm_county = {
				limit = {
					holder.top_liege = { save_temporary_scope_as = emperor } # Technically not always an Emperor, for Autocracies it can be lower
					trigger_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_empire }
						empire.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_kingdom }
						kingdom.holder = scope:emperor
					}
					trigger_else_if = {
						limit = { holder.top_liege.highest_held_title_tier = tier_duchy }
						duchy.holder = scope:emperor
					}
					trigger_else = { always = yes }
				}
				add = development_level
				if = {
					limit = {
						OR = {
							AND = {
								current_date <= 430.1.1
								game_start_date = 361.11.17
							}
							AND = {
								current_date <= 450.1.1
								game_start_date = 395.1.17
							}

							AND = {
								current_date <= 520.1.1
								game_start_date = 476.9.4
							}

							AND = {
								current_date <= 576.1.1
								game_start_date = 532.2.1
							}

							AND = {
								current_date <= 890.1.1
								game_start_date = 867.1.1
							}
							AND = {
								current_date <= 1100.1.1
								game_start_date = 1066.9.15
							}
						}
					}
					subtract = civic_competence_development_breakpoint
				}
				else_if = {
					limit = {
						OR = {
							AND = {
								current_date <= 530.1.1
								game_start_date = 361.11.17
							}

							AND = {
								current_date <= 550.1.1
								game_start_date = 395.1.17
							}

							AND = {
								current_date <= 630.1.1
								game_start_date = 476.9.4
							}

							AND = {
								current_date <= 690.1.1
								game_start_date = 532.2.1
							}

							AND = {
								current_date <= 910.1.1
								game_start_date = 867.1.1
							}
							AND = {
								current_date <= 1140.1.1
								game_start_date = 1066.9.15
							}
						}
					}
					subtract = civic_competence_development_breakpoint_after_450
				}
				else_if = {
					limit = {
						OR = {
							AND = {
								current_date <= 630.1.1
								game_start_date = 361.11.17
							}
							AND = {
								current_date <= 650.1.1
								game_start_date = 395.1.17
							}

							AND = {
								current_date <= 730.1.1
								game_start_date = 476.9.4
							}

							AND = {
								current_date <= 790.1.1
								game_start_date = 532.2.1
							}
							AND = {
								current_date <= 950.1.1
								game_start_date = 867.1.1
							}

							AND = {
								current_date <= 1180.1.1
								game_start_date = 1066.9.15
							}
						}
					}
					subtract = civic_competence_development_breakpoint_after_550
				}
				else = {
					subtract = civic_competence_development_breakpoint_after_650
				}
			}
		}
	}
}

# Lots of building is GOOD
civic_competence_buildings_point = 0.1
civic_competence_buildings = {
	value = 0
	
	add = {
		value = {
			every_realm_province = {
				limit = {
					trigger_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_empire }
						empire.holder = province_owner.top_liege
					}
					trigger_else_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_kingdom }
						kingdom.holder = province_owner.top_liege
					}
					trigger_else_if = {
						limit = { province_owner.top_liege.highest_held_title_tier = tier_duchy }
						duchy.holder = province_owner.top_liege
					}
					trigger_else = { always = yes }
				}
				add = combined_building_level
				# add = 10
			}
		}
	}
	multiply = civic_competence_buildings_point
}

## Diplomatic Competence
diplo_competence_net = {
	value = 0

	### General, shared in some forms by all competences
	add = {
		value = diplo_competence_diplomacy
		desc = "DIPLO_COMP_DIPLOMACY"
	}
	add = {
		value = diplo_competence_diplomacy_chancellor
		desc = "DIPLO_COMP_DIPLOMACY_CHANCELLOR"
	}
	add = {
		value = diplo_competence_diplomatic_court
		desc = "DIPLO_COMP_DIPLOMATIC_COURT"
	}
	add = {
		value = diplo_competence_county_opinion
		desc = "DIPLO_COMP_COUNTY_OPINION"
	}
	add = {
		value = diplo_competence_vassal_opinion
		desc = "DIPLO_COMP_VASSAL_OPINION"
	}
	
	# add = {
		# value = {
			# every_realm_county = {
				# limit = {
					# county_opinion > 70
				# }
				# add = 20
			# }
			# every_realm_county = {
				# limit = {
					# county_opinion <= -30
				# }
				# subtract = 5
			# }
		# }
		# desc = "DIPLO_COMP_OPINION"
	# }
	# add = {
		# value = {
			# every_ally = {
				# add = 10
			# }
		# }
		# desc = "DIPLO_COMP_ALLY"
	# }
	# add = {
		# value = {
			# every_vassal = {
				# limit = {
					# opinion = {
						# target = PREV
						# value > 60
					# }
				# }
				# add = 10
			# }
			# every_vassal = {
				# limit = {
					# opinion = {
						# target = PREV
						# value < -30
					# }
				# }
				# subtract = 5
			# }
		# }
		# desc = "DIPLO_COMP_VASSAL"
	# }
	if = {
		limit = {
			AND = {
				is_ai = yes
				has_title = title:e_roman_empire
				current_date <= 400.1.1
			}
		}
		multiply = 0.9 #slow down competence
	}
}
diplo_competence_total = {
	value = 0

	add = {
		value = diplo_competence_net
		desc = "DIPLO_COMP_TOTAL"
	}
}

# An Emperor with a high diplomacy is GOOD
diplo_competence_diplomacy = {
	add = diplomacy
}



diplo_competence_diplomacy_chancellor_compare = {
	value = 0
	
	every_diplomacy_councillor = {
		add = diplomacy
	}
	if = {
		limit = {
			is_ai = no
		}
		subtract = 7
	}
	if = {
		limit = {
			vassal_count > 0
		}
		divide = vassal_count
	}
	subtract = 1
}

# A Chancellor with a high diplomacy is GOOD
diplo_competence_diplomacy_chancellor = {
	value = 0
	
	every_diplomacy_councillor = {
		add = diplomacy
	}
	if = {
		limit = {
			AND = {
				is_ai = no
				has_title = title:e_byzantium
			}
		}
		subtract = 7
	}
	if = {
		limit = {
			vassal_count > 0
		}
		divide = vassal_count
	}
	subtract = 1

	if = {
		limit = {
			AND = {
				is_ai = yes
			}
		}
		multiply = 75
	}
	else = {
		multiply = 150
	}
}

# A Diplomatic court is GOOD
diplo_competence_diplomatic_court_grandeur_bonus = 10
diplo_competence_diplomatic_court = {
	value = 0
	
	if = {
		limit = {
			has_royal_court = yes
			has_court_type = court_diplomatic
		}
		add = court_grandeur_current_level
		multiply = diplo_competence_diplomatic_court_grandeur_bonus
	}
}

#Average County Opinion
diplo_competence_county_opinion_mult = 10
diplo_competence_county_opinion = {
	value = 0
	
	every_realm_county = {
		add = county_opinion
	}
	if = {
		limit = {
			realm_size > 0
		}
		divide = realm_size
	}
	multiply = diplo_competence_county_opinion_mult
}

#Average Vassal Opinion
diplo_competence_vassal_opinion_mult = 5
#This might exist in base game. If so, pls replace
diplo_competence_vassal_number = {
	value = 0
	
	every_vassal = {
		add = 1
	}
}
diplo_competence_vassal_opinion = {
	value = 0
	
	every_vassal = {
		if = {
			limit = {
				opinion = {
					target = PREV
					value >= 100
				}
			}
			add = 100
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 90
				}
			}
			add = 90
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 80
				}
			}
			add = 80
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 70
				}
			}
			add = 70
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 60
				}
			}
			add = 60
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 50
				}
			}
			add = 50
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 40
				}
			}
			add = 30
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 20
				}
			}
			subtract = 10
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 10
				}
			}
			subtract = 20
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value >= 0
				}
			}
			subtract = 30
		}

		if = {
			limit = {
				opinion = {
					target = PREV
					value <= -100
				}
			}
			subtract = 100
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -90
				}
			}
			subtract = 90
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -80
				}
			}
			subtract = 80
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -70
				}
			}
			subtract = 70
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -50
				}
			}
			subtract = 50
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -40
				}
			}
			subtract = 40
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -30
				}
			}
			subtract = 30
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -20
				}
			}
			subtract = 20
		}
		else_if = {
			limit = {
				opinion = {
					target = PREV
					value <= -10
				}
			}
			subtract = 10
		}
	}
	if = {
		limit = {
			diplo_competence_vassal_number > 0
		}
		divide = diplo_competence_vassal_number
	}
	multiply = diplo_competence_vassal_opinion_mult
}

### Monuments
monument_price = {
	value = 0
	if = {
		limit = {
			exists = var:statue
		}
		if = {
			limit = {
				var:statue = flag:gold
			}
			add = 20000
		}
		if = {
			limit = {
				var:statue = flag:marble
			}
			add = 15000
		}
		if = {
			limit = {
				var:statue = flag:limestone
			}
			add = 10000
		}
		if = {
			limit = {
				var:statue = flag:stone
			}
			add = 5000
		}
		if = {
			limit = {
				var:statue = flag:copper
			}
			add = 15000
		}
	}
}

monument_refund = {
	value = 0
	if = {
		limit = {
			exists = var:monument_material
		}
		if = {
			limit = {
				var:monument_material = flag:gold
			}
			add = 20000
		}
		if = {
			limit = {
				var:monument_material = flag:marble
			}
			add = 15000
		}
		if = {
			limit = {
				var:monument_material = flag:limestone
			}
			add = 10000
		}
		if = {
			limit = {
				var:monument_material = flag:stone
			}
			add = 5000
		}
		if = {
			limit = {
				var:monument_material = flag:copper
			}
			add = 15000
		}
		if = {
			limit = {
				var:monument_material = flag:copper_rust
			}
			add = 14500
		}
	}
	if = {
		limit = {
			exists = var:monument_gardens
		}
		add = 300
	}
	if = {
		limit = {
			exists = var:monument_fences
		}
		add = 400
	}
	multiply = 0.3
	divide = 2
}

### Misc
# Gladiators
sell_gladiator_price = {
	value = 10
	
	add = {
		value = prowess
		subtract = 8
		multiply = 2
	}
}

# Distribute Bread decision
distribute_bread_price_dev_modifier = 5

distribute_bread_price = {
	value = 0
	
	add = {
		value = {
			save_temporary_scope_as = current_title
			every_in_de_jure_hierarchy = {
				limit = {
					tier = tier_county
					
					holder = {
						OR = {
							this = scope:current_title.holder
							trigger_if = {
								limit = {
									exists = scope:current_title.holder
								}
								is_vassal_or_below_of = scope:current_title.holder
							}
						}
					}
				}
				add = this.development_level
			}
			multiply = distribute_bread_price_dev_modifier
		}
	}
}

# Abandoning Province gold gain
abandon_britannia_gold_gained = {
	value = 5000
}

# Total fort level of a county
total_county_fort_level = {
	value = 0
	
	every_in_de_jure_hierarchy = {
		limit = { tier = tier_barony }
		title_province = { add = fort_level }
	}
}

migrator_priority_value = {
	value = 0

	#Add martial score directly
	add = martial
	#Add prowess score directly
	add = prowess
	#Add reduced diplomacy score
	add = {
		value = diplomacy
		multiply = 0.5
	}
	#Add reduced intrigue score
	add = {
		value = intrigue
		multiply = 0.5
	}
	#Weight up for prestige level
	add = {
		value = prestige_level
		multiply = 10
	}
	#+++Ambitious
	if = {
		limit = { has_trait = ambitious }
		add = 15
	}
	#++Strategist
	if = {
		limit = { has_trait = strategist }
		add = 10
	}
	#++Brave
	if = {
		limit = { has_trait = brave }
		add = 10
	}
	#++Stubborn
	if = {
		limit = { has_trait = stubborn }
		add = 10
	}
	#++Varangian
	if = {
		limit = { has_trait = varangian }
		add = 10
	}
	#+Any blademaster
	if = {
		limit = { has_trait = lifestyle_blademaster }
		add = 5
	}
	#+Diligent
	if = {
		limit = { has_trait = diligent }
		add = 5
	}
	#+Wrathful
	if = {
		limit = { has_trait = wrathful }
		add = 5
	}
	#+Impatient
	if = {
		limit = { has_trait = impatient }
		add = 5
	}
	#+Arrogant
	if = {
		limit = { has_trait = arrogant }
		add = 5
	}
	#+Vengeful
	if = {
		limit = { has_trait = vengeful }
		add = 5
	}
	#+Berserker
	if = {
		limit = { has_trait = berserker }
		add = 5
	}
	#+Shieldmaiden
	if = {
		limit = { has_trait = shieldmaiden }
		add = 5
	}
	#-Forgiving
	if = {
		limit = { has_trait = forgiving }
		add = -5
	}
	#-Humble
	if = {
		limit = { has_trait = humble }
		add = -5
	}
	#-Patient
	if = {
		limit = { has_trait = patient }
		add = -5
	}
	#-Calm
	if = {
		limit = { has_trait = calm }
		add = -5
	}
	#-Lazy
	if = {
		limit = { has_trait = lazy }
		add = -5
	}
	#--Craven
	if = {
		limit = { has_trait = craven }
		add = -10
	}
	#---Content
	if = {
		limit = { has_trait = content }
		add = -15
	}
	#Weight down heavily for pacifist faith.
	if = {
		limit = {
			faith = { has_doctrine_parameter = pacifist_opinion_active }
		}
		add = -30
	}
	#Weight up if historically migrant culture and game rules say so
	if = {
		limit = {
			culture = {
				OR = {
					this = culture:gothic
					this = culture:visigothic
					this = culture:ostrogothic
					this = culture:vandal
					this = culture:langobard
					this = culture:old_suebi
					this = culture:old_saxon
					this = culture:jute
					this = culture:angle
					this = culture:alan
					this = culture:sclavenian
					this = culture:belocroat
					this = culture:beloserb
				}
			}
		}
		if = {
			limit = {
				has_game_rule = tfe_historical_migrations_strict
			}
			add = 1000
		}
		else_if = {
			limit = {
				has_game_rule = tfe_historical_migrations_default
			}
			add = 30
		}
	}
}

grand_raid_gold = {
	value = 0
	scope:defender = {
		every_realm_county = {
			add = 1
		}
	}
	multiply = 10
	
	min = 200
	max = 2000
}

grand_raid_gold_hun = {
	value = 0
	scope:defender = {
		every_realm_county = {
			add = 1
		}
	}
	multiply = 10

	min = 200
}

foederati_plunder = {
	value = 0
	scope:defender = {
		every_sub_realm_county = {
			add = 1
		}
	}
	multiply = 50
	
	min = 100
}

#traits for senate ideals, improve later
loyalist_senate = {
	value = 0
	if = {
		limit = {
			has_trait = content
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = compassionate
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = trusting
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = humble
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = arrogant
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = ambitious
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = paranoid
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = stubborn
		}
		subtract = 1
	}
	opinion_modifier = {
		opinion_target = top_liege
		multiplier = 0.5
		step = 1
		max = 5
	}
}
disloyal_senate = {
	value = 0
	if = {
		limit = {
			has_trait = content
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = compassionate
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = trusting
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = humble
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = arrogant
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = ambitious
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = paranoid
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = stubborn
		}
		add = 1
	}
	opinion_modifier = {
		opinion_target = top_liege
		multiplier = 0.5
		step = 1
		max = 5
	}
}
pragmatic_senate = {
	value = 0
	if = {
		limit = {
			has_trait = just
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = honest
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = fickle
		}
		add = 1
	}
}
gloryhound_senate = {
	value = 0
	if = {
		limit = {
			has_trait = ambitious
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = vengeful
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = callous
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = brave
		}
		add = 1
	}
	if = {
		limit = {
			has_trait = diligent
		}
		add = 1
	}

	if = {
		limit = {
			has_trait = content
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = forgiving
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = compassionate
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = craven
		}
		subtract = 1
	}
	if = {
		limit = {
			has_trait = lazy
		}
		subtract = 1
	}
}

culture_script_province_count = {
	value = 0
	if = {
		limit = {
			has_cultural_tradition = tradition_script_arabic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_arabic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_aramaic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_aramaic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_armenian
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_armenian
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_brahmi
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_brahmi
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_coptic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_coptic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_cuneiform
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_cuneiform
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_cyrillic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_cyrillic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_devanagari
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_devanagari
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_etruscan
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_etruscan
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_geez
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_geez
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_georgian
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_georgian
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_glagolitic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_glagolitic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_gothic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_gothic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_greek
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_greek
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_gupta
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_gupta
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_han
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_han
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_hebrew
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_hebrew
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_hieroglyphic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_hieroglyphic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_hungarian
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_hungarian
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_latin
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_latin
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_manichean
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_manichean
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_meroitic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_meroitic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_mon
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_mon
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_nabatean
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_nabatean
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_ogham
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_ogham
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_pahlavi
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_pahlavi
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_phoenician
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_phoenician
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_runic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_runic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_sinhala
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_sinhala
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_sogdian
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_sogdian
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_south_arabian
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_south_arabian
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_syriac
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_syriac
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_tamil
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_tamil
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_tibetan
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_tibetan
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_tifinagh
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_tifinagh
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
	else_if = {
		limit = {
			has_cultural_tradition = tradition_script_turkic
		}
		every_culture_global = {
			if = {
				limit = {
					has_cultural_tradition = tradition_script_turkic
				}
				every_culture_county = {
					add = 1
				}
			}
		}
	}
}

culture_script_grandeur_bonus = {
	value = 0
	add = culture_script_province_count
	divide = 50
	floor = yes
}

convert_culture_task = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_italy
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds won't want converting stuff but can like culture more than faith depending on traits
			}
			if = {
				limit = {
					OR = {
						has_trait = zealous 
						has_trait = devoted 
						has_trait = theologian 
					}
				}
				subtract = 1
			}
			else = {
				subtract = 0.5
			}
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 0.2
			}

			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 0.2
			}
		}
	}

	min = -10
}

convert_faith_task = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_italy
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds won't want converting stuff but can like faith more than culture depending on traits
			}
			if = {
				limit = {
					OR = {
						has_trait = zealous 
						has_trait = devoted 
						has_trait = theologian 
					}
				}
				add = 1
			}
			else = {
				subtract = 0.5
			}
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 0.2
			}

			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 0.2
			}
		}
	}

	min = -10
}

conquer_task = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_italy
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds like dis
			}
			add = 1
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						AND = {
							max_military_strength >= 6000
							any_neighboring_top_liege_realm_owner = {			#will redo later
								max_military_strength <= 2000
							}
						}
					}
				}
				add = 1
			}
			else = {
				subtract = 1
			}
		}
	}

	min = -10
}
building_task = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_italy
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds don't like dis
			}
			subtract = 1
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						civic_competence_buildings < 20
					}
				}
				add = 1
			}
			else = {
				subtract = 1
			}
		}
	}

	min = -10
}
convert_culture_task_eastern = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_eastern
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds won't want converting stuff but can like culture more than faith depending on traits
			}
			if = {
				limit = {
					OR = {
						has_trait = zealous 
						has_trait = devoted 
						has_trait = theologian 
					}
				}
				subtract = 1
			}
			else = {
				subtract = 0.5
			}
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				add = 0.2
			}

			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				subtract = 0.2
			}
		}
	}

	min = -10
}

convert_faith_task_eastern = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_eastern
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds won't want converting stuff but can like faith more than culture depending on traits
			}
			if = {
				limit = {
					OR = {
						has_trait = zealous 
						has_trait = devoted 
						has_trait = theologian 
					}
				}
				add = 1
			}
			else = {
				subtract = 0.5
			}
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								culture = holder.top_liege.culture
							}
						}
					}
				}
				subtract = 0.2
			}

			if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.7
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 1
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.5
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 0.5
			}
			else_if = {
				limit = {
					top_liege = {
						any_realm_county = {
							percent > 0.3
							NOT = {
								faith = holder.top_liege.faith
							}
						}
					}
				}
				add = 0.2
			}
		}
	}

	min = -10
}

conquer_task_eastern = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_eastern
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds like dis
			}
			add = 1
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						AND = {
							max_military_strength >= 6000
							any_neighboring_top_liege_realm_owner = {			#will redo later
								max_military_strength <= 2000
							}
						}
					}
				}
				add = 1
			}
			else = {
				subtract = 1
			}
		}
	}

	min = -10
}
building_task_eastern = {
	value = 0
	every_in_global_list = {
		variable  = all_senate_eastern
		if = {
			limit = {
				has_variable = gloryhound_senate #Gloryhounds don't like dis
			}
			subtract = 1
		}
		else_if = {
			limit = {
				has_variable = pragmatic_senate #Pragmatic just asses the state of the realm and go from there
			}
			if = {
				limit = {
					top_liege = {
						civic_competence_buildings < 20
					}
				}
				add = 1
			}
			else = {
				subtract = 1
			}
		}
	}

	min = -10
}

roman_bathhouse_cost_base_value = {
	value = 50
	if = {
		limit = {
			culture = {
				has_cultural_tradition = tradition_roman_architecture
			}
		}
		subtract = 10
	}
}




TFE_minor_flavor_activity_cost = {
	value = 20
	multiply = {
		value = root.primary_title.tier
		subtract = 1.5
		min = 1
	}
	if = {
		limit = {
			root.primary_title.tier > tier_duchy
		}
		add = 10
	}
}

missionary_chance = {
	value = 0
	every_court_position_holder = {
		type = missionary
		if = {
			limit = {
				aptitude = { court_position = missionary value >= 1 }
			}
			add = 1
		}
		if = {
			limit = {
				aptitude = { court_position = missionary value >= 2 }
			}
			add = 2
		}
		if = {
			limit = {
				aptitude = { court_position = missionary value >= 3 }
			}
			add = 3
		}
		if = {
			limit = {
				aptitude = { court_position = missionary value >= 4 }
			}
			add = 4
		}
		if = {
			limit = {
				aptitude = { court_position = missionary value >= 5 }
			}
			add = 5
		}
	}
}

##################################################
# Decisions

##### Struggle Ending Decisions #####

### Common

# Counts every county in region, to check against
struggle_britannia_ending_ending_decision_region_total_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		add = 1
	}
}

# Counts independent involved realms in Britannia, to compare
struggle_britannia_ending_ending_decision_foreign_realm_total_value = {
	value = 0
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				NOT = { this = root }
				is_independent_ruler = yes
				primary_title = { is_holy_order = no }
				primary_title = { is_mercenary_company = no }
			}
			add = 1
		}
	}
}

# Counts completely controlled de jure kingdoms of Britannia
britannia_struggle_ending_kingdom_counter_value = {
	every_held_title = {
		limit = {
			tier = tier_kingdom
			de_jure_liege = title:e_britannia
			root = { completely_controls = prev }
		}
		add = 1
	}
}

### Hostility

# Parameter for conversion speed multiplier
britannia_struggle_hostility_conversion_value = 1.5

# Parameter for culture and faith opinion loss
britannia_struggle_hostility_opinion_value = 15

britannia_struggle_hostility_opinion_negative_value = -30

# Paramter for cultural acceptance loss
britannia_struggle_hostility_culture_acceptance_value = -50

britannia_struggle_hostility_culture_acceptance_large_value = -75

# Counter for de jure capital kingdom's total counties
britannia_struggle_hostility_county_total_value = {
	capital_county.de_jure_liege.de_jure_liege = {
		every_de_jure_county = { add = 1 }
	}
}

britannia_struggle_hostility_county_total_light_value = {
	capital_county.de_jure_liege.de_jure_liege = {
		every_de_jure_county = { add = 1 }
	}
	multiply = 0.75
}

# Counter for de jure capital kingdom's same culture and faith counties
britannia_struggle_hostility_county_counter_value = {
	capital_county.de_jure_liege.de_jure_liege = {
		every_de_jure_county = {
			limit = {
				culture = root.culture
				faith = root.faith
			}
			add = 1
		}
	}
	multiply = 0.8
	ceiling = yes
}

# Counter for other rulers who own too much of Britannia
britannia_struggle_hostility_region_counter_value = {
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				NOT = { this = root }
				is_independent_ruler = yes
				primary_title = { is_holy_order = no }
				primary_title = { is_mercenary_company = no }
				any_county_in_region = {
					region = world_europe_west_britannia
					percent > britannia_struggle_hostility_region_percent_decimal_value # set by britannia_struggle_hostility_region_percent_value
					holder.top_liege = prev	
				}
			}
			add = 1
		}
	}
}

# Paramater for de jure kingdoms required
britannia_struggle_hostility_kingdom_total_value = 2

# Paramameter for percentage of Britannia that no other ruler can control
britannia_struggle_hostility_region_percent_value = 20

# Uses above to plug in to script as a decimal
britannia_struggle_hostility_region_percent_decimal_value = { 
	value = britannia_struggle_hostility_region_percent_value
	divide = 100
	max = 1
}

### Compromise 

# Counter for controlled counties in Britannia
struggle_britannia_ending_compromise_decision_region_owned_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		limit = { holder.top_liege = root }
		add = 1
	}
}

# Percentage of Britannian counties owned
struggle_britannia_ending_compromise_decision_region_owned_percent_value = {
	value = struggle_britannia_ending_compromise_decision_region_owned_value
	divide = struggle_britannia_ending_ending_decision_region_total_value
	multiply = 100
}

# Parameter for mininmum opinion
struggle_britannia_ending_compromise_decision_opinion_value = {
	value = 60
}

# Counter for hooked and friendly rulers
struggle_britannia_ending_compromise_decision_opinion_counter_value = {
	value = 0
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				NOT = { this = root }
				is_independent_ruler = yes
				primary_title = { is_holy_order = no }
				primary_title = { is_mercenary_company = no }
				save_temporary_scope_as = this_character
				OR = {
					root = { has_strong_hook = scope:this_character }
					opinion = {
						target = root
						value >= struggle_britannia_ending_compromise_decision_opinion_value
					}
				}
			}
			add = 1
		}
	}
}

# Counter for Britannian counties owned by non-Involved
struggle_britannia_ending_compromise_decision_region_interloper_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		limit = {
			holder.top_liege = { britannia_character_involved_in_struggle_trigger = no }
		}
		add = 1
	}
}

# Percentage of Britannian counties owned by non-Involved
struggle_britannia_ending_compromise_decision_region_interloper_percent_value = {
	value = struggle_britannia_ending_compromise_decision_region_interloper_value
	divide = struggle_britannia_ending_ending_decision_region_total_value
	multiply = 100
}

# Counter for independent king or higher Involved rulers
struggle_britannia_ending_compromise_decision_independent_counter_value = {
	value = 0
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				NOT = { this = root }
				is_independent_ruler = yes
				primary_title = {
					is_mercenary_company = no
					is_holy_order = no
					tier >= tier_kingdom
				}
			}
			add = 1
		}
	}
}

# Counter for inter-Involved character wars
struggle_britannia_ending_compromise_decision_war_counter_value = {
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				is_independent_ruler = yes
				primary_title = { is_mercenary_company = no }
				primary_title = { is_holy_order = no }
				any_primary_war_enemy = {
					is_independent_ruler = yes
					any_character_struggle = {
						involvement = involved
						is_struggle_type = britannia_struggle
					}
					primary_title = { is_holy_order = no }
					primary_title = { is_mercenary_company = no }
				}
			}
			add =  {
				value = 0
				if = {
					 limit = {
					 	any_character_war = {
							OR = {
								AND = {
									primary_attacker = prev
									primary_defender = {
										any_character_struggle = {
											involvement = involved
											is_struggle_type = britannia_struggle
										}
										is_independent_ruler = yes
										primary_title = { is_mercenary_company = no }
									}
								}
								AND = {
									primary_defender = prev
									primary_attacker = {
										any_character_struggle = {
											involvement = involved
											is_struggle_type = britannia_struggle
										}
										is_independent_ruler = yes
										primary_title = { is_mercenary_company = no }
									}
								}
							}
						}
					 }
					add = 0.5 # they are both primary participant so they will add 0.5 each
				}
				else = {
					add = 1 # only one of them is primary participant, so we need to add 1
				}
			}
		}
	}
}

# Paramameter for percentage of Britannia that you cannot control
britannia_struggle_compromise_owned_percent_value = 50

# Uses above to plug in to script as a decimal
britannia_struggle_compromise_owned_percent_decimal_value = { 
	value = britannia_struggle_compromise_owned_percent_value
	divide = 100
	max = 1
}

# Paramameter for percentage of Britannia that no other Involved ruler can control
britannia_struggle_compromise_involved_percent_value = 50

# Uses above to plug in to script as a decimal
britannia_struggle_compromise_involved_percent_decimal_value = { 
	value = britannia_struggle_compromise_involved_percent_value
	divide = 100
	max = 1
}

# Paramameter for percentage of Britannia that no Uninvolved ruler can control
britannia_struggle_compromise_uninvolved_percent_value = 25

# Uses above to plug in to script as a decimal
britannia_struggle_compromise_uninvolved_percent_decimal_value = { 
	value = britannia_struggle_compromise_uninvolved_percent_value
	divide = 100
	max = 1
}

### Conciliation

# Counter for allied Involved rulers 
struggle_britannia_ending_conciliation_decision_alliance_counter_value = {
	value = 0
	struggle:britannia_struggle = {
		every_involved_ruler = {
			limit = {
				NOT = { this = root }
				is_independent_ruler = yes
				primary_title = { is_holy_order = no }
				primary_title = { is_mercenary_company = no }
				is_allied_to = root
			}
			add = 1
		}
	}
}

# Parameter for num de jure kingdoms of Britannia must be owned
britannia_struggle_conciliation_kingdom_total_value = 1

# Parameter for cultural acceptance gain 
britannia_struggle_conciliation_culture_acceptance_value = 50

britannia_struggle_secure_britannian_foothold_years_value = 15

britannia_struggle_secure_britannian_foothold_faith_target_percent_value = 50

britannia_struggle_secure_britannian_foothold_faith_total_value = {
	if = {
		limit = { exists = scope:britannian_kingdom_temp }
		scope:britannian_kingdom_temp = {
			every_de_jure_county = { add = 1 }
		}
	}
	min = 1
}

britannia_struggle_secure_britannian_foothold_faith_value = {
	value = 0
	if = {
		limit = { exists = scope:britannian_kingdom_temp }
		scope:britannian_kingdom_temp = {
			every_de_jure_county = {
				limit = { faith = holder.top_liege.faith }
				add = 1
			}
		}
	}
	min = 1
}

britannia_struggle_secure_britannian_foothold_faith_percent_value = {
	value = britannia_struggle_secure_britannian_foothold_faith_value
	divide = britannia_struggle_secure_britannian_foothold_faith_total_value
	multiply = 100
}

##### Religion values #####

# Total Britannian counties of my Religion
britannia_struggle_secure_britannian_foothold_religion_total_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		limit = { religion = root.religion }
		add = 1
	}
}

# Held Britannian counties of my Religion
britannia_struggle_secure_britannian_foothold_religion_owned_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		limit = {
			religion = root.religion
			holder.top_liege = root
		}
		add = 1
	}
}

# Percentage owned Britannian counties of my Religion
britannia_struggle_secure_britannian_foothold_religion_percent_value = {
	value = britannia_struggle_secure_britannian_foothold_religion_owned_value
	divide = britannia_struggle_secure_britannian_foothold_religion_total_value
	multiply = 100
	min = 1
}

# Target percentage owned Britannia counties of my Religion
britannia_struggle_secure_britannian_foothold_religion_target_percent_value = 50

britannia_struggle_secure_britannian_foothold_religion_target_percent_decimal_value = {
	value = britannia_struggle_secure_britannian_foothold_religion_target_percent_value
	divide = 100
}

##### Outsider values #####

# Target percentage owned counties of Britannia
britannia_struggle_secure_britannian_foothold_outsider_target_percent_value = 33

britannia_struggle_secure_britannian_foothold_outsider_target_percent_decimal_value = {
	value = britannia_struggle_secure_britannian_foothold_outsider_target_percent_value
	divide = 100		
}

# Decimal target percentage owned counties of Britannia
britannia_struggle_secure_britannian_foothold_outsider_percent_decimal_value = {
	value = britannia_struggle_secure_britannian_foothold_outsider_percent_value
	divide = 100
	max = 1
}

# Percentage owned counties of Britannia
britannia_struggle_secure_britannian_foothold_outsider_percent_value = {
	value = britannia_struggle_secure_britannian_foothold_outsider_value
	divide = britannia_struggle_secure_britannian_foothold_outsider_total_value
	multiply = 100
}

britannia_struggle_secure_britannian_foothold_outsider_total_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		add = 1
	}
}

britannia_struggle_secure_britannian_foothold_outsider_value = {
	value = 0
	every_county_in_region = {
		region = world_europe_west_britannia
		limit = { holder.top_liege = root }
		add = 1
	}
}
tfe_struggle_britannia_hostility_county_counter_value = {
	capital_county.de_jure_liege.de_jure_liege = {
		every_de_jure_county = {
			limit = {
				culture = root.culture
				faith = root.faith
			}
			add = 1
		}
	}
}

tfe_struggle_britannia_hostility_county_total_value = {
	capital_county.de_jure_liege.de_jure_liege = {
		every_de_jure_county = { add = 1 }
	}
}

tfe_struggle_britannia_hostility_county_percent = {
	value = tfe_struggle_britannia_hostility_county_counter_value
	divide = tfe_struggle_britannia_hostility_county_total_value
	multiply = 100
}

sevenhouses_favor_value = {
	value = 0
	add = {
		value = sevenhouses_favor_value_opinion
		desc = "SEVEN_HOUSES_OPINION"
	}
	add = {
		value = sevenhouses_favor_value_hook
		desc = "SEVEN_HOUSES_HOOKS"
	}
	min = 0
	max = 100
}

sevenhouses_favor_value_minus_50 = {
	value = sevenhouses_favor_value
	subtract = 50
}
fifty_minus_sevenhouses_favor_value = {
	value = 50
	subtract = sevenhouses_favor_value
}

sevenhouses_strength_value = {
	value = 0
	add = {
		value = sevenhouses_favor_value_personal_counties
		desc = "SEVEN_HOUSES_PERSONAL_COUNTIES"
	}
	add = {
		value = sevenhouses_favor_value_vassal_num
		desc = "SEVEN_HOUSES_VASSAL_NUM"
	}
	add = {
		value = sevenhouses_favor_value_army_size
		desc = "SEVEN_HOUSES_ARMY_SIZE"
	}
	add = {
		value = sevenhouses_favor_value_dehqan
		desc = "SEVEN_HOUSES_DEHQAN"
	}
	min = 0
	max = 100
}

sevenhouses_favor_value_opinion = {
	value = 0
	every_in_global_list = {
		variable  = seven_houses
		limit = {
			AND = {
				exists = dynast
				dynast = {
					is_landed = yes
					is_independent_ruler = no
				}
				dynast.top_liege = title:e_persia.holder
				
			}
		}
		dynast = {
			top_liege = {
				save_temporary_scope_as = shah_opinion_target
			}
			if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 100
					}
				}
				add = 100
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 90
					}
				}
				add = 90
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 80
					}
				}
				add = 80
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 70
					}
				}
				add = 70
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 60
					}
				}
				add = 60
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 50
					}
				}
				add = 50
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 40
					}
				}
				add = 40
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 20
					}
				}
				add = 20
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 10
					}
				}
				add = 10
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value >= 0
					}
				}
				add = 5
			}
	
			if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -100
					}
				}
				subtract = 100
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -90
					}
				}
				subtract = 90
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -80
					}
				}
				subtract = 80
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -70
					}
				}
				subtract = 70
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -50
					}
				}
				subtract = 50
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -40
					}
				}
				subtract = 40
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -30
					}
				}
				subtract = 30
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -20
					}
				}
				subtract = 20
			}
			else_if = {
				limit = {
					opinion = {
						target = scope:shah_opinion_target
						value <= -10
					}
				}
				subtract = 10
			}
		}
	}
	divide = 5
}

sevenhouses_favor_value_hook = {
	value = 0
	every_in_global_list = {
		variable  = seven_houses
		limit = {
			AND = {
				exists = dynast
				dynast = {
					is_landed = yes
					is_independent_ruler = no
				}
				dynast.top_liege = title:e_persia.holder
				
			}
		}
		save_temporary_scope_as = dynasty_seven
		if = {
			limit = {
				PREV = {
					has_strong_hook = scope:dynasty_seven.dynast
				}
			}
			add = 10
		}
		else_if = {
			limit = {
				PREV = {
					has_hook = scope:dynasty_seven.dynast
				}
			}
			add = 5
		}
	}
}

sevenhouses_favor_value_personal_counties = {
	value = 0
	every_in_global_list = {
		variable  = seven_houses
		limit = {
			AND = {
				exists = dynast
				dynast = {
					is_landed = yes
					is_independent_ruler = no
				}
				dynast.top_liege = title:e_persia.holder
				
			}
		}
		dynast = {
			every_sub_realm_county = {
				limit = {
					holder = PREV

				}
				add = 1
			}
		}
	}
}

sevenhouses_favor_value_vassal_num = {
	value = 0
	every_in_global_list = {
		variable  = seven_houses
		limit = {
			AND = {
				exists = dynast
				dynast = {
					is_landed = yes
					is_independent_ruler = no
				}
				dynast.top_liege = title:e_persia.holder
				
			}
		}
		dynast = {
			every_vassal = {
				add = 1
			}
		}
	}
}

sevenhouses_favor_value_army_size = {
	value = 0
	every_in_global_list = {
		variable  = seven_houses
		limit = {
			AND = {
				exists = dynast
				dynast = {
					is_landed = yes
					is_independent_ruler = no
				}
				dynast.top_liege = title:e_persia.holder
				
			}
		}
		dynast = {
			add = current_military_strength
		}
	}
	divide = 200
}

sevenhouses_favor_value_dehqan = {
	value = 0
	if = {
		limit = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:TFE_instate_dehqans
			}
		}
		subtract = 10
	}
}

proxy_war_price = {
	value = 0
	if = {
		limit = {
			highest_held_title_tier <= tier_duchy
		}
		add = 500
	}
	else_if = {
		limit = {
			highest_held_title_tier <= tier_kingdom
		}
		add = 1000
	}
	else = {
		add = 1500
	}
}

urbanize_silk_road_price_dev_modifier = 10

urbanize_silk_road_price = {
	value = 0
	
	add = {
		value = {
			save_temporary_scope_as = current_title
			every_in_de_jure_hierarchy = {
				limit = {
					tier = tier_county
					title_province = {
						geographical_region = TFE_eastern_iranian_struggle_region
					}
					holder = {
						OR = {
							this = scope:current_title.holder
							is_vassal_or_below_of = scope:current_title.holder
						}
					}
				}
				add = this.development_level
			}
			multiply = urbanize_silk_road_price_dev_modifier
		}
	}

	if = {
		limit = {
			AND = {
				exists = struggle:eastern_iranian_struggle
				struggle:eastern_iranian_struggle = {
					is_struggle_phase = struggle_TFE_eastern_iranian_phase_development
				}
			}
		}
		multiply = 0.7
	}
}

urbanize_silk_road_price_duchy = {
	value = 0
	
	add = {
		value = {
			save_temporary_scope_as = current_title
			duchy = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_county
						title_province = {
							geographical_region = TFE_eastern_iranian_struggle_region
						}
						holder = {
							OR = {
								this = scope:current_title.holder
								is_vassal_or_below_of = scope:current_title.holder
							}
						}
					}
					add = this.development_level
				}
			}
			multiply = urbanize_silk_road_price_dev_modifier
		}
	}

	if = {
		limit = {
			AND = {
				exists = struggle:eastern_iranian_struggle
				struggle:eastern_iranian_struggle = {
					is_struggle_phase = struggle_TFE_eastern_iranian_phase_development
				}
			}
		}
		multiply = 0.7
	}
}

urbanize_silk_road_price_kingdom = {
	value = 0
	
	add = {
		value = {
			save_temporary_scope_as = current_title
			kingdom = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_county
						title_province = {
							geographical_region = TFE_eastern_iranian_struggle_region
						}
						holder = {
							OR = {
								this = scope:current_title.holder
								is_vassal_or_below_of = scope:current_title.holder
							}
						}
					}
					add = this.development_level
				}
			}
			multiply = urbanize_silk_road_price_dev_modifier
		}
	}

	if = {
		limit = {
			AND = {
				exists = struggle:eastern_iranian_struggle
				struggle:eastern_iranian_struggle = {
					is_struggle_phase = struggle_TFE_eastern_iranian_phase_development
				}
			}
		}
		multiply = 0.7
	}
}

urbanize_silk_road_price_empire = {
	value = 0
	
	add = {
		value = {
			save_temporary_scope_as = current_title
			empire = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_county
						title_province = {
							geographical_region = TFE_eastern_iranian_struggle_region
						}
						holder = {
							OR = {
								this = scope:current_title.holder
								is_vassal_or_below_of = scope:current_title.holder
							}
						}
					}
					add = this.development_level
				}
			}
			multiply = urbanize_silk_road_price_dev_modifier
		}
	}

	if = {
		limit = {
			AND = {
				exists = struggle:eastern_iranian_struggle
				struggle:eastern_iranian_struggle = {
					is_struggle_phase = struggle_TFE_eastern_iranian_phase_development
				}
			}
		}
		multiply = 0.7
	}
}

# urbanize_silk_road_prestige_bonus = {
# 	value = urbanize_silk_road_price
# 	if = {
# 		limit = {
# 			highest_held_title_tier >= tier_empire
# 		}
# 		multiply = 0.6
# 	}
# 	else_if = {
# 		limit = {
# 			highest_held_title_tier >= tier_kingdom
# 		}
# 		multiply = 0.4
# 	}
# 	else_if = {
# 		limit = {
# 			highest_held_title_tier >= tier_duchy
# 		}
# 		multiply = 0.2
# 	}
# 	else = {
# 		multiply = 0.1
# 	}

# 	max = 500
# }

urbanize_silk_road_prestige_bonus_small = {
	value = 50
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		multiply = 4
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		multiply = 3
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_duchy
		}
		multiply = 2
	}
}

urbanize_silk_road_prestige_bonus_medium = {
	value = 75
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		multiply = 4
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		multiply = 3
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_duchy
		}
		multiply = 2
	}
}

urbanize_silk_road_prestige_bonus_large = {
	value = 100
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		multiply = 4
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		multiply = 3
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_duchy
		}
		multiply = 2
	}
}

urbanize_silk_road_prestige_bonus_huge = {
	value = 125
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		multiply = 4
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_kingdom
		}
		multiply = 3
	}
	else_if = {
		limit = {
			highest_held_title_tier >= tier_duchy
		}
		multiply = 2
	}
}

hun_invasion_target_character_weight = {
	value = 1
	every_sub_realm_county = {
		if = {
			limit = {
				title_province = {
						geographical_region = ghw_region_crimea
				}
			}
			add = 10000
		}
		else_if = {
			limit = {
				title_province = {
					geographical_region = custom_carpathia
				}
			}
			add = 5000
		}
		else_if = {
			limit = {
				title_province = {
					geographical_region = custom_roman_illyricum
				}
			}
			add = 3000
		}
		else_if = {
			limit = {
				title_province = {
					geographical_region = custom_hun_no_thrace
				}
			}
			add = 1000
		}
		else = {
			multiply = 0
			#add = -1
		}
		if = { # Try to disincentivize slamming your head against byzantium immediately
			limit = {
				holder.top_liege = {
					has_title = title:e_byzantium
					#current_military_strength >= 25000
				}
			}
			multiply = 0.01
		}
		if = { # Try to disincentivize slamming your head against byzantium immediately
			limit = {
				holder.top_liege = {
					has_title = title:e_western_roman_empire
					#current_military_strength >= 25000
				}
			}
			multiply = 0.1
		}
	}
}




# Since the vanilla activity costs are unimmersively inflated at higher levels
TFE_basic_activity_cost = {
	value = 50
	multiply = {
		value = root.primary_title.tier
		subtract = 1
		min = 1
	}
	if = {
		limit = {
			root.primary_title.tier > tier_duchy
		}
		add = 25
	}
	if = {
		limit = {
			root= {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = law_legacy_1
				}
			}
		}
		multiply = law_legacy_cost_reduction_mult
	}
	if = {
		limit = {
			root= {
				government_has_flag = government_is_tribal
			}
		}
		multiply = 0.5
	}
	# Make it a little easier for smaller realms
	if = {
		limit = {
			root= {
				sub_realm_size < 3
			}
		}
		multiply = 0.8
	}
	min = 25
	max = 150
}

TFE_games_base_cost = {
	value = 400
}

TFE_games_predicted_cost = {
	value = 400
	multiply = { value = activity_cost_scale_by_era }
}

TFE_games_predicted_cost_half = {
	value = TFE_games_predicted_cost
	multiply = 0.5
}

TFE_games_colosseum_discount = {
	value = activity_cost_scale_by_era
	multiply = 0.2
}

TFE_games_military_buildings_discount = {
	value = activity_cost_scale_by_era
	multiply = 0.1
}

TFE_games_option_bad_cost = {
	value = 0
}

TFE_games_option_normal_cost = {
	value = 100
}

TFE_games_option_good_cost = {
	value = 200
}

TFE_games_option_very_good_cost = {
	value = 400
}

TFE_games_option_excellent_cost = {
	value = 800
}

gupta_ancestor_num = {
	value = 0
	every_ancestor = {
		even_if_dead = yes 
		limit = {
			OR = {
				has_trait = brahmin
				has_trait = kshatriya
				has_trait = vaishya
				has_trait = shudra
			}
		}
		add = 1
	}
}
caste_purity = {
	value = 0
	every_ancestor = {
		even_if_dead = yes 
		limit = {
			OR = {
				has_trait = brahmin
				has_trait = kshatriya
				has_trait = vaishya
				has_trait = shudra
			}
		}
		if = {
			limit = {
				has_trait = brahmin
			}
			add = 2
		}
		else_if = {
			limit = {
				has_trait = kshatriya
			}
			add = 1
		}
		else_if = {
			limit = {
				has_trait = vaishya
			}
			add = 0.5
		}
		else = {
			subtract = 2
		}
	}
	if = {
		limit = {
			gupta_ancestor_num > 0
		}
		divide = gupta_ancestor_num
	}
	if = {
		limit = {
			gupta_ancestor_num = 0
		}
		add = 0.5
	}
	min = 0
}
caste_purity_debug = {
	value = caste_purity
	multiply = 100
}



TFE_irrigation_tank_small_cost = {
	value = 50
	if = {
		limit = {
			culture = { has_cultural_parameter = unlock_rice_wewa_irrigation_tank_effects }
		}
		multiply = 0.5
	}
}

TFE_irrigation_tank_medium_cost = {
	value = 100
	if = {
		limit = {
			culture = { has_cultural_parameter = unlock_rice_wewa_irrigation_tank_effects }
		}
		multiply = 0.5
	}
}

TFE_irrigation_tank_large_cost = {
	value = 150
	if = {
		limit = {
			culture = { has_cultural_parameter = unlock_rice_wewa_irrigation_tank_effects }
		}
		multiply = 0.5
	}
}

TFE_irrigation_tank_huge_cost = {
	value = 200
	if = {
		limit = {
			culture = { has_cultural_parameter = unlock_rice_wewa_irrigation_tank_effects }
		}
		multiply = 0.5
	}
}




TFE_india_grant_decision_cost = {
	value = 25
	every_held_title = {
		limit = {
			tier = tier_county
		}
		add = 25
	}
	if = {
		limit = {
			root.primary_title.tier <= tier_duchy
		}
		multiply = 0.8
	}
	# Make it a little easier for smaller realms
	if = {
		limit = {
			root= {
				sub_realm_size <= 4
			}
		}
		multiply = 0.8
	}
	min = 25
	max = 300
}

TFE_india_grant_prestige_different_religion_value = {
	value = 0
	every_held_title = {
		limit = {
			tier = tier_county
		}
		add = 25
	}
	every_held_title = {
		limit = {
			has_holding_type = church_holding
			tier = tier_county
		}
		add = 10
	}
	min = 25
	max = 500
}

TFE_india_grant_piety_different_religion_value = {
	value = 0
	every_held_title = {
		limit = {
			tier = tier_county
		}
		add = 10
	}
	every_held_title = {
		limit = {
			has_holding_type = church_holding
			tier = tier_county
		}
		add = 5
	}
	min = 10
	max = 500
}


TFE_india_grant_prestige_same_religion_value = {
	value = 0
	every_held_title = {
		limit = {
			tier = tier_county
		}
		add = 10
	}
	every_held_title = {
		limit = {
			has_holding_type = church_holding
			tier = tier_county
		}
		add = 5
	}
	min = 10
	max = 500
}

TFE_india_grant_piety_same_religion_value = {
	value = 0
	every_held_title = {
		limit = {
			tier = tier_county
		}
		add = 25
	}
	every_held_title = {
		limit = {
			has_holding_type = church_holding
			tier = tier_county
		}
		add = 10
	}
	min = 25
	max = 500
}


#####################################
# Hero Stone
#####################################
raise_hero_stone_gold_cost = { value = medium_gold_value }
raise_hero_stone_county_preference_cap_value = {
	value = 0

	# Add +1 for every entity in the list.
	every_in_list = {
		list = personally_held_counties_list
		add = 1
	}
	# Cap it out at the max for the event.
	max = 3
}
raise_hero_stone_variant_ancestor_value = {
	value = 0

	# Weight up for hero_stone-celebrating culture.
	if = {
		limit = { culture = { has_cultural_pillar = heritage_dravidian } }
		add = 25
	}
	# Weight up for low popular opinion.
	add = {
		value = this.county_opinion
		multiply = -1
	}
	# Weight down for existing hero_stone.
	if = {
		limit = { exists = this.var:hero_stone_slot_occupied }
		add = -100
	}
}
dharma_hero_stone_duration_value = 50 
dharma_hero_stone_desc_normal_weight_value = 1
dharma_hero_stone_desc_upweight_weight_value = 5
dharma_hero_stone_desc_heavy_upweight_weight_value = 50
dharma_hero_stone_desc_always_upweight_weight_value = 10000

TFE_adopt_child_extra_cost_renown = {
	value = 0
	every_child = {
		subtract = 100
	}
}

TFE_adopt_child_extra_cost_prestige = {
	value = 0
	add = TFE_adopt_child_extra_cost_renown
	multiply = 2.5
}

TFE_adopt_child_extra_cost_prestige_check = {
	value = 0
	every_child = {
		add = 250
	}
}


ecostability_oases = {
	value = 0
	if = {
		limit = {
			government_has_flag = government_is_trade_city_state
		}
		every_held_title = {
			limit = {
				tier= tier_county
			}
			every_county_province = {
				limit = {
					terrain = oasis
				}
				add = 1
			}
		}
		divide = 10
	}
}

ecostability_net_change = {
	value = 0
	add = {
		value = var:ecostability
		desc = "ECOSTAB_CURRENT"
	}
	add = {
		value = monthly_character_income
		desc = "MONTHLY_INCOME_ECOSTAB"
	}
	subtract = {
		value = monthly_character_expenses
		desc = "MONTHLY_EXPENSES_ECOSTAB"
	}
	add = {
		value = ecostability_oases
		desc = "ECOSTAB_OASES_ECOSTAB"
	}
}

form_hre_TFE_county_trigger = {
	value = 0
	every_county_in_region = {
		region = form_the_hre_TFE_ere_region
		add = 1
	}
	multiply = 0.3
}

form_hre_TFE_strength_trigger = {
	value = root.current_military_strength
}