﻿is_european_norway_denmark = {
	OR = {
		this = title:d_viken
		this = title:d_agder
		this = title:d_vestlandi
		this = title:d_trandalog
		this = title:d_dalir
		this = title:d_halogaland
		this = title:d_jamtland
		this = title:d_sjaelland
		this = title:d_skane
		this = title:d_jylland
		this = title:d_slesvig
	}
}

is_north_sea_candidate_ruler = {
	top_liege = this
	is_landed = yes
	highest_held_title_tier > tier_county
	NOT = { highest_held_title_tier > tier_kingdom }
	culture = { has_cultural_pillar = heritage_north_germanic }
	OR = {
		government_has_flag = government_is_tribal
		government_has_flag = government_is_feudal
	}
	exists = capital_county
	capital_county = {
		duchy = { is_european_norway_denmark = yes }
	}
}

is_appropriate_north_sea_war_target = {
	is_ai = yes
	any_neighboring_and_across_water_top_liege_realm_owner = { this = root }
	has_no_war_preventing_relation = yes
	save_temporary_scope_as = target
	root.strength_with_relevant_allies_vs_target_character_value > scope:target_character.strength_with_relevant_allies_vs_root_value
	NOR = {
		dynasty = root.dynasty
		any_ally = {
			is_ruler = yes
			OR = {
				dynasty = root.dynasty
				has_no_war_preventing_relation = no
			}
		}
	}
}

can_claim_north_sea_empire = {
	highest_held_title_tier = tier_kingdom
	OR = {
		primary_title = title:k_denmark
		primary_title = title:k_norway
	}
	trigger_if = {
		limit = {
			primary_title = title:k_denmark
			NOT = { has_title = title:k_norway }
			exists = title:k_norway.holder
		}
		sub_realm_size > title:k_norway.holder.sub_realm_size
	}
	trigger_if = {
		limit = {
			primary_title = title:k_norway
			NOT = { has_title = title:k_denmark }
			exists = title:k_denmark.holder
		}
		sub_realm_size > title:k_denmark.holder.sub_realm_size
	}
	OR = {
		has_title = title:k_denmark
		sub_realm_size >= 30
		any_sub_realm_county = {
			count > 7
			duchy = {
				OR = {
					this = title:d_sjaelland
					this = title:d_skane
					this = title:d_jylland
					this = title:d_slesvig
				}
			}
		}
	}
	OR = {
		has_title = title:k_norway
		sub_realm_size >= 30
		any_sub_realm_county = {
			count > 12
			duchy = {
				OR = {
					this = title:d_viken
					this = title:d_agder
					this = title:d_vestlandi
					this = title:d_trandalog
					this = title:d_dalir
					this = title:d_halogaland
					this = title:d_jamtland
				}
			}
		}
	}
}

is_appropriate_northern_isles_target = {
	is_contested = no
	NOT = { has_variable = had_isles_invasion }
	holder = {
		is_ai = yes
		NOT = { top_liege = root }
		has_no_war_preventing_relation = yes
		top_liege = {
			has_no_war_preventing_relation = yes
			save_temporary_scope_as = target
			root.strength_with_relevant_allies_vs_target_value > scope:target.one_and_a_half_times_current_strength_with_relevant_allies_vs_root
		}
	}
}

can_receive_northern_islands = {
	is_alive = yes
	is_male = yes
	is_adult = yes
	basic_is_available_ai = yes
	has_culture = root.culture
	faith = root.faith
	NOT = { has_relation_rival = root }
	OR = {
		age <= 40
		any_child = {
			is_male = yes
			NOT = { has_trait = bastard }
			age >= 10
		}
	}
	trigger_if = {
		limit = { is_ruler = yes }
		is_at_war = no
		OR = {
			has_government = landless_adventurer_government
			top_liege = root
		}
	}
	trigger_else_if = {
		limit = { is_courtier = yes }
		liege = {
			is_ai = yes
			top_liege = root
		}
	}
	trigger_else = {
		always = yes
	}
}

