﻿# GORA UI+ — Improved Parliament Graph: seat allocation
# ─────────────────────────────────────────────────────────────────────────────
# All three views retain exactly 300 seats. Expensive aggregate denominators
# are snapshotted once per refresh, and each ranking is produced by one ordered
# range pass (power IGs, alignment IGs, electoral parties, electoral IGs).
#
# Country pointers consumed by the GUI:
#   ipg_power_rank_N_ig                N = 1..12
#   ipg_alignment_rank_N_ig            N = 1..12
#   ipg_electoral_party_rank_N_party    N = 1..8
#   ipg_electoral_ig_rank_N_ig          N = 1..6
#
# Floor-rounding leftovers preserve the original behavior: power/alignment
# assign them to rank 1 and shift later ranges; electoral assigns them to the
# grey catch-all. Every completed view therefore covers seat indices 0..299.
# ─────────────────────────────────────────────────────────────────────────────

# Master entry point — invoked from on_actions in Country scope.
ipg_recalculate_parliament = {
	# A real in-game-day cooldown: overlapping law/election/monthly hooks on
	# the same date are collapsed into one refresh.
	set_variable = { name = ipg_last_refresh_day days = 1 }

	# Snapshot shared denominators once. The old implementation re-ran these
	# aggregate loops for every ranked entity.
	set_variable = {
		name = ipg_cache_total_active_ig_clout
		value = ipg_total_active_ig_clout
	}
	set_variable = {
		name = ipg_cache_total_aligned_population_share
		value = ipg_total_aligned_population_share
	}
	set_variable = {
		name = ipg_cache_total_unaligned_population_share
		value = {
			value = 1
			subtract = var:ipg_cache_total_aligned_population_share
			min = 0
			max = 1
		}
	}
	every_active_party = {
		set_variable = {
			name = ipg_cached_party_clout
			value = ipg_party_total_clout
		}
	}

	ipg_calc_power_structure = yes
	ipg_calc_political_alignment = yes
	ipg_calc_electoral_parliament = yes

	every_active_party = {
		remove_variable = ipg_cached_party_clout
	}
	remove_variable = ipg_cache_total_active_ig_clout
	remove_variable = ipg_cache_total_aligned_population_share
	remove_variable = ipg_cache_total_unaligned_population_share
}

# ═══ 1. POWER STRUCTURE ════════════════════════════════════════════════════
ipg_calc_power_structure = {
	set_variable = { name = ipg_power_seats_assigned value = 0 }
	set_variable = { name = ipg_power_cursor value = 0 }

	remove_variable = ipg_power_rank_1_ig
	remove_variable = ipg_power_rank_2_ig
	remove_variable = ipg_power_rank_3_ig
	remove_variable = ipg_power_rank_4_ig
	remove_variable = ipg_power_rank_5_ig
	remove_variable = ipg_power_rank_6_ig
	remove_variable = ipg_power_rank_7_ig
	remove_variable = ipg_power_rank_8_ig
	remove_variable = ipg_power_rank_9_ig
	remove_variable = ipg_power_rank_10_ig
	remove_variable = ipg_power_rank_11_ig
	remove_variable = ipg_power_rank_12_ig

	# Prevent stale ranges from participating in the leftover shift.
	every_interest_group = {
		remove_variable = power_seats
		remove_variable = power_seat_min
		remove_variable = power_seat_max
		remove_variable = power_share
	}

	if = {
		limit = {
			var:ipg_cache_total_active_ig_clout > 0
			ipg_number_of_seats > 0
		}

		set_variable = { name = ipg_power_rank_index value = 0 }
		ordered_interest_group = {
			limit = { ig_clout > 0 }
			order_by = ig_clout
			min = 0
			# min/max are inclusive: positions 0..11 are the 12 displayed ranks.
			max = 11
			check_range_bounds = no

			if = {
				limit = { prev.var:ipg_power_rank_index = 0 }
				gora_plus_ipg_store_power_rank = { RANK = 1 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 1 }
				gora_plus_ipg_store_power_rank = { RANK = 2 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 2 }
				gora_plus_ipg_store_power_rank = { RANK = 3 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 3 }
				gora_plus_ipg_store_power_rank = { RANK = 4 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 4 }
				gora_plus_ipg_store_power_rank = { RANK = 5 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 5 }
				gora_plus_ipg_store_power_rank = { RANK = 6 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 6 }
				gora_plus_ipg_store_power_rank = { RANK = 7 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 7 }
				gora_plus_ipg_store_power_rank = { RANK = 8 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 8 }
				gora_plus_ipg_store_power_rank = { RANK = 9 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 9 }
				gora_plus_ipg_store_power_rank = { RANK = 10 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 10 }
				gora_plus_ipg_store_power_rank = { RANK = 11 }
			}
			else_if = {
				limit = { prev.var:ipg_power_rank_index = 11 }
				gora_plus_ipg_store_power_rank = { RANK = 12 }
			}
			prev = {
				change_variable = { name = ipg_power_rank_index add = 1 }
			}
		}
		remove_variable = ipg_power_rank_index

		set_variable = {
			name = ipg_power_leftover
			value = {
				value = ipg_number_of_seats
				subtract = var:ipg_power_seats_assigned
				min = 0
			}
		}
		if = {
			limit = {
				var:ipg_power_leftover > 0
				has_variable = ipg_power_rank_1_ig
			}
			var:ipg_power_rank_1_ig = {
				change_variable = { name = power_seats add = prev.var:ipg_power_leftover }
				change_variable = { name = power_seat_max add = prev.var:ipg_power_leftover }
			}
			every_interest_group = {
				limit = {
					has_variable = power_seat_min
					var:power_seat_min > 0
				}
				change_variable = { name = power_seat_min add = prev.var:ipg_power_leftover }
				change_variable = { name = power_seat_max add = prev.var:ipg_power_leftover }
			}
		}
		remove_variable = ipg_power_leftover
	}

	remove_variable = ipg_power_seats_assigned
	remove_variable = ipg_power_cursor
}

# Called in InterestGroup scope by the single ordered range above.
gora_plus_ipg_store_power_rank = {
	set_variable = { name = ipg_tmp_clout value = ig_clout }
	prev = {
		set_variable = { name = ipg_power_rank_$RANK$_ig value = prev }
		set_variable = {
			name = ipg_tmp_seats
			value = {
				value = prev.var:ipg_tmp_clout
				divide = var:ipg_cache_total_active_ig_clout
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_tmp_min value = var:ipg_power_cursor }
		set_variable = {
			name = ipg_tmp_max
			value = {
				value = var:ipg_power_cursor
				add = var:ipg_tmp_seats
				subtract = 1
			}
		}
		set_variable = {
			name = ipg_tmp_share_pct
			value = {
				value = prev.var:ipg_tmp_clout
				divide = var:ipg_cache_total_active_ig_clout
				multiply = 100
			}
		}
		change_variable = { name = ipg_power_seats_assigned add = var:ipg_tmp_seats }
		change_variable = { name = ipg_power_cursor add = var:ipg_tmp_seats }
	}
	set_variable = { name = power_seats value = prev.var:ipg_tmp_seats }
	set_variable = { name = power_seat_min value = prev.var:ipg_tmp_min }
	set_variable = { name = power_seat_max value = prev.var:ipg_tmp_max }
	set_variable = { name = power_share value = prev.var:ipg_tmp_share_pct }
	remove_variable = ipg_tmp_clout
	prev = {
		remove_variable = ipg_tmp_seats
		remove_variable = ipg_tmp_min
		remove_variable = ipg_tmp_max
		remove_variable = ipg_tmp_share_pct
	}
}

# ═══ 2. POLITICAL ALIGNMENT ════════════════════════════════════════════════
ipg_calc_political_alignment = {
	set_variable = { name = ipg_alignment_seats_assigned value = 0 }
	set_variable = { name = ipg_alignment_share_counted value = 0 }
	set_variable = { name = ipg_alignment_cursor value = 0 }

	remove_variable = ipg_alignment_rank_1_ig
	remove_variable = ipg_alignment_rank_2_ig
	remove_variable = ipg_alignment_rank_3_ig
	remove_variable = ipg_alignment_rank_4_ig
	remove_variable = ipg_alignment_rank_5_ig
	remove_variable = ipg_alignment_rank_6_ig
	remove_variable = ipg_alignment_rank_7_ig
	remove_variable = ipg_alignment_rank_8_ig
	remove_variable = ipg_alignment_rank_9_ig
	remove_variable = ipg_alignment_rank_10_ig
	remove_variable = ipg_alignment_rank_11_ig
	remove_variable = ipg_alignment_rank_12_ig
	remove_variable = ipg_alignment_other_seats
	remove_variable = ipg_alignment_other_min
	remove_variable = ipg_alignment_other_max
	remove_variable = ipg_alignment_other_share
	remove_variable = ipg_alignment_unaligned_seats
	remove_variable = ipg_alignment_unaligned_min
	remove_variable = ipg_alignment_unaligned_max
	remove_variable = ipg_alignment_unaligned_share

	every_interest_group = {
		remove_variable = alignment_seats
		remove_variable = alignment_seat_min
		remove_variable = alignment_seat_max
		remove_variable = alignment_share
	}

	if = {
		limit = { ipg_number_of_seats > 0 }

		set_variable = { name = ipg_alignment_rank_index value = 0 }
		ordered_interest_group = {
			limit = { interest_group_population_percentage > 0 }
			order_by = interest_group_population_percentage
			min = 0
			# min/max are inclusive: positions 0..11 are the 12 displayed ranks.
			max = 11
			check_range_bounds = no

			if = {
				limit = { prev.var:ipg_alignment_rank_index = 0 }
				gora_plus_ipg_store_alignment_rank = { RANK = 1 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 1 }
				gora_plus_ipg_store_alignment_rank = { RANK = 2 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 2 }
				gora_plus_ipg_store_alignment_rank = { RANK = 3 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 3 }
				gora_plus_ipg_store_alignment_rank = { RANK = 4 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 4 }
				gora_plus_ipg_store_alignment_rank = { RANK = 5 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 5 }
				gora_plus_ipg_store_alignment_rank = { RANK = 6 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 6 }
				gora_plus_ipg_store_alignment_rank = { RANK = 7 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 7 }
				gora_plus_ipg_store_alignment_rank = { RANK = 8 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 8 }
				gora_plus_ipg_store_alignment_rank = { RANK = 9 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 9 }
				gora_plus_ipg_store_alignment_rank = { RANK = 10 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 10 }
				gora_plus_ipg_store_alignment_rank = { RANK = 11 }
			}
			else_if = {
				limit = { prev.var:ipg_alignment_rank_index = 11 }
				gora_plus_ipg_store_alignment_rank = { RANK = 12 }
			}
			prev = {
				change_variable = { name = ipg_alignment_rank_index add = 1 }
			}
		}
		remove_variable = ipg_alignment_rank_index

		set_variable = {
			name = ipg_alignment_other_share
			value = {
				value = var:ipg_cache_total_aligned_population_share
				subtract = var:ipg_alignment_share_counted
				min = 0
				max = 1
			}
		}
		set_variable = {
			name = ipg_alignment_other_seats
			value = {
				value = var:ipg_alignment_other_share
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_alignment_other_min value = var:ipg_alignment_cursor }
		set_variable = {
			name = ipg_alignment_other_max
			value = {
				value = var:ipg_alignment_cursor
				add = var:ipg_alignment_other_seats
				subtract = 1
			}
		}
		change_variable = { name = ipg_alignment_other_share multiply = 100 }
		change_variable = { name = ipg_alignment_seats_assigned add = var:ipg_alignment_other_seats }
		change_variable = { name = ipg_alignment_cursor add = var:ipg_alignment_other_seats }

		set_variable = {
			name = ipg_alignment_unaligned_share
			value = {
				value = var:ipg_cache_total_unaligned_population_share
				multiply = 100
			}
		}
		set_variable = {
			name = ipg_alignment_unaligned_seats
			value = {
				value = var:ipg_cache_total_unaligned_population_share
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_alignment_unaligned_min value = var:ipg_alignment_cursor }
		set_variable = {
			name = ipg_alignment_unaligned_max
			value = {
				value = var:ipg_alignment_cursor
				add = var:ipg_alignment_unaligned_seats
				subtract = 1
			}
		}
		change_variable = { name = ipg_alignment_seats_assigned add = var:ipg_alignment_unaligned_seats }
		change_variable = { name = ipg_alignment_cursor add = var:ipg_alignment_unaligned_seats }

		set_variable = {
			name = ipg_alignment_leftover
			value = {
				value = ipg_number_of_seats
				subtract = var:ipg_alignment_seats_assigned
				min = 0
			}
		}
		if = {
			limit = {
				var:ipg_alignment_leftover > 0
				has_variable = ipg_alignment_rank_1_ig
			}
			var:ipg_alignment_rank_1_ig = {
				change_variable = { name = alignment_seats add = prev.var:ipg_alignment_leftover }
				change_variable = { name = alignment_seat_max add = prev.var:ipg_alignment_leftover }
			}
			every_interest_group = {
				limit = {
					has_variable = alignment_seat_min
					var:alignment_seat_min > 0
				}
				change_variable = { name = alignment_seat_min add = prev.var:ipg_alignment_leftover }
				change_variable = { name = alignment_seat_max add = prev.var:ipg_alignment_leftover }
			}
			change_variable = { name = ipg_alignment_other_min add = var:ipg_alignment_leftover }
			change_variable = { name = ipg_alignment_other_max add = var:ipg_alignment_leftover }
			change_variable = { name = ipg_alignment_unaligned_min add = var:ipg_alignment_leftover }
			change_variable = { name = ipg_alignment_unaligned_max add = var:ipg_alignment_leftover }
		}
		remove_variable = ipg_alignment_leftover
	}

	remove_variable = ipg_alignment_seats_assigned
	remove_variable = ipg_alignment_share_counted
	remove_variable = ipg_alignment_cursor
}

# Called in InterestGroup scope by the single ordered range above.
gora_plus_ipg_store_alignment_rank = {
	set_variable = {
		name = ipg_tmp_share
		value = interest_group_population_percentage
	}
	prev = {
		set_variable = { name = ipg_alignment_rank_$RANK$_ig value = prev }
		set_variable = {
			name = ipg_tmp_seats
			value = {
				value = prev.var:ipg_tmp_share
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_tmp_min value = var:ipg_alignment_cursor }
		set_variable = {
			name = ipg_tmp_max
			value = {
				value = var:ipg_alignment_cursor
				add = var:ipg_tmp_seats
				subtract = 1
			}
		}
		set_variable = {
			name = ipg_tmp_share_pct
			value = {
				value = prev.var:ipg_tmp_share
				multiply = 100
			}
		}
		change_variable = { name = ipg_alignment_seats_assigned add = var:ipg_tmp_seats }
		change_variable = { name = ipg_alignment_share_counted add = prev.var:ipg_tmp_share }
		change_variable = { name = ipg_alignment_cursor add = var:ipg_tmp_seats }
	}
	set_variable = { name = alignment_seats value = prev.var:ipg_tmp_seats }
	set_variable = { name = alignment_seat_min value = prev.var:ipg_tmp_min }
	set_variable = { name = alignment_seat_max value = prev.var:ipg_tmp_max }
	set_variable = { name = alignment_share value = prev.var:ipg_tmp_share_pct }
	remove_variable = ipg_tmp_share
	prev = {
		remove_variable = ipg_tmp_seats
		remove_variable = ipg_tmp_min
		remove_variable = ipg_tmp_max
		remove_variable = ipg_tmp_share_pct
	}
}

# ═══ 3. ELECTORAL PARLIAMENT (clout-based Party Structure) ════════════════
ipg_calc_electoral_parliament = {
	set_variable = { name = ipg_electoral_cursor value = 0 }

	remove_variable = ipg_electoral_party_rank_1_party
	remove_variable = ipg_electoral_party_rank_2_party
	remove_variable = ipg_electoral_party_rank_3_party
	remove_variable = ipg_electoral_party_rank_4_party
	remove_variable = ipg_electoral_party_rank_5_party
	remove_variable = ipg_electoral_party_rank_6_party
	remove_variable = ipg_electoral_party_rank_7_party
	remove_variable = ipg_electoral_party_rank_8_party
	remove_variable = ipg_electoral_ig_rank_1_ig
	remove_variable = ipg_electoral_ig_rank_2_ig
	remove_variable = ipg_electoral_ig_rank_3_ig
	remove_variable = ipg_electoral_ig_rank_4_ig
	remove_variable = ipg_electoral_ig_rank_5_ig
	remove_variable = ipg_electoral_ig_rank_6_ig
	remove_variable = ipg_electoral_other_seats
	remove_variable = ipg_electoral_other_min
	remove_variable = ipg_electoral_other_max

	every_active_party = {
		remove_variable = electoral_seats
		remove_variable = electoral_seat_min
		remove_variable = electoral_seat_max
	}
	every_interest_group = {
		remove_variable = electoral_seats
		remove_variable = electoral_seat_min
		remove_variable = electoral_seat_max
	}

	if = {
		limit = {
			var:ipg_cache_total_active_ig_clout > 0
			ipg_number_of_seats > 0
		}

		set_variable = { name = ipg_electoral_party_rank_index value = 0 }
		ordered_active_party = {
			limit = { party_has_members = yes }
			order_by = ipg_cached_party_clout_value
			min = 0
			# min/max are inclusive: positions 0..7 are the 8 displayed ranks.
			max = 7
			check_range_bounds = no

			if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 0 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 1 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 1 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 2 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 2 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 3 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 3 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 4 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 4 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 5 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 5 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 6 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 6 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 7 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_party_rank_index = 7 }
				gora_plus_ipg_store_electoral_party_rank = { RANK = 8 }
			}
			prev = {
				change_variable = { name = ipg_electoral_party_rank_index add = 1 }
			}
		}
		remove_variable = ipg_electoral_party_rank_index

		set_variable = { name = ipg_electoral_ig_rank_index value = 0 }
		ordered_interest_group = {
			limit = {
				has_party = no
				is_marginal = no
				ig_clout > 0
			}
			order_by = ig_clout
			min = 0
			# min/max are inclusive: positions 0..5 are the 6 displayed ranks.
			max = 5
			check_range_bounds = no

			if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 0 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 1 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 1 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 2 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 2 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 3 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 3 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 4 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 4 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 5 }
			}
			else_if = {
				limit = { prev.var:ipg_electoral_ig_rank_index = 5 }
				gora_plus_ipg_store_electoral_ig_rank = { RANK = 6 }
			}
			prev = {
				change_variable = { name = ipg_electoral_ig_rank_index add = 1 }
			}
		}
		remove_variable = ipg_electoral_ig_rank_index

		# Catch-all naturally absorbs lower ranks and every flooring deficit.
		set_variable = {
			name = ipg_electoral_other_seats
			value = {
				value = ipg_number_of_seats
				subtract = var:ipg_electoral_cursor
				min = 0
			}
		}
		set_variable = { name = ipg_electoral_other_min value = var:ipg_electoral_cursor }
		set_variable = {
			name = ipg_electoral_other_max
			value = {
				value = var:ipg_electoral_cursor
				add = var:ipg_electoral_other_seats
				subtract = 1
			}
		}
	}

	remove_variable = ipg_electoral_cursor
}

# Called in Party scope by the single ordered party range.
gora_plus_ipg_store_electoral_party_rank = {
	prev = {
		set_variable = { name = ipg_electoral_party_rank_$RANK$_party value = prev }
		set_variable = {
			name = ipg_tmp_seats
			value = {
				value = prev.var:ipg_cached_party_clout
				divide = var:ipg_cache_total_active_ig_clout
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_tmp_min value = var:ipg_electoral_cursor }
		set_variable = {
			name = ipg_tmp_max
			value = {
				value = var:ipg_electoral_cursor
				add = var:ipg_tmp_seats
				subtract = 1
			}
		}
		change_variable = { name = ipg_electoral_cursor add = var:ipg_tmp_seats }
	}
	set_variable = { name = electoral_seats value = prev.var:ipg_tmp_seats }
	set_variable = { name = electoral_seat_min value = prev.var:ipg_tmp_min }
	set_variable = { name = electoral_seat_max value = prev.var:ipg_tmp_max }
	prev = {
		remove_variable = ipg_tmp_seats
		remove_variable = ipg_tmp_min
		remove_variable = ipg_tmp_max
	}
}

# Called in InterestGroup scope by the single ordered independent-IG range.
gora_plus_ipg_store_electoral_ig_rank = {
	set_variable = { name = ipg_tmp_clout value = ig_clout }
	prev = {
		set_variable = { name = ipg_electoral_ig_rank_$RANK$_ig value = prev }
		set_variable = {
			name = ipg_tmp_seats
			value = {
				value = prev.var:ipg_tmp_clout
				divide = var:ipg_cache_total_active_ig_clout
				multiply = ipg_number_of_seats
				floor = yes
			}
		}
		set_variable = { name = ipg_tmp_min value = var:ipg_electoral_cursor }
		set_variable = {
			name = ipg_tmp_max
			value = {
				value = var:ipg_electoral_cursor
				add = var:ipg_tmp_seats
				subtract = 1
			}
		}
		change_variable = { name = ipg_electoral_cursor add = var:ipg_tmp_seats }
	}
	set_variable = { name = electoral_seats value = prev.var:ipg_tmp_seats }
	set_variable = { name = electoral_seat_min value = prev.var:ipg_tmp_min }
	set_variable = { name = electoral_seat_max value = prev.var:ipg_tmp_max }
	remove_variable = ipg_tmp_clout
	prev = {
		remove_variable = ipg_tmp_seats
		remove_variable = ipg_tmp_min
		remove_variable = ipg_tmp_max
	}
}
