﻿# Called by the settled title-gain observer. The founding ruler seeds the comparison without a crisis.
aureliani_senate_observe_succession_effect = {
	if = {
		limit = { house = { NOT = { has_variable = aureliani_senate_recognized_ruler } } }
		house:house_aureliani = { set_variable = { name = aureliani_senate_recognized_ruler value = root } remove_variable = aureliani_senate_recognition_pending }
	}
	# A recognized ruler returning to office cancels the displaced ruler's hearing.
	else_if = {
		limit = {
			aureliani_senate_recognition_candidate_trigger = yes
			this = house:house_aureliani.var:aureliani_senate_recognized_ruler
			house = { has_variable = aureliani_senate_recognition_pending }
		}
		house:house_aureliani = {
			remove_variable = aureliani_senate_recognition_pending
			remove_variable = aureliani_senate_recognition_hearing_funded
			remove_variable = aureliani_senate_recognition_cooldown
		}
	}
	else_if = {
		limit = {
			aureliani_senate_recognition_candidate_trigger = yes
			NOT = { this = house:house_aureliani.var:aureliani_senate_recognized_ruler }
			NOT = { house = { var:aureliani_senate_recognition_pending = root } }
		}
		house:house_aureliani = {
			if = { limit = { NOT = { has_variable = aureliani_senate_recognition_serial } } set_variable = { name = aureliani_senate_recognition_serial value = 0 } }
			remove_variable = aureliani_senate_recognition_hearing_funded
			remove_variable = aureliani_senate_recognition_cooldown
			set_variable = { name = aureliani_senate_recognition_pending value = root }
			change_variable = { name = aureliani_senate_recognition_serial add = 1 }
		}
	}
}

aureliani_senate_recognition_mark_effect = {
	house:house_aureliani = {
		set_variable = { name = aureliani_senate_recognized_ruler value = root }
		remove_variable = aureliani_senate_recognition_pending
	}
}

aureliani_senate_recognition_funded_hearing_effect = {
	if = {
		limit = { aureliani_senate_recognition_funding_available_trigger = yes gold >= 100 }
		remove_short_term_gold = 100
		house = { set_variable = { name = aureliani_senate_recognition_hearing_funded value = 1 } }
		house:house_aureliani.var:aureliani_senator_1 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_2 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_3 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_4 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_5 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_6 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_7 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_8 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_9 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_10 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_11 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_12 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_13 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_14 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
		house:house_aureliani.var:aureliani_senator_15 ?= { if = { limit = { aureliani_senator_eligible_trigger = yes } add_opinion = { target = root modifier = aureliani_senate_recognition_hearing_opinion years = 1 } } }
	}
}

aureliani_senate_recognition_concession_effect = {
	if = {
		limit = { aureliani_senate_recognition_attempt_trigger = yes aureliani_senate_recognition_concession_ready_trigger = yes }
		every_vassal = { add_opinion = { target = root modifier = aureliani_senate_recognition_concession_opinion years = 5 } }
		add_character_modifier = { modifier = aureliani_senate_recognition_tax_concession years = 5 }
		aureliani_senate_recognition_mark_effect = yes
	}
}

aureliani_senate_recognition_refusal_effect = {
	if = {
		limit = { aureliani_senate_recognition_attempt_trigger = yes prestige >= 150 }
		add_prestige = -150
		every_vassal = { add_opinion = { target = root modifier = aureliani_senate_recognition_refusal_opinion years = 5 } }
		aureliani_senate_recognition_mark_effect = yes
	}
}
