﻿#Creating Switzerland "Kingdom"
### Form the Swiss Confederation ###
form_switzerland_kingdom_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	desc = form_switzerland_kingdom_decision_desc
	selection_tooltip = form_switzerland_kingdom_decision_tooltip
	decision_group_type = major
	sort_order = 110

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

	is_shown = {
		OR = {
			culture ?= { has_cultural_pillar = heritage_central_germanic }
			culture ?= { has_cultural_pillar = heritage_frankish }
			culture ?= { has_cultural_pillar = heritage_latin }
		}
		#Must be within an empire.
		top_liege.primary_title.tier >= tier_empire
		any_sub_realm_county = {
			OR = {
				title_province ?= { geographical_region = custom_core_switzerland }
				this = title:c_aosta
				this = title:c_geneva
			}
		}
		#No kings or emperors.
		highest_held_title_tier <= tier_duchy
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_switzerland_kingdom
			}
		}
		NOT = { exists = title:k_switzerland.holder }
		top_liege != this
	}

	is_valid = {
		#Must have imperial immediacy.
		liege = top_liege
		prestige_level >= high_prestige_level
		#And the core of the Old Confederacy.
		completely_controls_region = custom_core_switzerland
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		top_liege != this
		is_at_war = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 250
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 250
			}
		}
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		show_as_tooltip = {
			form_switzerland_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0001
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_switzerland_kingdom
			}
			set_global_variable = {
				name = flag_formed_switzerland_kingdom
				value = root
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

#Creating Austrian Archduchy
### Form Archduchy of Austria ###
form_austria_kingdom_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	desc = form_austria_kingdom_decision_desc
	selection_tooltip = form_austria_kingdom_decision_tooltip
	decision_group_type = major
	sort_order = 110
	ai_goal = yes

	is_shown = {
		#Must hold land within the relevant areas directly.
		any_held_title = {
			title_tier = county
			OR = {
				title_province ?= { geographical_region = custom_core_austria }
				title_province ?= { geographical_region = custom_stretch_austria }
			}
		}
		NOT = { exists = title:k_austria.holder }
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_austria_kingdom
			}
		}
		#No kings or emperors...
		highest_held_title_tier <= tier_duchy
		top_liege != this
		#Must be within the HRE, else the bid & flavour make no sense.
		top_liege ?= { has_title = title:e_hre }
	}

	is_valid = {
		#Must enjoy imperial immediacy.
		liege = title:e_hre.holder
		#Must be suitably prestigious.
		prestige_level >= high_prestige_level
		#Must control core Austria
		completely_controls_region = custom_core_austria
		#Must not be of the ruling dynasty
		custom_description = {
			text = "form_austria_hre_dynasty_trigger"
			NOT = { dynasty = title:e_hre.holder.dynasty }
		}
		#Must have a hook on the emperor
		has_strong_usable_hook = title:e_hre.holder
		#Must not be too early
		OR = {
			has_realm_law = crown_authority_2
			has_realm_law = crown_authority_3
		}
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		is_at_war = no
		faith = top_liege.faith	#Must share the faith of your emperor.
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 1000
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 1000
			}
		}
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		show_as_tooltip = {
			form_austria_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0003
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_austria_kingdom
			}
			set_global_variable = {
				name = flag_formed_austria_kingdom
				value = root
			}
		}
	}

	ai_potential = {
		prestige_level >= high_prestige_level
	}

	ai_will_do = {
		base = 0

		#Only worth considering if you actually have your capital in Austria.
		modifier = {
			add = 20
			capital_county.title_province = { geographical_region = custom_core_austria }
		}

		#More brazen characters are more likely to have a bash.
		ai_value_modifier = {
			ai_boldness = 0.75
			ai_greed = 0.25
		}
	}
}

#Reform Carolingian Empire
### Restore Carolingian Borders ###
reform_carolingian_empire_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	desc = reform_carolingian_empire_decision_desc
	selection_tooltip = reform_carolingian_empire_decision_tooltip
	decision_group_type = major
	sort_order = 130

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

	is_shown = {
		OR = {
			has_title = title:e_france
			has_title = title:e_hre
		}
		is_playable_character = yes
		capital_province ?= { geographical_region = world_europe_west }
		faith.religion ?= faith:catholic.religion #Christian
		NOT = { government_has_flag = government_is_theocracy }
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_reformed_carolingian_empire
			}
		}
		top_liege ?= this
		culture = { 
			OR = {
				has_cultural_pillar = heritage_frankish 
				has_cultural_pillar = heritage_central_germanic
			}
		}
		capital_province ?= { geographical_region = world_europe_west }
	}

	is_valid = {
		OR = {
			prestige_level >= 5
			trigger_if = {
				limit = {
					has_legitimacy = yes
				}
				legitimacy_level >= 5
			}
		}
		OR = {
			custom_tooltip = {
				text = carolingian_primary_title_france_check
				primary_title = title:e_france
			}
			custom_tooltip = {
				text = carolingian_primary_title_hre_check
				primary_title = title:e_hre
			}
		}
		# No competing Carolingian emperor may exist — hold them or leave them without a claimant
		trigger_if = {
			limit = {
				title:e_france ?= {
					is_titular = no
					exists = holder
				}
			}
			title:e_france = {
				save_temporary_scope_as = current_title_check
			}
			custom_tooltip = {
				text = carolingian_border_other_empires_check
				OR = {
					has_title = title:e_france
					NOT = { exists = title:e_france.holder }
				}
			}
		}
		trigger_if = {
			limit = {
				title:e_germany ?= {
					is_titular = no
					exists = holder
				}
			}
			title:e_germany = {
				save_temporary_scope_as = current_title_check
			}
			custom_tooltip = {
				text = carolingian_border_other_empires_check
				OR = {
					has_title = title:e_germany
					NOT = { exists = title:e_germany.holder }
				}
			}
		}
		trigger_if = {
			limit = {
				title:e_italy ?= {
					is_titular = no
					exists = holder
				}
			}
			title:e_italy = {
				save_temporary_scope_as = current_title_check
			}
			custom_tooltip = {
				text = carolingian_border_other_empires_check
				OR = {
					has_title = title:e_italy
					NOT = { exists = title:e_italy.holder }
				}
			}
		}
		trigger_if = {
			limit = {
				title:e_hre ?= {
					is_titular = no
					exists = holder
				}
			}
			title:e_hre = {
				save_temporary_scope_as = current_title_check
			}
			custom_tooltip = {
				text = carolingian_border_other_empires_check
				OR = {
					has_title = title:e_hre
					NOT = { exists = title:e_hre.holder }
				}
			}
		}
		#All of starting e_france
		completely_controls_region = custom_carolingian_francia
		#Frisia
		completely_controls_region = custom_frisia
		#Lotharingia
		completely_controls_region = custom_lotharingia
		#Bavaria
		completely_controls_region = custom_bavaria
		#Germany
		completely_controls_region = custom_carolingian_germany
		#Aragon (except Mallorca) & Navarra
		completely_controls_region = custom_carolingian_iberia
		#Northern Italy (except Venice, Sardinia, and Rome)
		completely_controls_region = custom_northern_italy
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		top_liege = this
		is_at_war = no
	}

	cost = {
		gold = {
			value = 1000
		}
	}

	effect = {
		custom_tooltip = reform_carolingian_empire_decision_effect_tooltip
		show_as_tooltip = {
			form_carolingian_hegemony_gdp_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0005
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_reformed_carolingian_empire
			}
			set_global_variable = {
				name = flag_reformed_carolingian_empire
				value = root
			}
		}
		gain_heroic_legend_seed_tooltip_effect = yes
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

#Uniting the Burgundies
### Unify the Burgundies ###
unify_burgundy_kingdom_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	desc = unify_burgundy_kingdom_decision_desc
	selection_tooltip = unify_burgundy_kingdom_decision_tooltip
	decision_group_type = major
	sort_order = 110
	ai_goal = yes

	is_shown = {
		culture ?= { has_cultural_pillar = heritage_frankish }
		is_playable_character = yes
		highest_held_title_tier < 4 #No Kings or Emperors.
		top_liege ?= {
			OR = {
				has_title = title:e_hre
				has_title = title:k_france
				has_title = title:e_france
			}
		}
		capital_province ?= { geographical_region = custom_burgundy }
		NOR = {
			exists = title:k_burgundy.holder
			#Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_unified_burgundy_kingdom
			}
		}
		is_ruler = yes
	}

	is_valid = {
		prestige_level >= high_prestige_level
		completely_controls_region = custom_burgundy
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		top_liege != this
		is_at_war = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 1000
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 1000
			}
		}
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		if = {
			limit = {
				NOT = { has_culture = culture:occitan }
			}
			set_culture = culture:occitan
			add_character_flag = converted_culture_this_lifetime
		}
		custom_tooltip = unify_burgundy_kingdom_decision_effect_tooltip
		show_as_tooltip = {
			unite_burgundies_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0007
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_unified_burgundy_kingdom
			}
			set_global_variable = {
				name = flag_unified_burgundy_kingdom
				value = root
			}
		}
	}

	ai_potential = {
		NOT = { exists = title:k_burgundy.holder }
		capital_province ?= { geographical_region = custom_burgundy }
	}

	ai_will_do = {
		base = 5
		ai_value_modifier = {
			ai_boldness = 1.0
		}
	}
}

### Empower Sicilian Parliament ###
empower_sicilian_parliament_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	desc = empower_sicilian_parliament_decision_desc
	selection_tooltip = empower_sicilian_parliament_decision_tooltip
	decision_group_type = major
	sort_order = 100
	ai_goal = yes

	is_shown = {
		highest_held_title_tier >= 4 #Kings and Emperors only.
		culture ?= { has_cultural_pillar = heritage_latin }
		capital_province ?= { geographical_region = custom_sicily }
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_empowered_sicilian_parliament
			}
		}
		top_liege ?= this
		NOT = { government_has_flag = government_is_tribal }
		is_ruler = yes
	}

	is_valid = {
		prestige_level >= 3
		learning >= 10
		NOT = { has_realm_law = crown_authority_0 }
		OR = {
			has_title = title:k_sicily
			has_title = title:k_naples
			has_title = title:k_trinacria
		}
		OR = {
			AND = {
				completely_controls = title:d_sicily # The Island
				title:c_palermo = {
					title_province = { has_special_district = no }
				}
			}
			AND = {
				completely_controls = title:d_capua # The Boot
				title:c_napoli = {
					title_province = { has_special_district = no }
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		top_liege = this
		is_at_war = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 1500
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 1500
			}
		}
		prestige = 3000
	}

	effect = {
		show_as_tooltip = {
			if = { #Only for tooltip, player gets to choose in the event when owning both.
				limit = { completely_controls = title:d_sicily }
				title:c_palermo = {
					sicilian_parliament_building_scripted_effect = yes
				}
			}
			else_if = {
				limit = { completely_controls = title:d_capua }
				custom_tooltip = middle_europe_decisions.0010.tt_napoli_warning
				title:c_napoli = {
					sicilian_parliament_building_scripted_effect = yes
				}
			}
			empower_sicilian_parliament_decision_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0010
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_empowered_sicilian_parliament
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 15
		ai_value_modifier = {
			ai_boldness = 1.0
		}
	}
}

#Little Medieval French Renaissance.
### Inspire Opus Francigenum ###
promote_gothic_innovations_decision = { #12th century Renaissance
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_misc.dds"
	}
	desc = promote_gothic_innovations_decision_desc
	selection_tooltip = promote_gothic_innovations_decision_tooltip
	decision_group_type = major
	sort_order = 100
	ai_goal = yes

	is_shown = {
		highest_held_title_tier >= 4 #Kings and Emperors only.
		is_landed = yes
		OR = {
			culture ?= { has_cultural_pillar = heritage_frankish }
			culture ?= { has_cultural_pillar = heritage_latin }
		}
		OR = {
			has_title = title:k_france
			has_title = title:e_france
			has_title = title:k_burgundy
		}
		NOT = { has_culture = culture:italian }
		is_ruler = yes
		root.culture ?= {
			has_cultural_era_or_later = culture_era_early_medieval
		}
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_promoted_gothic_innovations
			}
		}
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_clan
			government_has_flag = government_is_theocracy
		}
	}

	is_valid = {
		prestige_level >= 4
		learning >= 10
		NOT = { has_realm_law = crown_authority_0 }
		#Must control core provinces either in the North or the South:
		OR = {
			AND = {
				completely_controls = title:d_valois
				completely_controls = title:d_orleans
			}
			AND = {
				completely_controls = title:d_provence
				completely_controls = title:d_toulouse
			}
		}
		#Must have basic innovations:
		root.culture = {
			has_innovation = innovation_royal_prerogative
			has_innovation = innovation_knighthood
			has_innovation = innovation_windmills
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		is_at_war = no
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 500
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 500
			}
		}
		prestige = 3000
	}

	effect = {
		show_as_tooltip = {
			promote_gothic_innovations_decision_scripted_effect = yes
		}
		trigger_event = {
			id = middle_europe_decisions.0012
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_promoted_gothic_innovations
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 15
		ai_value_modifier = {
			ai_boldness = 1.0
		}
	}
}

#############################
# Refound HRE 				#
# by Ewan Cowhig Croft		#
#############################
### Restore the Holy Roman Empire ###
restore_holy_roman_empire_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	decision_group_type = major
	sort_order = 120

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

	desc = restore_holy_roman_empire_decision_desc
	selection_tooltip = restore_holy_roman_empire_decision_tooltip

	is_shown = {
		highest_held_title_tier >= tier_kingdom
		is_landed_or_landless_administrative = yes
		exists = dynasty # Everyone should have a dynasty, but in case they don't...
		NOT = { has_global_variable = flag_restored_roman_empire } # Not if Rome already exists (prevent Rome from restoring HRE)
		highest_held_title_tier < tier_hegemony	# Don't destroy your hegemony.
		NOR = {	#Title existence conditions.
			exists = title:e_hre.holder	#Well, that'd be redundant.
		}
		NOR = { #It doesn't make sense for these competing empires.
			is_roman_emperor_trigger = yes
			mpo_has_gok_mongol_empire_trigger = yes
		}
		AND = {	#Faith conditions.
			faith = {
				religion_tag = christianity_religion
			}
			trigger_if = {
				limit = { exists = faith.religious_head }
				this != faith.religious_head
			}
			trigger_else = {
				NOT = { faith.main_rite.head_of_rite ?= this }
			}
			#NAND = {	#No need for a competing empire if your faith controls the ERE.
			#	exists = title:e_byzantium.holder
			#	faith = title:e_byzantium.holder.faith
			#}
		}
		OR = {	#Government conditions.
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
			government_has_mechanic = administrative
		}
	}

	is_valid = {
		#Standard requirements.
		top_liege = this
		custom_description = {
			text = restore_hre_mainline_rite_requirement_tt
			OR = {
				rite = faith.main_rite
				rite = rite:carolingian_christianity
			}
		}
		trigger_if = {
			limit = {
				is_ai = no
			}
			prestige_level >= high_prestige_level
		}
		#Title ownership conditions.
		custom_tooltip = {
			text = decision_refound_hre_kingdom_list.tt
			OR = { #Gotta be King of a core Carolingian Kingdom.
				has_title = title:k_east_francia
				has_title = title:k_bavaria
				has_title = title:k_france
				has_title = title:k_italy
				has_title = title:k_lotharingia
				any_vassal = {
					OR = {
						has_title = title:k_east_francia
						has_title = title:k_bavaria
						has_title = title:k_france
						has_title = title:k_italy
						has_title = title:k_lotharingia
					}
				}
			}
		}
		trigger_if = {
			limit = {
				is_ai = no
			}
			custom_description = {	#And have some additional royal dignity for good measure.
				text = decision_refound_hre_own_three_kingdoms.tt
				any_held_title = {
					title_tier = kingdom
					count >= 3
				}
			}
		}
		sub_realm_size >= 120	#Plus your various kingdoms should be ruling something.
		# Must be 7 potential Electors
		custom_tooltip = {
			text = restore_holy_roman_empire_decision_trigger_de_jure_vassals.tt
			any_vassal = {
				count >= 7
				hre_valid_prince_elector_trigger = yes
				# prince-bishopric or duchy
				trigger_if = {
					limit = { government_has_flag = government_is_theocracy }
					any_held_title = {
						tier >= tier_county
						is_landless_type_title = no
						has_clerical_region = no
					}
				}
				trigger_else = {
					OR = {
						primary_title.tier >= tier_duchy
						has_character_flag = hre_kingdom_destroyed
					}
				}
			}
		}
		rule_title_creation_imperial_power_projection_title_creation_trigger = yes
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		NOT = { has_trait = excommunicated }
	}

	effect = {
		hre_assign_dynamic_prince_electors_effect = yes
		save_scope_as = founder
		if = {
			limit = { exists = faith.religious_head }
			faith.religious_head = { save_scope_as = founder_religious_authority }
		}
		else_if = {
			limit = { exists = faith.main_rite.head_of_rite }
			faith.main_rite.head_of_rite = { save_scope_as = founder_religious_authority }
		}
		capital_province ?= { save_scope_as = ceremony_locale }
		if = {
			limit = {
				exists = scope:founder_religious_authority
				scope:founder_religious_authority = {
					is_available_adult = yes
					OR = {
						opinion = {
							target = root
							value >= high_positive_opinion
						}
						root = { has_strong_usable_hook = this }
						root = { has_weak_hook = this }
					}
				}
				NOT = { is_at_war_with = scope:founder_religious_authority }
			}
			scope:founder_religious_authority = {
				save_scope_as = hre_blessing_authority
				if = {
					limit = { is_playable_character = yes }
					capital_province ?= { save_scope_as = ceremony_locale }
				}
			}
		}
		if = {
			limit = { exists = scope:hre_blessing_authority }
			custom_tooltip = restore_hre_with_blessing_tt
		}
		else = {
			custom_tooltip = restore_hre_without_blessing_tt
		}
		show_as_tooltip = {
			restore_holy_roman_empire_decision_scripted_effect = yes
		}
		custom_tooltip = hre_elector_list_creation_tt
		gain_heroic_legend_seed_tooltip_effect = yes
		trigger_event = middle_europe_decisions.0015
		#Notify other players.
		every_player = {
			limit = {
				this != root
				is_within_diplo_range = { CHARACTER = root }
			}
			trigger_event = middle_europe_decisions.0016
		}
		if = {
			limit = {
				is_ai = no
				NOT = { exists = global_var:restore_holy_roman_empire_decision  }
			}
			set_global_variable = {
				name = restore_holy_roman_empire_decision
				value = root
			}
		}
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
					is_ai = no
				}
				add = 500
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
					is_ai = no
				}
				add = 500
			}
		}
		piety = 200
	}

	ai_potential = {
		top_liege = this
		highest_held_title_tier >= tier_kingdom
	}

	ai_will_do = {
		base = 100

		modifier = { # We don't want a solo-France to form the HRE
			factor = 0
			NOR = {
				has_title = title:k_east_francia
				has_title = title:k_bavaria
				has_title = title:k_italy
				has_title = title:k_lotharingia
				any_vassal = {
					OR = {
						has_title = title:k_east_francia
						has_title = title:k_bavaria
						has_title = title:k_italy
						has_title = title:k_lotharingia
					}
				}
			}
		}
	}
}

#############################
# Establish Norman Cultue 	#
# by Sean Hughes			#
#############################

### Establish Norman Culture ###
establish_norman_culture_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	sort_order = 100

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

	desc = establish_norman_culture_decision_desc
	selection_tooltip = establish_norman_culture_decision_tooltip

	is_shown = {
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_normandy_decision
			}
		}
		any_sub_realm_county = {
			target_is_de_jure_liege_or_above = title:d_normandy
			culture ?= culture:french
		}
		culture ?= culture:norse
	}

	is_valid = {
		culture = culture:norse
		completely_controls = title:d_normandy
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_imprisoned = no
	}

	effect = {
		hidden_effect = {
			# Generate a list of counties we want to flip to the new culture.
			title:d_normandy = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_county}
					add_to_list = norman_counties
				}
			}
			every_sub_realm_title = {
				limit = {
					tier = tier_county
				}
				if = {
					limit = {
						title_province = { geographical_region = custom_normandy_and_adjacent }
						OR = {
							culture = culture:french
							culture = culture:norse
						}
					}
					add_to_list = norman_counties
				}
			}

			# Perform the culture flip.
			every_in_list = {
				list = norman_counties
				merge_cultures_in_region_effect = {
					OLD_CULTURE_1 = culture:norse
					OLD_CULTURE_2 = culture:french
					NEW_CULTURE = culture:norman
					REGION = custom_normandy_and_adjacent
				}
			}

			# Send all players in the game a notification event about the flip.
			save_scope_as = norman_founder
			culture:norse = {save_scope_as = old_culture_1}
			culture:french = {save_scope_as = old_culture_2}
			culture:norman = {
				reset_culture_creation_date = yes
				get_all_innovations_from = scope:old_culture_1
				get_all_innovations_from = scope:old_culture_2
				save_scope_as = new_culture
			}
			every_player = {
				if = {
					limit = {
						this != root
						OR = {
							culture = culture:french
							culture = culture:norse
						}
						capital_province ?= { geographical_region = custom_normandy_and_adjacent }
					}
					trigger_event = global_culture.3002
				}
				else_if = {
					limit = { this = root }
					trigger_event = global_culture.3003
				}
				else_if = {
					limit = {
						capital_province ?= { geographical_region = world_europe }
					}
					trigger_event = global_culture.3005
				}
			}
		}

		# Player changes culture
		set_culture = culture:norman
		add_character_flag = converted_culture_this_lifetime
		hidden_effect = {
			every_in_list = {
				list = norman_counties
				limit = {
					holder.capital_county = { is_in_list = norman_counties }
				}
				holder = {
					add_to_list = mass_melting_pot_list
					every_courtier = { add_to_list = mass_melting_pot_list }
					every_courtier_away = { add_to_list = mass_melting_pot_list }
				}
				every_in_list = {
					list = mass_melting_pot_list
					limit = {
						OR = {
							culture = culture:french
							culture = culture:norse
						}
					}
					set_culture = culture:norman
				}
			}
		}

		# Summary of above hidden effects to inform players of the decision's impact.
		show_as_tooltip = {
			custom_tooltip = establish_norman_culture_decision_effect.tt
			culture:norman = {
				get_all_innovations_from = scope:old_culture_1
				get_all_innovations_from = scope:old_culture_2
			}
		}

		# Rename the duchy to Normandy
		title:d_normandy = {
			save_scope_as = normandy_title
			hidden_effect = {
				set_title_name = d_normandy
			}
			custom_tooltip = establish_norman_culture_decision_effect.tt.2
		}
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_formed_normandy_decision
		}
	}

	cost = {
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			any_sub_realm_county = {
				percent >= 0.5
				culture = culture:french
			}
		}
	}
}

##################################
# Establish Italo-Norman Culture #
##################################

### Establish Italo-Norman Culture ###
establish_italo_norman_culture_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	sort_order = 100

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

	desc = establish_italo_norman_culture_decision_desc
	selection_tooltip = establish_italo_norman_culture_decision_tooltip

	is_shown = {
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_italo_norman_decision
			}
		}
		any_sub_realm_county = {
			OR = {
				target_is_de_jure_liege_or_above = title:d_sicily
				target_is_de_jure_liege_or_above = title:d_apulia
			}
			culture ?= culture:sicilian
		}
		culture ?= culture:norman
	}

	is_valid = {
		culture = culture:norman
		completely_controls = title:d_sicily
		completely_controls = title:d_apulia
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		is_imprisoned = no
	}

	effect = {
		hidden_effect = {
			title:d_sicily = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_county }
					add_to_list = italo_norman_counties
				}
			}
			title:d_apulia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_county }
					add_to_list = italo_norman_counties
				}
			}
			every_sub_realm_title = {
				limit = {
					tier = tier_county
				}
				if = {
					limit = {
						title_province = { geographical_region = custom_sicily }
						OR = {
							culture = culture:norman
							culture = culture:sicilian
						}
					}
					add_to_list = italo_norman_counties
				}
			}

			every_in_list = {
				list = italo_norman_counties
				merge_cultures_in_region_effect = {
					OLD_CULTURE_1 = culture:norman
					OLD_CULTURE_2 = culture:sicilian
					NEW_CULTURE = culture:italo_norman
					REGION = custom_sicily
				}
			}

			# Notify players the same way a dynamic hybrid culture does (see on_culture_created)
			save_scope_as = founder
			culture:norman = { save_scope_as = old_culture_1 save_scope_as = parent_1 }
			culture:sicilian = { save_scope_as = old_culture_2 save_scope_as = parent_2 }
			culture:italo_norman = {
				reset_culture_creation_date = yes
				get_all_innovations_from = scope:old_culture_1
				get_all_innovations_from = scope:old_culture_2
				save_scope_as = new_culture
			}
			every_player = {
				if = {
					limit = {
						OR = {
							culture = scope:new_culture
							culture = scope:parent_1
							culture = scope:parent_2
						}
					}
					trigger_event = {
						id = culture_notification.1011
						days = 0
					}
				}
				else_if = {
					limit = {
						in_diplomatic_range = scope:founder
					}
					trigger_event = {
						id = culture_notification.1001
						days = 0
					}
				}
			}
		}

		# Player changes culture
		set_culture = culture:italo_norman
		add_character_flag = converted_culture_this_lifetime
		hidden_effect = {
			every_in_list = {
				list = italo_norman_counties
				limit = {
					holder.capital_county = { is_in_list = italo_norman_counties }
				}
				holder = {
					add_to_list = mass_melting_pot_list
					every_courtier = { add_to_list = mass_melting_pot_list }
					every_courtier_away = { add_to_list = mass_melting_pot_list }
				}
				every_in_list = {
					list = mass_melting_pot_list
					limit = {
						OR = {
							culture = culture:norman
							culture = culture:sicilian
						}
					}
					set_culture = culture:italo_norman
				}
			}
		}

		show_as_tooltip = {
			custom_tooltip = establish_italo_norman_culture_decision_effect.tt
			culture:italo_norman = {
				get_all_innovations_from = scope:old_culture_1
				get_all_innovations_from = scope:old_culture_2
			}
		}

		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:flag_formed_italo_norman_decision
		}
	}

	cost = {
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			any_sub_realm_county = {
				percent >= 0.5
				culture = culture:sicilian
			}
		}
	}
}

######################################
# Establish the Electorate of Saxony #
# by James Beaumont			 		 #
######################################

### Establish the Electorate of Saxony ###
establish_the_electorate_of_saxony_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	decision_group_type = major
	sort_order = 100

	ai_check_interval = 0

	desc = establish_the_electorate_of_saxony_decision_desc
	selection_tooltip = establish_the_electorate_of_saxony_decision_tooltip

	is_shown = {
		# Temporarily disabled due to stability issues in the HRE.
		always = no
		# Can't form Saxony if Saxony already formed.
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_saxony
			}
		}
		# Is in the HRE or is the Emperor
		OR = {
			liege ?= title:e_hre.holder
			has_primary_title = title:e_hre
		}
	}

	is_valid = {
		OR = {
			has_primary_title = title:e_hre
			# Avoid some funky tooltips.
			AND = {
				highest_held_title_tier <= tier_kingdom
				top_liege = { has_title = title:e_hre }
			}
		}
		custom_tooltip = {
			text = polabia_held_or_nonexistent.tt
			OR = {
				has_title = title:k_sorbia
				NOT = { exists = title:k_sorbia.holder }
			}
		}
		completely_controls = title:d_meissen
		completely_controls = title:d_lausitz
		completely_controls = title:d_anhalt
		completely_controls = title:d_thuringia
		# Most of the Kingdom of Polabia is at least somewhat pro-HRE
		custom_tooltip = {
			text = polabia_must_be_hre_culture_tt
			any_county_in_region = {
				region = custom_polabia
				# At least half.
				count >= 12
				OR = {
					culture = root.culture
					culture = title:e_hre.holder.culture
				}
			}
		}
	}

	effect = {
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_saxony
			}
			save_scope_as = founder
			title:e_hre.holder = { save_scope_as = hre_emperor_scope }
			trigger_event =  middle_europe_decisions.0017
		}
		show_as_tooltip = {
			create_kingdom_of_saxony_effect = { CHARACTER = root }
		}
		if = {
			limit = { has_title = title:e_hre }
			custom_tooltip = middle_europe_decision.0017.tt
		}
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 200
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 200
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

##############
# Carantania #
##############
decision_restore_carantania = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_castle_view.dds"
	}
	decision_group_type = major
	sort_order = 100

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

	is_shown = {
		exists = title:k_carantania
		has_culture = culture:carantanian
		OR = {
			has_title = title:d_krain
			has_title = title:d_carinthia
			has_title = title:d_steyermark
		}
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_carantania
			}
		}
		OR = {
			title:d_krain = { is_titular = no }
			title:d_carinthia = { is_titular = no }
			title:d_steyermark = { is_titular = no }
		}
	}

	is_valid = {
		is_independent_ruler = yes
		highest_held_title_tier < tier_kingdom
		prestige_level >= 3
		trigger_if = {
			limit = {
				title:d_krain = { is_titular = no }
			}
			completely_controls = title:d_krain
		}
		trigger_if = {
			limit = {
				title:d_carinthia = { is_titular = no }
			}
			completely_controls = title:d_carinthia
		}
		trigger_if = {
			limit = {
				title:d_steyermark = { is_titular = no }
			}
			completely_controls = title:d_steyermark
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
	}

	effect = {
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_formed_carantania
			}
		}
		show_as_tooltip = {
			decision_restore_carantania_effect = yes
		}
		trigger_event = major_decisions.3400
	}

	cost = {
		gold = {
			value = 500
			if = {
				limit = {
					is_ai = yes
				}
				multiply = 0
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}
