﻿pv_overthrow_threshold_value = {
	value = 0
	# Grab our sum total of powerful vassals.
	liege = {
		every_powerful_vassal = { 
			limit = {
				house ?= {
					OR = {
						is_powerful_family = no
						AND = {
							house_head != prev
							is_powerful_family = yes
						}
					}
				}
			}
			add = 1 
		}
		every_powerful_family = {
			add = 1 
		}
	}
	# Halve it.
	multiply = 0.5
	# Now round down to even us out.
	floor = yes
	# And add +1 to get a simple majority.
	add = 1
	# ... but then subtract one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	if = {
		limit = { 
			OR = {
				AND = {
					is_powerful_vassal = yes 
					house ?= {
						OR = {
							is_powerful_family = no
							AND = {
								house_head != prev
								is_powerful_family = yes
							}
						}
					}
				}
				house ?= {
					house_head = prev
					is_powerful_family = yes				
				}
			}
		}
		add = -1
	}
}

pv_overthrow_tally_value = {
	value = 0
	every_in_list = {
		variable = coup_pv_supporters_list
		limit = {
			OR = {
				AND = {
					is_powerful_vassal_of = root.liege
					house ?= {
						OR = {
							is_powerful_family = no
							AND = {
								house_head != prev
								is_powerful_family = yes
							}
						}
					}
				}
				house ?= {
					house_head = prev
					is_powerful_family = yes
				}
			}
			is_alive = yes
		}
		add = 1
	}
}

# Display versions of the values: these are one higher to adjust for root potentially being in them.
pv_overthrow_threshold_display_value = {
	value = pv_overthrow_threshold_value
	# ... but then add back the one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	if = {
		limit = { 
			OR = {
				AND = {
					is_powerful_vassal = yes
					house ?= {
						OR = {
							is_powerful_family = no
							AND = {
								house_head != prev
								is_powerful_family = yes
							}
						}
					}
				}
				house ?= {
					house_head = prev
					is_powerful_family = yes
				}
			}
		}
		add = 1
	}
}

pv_overthrow_tally_display_value = {
	value = pv_overthrow_tally_value
	# ... and remember to add one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	## We have to separate out the values like this, since the actual list checks powerful vassals and we're not actually in it.
	if = {
		limit = { 
			OR = {
				AND = {
					is_powerful_vassal = yes
					house ?= {
						OR = {
							is_powerful_family = no
							AND = {
								house_head != prev
								is_powerful_family = yes
							}
						}
					}
				}
				house ?= {
					house_head = prev
					is_powerful_family = yes
				}
			}
		}
		add = 1
	}
}












