﻿##################################################
### Mod Notes:
### Modder's Note: Removed "Restore the Holy Roman Empire" decision.
##################################################
#Creating Switzerland "Kingdom"
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

	ai_check_interval = 120

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

	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
		is_independent_ruler = no
		is_at_war = no
	}

	cost = {
		gold = 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_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
	ai_goal = yes

	is_shown = {
		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
		is_independent_ruler = no
		#Must be within the HRE, else the bid & flavour make no sense.
		top_liege ?= { has_title = title:e_hre }
		#Must hold land within the relevant areas directly.
		any_held_title = {
			tier = tier_county
			OR = {
				title_province = { geographical_region = custom_core_austria }
				title_province = { geographical_region = custom_stretch_austria }
			}
		}
	}

	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 = 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
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

	ai_check_interval = 120

	is_shown = {
		faith.religion = faith:catholic.religion #Christian
		is_ruler = yes
		is_playable_character = yes
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_reformed_carolingian_empire
			}
		}
		is_independent_ruler = yes
		culture = { has_cultural_pillar = heritage_frankish }
		capital_province = { geographical_region = world_europe_west }
		NOT = { has_title = title:e_hre } #HRE title holders can't Restore Carolingian Borders as the decision requires the HRE to serve as an "antagonist"
	}

	is_valid = {
		prestige_level >= high_prestige_level
		has_title = title:e_france
		#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
		is_independent_ruler = yes
		is_at_war = no
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		custom_tooltip = reform_carolingian_empire_decision_effect_tooltip
		show_as_tooltip = {
			form_carolingian_empire_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
			}
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

#Uniting 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
	ai_goal = yes

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

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

	cost = {
		gold = 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 = {
		always = yes
	}

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

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
	ai_goal = yes

	is_shown = {
		culture = { has_cultural_pillar = heritage_latin }
		is_ruler = yes
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_empowered_sicilian_parliament
			}
		}
		highest_held_title_tier >= 4 #Kings and Emperors only.
		is_independent_ruler = yes
		capital_province = { geographical_region = custom_sicily }
		NOT = { government_has_flag = government_is_tribal }
	}
	
	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 = {
			completely_controls = title:d_sicily # The Island
			completely_controls = title:d_capua # The Boot
		}
	}

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

	cost = {
		gold = 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 }
				
				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.
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
	ai_goal = yes

	is_shown = {
		OR = {
			culture = { has_cultural_pillar = heritage_latin }
			culture = { has_cultural_pillar = heritage_frankish }
		}
		NOT = { has_culture = culture:italian }
		is_ruler = yes
		is_landed = 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
			}
		}
		highest_held_title_tier >= 4 #Kings and Emperors only.
		OR = {
			has_title = title:k_france
			has_title = title:e_france
			has_title = title:k_burgundy
		}
		NOR = {
			government_has_flag = government_is_theocracy
			government_has_flag = government_is_clan
			government_has_flag = government_is_tribal
		}
	}
	
	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 = 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
		}
	}
}

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

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

	ai_check_interval = 120

	desc = establish_norman_culture_decision_desc
	selection_tooltip = establish_norman_culture_decision_tooltip

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

	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 = {
						NOT = { this = root }
						OR = {
							culture = culture:french
							culture = culture:norse
						}
						exists = capital_province
						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 = {
						exists = capital_province
						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 the Electorate of Saxony #
# by James Beaumont			 		 #
######################################

establish_the_electorate_of_saxony_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	decision_group_type = major

	ai_check_interval = 120

	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 = 200 }

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}
