###DECISIONS LIST###

#unite_the_western_slavs_decision
#unite_the_southern_slavs_decision
#unite_the_slavs_decision
#promote_hungarian_settlement_decision
#revive_magyar_paganism_decision

### Unite the West Slavs ###
unite_the_western_slavs_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	desc = unite_the_western_slavs_decision_desc

	is_shown = {
		culture = { has_cultural_pillar = heritage_west_slavic }
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:unite_the_western_slavs_decision
			}
		}
	}

	is_valid = {
		culture = { has_cultural_pillar = heritage_west_slavic }
		completely_controls_region = custom_west_slavia #Has de jure Lands
		OR = {
			custom_description = {
				text = unite_the_western_slavs_decision_tt_1
				OR = {
					has_primary_title = title:k_poland
					has_primary_title = title:k_pomerania
					has_primary_title = title:k_bohemia
					has_primary_title = title:k_moravia
					has_primary_title = title:k_sorbia
				}
			}
			custom_description = {
				text = unite_the_western_slavs_decision_tt_2
				AND = {
					highest_held_title_tier = tier_empire
					OR = {
						has_title = title:k_poland
						has_title = title:k_pomerania
						has_title = title:k_bohemia
						has_title = title:k_moravia
						has_title = title:k_sorbia
					}
				}
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_landed = yes
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		save_scope_as = western_slav_uniter

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

		#Events
		trigger_event = east_europe.0001
		every_player = {
			limit = {
				this != scope:western_slav_uniter
				is_within_diplo_range = { CHARACTER = scope:western_slav_uniter }
			}
			trigger_event = east_europe.0002
		}

		#Can only be done once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:unite_the_western_slavs_decision
		}
		set_global_variable = {
			name = unite_the_western_slavs_decision
			value = scope:western_slav_uniter
		}
		set_global_variable = {
			name = unite_the_western_slavs_decision_title
			value = scope:western_slav_uniter.primary_title
		}
		close_view = {
			view = decisions
			player = root
		}
	}
	

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}


### Unite the South Slavs ###
unite_the_southern_slavs_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	desc = unite_the_southern_slavs_decision_desc

	is_shown = {
		culture = { has_cultural_pillar = heritage_south_slavic }
		NOR = {
			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
		}
	}
	
	is_valid_showing_failures_only = {
		is_landed = yes
	}

	effect = {
		gain_heroic_legend_seed_tooltip_effect = yes
		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 = {
				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
	}
}


### Unite the Slavs ###
unite_the_slavs_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = major
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	desc = unite_the_slavs_decision_desc

	is_shown = {
		OR = {
			culture = { has_cultural_pillar = heritage_west_slavic }
			culture = { has_cultural_pillar = heritage_east_slavic }
			culture = { has_cultural_pillar = heritage_south_slavic }
			}
		NOR = {
			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_slavs_decision
			}
		}
	}

	is_valid = {
		OR = {
			culture = { has_cultural_pillar = heritage_west_slavic }
			culture = { has_cultural_pillar = heritage_east_slavic }
			culture = { has_cultural_pillar = heritage_south_slavic }
		}
		completely_controls_region = custom_slavia
	}
	
	is_valid_showing_failures_only = {
		is_landed = yes
	}

	effect = {
		save_scope_as = slav_uniter

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

		#Events
		trigger_event = east_europe.0010
		every_player = {
			limit = {
				this != scope:slav_uniter
				is_within_diplo_range = { CHARACTER = scope:slav_uniter }
			}
			trigger_event = east_europe.0011
		}

		#Can only happen once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:unite_the_slavs_decision
		}
		set_global_variable = {
			name = unite_the_slavs_decision
			value = scope:slav_uniter
		}
	}


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

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}


### Defenders of [ROOT.Char.GetFaith.HighGodName] ###
defenders_of_highgod_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"
	}
	decision_group_type = major
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	desc = defenders_of_highgod_decision_desc

	is_shown = {
		OR = {
			faith = faith:baltic_pagan
			faith = faith:slavic_pagan
			faith = faith:finnish_pagan
		}
		#Only once per faith
		NOR = {
			AND = {
				faith = faith:baltic_pagan
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:defenders_of_highgod_baltic_decision
				}
			}
			AND = {
				faith = faith:slavic_pagan
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:defenders_of_highgod_slavic_decision
				}
			}
			AND = {
				faith = faith:finnish_pagan
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:defenders_of_highgod_finnish_decision
				}
			}
		}
	}

	is_valid = {
		#Holds a holy site
		faith = {
			any_holy_site = {
				county = {
					holder = root
					title_province = { has_special_building = no  }
				}
			}
		}
		piety_level >= 3
 		#Have loyal powerful vassals
		trigger_if = {
			limit = {
				OR = {
					highest_held_title_tier = tier_county
					highest_held_title_tier = tier_duchy
				}
			}
			any_vassal = {
				count >= 3 #Counts/dukes need 3
				is_powerful_vassal = yes
				opinion = {
					target = root
					value >= high_positive_opinion
				}
			}
		}
		trigger_if = {
			limit = { highest_held_title_tier = tier_kingdom }
			any_vassal = {
				count >= 4 #Kings need 4
				is_powerful_vassal = yes
				opinion = {
					target = root
					value >= high_positive_opinion
				}
			}
		}
		trigger_if = {
			limit = { highest_held_title_tier = tier_empire }
			any_vassal = {
				count >= 5 #Emperor need 5
				is_powerful_vassal = yes
				opinion = {
					target = root
					value >= high_positive_opinion
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		top_liege = this
		is_landed = yes
	}


	effect = {
		save_scope_as = defender_of_highgod

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

		#Events
		if = {
			limit = {
				faith = {
					any_holy_site = {
						count > 1
						county.holder = root
						title_province = { has_special_building = no  }
					}
				}
			}	
			trigger_event = east_europe.0015
		}
		else = {
			faith = {
				random_holy_site = {
					limit = {
						county.holder = root
						title_province = { has_special_building = no  }
					}
					save_scope_as = holy_site
				}
			}
			trigger_event = east_europe.0016
		}
		#Event to every player (east_europe.0017) is actually send through east_europe.0016 to make sure the right holy site scope is set

		#Can only happen once per faith
		if = {
			limit = { faith = faith:baltic_pagan }
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:defenders_of_highgod_baltic_decision
			}
		}
		else_if = {
			limit = { faith = faith:slavic_pagan }
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:defenders_of_highgod_slavic_decision
			}
		}
		else_if = {
			limit = { faith = faith:finnish_pagan }
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:defenders_of_highgod_finnish_decision
			}
		}
	}

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

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

#Hungary: historical re-settlement program.
### Promote Christian Settlements ###
promote_hungarian_settlement_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	desc = promote_hungarian_settlement_decision_desc
	selection_tooltip = promote_hungarian_settlement_decision_tooltip
	decision_group_type = major
	ai_goal = yes

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		game_start_date < 1066.1.1
		culture = { has_cultural_pillar = heritage_magyar }
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_promoted_hungarian_settlement
			}
		}
		NOT = {  #Can only do either or.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_revived_magyar_paganism
			}
		}
		OR = {
			has_title = title:k_hungary
			has_title = title:e_carpathia
		}
		any_neighboring_top_liege_realm_owner = { #There are same reli neighboring Realms/Empires to take people from.
			OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
			count >= 2
		}
	}
	
	is_valid = {
		# Must be an Ecumenical Christian
		custom_description = {
  			text = promote_hungarian_settlement_decision_ecumenical_christian
			faith = { #Denomination of Faith must not be a heresy and must have some degree of control over its core regions.
				OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
				has_doctrine = special_doctrine_ecumenical_christian	
			}
		}
		
		#Must completely control the Carpathian Basin (Hungary De Jure)
		completely_controls = title:k_hungary

		# Capital is Hungarian culture group
		capital_province = { culture = { has_cultural_pillar = heritage_magyar } }
	}

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

	cost = {
		prestige = 2000
		piety = 500
	}

	effect = {
		show_as_tooltip = {
			promote_hungarian_settlement_decision_scripted_effect = yes
		}
		trigger_event = {
			id = east_europe.0030
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_promoted_hungarian_settlement
			}
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 50
		ai_value_modifier = {
			ai_zeal = 1.0
			ai_greed = 1.0
		}
	}
}

#########################################
# Return to Magyar Paganism				#
# by Flavio Verna & Ewan Cowhig Croft	#
#########################################
### Revive Táltosism ###
revive_magyar_paganism_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_major_religion.dds"
	}
	desc = revive_magyar_paganism_decision_desc
	selection_tooltip = revive_magyar_paganism_decision_tooltip
	decision_group_type = major
	ai_check_interval = 0

	is_shown = {
		is_landed = yes
		#Must be some flavour of Magyar.
		culture = { has_cultural_pillar = heritage_magyar }
		#Should be done early.
		custom_tooltip = {
			text = revive_taltoism_decision_before_last_date
			current_date <= 1100.1.1
		}
		NOR = {
			#Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_revived_magyar_paganism
			}
		}
		#Must be the ruler of the Carpathian Basin.
		any_sub_realm_county = {
			title_province = { geographical_region = custom_hungary }
		}
		#Must be feudalised.
		OR = {
			government_has_flag = government_is_feudal
			government_allows = administrative
		}
		#Must be something other than pagan.
		NOT = {
			faith.religion = { is_in_family = rf_pagan }
		}
		#Magyar Paganism must not have been reformed.
		religion:magyar_religion = {
			any_faith = {
				count = all
				has_doctrine_parameter = unreformed
			}
		}
	}
	
	is_valid = {
		#Must be suitably prestigious.
		prestige_level >= high_prestige_level
		#Either you hold k_hungary directly, or your vassal does.
		OR = {
			has_title = title:k_hungary
			AND = {
				has_title = title:e_carpathia
				any_vassal = { has_title = title:k_hungary }
			}
		}
		#Must control at least 80% of de jure Hungary (usually we'd use a region, but if Hungary has shrunk/grown for some reason, the people and title are more important than the actual area).
		any_realm_county = {
			count >= 30
			culture = { has_cultural_pillar = heritage_magyar }
		}
		#Must be a noted scholar of theology (and thus filled out the entire Theologian tree).
		OR = {
			piety_level >= high_piety_level
			has_trait = theologian
		}
		#Should be done early: reiterate this here so the player isn't surprised by losing the decision when shifting up an era.
		custom_tooltip = {
			text = revive_taltoism_decision_before_last_date
			current_date <= 1100.1.1
		}
	}

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

	cost = {
		piety = 2000
	}

	effect = {
		gain_holy_legend_seed_tooltip_effect = yes
		custom_tooltip = revive_magyar_paganism_decision.adjust_the_faith.tt
		show_as_tooltip = { revive_magyar_paganism_decision_scripted_effect = yes }
		trigger_event = { id = east_europe.0032 }
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_revived_magyar_paganism
			}
		}
	}
	
	ai_potential = {
		always = no
	}
}

#################################
# Found the Kingdom of Bosnia	#
# by Ewan Cowhig Croft			#
#################################
### Found Kingdom of Bosnia ###
found_kingdom_of_bosnia_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	decision_group_type = major

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

	desc = found_kingdom_of_bosnia_decision_desc
	selection_tooltip = found_kingdom_of_bosnia_decision_tooltip

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		exists = dynasty
		OR = {
			#Must be a Serb or Croat within the Bosnian highlands.
			AND = {
				OR = {
					culture = culture:serbian
					culture = culture:croatian
				}
				capital_county = {
					OR = {
						this = title:c_vodica
						this = title:c_pset
						this = title:c_vrbas
						this = title:c_donjikraji
						this = title:c_usora
						this = title:c_rama
						this = title:c_soli
						this = title:c_vhrbosna
						this = title:c_zavrsje
						this = title:c_zachlumia
						this = title:c_pagania
					}
				}
			}
			#Or just be Bosnian.
			culture = culture:bosnian
		}
		NOT = {	#You can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_founded_kingdom_of_bosnia
			}
		}
		NOR = {
			government_has_flag = government_is_mercenary
			government_has_flag = government_is_holy_order
		}
		highest_held_title_tier <= tier_duchy
	}

	is_valid = {
		#You must have sufficient clout.
		top_liege = this

		#You must control the kingdom's heartlands.
		has_title = title:d_bosna
		has_title = title:d_lower_bosna
		has_title = title:d_usora
		completely_controls = title:d_bosna
		completely_controls = title:d_lower_bosna
		completely_controls = title:d_usora

		#You must be sufficiently advanced to conceive of having a separate kingdom, rather than being Croatian or Serbian.
		culture = { has_cultural_era_or_later = culture_era_early_medieval }
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_available_adult = yes
	}

	effect = {
		save_scope_as = founder
		show_as_tooltip = { found_kingdom_of_bosnia_decision_scripted_effect = yes }
		gain_heroic_legend_seed_tooltip_effect = yes
		trigger_event = { id = east_europe.0101 }
		#Notify other players.
		every_player = {
			limit = {
				this != scope:founder
				top_liege = {
					OR = {
						this = scope:founder
						any_neighboring_and_across_water_top_liege_realm_owner = { this = scope:founder }
					}
				}
			}
			trigger_event = east_europe.0102
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_founded_kingdom_of_bosnia
			}
			set_global_variable = {
				name = flag_founded_kingdom_of_bosnia
				value = scope:founder
			}
		}
	}

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

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

#################################
# Accuse the Krstjani of Heresy	#
# by Ewan Cowhig Croft			#
#################################
### Accuse the Krstjani of Heresy ###
accuse_krstjani_of_heresy_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_major_religion.dds"
	}
	decision_group_type = major

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

	desc = accuse_krstjani_of_heresy_decision_desc
	selection_tooltip = accuse_krstjani_of_heresy_decision_tooltip

	is_shown = {
		top_liege = this
		is_landed_or_landless_administrative = yes
		exists = dynasty
		#Gotta be an ecumenical Christian...
		faith = {
			religion_tag = christianity_religion
			has_doctrine = special_doctrine_ecumenical_christian
		}
		#... with an existing Head of Faith.
		exists = faith.religious_head
		#Shouldn't be possible, but, just in case: you also can't be a Krstjani yourself.
		NOT = { faith = faith:bosnian_church }
		#The world mustn't already consider the Krstjani to be heretics.
		faith:bosnian_church = { has_doctrine = special_doctrine_ecumenical_christian }
		#Aaaaand you need an independent Krstjani neighbour of at least a notable level (i.e., at least the size of a fully-independent d_bosnia).
		any_neighboring_top_liege_realm_owner = { accuse_krstjani_of_heresy_decision_suitable_krstjani_realm_owner_trigger = yes }
		NOT = {	#It mustn't have been done recently (this is removed in a hidden cooldown event after the chain is finished, if it fails).
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_krstjani_accused_of_heresy
			}
		}
		#Should always be a playable government, ideally.
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
			government_allows = administrative
		}
	}

	is_valid = {
		#You must have sufficient clout.
		piety_level >= high_piety_level
		highest_held_title_tier >= tier_duchy
	}

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

	effect = {
		save_scope_as = accuser
		faith.religious_head = { save_scope_as = hof }
		random_neighboring_top_liege_realm_owner = {
			limit = { accuse_krstjani_of_heresy_decision_suitable_krstjani_realm_owner_trigger = yes }
			save_scope_as = heretic
		}
		custom_tooltip = accuse_krstjani_of_heresy_flavour_effect.tt
		#Begin the chain.
		trigger_event = { id = east_europe.0111 }
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_krstjani_accused_of_heresy
			}
		}
	}

	cost = {
		piety = major_piety_value
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 50
		#Weight up for zealous characters.
		modifier = {
			add = 25
			has_trait = zealous
		}
		#Ironically, weight up for cynical characters: they stand to gain the most.
		modifier = {
			add = 15
			has_trait = cynical
		}
		#Mildly weight up crusaders, who would be more likely to see/look for heresy.
		modifier = {
			add = 10
			has_trait = faith_warrior
		}
		#Mildly weight up order members, who would be more likely to see/look for heresy.
		modifier = {
			add = 10
			has_trait = order_member
		}
		#Mildly weight up theologians, who would understand the theological problems of their neighbours best.
		modifier = {
			add = 10
			has_trait = theologian
		}
		#Exempt if any friend is Krstjani.
		modifier = {
			add = -100
			any_relation = {
				type = friend
				faith = faith:bosnian_church
			}
		}
		#Exempt if any lover is Krstjani.
		modifier = {
			add = -100
			any_relation = {
				type = lover
				faith = faith:bosnian_church
			}
		}
		#Exempt if any formal partner (spouse or concubine) is Krstjani.
		modifier = {
			add = -100
			any_consort = { faith = faith:bosnian_church }
		}
		#Exempt if any ally is Krstjani.
		modifier = {
			add = -100
			any_ally = { faith = faith:bosnian_church }
		}
		#Exempt the HRE: they're not fussed about some remote Balkan peasants.
		modifier = {
			add = -100
			any_held_title = { this = title:e_hre }
		}
		#Exempt the ERE: they almost certainly have bigger fish to fry.
		modifier = {
			add = -100
			any_held_title = { this = title:e_byzantium }
		}
		#Exempt characters who are at war: they're too busy.
		modifier = {
			add = -100
			is_at_war = yes
		}
	}
}

#####################################
# Last Gasp of the Great Migrations	#
# by Ewan Cowhig Croft				#
#####################################
### Prepare to Cross the Carpathians ###
launch_hungarian_migration_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	decision_group_type = major

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

	desc = launch_hungarian_migration_decision_desc
	selection_tooltip = launch_hungarian_migration_decision_tooltip

	is_shown = {
		is_ruler = yes
		is_landed = yes
		exists = dynasty
		#Either be independent, or else not beneath another Mogyer.
		OR = {
			top_liege = this
			NOT = { liege = { culture = culture:mogyer } }
		}
		#Must be a steppe Hungarian.
		culture = culture:mogyer
		#Must not already control a large chunk of Pannonia.
		NOT = {
			any_county_in_region = {
				region = custom_hungary
				count >= 12
				OR = {
					holder = root
					holder = {
						any_liege_or_above = { this = root }
					}
				}
			}
		}
		#You can only do it once.
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_launched_hungarian_migration
			}
		}
		#And the moment for the migration must not have passed.
		current_date <= 911.1.1
	}

	is_valid = {
		#An emperor does not voluntarily lose a tier.
		highest_held_title_tier <= tier_kingdom
		#Reshow this here so that players realise they're on a timer.
		custom_description = {
			text = launch_hungarian_migration_decision_before_last_date
			current_date <= 911.1.1
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		#Can't be fighting elsewhere.
		is_at_war = no
	}

	effect = {
		save_scope_as = invader
		custom_tooltip = launch_hungarian_migration_decision_flavour_effect
		add_character_flag = undertaking_hungarian_migration
		trigger_event = east_europe.0141
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_launched_hungarian_migration
			}
		}
	}

	cost = {
		#Charge a reasonable lump of prestige.
		prestige = 1000
	}

	ai_potential = {
		#AI decision making is governed via event.
		always = no
	}

	ai_will_do = {
		#AI decision making is governed via event.
		base = 0
	}
}

#################################
# Found the Kingdom of Livonia	#
# by James Beaumont				#
#################################
### Proclaim Terra Mariana ###
found_kingdom_of_livonia_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	decision_group_type = major

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

	desc = found_kingdom_of_livonia_decision_desc
	selection_tooltip = found_kingdom_of_livonia_decision_tooltip

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		exists = dynasty
		OR = {
			#Must be a Latvian or Christian in Livonia
			AND = {
				NOT = {
					culture = culture:estonian #Estonians already have their Kingdom.
				}
				OR = {
					#Considers themselves to be a "Balt"
					root.culture = { has_cultural_pillar = heritage_baltic }
					root.faith = {
						religion_tag = baltic_religion
					}
					#Is a Crusader founding the Kingdom
					root.faith = {
						NOT = { religion_tag = baltic_religion }
						NOT = { has_doctrine_parameter = unreformed }
					}
				}
				capital_province = {
					geographical_region = ghw_region_baltic
				}
			}
			#Or just be Latvian.
			culture = culture:latvian
		}
		NOT = {	#You can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_founded_kingdom_of_livonia
			}
		}
		highest_held_title_tier <= tier_duchy
	}

	is_valid = {
		OR = { #Independent or vassal of an Emperor
			top_liege = this
			top_liege.primary_title.tier >= tier_empire
		}
		prestige_level >= medium_prestige_level

		#You must control the kingdom's heartlands.
		has_title = title:d_latgalia
		has_title = title:d_courland
		has_title = title:d_livonia
		completely_controls_region = custom_latvia
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_available_adult = yes
	}

	effect = {
		save_scope_as = founder
		show_as_tooltip = { found_kingdom_of_livonia_decision_scripted_effect = yes }
		gain_heroic_legend_seed_tooltip_effect = yes
		trigger_event = { id = east_europe.0200 }
		#Notify other players.
		every_player = {
			limit = {
				this != scope:founder
				top_liege = {
					OR = {
						this = scope:founder
						any_neighboring_and_across_water_top_liege_realm_owner = { this = scope:founder }
					}
				}
			}
			trigger_event = east_europe.0201
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_founded_kingdom_of_livonia
			}
		}
	}

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

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}
