﻿french_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 = 12
		kingdom = 0
		empire = 0
		hegemony = 0
	}

	desc = french_claim_england_decision_desc
	selection_tooltip = french_claim_england_decision_tooltip

	is_shown = {
		is_ai = yes
		game_start_date <= 1066.1.1
		current_year >= 1050
		culture = { has_cultural_pillar = heritage_frankish }
		trigger_if = {
			limit = { has_game_rule = normandy_always_invades_england }
			has_title = title:d_normandy
		}
		trigger_else = {
			OR = {
				has_title = title:d_normandy
				has_title = title:d_brittany
				has_title = title:d_flanders
			}
		}
		title:k_england = {
			is_contested = no
			holder ?= {
				is_ai = yes
				top_liege = this
				faith.religion = root.faith.religion
				has_no_war_preventing_relation = yes
			}
		}
		OR = {
			top_liege = this
			NOT = { has_realm_law = crown_authority_3 }
			top_liege = { is_ai = yes }
		}
		NOR = {
			has_game_rule = no_invasion_england
			any_liege_or_above = {
				is_allied_to = title:k_england.holder
			}			
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_french_claim_england_decision
			}
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:embrace_english_culture_decision
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_available_adult = yes
		has_short_disease_trigger = no
		has_any_aging_trait = no
		highest_held_title_tier = tier_duchy
	}

	effect = {
		# can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_french_claim_england_decision
		}
		
		if = {
			limit = { NOT = { has_claim_on = title:k_england } }
			add_unpressed_claim = title:k_england
		}
		start_war = {
			casus_belli = norman_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 = yes
				location = root.capital_province
				name = event_troop_default_name
			}
		}
		if = {
			limit = {
				culture = { has_innovation = innovation_mangonel }
			}
			spawn_army = {
				levies = 1500
				men_at_arms = {
					type = armored_footmen
					stacks = 5
				}
				men_at_arms = {
					type = armored_horsemen
					stacks = 3
				}
				men_at_arms = {
					type = mangonel
					stacks = 3
				}
				inheritable = yes
				location = root.capital_province
				name = event_troop_default_name
			}
		}
		else = {
			spawn_army = {
				levies = 1500
				men_at_arms = {
					type = armored_footmen
					stacks = 5
				}
				men_at_arms = {
					type = armored_horsemen
					stacks = 3
				}
				men_at_arms = {
					type = onager
					stacks = 3
				}
				inheritable = yes
				location = root.capital_province
				name = event_troop_default_name
			}
		}
		add_gold = 1000
	}

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

	ai_will_do = {
		base = 100
		modifier = {
			factor = 0
			days_of_continuous_peace < 180
		}
		modifier = {
			factor = 0
			NOT = { has_game_rule = normandy_always_invades_england }
			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
		}
	}
}

summon_norman_bannermen_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_varangian_guard.dds"
	}
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 24
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}
	
	sort_order = 75
	
	desc = summon_norman_bannermen_decision_desc
	selection_tooltip = summon_norman_bannermen_decision_tooltip
	
	is_shown = {
		has_dynasty = yes
		highest_held_title_tier >= tier_county
		culture = { has_cultural_tradition = tradition_ep3_audacious_cadets }
		trigger_if = {
			limit = { has_government = landless_adventurer_government }
			exists = domicile.domicile_location
		}
		trigger_else = {
			exists = capital_county
		}
		NOT = { has_variable = summoned_norman_bannermen }
		OR = {
			top_liege = this
			NOT = { culture = liege.culture }
		}
	}
	
	is_valid_showing_failures_only = {
		is_adult = yes
		is_imprisoned = no
		is_incapable = no
	}
	
	cost = {
		prestige = {
			if = {
				limit = { is_ai = no }
				add = 250
			}
		}
	}
	
	effect = {
		set_variable = { name = summoned_norman_bannermen value = yes }
		if = {
			limit = { has_government = landless_adventurer_government }
			domicile.domicile_location = { save_scope_as = home_capital }
		}
		else = {
			capital_province = { save_scope_as = home_capital }
		}
		custom_tooltip = summon_norman_bannermen_tt
		hidden_effect = {
			spawn_army = {
				men_at_arms = {
					type = pikemen_unit
					stacks = root.norman_summoned_bannermen_stacks
				}
				men_at_arms = {
					type = armored_horsemen
					stacks = root.norman_summoned_bannermen_stacks
				}
				inheritable = no
				uses_supply = no
				location = scope:home_capital
				name = spawned_norman_bannermen_name
			}
			save_temporary_scope_as = new_ruler
			create_character = {
				template = new_commander_character
				gender_female_chance = scandi_commander_female_chance
				employer = scope:new_ruler
				faith = scope:new_ruler.faith
				culture = scope:new_ruler.culture
				prowess = { medium_skill_rating high_skill_rating }
				save_scope_as = new_commander
				after_creation = {
					spawned_soldier_traits_effect = yes
				}
			}
			send_interface_message = {
				type = event_generic_good_with_text
				title = histmod.new_commander.title
				desc = histmod.new_commander.tt
				left_icon = scope:new_commander
			}
			create_character = {
				template = new_commander_character
				gender_female_chance = scandi_commander_female_chance
				employer = scope:new_ruler
				faith = scope:new_ruler.faith
				culture = scope:new_ruler.culture
				prowess = { medium_skill_rating high_skill_rating }
				save_scope_as = new_commander
				after_creation = {
					spawned_soldier_traits_effect = yes
				}
			}
			send_interface_message = {
				type = event_generic_good_with_text
				title = histmod.new_commander.title
				desc = histmod.new_commander.tt
				left_icon = scope:new_commander
			}
		}
	}
	
	ai_potential = {
		is_ruler = yes
	}
	
	ai_will_do = {
		base = 0
		modifier = {
			add = 25
			prestige_level >= high_prestige_level
		}
		modifier = {
			add = 25
			prestige_level >= very_high_prestige_level
		}
		modifier = {
			add = 50
			prestige_level = max_prestige_level
		}
		modifier = {
			add = 100
			is_at_war = yes
			OR = {
				any_character_war = {
					primary_attacker = root
					primary_defender = { strength_with_relevant_allies_vs_root_seventy_five_percent_value > root.strength_with_relevant_allies_value }
				}
				any_character_war = {
					primary_defender = root
					primary_attacker = { strength_with_relevant_allies_vs_root_seventy_five_percent_value > root.strength_with_relevant_allies_value }
				}
			}
		}
	}
}

rollo_claim_normandy_decisison = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_varangian_guard.dds"
	}
	decision_group_type = adventurer
	sort_order = 350
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 12
		kingdom = 0
		empire = 0
		hegemony = 0
	}
	
	desc = rollo_claim_normandy_decisison_desc
	selection_tooltip = rollo_claim_normandy_decisison_tooltip
	
	is_shown = {
		has_government = landless_adventurer_government
		has_character_flag = is_rollo
		game_start_date = 867.1.1
		current_year <= 925
		culture = {
			NOT = { has_cultural_era_or_later = culture_era_early_medieval }
			this = culture:norse
		}
		title:c_rouen = {
			culture = culture:french
			holder = { is_ai = yes }
			holder.top_liege = {
				is_ai = yes
				highest_held_title_tier > tier_duchy
			}
		}
		OR = {
			NOT = { has_character_modifier = histmod_save_for_planned_war }
			is_ai = no
		}
		NOR = {
			has_character_flag = already_attempted_scandi_invasion
			has_game_rule = no_forced_normandy_invasion
			AND = {
				has_game_rule = rollo_exists_vanilla
				exists = global_var:is_RICE_loaded_global_variable
			}
		}
	}
	
	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { has_game_rule = rollo_exists_vanilla }
			custom_tooltip = {
				text = year_is_past_880_tt
				current_year >= 880
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = year_is_past_900_tt
				current_year >= 900
			}
		}
		is_available_adult = yes
		is_at_war = no
		has_raised_armies = no
		custom_description = {
			text = "is_not_bankrupt"
			gold > 0
		}
		title:c_rouen.holder = { save_temporary_scope_as = target_holder }
		NOR = {
			is_allied_to = scope:target_holder
			is_allied_to = scope:target_holder.top_liege
			has_truce = scope:target_holder.holder
			has_truce = scope:target_holder.top_liege
		}
		trigger_if = {
			limit = { is_ai = no }
			custom_tooltip = {
				text = not_with_range_normandy_liege_tt
				in_diplomatic_range = scope:target_holder.top_liege
			}
		}
		trigger_if = {
			limit = { is_married = yes }
			patrilinear_marriage = yes
		}
		trigger_else = {
			can_marry_common_trigger = yes
		}
		custom_description = {
			text = camped_in_target_realm
			subject = title:c_rouen.holder.top_liege
			exists = domicile.domicile_location
			domicile.domicile_location.county.holder = {
				NOR = {
					this = title:c_rouen.holder.top_liege
					any_liege_or_above = { this = title:c_rouen.holder.top_liege }
				}
			}
		}
		custom_description = {
			text = attacked_recently_by_scandi_adventurers
			subject = title:c_rouen.holder
			NOT = {
				title:c_rouen.holder.top_liege = {
					any_character_war = {
						OR = {
							using_cb = fp1_scandi_adventurer_conquest
							using_cb = histmod_laamp_adventurer_duchy_invasion
						}
					}
				}
			}
			trigger_if = {
				limit = { current_year < 910 }
				NOT = {
					title:c_rouen.holder = {
						OR = {
							has_character_modifier = fp1_reprieve_from_sa_modifier
							any_liege_or_above = { has_character_modifier = fp1_reprieve_from_sa_modifier }
						}
					}
				}
			}
		}
		trigger_if = {
			limit = { has_variable_list = subjugation_offer_under_consideration }
			custom_description = {
				text = is_not_considering_offer_of_subjugation
				NOT = {
					is_target_in_variable_list = {
						name = subjugation_offer_under_consideration
						target = title:c_rouen.holder.top_liege
					}
				}
			}
		}
		title:c_rouen.holder = {
			NOR = {
				culture = { has_cultural_pillar = heritage_north_germanic }
				has_culture = culture:norman
				has_character_modifier = embraced_local_traditions_modifier
				dynasty = { has_dynasty_modifier = settled_norse_dynasty_modifier }
			}
			top_liege = {
				trigger_if = {
					limit = { is_imprisoned = yes }
					NOT = { imprisoner = root }
				}
				NOT = { has_strong_hook = root }
				OR = {
					is_ai = yes
					AND = {
						is_ai = no
						sub_realm_size >= 8
					}
				}
			}
		}
	}
	
	cost = {
		prestige = {
			value = 500
			if = {
				limit = { is_ai = no }
				value = 0
			}
		}
	}
	
	effect = {
		add_character_flag = already_attempted_scandi_invasion
		add_character_flag = prioritised_scandinavian_adventurer
		save_scope_as = scandi_adventurer
		title:c_rouen = {
			set_variable = { name = had_rollo_invasion value = yes }
			save_scope_as = adventurer_target
			holder.top_liege = { save_scope_as = adventurer_target_top_liege }
			duchy = { save_scope_as = adventurer_target_title }
		}
		
		#move domicile if AI
		if = {
			limit = { is_ai = yes }
			random_county_in_region = {
				region = world_europe_north
				limit = {
					is_coastal_county = yes
					holder = { fp1_is_norse = yes }
				}
				alternative_limit = {
					is_coastal_county = yes
				}
				weight = {
					modifier = {
						add = {
							value = development_level
							multiply = 10
						}
					}
					modifier = {
						factor = 2
						culture = root.culture
					}
				}
				save_temporary_scope_as = selected_county
				root = {
					set_variable = {
						name = random_location
						value = scope:selected_county.title_province
						days = 365
					}
				}
			}
			domicile = { move_domicile = root.var:random_location }
		}
		
		custom_tooltip = rollo_claim_normandy_decisison_tt
		
		hidden_effect = {
			start_war = {
				casus_belli = histmod_laamp_adventurer_duchy_invasion
				target = scope:adventurer_target_top_liege
				target_title = scope:adventurer_target_title
			}
		}
		random_character_war = {
			limit = { using_cb = histmod_laamp_adventurer_duchy_invasion }
			save_scope_as = scandi_war
		}
		
		if = {
			limit = { is_ai = yes }
			histmod_spawn_court_effect = yes
		}
		
		scandi_adventurer_army_spawn = {
			SCANDI_WAR = scope:scandi_war
			TARGET = scope:adventurer_target
			LAUNCH = root.domicile.domicile_location
		}
	}
	
	ai_potential = {
		has_government = landless_adventurer_government
	}
	
	ai_will_do = {
		base = 100
		modifier = {
			factor = 0.20
			current_year < 910
			NOT = { has_game_rule = rollo_exists_vanilla }
		}
		modifier = {
			factor = 0.20
			current_year < 900
			has_game_rule = rollo_exists_vanilla
		}
		modifier = {
			factor = 0
			has_any_debilitating_illness = yes
		}
	}
}

