﻿# Sums up all relevant skills.
regula_character_total_skills = {
	value = 0
	add = diplomacy
	add = martial
	add = stewardship
	add = intrigue
	add = learning
}

# Counts the number of powerful vassals that are crypto-famuli.
regula_num_covert_powerful_vassals = {
	value = 0
	every_vassal = {
		limit = {
			is_powerful_vassal_of = root
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		add = 1
	}
}

# Counts the number of children that the magister has with this woman.
regula_num_magister_children = {
	value = 0	
	every_child = {
		limit = {
			this.father = global_var:magister_character
		}
		add = 1
	}
}

regula_num_children = {
	value = 0
	every_child = {
		add = 1
	}
}

# Counts the nuber of pregnant wives, concubines, and lovers.
regula_num_pregnant_consorts_and_lovers = {
	value = 0
	every_consort = {
		limit = {
			is_pregnant = yes
		}
		add = 1
	}
	# every_relation = {
	# 	type = lover
	# 	limit = {
	# 		NOT = { primary_spouse = prev }  ### UPDATE - verify code
	# 		is_pregnant = yes
	# 	}
	# 	add = 1
	# }
}

# Calculates the number of concubines with titles. Catches domina too.
regula_num_landed_concubines = {
	value = 0
	every_consort= {
		limit = {
			highest_held_title_tier >= tier_county
			OR = {
				has_trait = paelex
				has_trait = domina
			}
		}
		add = 1
	}
}

regula_num_unlanded_consorts = {
	value = 0
	every_consort= {
		limit = {
			is_landed = no
		}
		add = 1
	}
}

regula_potestas_non_transfunde_cost = {
	value = 0
	every_held_title = {
		if = {
			limit = {
				tier = 1
			}
			add = 100 # Just in case.
		}
		if = {
			limit = {
				tier = 2
			}
			add = 300
		}
		if = {
			limit = {
				tier = 3
			}
			add = 600
		}
		if = {
			limit = {
				tier = 4
			}
			add = 1000
		}
	}
	every_vassal_or_below = { # Vassals count for half.
		limit = {
			highest_held_title_tier = tier_duchy
		}
		add = 300
	}
	every_vassal_or_below = {
		limit = {
			highest_held_title_tier = tier_county
		}
		add = 150
	}

	if = {
		limit = {
			tier_difference = {
				target = scope:actor
				value = -2
			}
		}
		multiply = 0.5
	}
	if = {
		limit = {
			tier_difference = {
				target = scope:actor
				value = -3
			}
		}
		multiply = 0.25
	}
	if = {
		limit = {
			AND = {
				character_is_realm_neighbor = scope:actor
				NOT = {
					character_is_land_realm_neighbor = scope:actor
				}
			}
		}
		multiply = 1.25 # A little pricier if they're not nearby.
	}
	# if = {   ### UPDATE - has_trait triggers register as false, regardless of validity. Not restricted to devoted traits or recipient.
	# 	limit = {
	# 		OR = {
	# 			has_trait = mulsa
	# 			has_trait = paelex # Just in case
	# 			has_trait = domina # Just in case
	# 		}
	# 	}
	# 	multiply = 0.5 # You're also convincing the smallfolk and the minor lords. Having the target on your side isn't everything.
	# }
	if = {
		limit = {
			scope:actor = {
				piety_level = 6
			}
		}
		multiply = 0.5
	}
	if = {
		limit = {
			scope:actor = {
				piety_level = 5
			}
		}
		multiply = 0.75
	}
}