﻿is_rurikid_candidate_ruler = {
	top_liege = this
	is_landed = yes
	capital_county.empire ?= title:e_russia
	government_has_flag = government_is_tribal
	OR = {
		highest_held_title_tier = tier_duchy
		highest_held_title_tier = tier_kingdom
	}
	OR = {
		dynasty = { this = dynasty:705 } #Rurikid
		AND = {
			is_ai = yes
			ai_boldness >= high_positive_ai_value
			OR = {
				culture = culture:norse
				dynasty = { has_dynasty_modifier = settled_norse_dynasty_modifier }
			}
		}
	}
	NOR = {
		title:e_russia = { exists = holder }
		title:e_russia = { exists = previous_holder }
	}
}

is_rurikid_subjugation_target = {
	top_liege = this
	is_landed = yes
	# their primary title lies within Russia
	exists = capital_county
	capital_county.empire = title:e_russia
	# their realm is smaller
	sub_realm_size < $SUBJUGATOR$.sub_realm_size
	highest_held_title_tier >= tier_county
	highest_held_title_tier <= $SUBJUGATOR$.highest_held_title_tier
	# they are also tribal
	government_has_flag = government_is_tribal
	NOR = {
		government_has_flag = can_not_be_vassal_or_liege
		any_held_title = {
			tier = $SUBJUGATOR$.highest_held_title_tier
			is_titular = yes
		}
		any_held_title = {
			tier = $SUBJUGATOR$.highest_held_title_tier
			count > 1
		}
		has_opinion_modifier = {
			modifier = demanded_my_subjugation_opinion
			target = $SUBJUGATOR$
		}
	}
}

is_rurikid_county_target = {
	empire = title:e_russia
	is_neighbor_to_realm = root
	is_contested = no
	duchy = { is_contested = no }
}

is_better_rurikid_county_target = {
	kingdom = {
		OR = {
			this = title:k_ruthenia
			this = title:k_novgorod
			this = title:k_white_rus
		}
	}
	is_neighbor_to_realm = root
	is_contested = no
	duchy = { is_contested = no }
}

is_appropriate_rurikid_war_target = {
	is_ai = yes
	save_temporary_scope_as = target
	OR = {
		root.strength_with_relevant_allies_vs_target_value > scope:target.one_and_a_half_times_current_strength_with_relevant_allies_vs_root
		AND = {
			has_game_rule = yes_full_stronger_rurikid
			primary_title = { this = title:e_caspian-pontic_steppe }
			NOT = {	
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:had_rurikid_khazaria_war
				}
			}
		}
	}
	any_realm_county = { is_rurikid_county_target = yes }
	has_no_war_preventing_relation = yes
	OR = {
		NOT = { culture = culture:mogyer }
		title:k_hungary = { holder.culture = culture:mogyer }
	}
	OR = {
		NOT = {
			is_rurikid_subjugation_target = { SUBJUGATOR = root }
		}
		is_at_war = yes
	}
}

