﻿#####################################
# Unifying Italy [Modified]	        #
# by EmrysValdr      			    #
##################################### 
unify_italian_empire_decision = {
	picture = {
        reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	desc = unify_italian_empire_decision_desc
	selection_tooltip = unify_italian_empire_decision_tooltip
	decision_group_type = major

	ai_check_interval = 120

	is_shown = {
		culture = { has_cultural_pillar = heritage_latin }
		is_ruler = yes
		is_landed = yes
		highest_held_title_tier > 2 #Dukes and above
		capital_province = { geographical_region = world_europe_south_italy }
		NOT = { has_title = title:e_hre } #Italia is a Roman Empire Claimant; therefore you can not hold another equalivalent title
		NOT = { has_title = title:e_byzantium } #Italia is a Roman Empire Claimant; therefore you can not hold another equalivalent title
		NOT = { highest_held_title_tier = tier_empire }
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_unified_italian_empire
			}
		}
		NOT = {  #Too late.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_restored_roman_empire
			}
		}
		NOT = {  #Too late.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_reformed_carolingian_empire
			}
		}
	}

	is_valid = {
		#You must have sufficient clout.
		is_independent_ruler = yes
		prestige_level >= very_high_prestige_level

        #You must be Christian
		religion = religion:christianity_religion

		#Has power based in Italia.
		has_title = title:k_italy
		
		#All the Peninsula
		completely_controls_region = world_europe_south_italy
		#And Illyria
		completely_controls_region = custom_roman_illyricum
		OR = {
			faith.religious_head = {	#And they have to actually like you enough to want to invest you.
				opinion = {
					target = root
					value >= high_positive_opinion
				}
			}
			root = { has_strong_usable_hook = faith.religious_head }	#Or you have a strong hook on them that you can actually use.
			root = { has_weak_hook = faith.religious_head }	#Or a regular hook, to be fair, provided you meet the other criteria.
		}
	}

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

	cost = {
		gold = 500
		prestige = 1000
	}	

	effect = {
		show_as_tooltip = {
			modified_unify_italy_decision_scripted_effect = yes
		}
		trigger_event = {
			id = DE_decision_event.0012
		}
		hidden_effect = {
			modified_unify_italy_decision_scripted_effect = yes
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_unified_italian_empire
			}
			set_global_variable = {
				name = flag_unified_italian_empire
				value = root
			}
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

to_avoid_roman_orphan_error_decision = {
	picture = {
        reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	desc = to_avoid_roman_orphan_error_decision_desc
	selection_tooltip = to_avoid_roman_orphan_error_decision_tooltip
	decision_group_type = major

	ai_check_interval = 120

	is_shown = {
		always = no
	}

	is_valid = {
		always = no
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
	}

	effect = {
		trigger_event = {
			id = roman_restoration.0140
		}
	}
	
	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 100
	}
}

#############################
# Establish Norman Culture 	#
# by Sean Hughes (MODIFIED}	#
#############################

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 = { has_cultural_pillar = heritage_north_germanic }
		NOT = {
			culture = culture:norwegian
			culture = culture:swedish
			culture = culture:danish
		}
		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 = { has_cultural_pillar = heritage_north_germanic }
		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 = { has_cultural_pillar = heritage_north_germanic }
						}
						NOT = {
							culture = culture:norwegian
							culture = culture:swedish
							culture = culture:danish
						}
					}
					add_to_list = norman_counties
				}
			}
			
			culture = { save_scope_as = cultureforeffect }
			
			# Perform the culture flip.
			every_in_list = {
				list = norman_counties
				merge_cultures_in_region_effect = {
					OLD_CULTURE_1 = scope:cultureforeffect
					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
			scope:cultureforeffect = {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 = { has_cultural_pillar = heritage_north_germanic }
						}
						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 = { has_cultural_pillar = heritage_north_germanic }
						}
					}
					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
			}
		}
	}
}

#############################
# Create Portugal 			#
# by Sean Hughes (MODIFIED)	#
#############################

form_portugal_decision = {
	picture = {
        reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	decision_group_type = major
	ai_check_interval = 36
	desc = form_portugal_decision_desc

	is_shown = {
		culture = { has_cultural_pillar = heritage_iberian }
		capital_province = { geographical_region = custom_portuguese }
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:form_portugal_decision
			}
		}
		highest_held_title_tier <= tier_duchy
	}

	is_valid = {
		culture = { has_cultural_pillar = heritage_iberian }
		prestige_level >= high_prestige_level
		trigger_if = {
			limit = {
				has_fp2_dlc_trigger = yes
				exists = struggle:iberian_struggle
			}
			OR = {
				custom_tooltip = {
					text = struggle_iberia_form_portugal_decision_correct_phase_tt
					any_character_struggle = {
						involvement = involved
						is_struggle_type = iberian_struggle
						is_struggle_phase = struggle_iberia_phase_opportunity
					}
				}
				is_independent_ruler = yes
			}
			completely_controls_region = custom_core_portucale
			OR = {
				has_title = title:c_porto
				has_title = title:d_porto
			}
		}
		trigger_else = {
			is_independent_ruler = yes
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		is_at_war = no
	}
	
	effect = {
		save_scope_as = portugal_former

		show_as_tooltip = { form_portugal_decision_effects = yes } #Actually applied in iberia_north_africa.0001 - title changes, prestige, culture swap etc.

		#Events
		trigger_event = iberia_north_africa.0001
		every_player = {
			limit = {
				NOT = { this = scope:portugal_former }
				is_within_diplo_range = { CHARACTER = scope:portugal_former }
			}
			trigger_event = iberia_north_africa.0002
		}
		# every_held_title = { # And any other held Duchy.
		# 	limit = {
		# 		tier = tier_duchy
		# 	}
		# 	set_de_jure_liege_title = title:k_portugal
		# }
		every_vassal_or_below = {
			limit = {
				is_ai = yes
				exists = capital_province
				capital_province = {
					county = {
						any_this_title_or_de_jure_above = {
							this = title:k_portugal
						}
					}
				}
			}
			trigger_event = iberia_north_africa.0002 #So they can convert
		}
		#Can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:form_portugal_decision
		}
		set_global_variable = {
			name = form_portugal_decision
			value = scope:portugal_former
		}
	}

	cost = { gold = { value = 300 } }

	ai_potential = {
		# Only for the AI if independent ruler
		is_independent_ruler = yes
	}

	ai_will_do = {
		base = 100
	}
}

#############################
# Unite the Southern Slavs  #
# 		MODIFIED			#
#############################

unite_the_southern_slavs_decision = {
	picture = {
        reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	ai_check_interval = 120
	desc = unite_the_southern_slavs_decision_desc

	is_shown = {
		culture = { has_cultural_pillar = heritage_south_slavic }
		NOT = {
			has_culture = culture:vlach # Not technically Slavic despite being in the South Slavic group.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:unite_the_southern_slavs_decision
			}
		}
	}

	is_valid = {
		culture = { has_cultural_pillar = heritage_south_slavic }
		completely_controls_region = custom_south_slavia #Has de jure Lands
		OR = {
			has_primary_title = title:k_croatia
			has_primary_title = title:k_serbia
			has_primary_title = title:k_bulgaria
			has_primary_title = title:k_dacia
			has_primary_title = title:k_moldavia
			has_primary_title = title:k_bosnia
			has_primary_title = title:k_illyria
		}
	}

	effect = {
		save_scope_as = southern_slav_uniter

		show_as_tooltip = { unite_the_southern_slavs_decision_effects = yes } #Actually applied in east_europe.0006 - prestige, laws, title, innovation effects

		#Events
		trigger_event = east_europe.0005
		every_player = {
			limit = {
				NOT = { this = scope:southern_slav_uniter }
				is_within_diplo_range = { CHARACTER = scope:southern_slav_uniter }
			}
			trigger_event = east_europe.0006
		}

		#Can only be done once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:unite_the_southern_slavs_decision
		}
		set_global_variable = {
			name = unite_the_southern_slavs_decision
			value = scope:southern_slav_uniter
		}
		set_global_variable = {
			name = unite_the_southern_slavs_decision_title
			value = scope:southern_slav_uniter.primary_title
		}
	}
	

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

##############################
# Enforce Bactrian Supremacy #
# 		MODIFIED	         #
##############################
establish_bactrian_supremacy_decision = {
	picture = {
        reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	decision_group_type = major
	desc = establish_bactrian_supremacy_decision_desc

	ai_check_interval = 120

	is_shown = {
		highest_held_title_tier >= tier_county
		culture = {
			OR = {
				this = culture:afghan
				this = culture:tajik
				this = culture:sogdian
				this = culture:tokhari
				this = culture:bactrian
				any_parent_culture_or_above = {
					OR = {
						this = culture:tajik
						this = culture:afghan
						this = culture:sogdian
						this = culture:tokhari
						this = culture:bactrian
					}
				}
			}
		}
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:establish_bactrian_supremacy_decision
			}
		}
	}

	is_valid = {
		completely_controls_region = custom_bactria
		custom_description = {
			text = "is_king_or_emperor"
			highest_held_title_tier >= tier_kingdom
		}
		OR = {
			religion = religion:zoroastrianism_religion
			religion = religion:buddhism_religion
		}
		prestige_level >= 3
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
		}
		capital_province = {
			geographical_region = custom_bactria
		}
	}

	is_valid_showing_failures_only = {
		is_adult = yes
		is_available = yes
		is_independent_ruler = yes
	}

	cost = {
		gold = {
			value = massive_gold_value
		}
		prestige = {
			value = major_prestige_value
		}
	}

	effect = {
		#Can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:establish_bactrian_supremacy_decision
		}

		save_scope_as = bactrian_emperor

		show_as_tooltip = {
			establish_bactrian_supremacy_effect = yes
		}
		trigger_event = central_asia.0011

		add_to_list = notification_sent
	}

	ai_will_do = {
		base = 100
	}
}

##############################
# 	Embrace English Culture  #
# 		MODIFIED	         #
##############################

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

	ai_check_interval = 120

	desc = embrace_english_culture_decision_desc

	is_shown = {
		is_landed = yes
		culture = { has_cultural_pillar = heritage_frankish }
		OR = {	
			title:k_england = {
				any_in_de_jure_hierarchy = {
					root.primary_title = this
				}
			}
			root.primary_title = title:e_britannia
		}
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:embrace_english_culture_decision
			}
		}
	}

	is_valid = {
		custom_description = {
			text = capital_in_england_region_tooltip
			capital_province = {
				geographical_region = custom_england
			}
		}
		has_title = title:k_england
		culture:anglo_saxon = {
			cultural_acceptance = {
				target = root.culture
				value >= 50
			}
		}
	}

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

	effect = {
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:embrace_english_culture_decision
		}
		show_as_tooltip = {
			embrace_english_culture_effect = yes
		}

		trigger_event = british_isles.2001
	}
	
	ai_potential = {
		is_landed = yes
		culture = { has_cultural_pillar = heritage_frankish }
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:embrace_english_culture_decision
			}
		}
	}

	ai_will_do = {
		base = 100
	}
}