﻿begin_north_sea_conquer_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 12
		kingdom = 12
		empire = 0
		hegemony = 0
	}
	
	desc = begin_north_sea_conquer_decision_desc
	selection_tooltip = begin_north_sea_conquer_decision_tooltip
	
	is_shown = {
		is_ai = yes
		game_start_date < 1040.1.1
		current_year >= 1000
		current_year <= 1040
		is_north_sea_candidate_ruler = yes
		can_be_histmod_conqueror = yes
		sub_realm_size >= 5
		NOR = {
			has_game_rule = no_conquerors_frequency
			has_game_rule = no_north_sea_empire
			can_claim_north_sea_empire = yes
			any_independent_ruler = {
				this != root
				is_north_sea_candidate_ruler = yes
				OR = {
					has_trait = conqueror
					has_character_modifier = ai_weak_conqueror_modifier
					is_ai = no
					can_claim_north_sea_empire = yes
					AND = {
						can_be_histmod_conqueror = yes
						max_military_strength > root.max_military_strength
					}
				}
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_ai_adult = yes
	}
	
	effect = {
		add_gold = 500
		add_prestige = 800
		
		# start the histmod conqueror story
		add_character_flag = histmod_seeking_north_sea
		create_story = histmod_conqueror_story_cycle
		every_vassal = {
			limit = { has_vassal_stance = glory_hound }
			add_opinion = {
				modifier = approving_opinion
				target = root
				opinion = 20
			}
		}
		every_vassal = {
			limit = { has_vassal_stance = parochial }
			add_opinion = {
				modifier = disapproving_opinion
				opinion = -20
				target = root
			}
		}
		spawn_army = {
			name = harald_vestfold_troops_name
			levies = 2000
			men_at_arms = {
				type = huscarl
				stacks = 5
			}
			men_at_arms = {
				type = armored_footmen
				stacks = 5
			}
			location = root.capital_province
			origin = root.capital_province
			inheritable = yes
			uses_supply = no
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_county
	}
	
	ai_will_do = {
		base = 100
		modifier = {
			factor = 0
			can_execute_decision = norse_claim_england_decision
		}
		modifier = {
			factor = 0
			gold < 0
		}
	}
}

begin_northern_isles_war_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_varangian_guard.dds"
	}
	decision_group_type = major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 24
		empire = 0
		hegemony = 0
	}

	desc = begin_northern_isles_war_decision_desc
	selection_tooltip = begin_northern_isles_war_decision_tooltip
	
	is_shown = {
		has_title = title:k_norway
		highest_held_title_tier = tier_kingdom
		has_culture = culture:norse
		is_landed = yes
		current_year < 1000
		government_has_flag = government_is_tribal
		OR = {
			title:c_orkney = { is_appropriate_northern_isles_target = yes }
			title:c_shetland = { is_appropriate_northern_isles_target = yes }
		}
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_adult = yes
		top_liege = this
	}
	
	effect = {
		if = {
			limit = {
				title:c_shetland = { is_appropriate_northern_isles_target = yes }
			}
			title:c_shetland = {
				save_scope_as = target_county
				holder.top_liege = { save_scope_as = target }
			}
		}
		else = {
			title:c_orkney = {
				save_scope_as = target_county
				holder.top_liege = { save_scope_as = target }
			}
		}
		scope:target_county = {
			set_variable = { name = had_isles_invasion value = yes }
		}
		
		if = {
			limit = {
				root = { is_ai = yes }
				scope:target = {
					is_ai = yes
					top_liege = this
					has_culture = culture:norse
					capital_county.kingdom = title:k_norway
					highest_held_title_tier < tier_kingdom
				}
			}
			subjugates_then_vassalizes_effect = { SUBJUGATOR = root TARGET = scope:target }
		}
		else = {
			start_war = {
				casus_belli = county_conquest_cb
				target = scope:target
				target_title = scope:target_county
			}
			if = {
				limit = {
					scope:target_county.holder = { top_liege = this }
				}
				add_prestige = 250
				add_gold = 100
			}
			else = {
				add_prestige = 500
				add_gold = 200
				if = {
					limit = { is_ai = yes }
					spawn_army = {
						name = event_troop_default_name
						men_at_arms = {
							type = huscarl
							stacks = 3
							inheritable = no
						}
						location = root.capital_province
						origin = root.capital_province
					}
				}
			}
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_duchy
		is_available_ai_adult = yes
	}
	
	ai_will_do = {
		base = 20
		modifier = {
			current_year > 900
			add = 80
		}
		modifier = {
			current_year < 875
			factor = 0
		}
		modifier = {
			factor = 0
			current_military_strength < eighty_percent_of_max_military_strength
		}
		modifier = {
			factor = 0
			gold < 50
		}
		modifier = {
			factor = 0
			has_ongoing_grand_activity_trigger = yes
		}
	}
}

settle_the_northern_isles_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_recruitment.dds"
	}

	sort_order = 200
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 0
		hegemony = 0
	}

	desc = settle_the_northern_isles_decision_desc
	selection_tooltip = settle_the_northern_isles_decision_tooltip
	
	is_shown = {
		has_title = title:k_norway
		highest_held_title_tier = tier_kingdom
		has_culture = culture:norse
		is_landed = yes
		government_has_flag = government_is_tribal
		
		title:c_orkney = {
			NOT = { culture = culture:norse }
			trigger_if = {
				limit = {
					holder = { is_ai = no }
				}
				holder = root
			}
		}
		title:c_shetland = {
			NOT = { culture = culture:norse }
			trigger_if = {
				limit = {
					holder = { is_ai = no }
				}
				holder = root
			}
		}
		
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:settle_the_northern_isles_decision
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_at_war = no
		top_liege = this
		
		trigger_if = {
			limit = {
				title:c_orkney.holder = {
					OR = {
						is_ai = yes
						this = root
					}
				}
			}
			title:c_orkney.holder.top_liege = root
		}
		trigger_if = {
			limit = {
				title:c_shetland.holder = {
					OR = {
						is_ai = yes
						this = root
					}
				}
			}
			title:c_shetland.holder.top_liege = root
		}
	}
	
	effect = {
		# can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:settle_the_northern_isles_decision
		}
		add_prestige = 500
		
		title:c_orkney = {
			if = {
				limit = { holder.top_liege = root }
				set_county_culture = culture:norse
				set_county_faith = root.faith
			}
		}
		title:c_shetland = {
			if = {
				limit = { holder.top_liege = root }
				set_county_culture = culture:norse
				set_county_faith = root.faith
			}
		}
		
		# pick out a ruler to take them
		if = {
			limit = {
				character:186009 = { can_receive_northern_islands = yes } # Torf-Einarr
			}
			character:186009 = { save_scope_as = recipient }
		}
		else_if = {
			limit = {
				character:186004 = { can_receive_northern_islands = yes } # Rognvald
			}
			character:186009 = { save_scope_as = recipient }
		}
		else_if = {
			limit = {
				any_in_global_list = {
					variable = western_scandinavian_adventurer_list
					count >= 1
					can_receive_northern_islands = yes
					NOT = { has_character_flag = prioritised_scandinavian_adventurer }
				}
			}
			ordered_in_global_list = {
				variable = western_scandinavian_adventurer_list
				limit = {
					can_receive_northern_islands = yes
					is_landed = no
					NOT = { has_character_flag = prioritised_scandinavian_adventurer }
				}
				order_by = {
					value = scandinavian_adventurer_priority_value
					if = {
						limit = { has_trait = bastard }
						add = 100
					}
					if = {
						limit = { is_close_or_extended_family_of = root }
						add = 50
					}
					if = {
						limit = { has_government = landless_adventurer_government }
						add = 50
					}
				}
				save_scope_as = recipient
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = histmod_western_warrior_character
				save_scope_as = scandi_adventurer
				after_creation = {
					title:c_orkney = { save_scope_as = adventurer_target }
					scope:scandi_adventurer = {
						save_scope_as = recipient
						scandi_adventurer_family_check = yes
					}
				}
			}
		}
	
		scope:recipient = {
			if = {
				limit = { has_government = landless_adventurer_government }
				root = {
					save_scope_as = actor
					save_scope_as = adventurer
				}
				if = {
					limit = {
						OR = {
							NOT = { exists = title:d_northern_isles.holder }
							title:d_northern_isles.holder.top_liege = root
						}
					}
					title:d_northern_isles = { add_to_list = offered_titles }
				}
				if = {
					limit = { title:c_orkney.holder.top_liege = root }
					title:c_orkney = { add_to_list = offered_titles }
				}
				if = {
					limit = { title:c_shetland.holder.top_liege = root }
					title:c_shetland = { add_to_list = offered_titles }
				}
				ordered_in_list = {
					list = offered_titles
					save_scope_as = new_primary_title
				}
				save_scope_value_as = {
					name = negotiate_settlement_legitimacy_cost
					value = 50
				}
				show_as_tooltip = { negotiate_settlement_interaction_effect = yes }
				scope:actor = { trigger_event = ep3_laamps.0300 }
			}
			else = {
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				if = {
					limit = { title:c_orkney.holder.top_liege = root }
					title:c_orkney = {
						change_title_holder = {
							holder = scope:recipient
							change = scope:change
						}
					}
				}
				if = {
					limit = { title:c_shetland.holder.top_liege = root }
					title:c_shetland = {
						change_title_holder = {
							holder = scope:recipient
							change = scope:change
						}
					}
				}
				if = {
					limit = {
						OR = {
							NOT = { exists = title:d_northern_isles.holder }
							title:d_northern_isles.holder.top_liege = root
						}	
					}
					title:d_northern_isles = {
						change_title_holder = {
							holder = scope:recipient
							change = scope:change
						}
					}
				}
				resolve_title_and_vassal_change = scope:change
			}
			add_opinion = { target = root modifier = pleased_opinion opinion = 100 }
			hidden_effect = {
				add_prestige = 500
				add_gold = 100
				reverse_add_opinion = { target = root  modifier = respect_opinion opinion = 100 }
				if = {
					limit = { exists = scope:recipient.capital_province }
					spawn_army = {
						men_at_arms = {
							type = huscarl
							stacks = 3
						}
						men_at_arms = {
							type = bondi
							stacks = 2
						}
						men_at_arms = {
							type = vigmen
							stacks = 2
						}
						inheritable = yes
						location = scope:recipient.capital_province
						name = scandi_adventurer_event_troops
					}
				}
			}
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_duchy
	}
	
	ai_will_do = {
		base = 100
	}
}

norse_claim_england_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 24
		empire = 0
		hegemony = 0
	}

	desc = norse_claim_england_decision_desc
	selection_tooltip = norse_claim_england_decision_tooltip

	is_shown = {
		is_ai = yes
		top_liege = this
		game_start_date < 1050.1.1
		current_year >= 1000
		current_year < 1050
		culture = { has_cultural_pillar = heritage_north_germanic }
		can_claim_north_sea_empire = yes
		title:k_england = {
			is_contested = no
			holder ?= {
				is_ai = yes
				top_liege = this
				has_no_war_preventing_relation = yes
				NOT = {
					culture = { has_cultural_pillar = heritage_north_germanic }
				}
			}
		}
		NOR = {
			title:k_danelaw = { exists = holder }
			has_game_rule = no_invasion_england_north_sea
			has_game_rule = no_north_sea_empire
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_secured_high_kingdom_north_sea
			}
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_norse_claim_england_decision
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_adult = yes
		highest_held_title_tier = tier_kingdom
	}

	effect = {
		# can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_norse_claim_england_decision
		}
		
		if = {
			limit = { NOT = { has_claim_on = title:k_england } }
			add_unpressed_claim = title:k_england
		}
		start_war = {
			casus_belli = north_sea_conquest_cb
			target = title:k_england.holder
			claimant = root
			target_title = title:k_england
		}
		if = {
			limit = { title:k_england.holder.strength_with_relevant_allies_vs_root_value > root.strength_with_relevant_allies_vs_england_value }
			spawn_army = {
				levies = {
					add = {
						add = title:k_england.holder.strength_with_relevant_allies_vs_root_value
						subtract = root.strength_with_relevant_allies_vs_england_value
						min = 1000
					}
				}
				inheritable = no
				uses_supply = no
				location = root.capital_province
				origin = root.capital_province
				name = event_troop_default_name
			}
		}
		spawn_army = {
			name = event_troop_default_name
			men_at_arms = {
				type = huscarl
				stacks = 5
				inheritable = yes
			}
			location = root.capital_province
			origin = root.capital_province
		}
		add_gold = 1000
		add_prestige = 1000
	}

	ai_potential = {
		is_landed = yes
		culture = { has_cultural_pillar = heritage_north_germanic }
	}

	ai_will_do = {
		base = 100
		modifier = {
			factor = 0
			OR = {
				days_of_continuous_peace < 90
				current_military_strength < eighty_percent_of_max_military_strength
			}
			current_year < 1025
		}
		modifier = {
			factor = 0
			title:k_england.holder.strength_with_relevant_allies_vs_root_seventy_five_percent_value > root.strength_with_relevant_allies_vs_england_value
		}
		modifier = {
			factor = 0
			ai_boldness < 0
		}
	}
}

norse_resist_scandinavia_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_varangian_guard.dds"
	}
	decision_group_type = major
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 24
		kingdom = 12
		empire = 0
		hegemony = 0
	}

	desc = norse_resist_scandinavia_decision_desc
	selection_tooltip = norse_resist_scandinavia_decision_tooltip
	
	is_shown = {
		is_ai = yes
		game_start_date < 1000.1.1
		current_year < 1000
		government_has_flag = government_is_tribal
		culture = { has_cultural_pillar = heritage_north_germanic }
		is_independent_ruler = no
		is_powerful_vassal = yes
		exists = capital_province
		liege = {
			is_ai = yes
			OR = {
				primary_title = title:e_scandinavia
				AND = {
					primary_title.tier = tier_kingdom
					primary_title.empire = title:e_scandinavia
				}
			}
			NOR = {
				has_character_flag = recent_independence_faction_war
				liege.capital_county.kingdom = root.capital_county.kingdom
			}
		}
		NOR = {
			has_character_modifier = ach_intent_faction_joining_prevention_modifier
			has_character_flag = norse_resisting_scandinavia
		}
	}
	
	is_valid_showing_failures_only = {
		is_physically_able_adult = yes
		is_at_war = no
		liege = {
			NOR = {
				has_relation_friend = root
				has_relation_lover = root
				is_child_of = root
				is_consort_of = root
				any_consort = { is_close_family_of = root }
				primary_heir ?= root
				root = { has_truce = prev }
				any_warden_hostage = { is_close_family_of = root }
				any_close_family_member = { is_hostage_of = root }
				AND = {
					exists = root.faith.religious_head
					this = root.faith.religious_head
				}
			}
		}
	}
	
	effect = {
		add_character_flag = norse_resisting_scandinavia
		# break any current alliance
		if = {
			limit = { is_allied_to = root.liege }
			break_alliance = root.liege
		}
		# make them hate each other
		if = {
			limit = {
				can_set_relation_rival_trigger = { CHARACTER = root.liege }
			}
			set_random_rivalry_reason = {
				TARGET = root.liege
				RELATION = rival
			}
		}
		else = {
			add_opinion = { target = liege modifier = envy_opinion opinion = -100 }
			reverse_add_opinion = { target = liege modifier = disrespect_opinion opinion = -100 }
		}
		# give the vassal a boost
		add_gold = 500
		add_prestige = 800
		if = {
			limit = { has_fp1_dlc_trigger = yes }
			spawn_army = {
				name = varangian_novgorod_troops_name
				levies = 1000
				men_at_arms = {
					type = huscarl
					stacks = 5
				}
				men_at_arms = {
					type = varangian_veterans
					stacks = 5
				}
				men_at_arms = {
					type = armored_footmen
					stacks = 3
				}
				location = root.capital_province
				origin = root.capital_province
				inheritable = no
				uses_supply = no
			}
		}
		else = {
			spawn_army = {
				name = varangian_novgorod_troops_name
				levies = 1000
				men_at_arms = {
					type = huscarl
					stacks = 5
				}
				men_at_arms = {
					type = armored_footmen
					stacks = 5
				}
				location = root.capital_province
				origin = root.capital_province
				inheritable = no
				uses_supply = no
			}
		}
	}
	
	ai_potential = {
		is_landed = yes
		highest_held_title_tier > tier_county
	}
	
	ai_will_do = {
		base = 0
		modifier = {
			add = 100
			OR = {
				has_relation_rival = liege
				has_trait = ambitious
				NOT = { faith = liege.faith }
				liege = {
					any_targeting_faction = {
						faction_is_type = independence_faction
						OR = {
							any_faction_member = { this = root }
							root = { can_join_faction = prev }
						}
					}
				}
			}
		}
		modifier = {
			add = 50
			NOT = { faith = liege.faith }
		}
		modifier = {
			add = 50
			NOT = { culture = liege.culture }
		}
		modifier = {
			add = 20
			is_sibling_of = liege
		}
		ai_value_modifier = {
			ai_greed = 1.0
			ai_boldness = 1.0
			ai_rationality = -0.5
			ai_energy = 0.5
		}
		modifier = {
			factor = 0.5
			house = liege.house
		}
		# we're not trying to prompt liberty/claimant wars
		modifier = {
			factor = 0
			liege = {
				any_targeting_faction = {
					OR = {
						faction_is_type = claimant_faction
						faction_is_type = liberty_faction
					}
					any_faction_member = { this = root }
				}
			}
		}
	}
}

