#################
# Shroud Events #
#################

namespace = shroud

#==================================
# 0-99 Miscellaneous
#==================================

country_event = {
	id = shroud.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
	}

	immediate = {
		refresh_accords = yes
	}
}

country_event = {
	id = shroud.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
	}

	immediate = {
		remove_modifier = reduce_next_delve_cooldown

		# Non-Components delve chance
		if = {
			limit = { NOT =  { is_variable_set = non_component_delve_count } }
			set_variable = {
				which = non_component_delve_count
				value = 0
			}
		}
		else = {
			change_variable = {
				which = non_component_delve_count
				value = 1
			}
		}

		# Shroud Songs roll
		set_country_flag = has_delved_in_shroud
		if = {
			limit = { NOT =  { is_variable_set = songs_delve_count } }
			set_variable = {
				which = songs_delve_count
				value = 0
			}
		}
		change_variable = {
			which = songs_delve_count
			value = 1
		}
		if = {
			limit = {
				NOR = {
					has_country_flag = shroud_songs_rolled
					has_country_flag = shroud_songs_started
					# EotC cancels advanced authorities
					has_origin = origin_endbringers
					has_covenant_with_end_of_the_cycle = yes
				}
			}
			random = {
				chance = value:shroud_song_roll
				set_country_flag = shroud_songs_rolled
			}
		}
	}
}

## Base Event for Delve events
country_event = {
	id = shroud.3
	title = BLANK_STRING
	diplomatic_title = shroud.3.diplo_title
	desc = BLANK_STRING

	is_triggered_only = yes
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	option = {
		name = BLANK_STRING
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
}

ship_event = {
	id = shroud.5
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_ship_flag = is_terrified
	}

	immediate = {
		remove_terrified = yes
		remove_ship_flag = is_terrified
	}
}

# Synth Queen updated Shroud flow
country_event = {
	id = shroud.10
	diplomatic_title = shroud.3.diplo_title
	title = shroud.10.name

	desc = {
		trigger = {
			has_country_flag = has_met_animator_of_clay
		}
		text = shroud.10.desc.1
	}
	desc = {
		trigger = {
			NOT = { has_country_flag = has_met_animator_of_clay }
		}
		text = shroud.10.desc
	}

	is_triggered_only = yes
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	trigger = {
		has_country_flag = synth_queen_can_contact_the_animator_of_clay
		NOR = {
			has_origin = origin_shroud_forged
			has_country_flag = synth_queen_contacted_the_animator_already
			has_country_flag = synth_queen_refused_the_animator_contact
			has_covenant_with_end_of_the_cycle = yes
		}
		resource_stockpile_compare = {
			resource = energy
			value >= 2000
		}
		resource_stockpile_compare = {
			resource = sr_zro
			value >= 500
		}
	}

	option = {
		name = shroud.10.a
		add_resource = {
			energy = -2000
			sr_zro = -500
		}
		hidden_effect = {
			country_event = { id = crisis.24100 }
		}
	}
	option = {
		name = shroud.10.b
		custom_tooltip = shroud.10.b.tt
		set_country_flag = synth_queen_refused_the_animator_contact
	}
}

country_event = {
	id = shroud.20
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = shroud_songs_rolled
		NOR = {
			has_country_flag = shroud_songs_started
			has_origin = origin_endbringers
			has_covenant_with_end_of_the_cycle = yes
		}
	}

	immediate = {
		set_country_flag = shroud_songs_started
		country_event = {
			id = shroud.7099
		}
	}
}

# Monthly attunement modifier: Eater of Worlds
country_event = {
	id = shroud.50
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_modifier_value = {
			modifier = eater_of_worlds_monthly_attunement_add
			value != 0
		}
	}

	immediate = {
		add_attunement = {
			the_eater_of_worlds = modifier:eater_of_worlds_monthly_attunement_add
		}
	}
}

# Monthly attunement modifier: Composer of Strands
country_event = {
	id = shroud.51
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_modifier_value = {
			modifier = composer_of_strands_monthly_attunement_add
			value != 0
		}
	}

	immediate = {
		add_attunement = {
			the_composer_of_strands = modifier:composer_of_strands_monthly_attunement_add
		}
	}
}

# Monthly attunement modifier: Instrument of Desire
country_event = {
	id = shroud.52
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_modifier_value = {
			modifier = instrument_of_desire_monthly_attunement_add
			value != 0
		}
	}

	immediate = {
		add_attunement = {
			the_instrument_of_desire = modifier:instrument_of_desire_monthly_attunement_add
		}
	}
}

# Monthly attunement modifier: Cradle of Souls
country_event = {
	id = shroud.53
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_modifier_value = {
			modifier = cradle_of_souls_monthly_attunement_add
			value != 0
		}
	}

	immediate = {
		add_attunement = {
			the_cradle_of_souls = modifier:cradle_of_souls_monthly_attunement_add
		}
	}
}

# Monthly attunement modifier: Whisperers in the Void
country_event = {
	id = shroud.54
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_modifier_value = {
			modifier = whisperers_in_the_void_monthly_attunement_add
			value != 0
		}
	}

	immediate = {
		add_attunement = {
			whisperers_in_the_void = modifier:whisperers_in_the_void_monthly_attunement_add
		}
	}
}

# Psionic Aura suppression dismantled (for empires with auras)
# From = system
# FromFrom = country (previous owner)
# This = country (new owner)
country_event = {
	id = shroud.60
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_technology = tech_psionic_aura
		OR = {
			NOT = { has_country_flag = psionic_suppression_policy_enabled }
			has_policy_flag = psionic_suppression_dismantle
		}
		from = { check_aura_suppression_buildings = yes }
	}

	immediate = {
		from = { remove_system_aura_suppressors = yes }
		country_event = {
			id = shroud.80
			scopes = { from = from }
		}
	}
}

# Psionic Aura suppression dismantled from giving system (for empires with auras)
# This = System
# FROM = Country: New controller of the system
# FROMFROM = Country: Old controller of the system
system_event = {
	id = shroud.65
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			has_technology = tech_psionic_aura
			OR = {
				NOT = { has_country_flag = psionic_suppression_policy_enabled }
				has_policy_flag = psionic_suppression_dismantle
			}
		}
		check_aura_suppression_buildings = yes
		if = {
			limit = { exists = fromfrom }
			from = { # Subject integration is handled in shroud.70
				NOT = { is_same_value = root.fromfrom }
			}
		}
	}

	immediate = {
		remove_system_aura_suppressors = yes
		from = {
			country_event = {
				id = shroud.80
				scopes = { from = root }
			}
		}
	}
}

# Psionic Aura suppression dismantled after subjugation (for Endbringers)
# This = subject
# From = overlord
country_event = {
	id = shroud.70
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			has_technology = tech_psionic_aura
			has_origin = origin_endbringers
			OR = {
				NOT = { has_country_flag = psionic_suppression_policy_enabled }
				has_policy_flag = psionic_suppression_dismantle
			}
		}
		OR = {
			any_system_within_border = {
				check_aura_suppression_buildings = yes
			}
			any_owned_colony = {
				is_planet_class = pc_ark
				OR = {
					has_active_building = building_psionic_suppressor
					has_active_building = building_ancient_ward_2
				}
			}
		}
	}

	immediate = {
		every_system_within_border = {
			limit = { check_aura_suppression_buildings = yes }
			remove_system_aura_suppressors = yes
			if = {
				limit = {
					NOT = { exists = event_target:selected_system_to_suppress }
				}
				save_event_target_as = selected_system_to_suppress
			}
		}
		every_owned_colony = {
			limit = {
				is_planet_class = pc_ark
				OR = {
					has_active_building = building_psionic_suppressor
					has_active_building = building_ancient_ward_2
				}
			}
			while = {
				limit = { has_active_building = building_psionic_suppressor }
				remove_building = building_psionic_suppressor
				remove_eotc_aura_psionic_suppressor = yes
			}
			while = {
				limit = { has_active_building = building_ancient_ward_2 }
				remove_building = building_ancient_ward_2
				remove_eotc_aura_grand_ward = yes
			}
			if = {
				limit = {
					NOT = { exists = event_target:selected_system_to_suppress }
				}
				solar_system = {
					save_event_target_as = selected_system_to_suppress
				}
			}
		}
		if = {
			limit = { exists = event_target:selected_system_to_suppress }
			from = {
				country_event = {
					id = shroud.80
					scopes = { from = event_target:selected_system_to_suppress }
				}
			}
		}
	}
}

# Psionic Aura suppression dismantled from subject integration
# This = overlord
# From = subject
country_event = {
	id = shroud.75
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_technology = tech_psionic_aura
		OR = {
			NOT = { has_country_flag = psionic_suppression_policy_enabled }
			has_policy_flag = psionic_suppression_dismantle
		}
		from = {
			OR = {
				any_system_within_border = {
					check_aura_suppression_buildings = yes
				}
				any_owned_colony = {
					is_planet_class = pc_ark
					OR = {
						has_active_building = building_psionic_suppressor
						has_active_building = building_ancient_ward_2
					}
				}
			}
		}
	}

	immediate = {
		from = {
			every_system_within_border = {
				limit = { check_aura_suppression_buildings = yes }
				remove_system_aura_suppressors = yes
				if = {
					limit = {
						NOT = { exists = event_target:selected_system_to_suppress }
					}
					save_event_target_as = selected_system_to_suppress
				}
			}
			every_owned_colony = {
				limit = {
					is_planet_class = pc_ark
					OR = {
						has_active_building = building_psionic_suppressor
						has_active_building = building_ancient_ward_2
					}
				}
				while = {
					limit = { has_active_building = building_psionic_suppressor }
					remove_building = building_psionic_suppressor
					remove_eotc_aura_psionic_suppressor = yes
				}
				while = {
					limit = { has_active_building = building_ancient_ward_2 }
					remove_building = building_ancient_ward_2
					remove_eotc_aura_grand_ward = yes
				}
				if = {
					limit = {
						NOT = { exists = event_target:selected_system_to_suppress }
					}
					solar_system = {
						save_event_target_as = selected_system_to_suppress
					}
				}
			}
		}
		if = {
			limit = { exists = event_target:selected_system_to_suppress }
			country_event = {
				id = shroud.80
				scopes = { from = event_target:selected_system_to_suppress }
			}
		}
	}
}

country_event = {
	id = shroud.80
	title = shroud.80.title
	desc = shroud.80.desc
	picture = GFX_evt_shroud_shroud_seal
	show_sound = event_psionic
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = psionic_suppression_policy_enabled }
	}

	immediate = {
		set_country_flag = psionic_suppression_policy_enabled
	}

	option = {
		name = shroud.80.a
		set_policy = {
			policy = psionic_suppression_policy
			option = psionic_suppression_dismantle
		}
		try_start_chain_aura_suppressors = yes
	}
}

# AI bonus attunement
country_event = {
	id = shroud.90
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		is_ai = yes
		has_breached_shroud = yes
	}

	immediate = {
		if = {
			limit = { is_preferred_patron = the_eater_of_worlds }
			if = {
				limit = {
					has_patron_relation = {
						patron = the_eater_of_worlds
						contact = completed
					}
				}
				add_attunement = { the_eater_of_worlds = @ai_bonus_attunement }
			}
		}
		else_if = {
			limit = { is_preferred_patron = the_cradle_of_souls }
			if = {
				limit = {
					has_patron_relation = {
						patron = the_cradle_of_souls
						contact = completed
					}
				}
				add_attunement = { the_cradle_of_souls = @ai_bonus_attunement }
			}
		}
		else_if = {
			limit = { is_preferred_patron = the_instrument_of_desire }
			if = {
				limit = {
					has_patron_relation = {
						patron = the_instrument_of_desire
						contact = completed
					}
				}
				add_attunement = { the_instrument_of_desire = @ai_bonus_attunement }
			}
		}
		else_if = {
			limit = { is_preferred_patron = the_composer_of_strands }
			if = {
				limit = {
					has_patron_relation = {
						patron = the_composer_of_strands
						contact = completed
					}
				}
				add_attunement = { the_composer_of_strands = @ai_bonus_attunement }
			}
		}
		else_if = {
			limit = { is_preferred_patron = whisperers_in_the_void }
			if = {
				limit = {
					has_patron_relation = {
						patron = whisperers_in_the_void
						contact = completed
					}
				}
				add_attunement = { whisperers_in_the_void = @ai_bonus_attunement }
			}
		}
	}
}

#==================================
# 100-999 Superstitious Beliefs
#==================================

# Roll a Cycle
country_event = {
	id = shroud.100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		random_list = {
			13 = {
				modifier = {
					has_country_flag = cycle_of_fortune_rolled
					has_country_flag = cycle_of_omens_rolled
					factor = 0
				}
				country_event = { id = shroud.105 }
			}
			87 = {
				country_event = { id = shroud.110 }
			}
		}
		country_event = { # Roll a new cycle in 13 years
			id = shroud.100
			years = @sb_cycles_duration_years
		}
	}
}

country_event = {
	id = shroud.105
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		random_list = {
			50 = { # Cycle of Fortune
				modifier = {
					has_country_flag = cycle_of_fortune_rolled
					factor = 0
				}
				country_event = { id = shroud.120 }
			}
			50 = { # Cycle of Omens
				modifier = {
					has_country_flag = cycle_of_omens_rolled
					factor = 0
				}
				country_event = { id = shroud.130 }
			}
		}
	}
}

# Roll a common Cycle
country_event = {
	id = shroud.110
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		random_list = {
			20 = { # Cycle of Growth
				modifier = {
					has_country_flag = cycle_of_growth_rolled
					factor = 0
				}
				country_event = { id = shroud.140 }
			}
			20 = { # Cycle of Prosperity
				modifier = {
					has_country_flag = cycle_of_prosperity_rolled
					factor = 0
				}
				country_event = { id = shroud.150 }
			}
			20 = { # Cycle of Conflict
				modifier = {
					has_country_flag = cycle_of_conflict_rolled
					factor = 0
				}
				country_event = { id = shroud.160 }
			}
			20 = { # Cycle of Harmony
				modifier = {
					has_country_flag = cycle_of_harmony_rolled
					factor = 0
				}
				country_event = { id = shroud.170 }
			}
			20 = { # Cycle of Knowledge
				modifier = {
					has_country_flag = cycle_of_knowledge_rolled
					factor = 0
				}
				country_event = { id = shroud.180 }
			}
		}
	}
}

# Cycle of Fortune
country_event = {
	id = shroud.120
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_fortune_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.210 }
		}
		launch_cycle_of_fortune = yes
	}
}

# Cycle of Omens
country_event = {
	id = shroud.130
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_omens_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.220 }
		}
		launch_cycle_of_omens = yes
	}
}

# Cycle of Growth
country_event = {
	id = shroud.140
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_growth_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.230 }
		}
		launch_cycle_of_growth = yes
	}
}

# Cycle of Prosperity
country_event = {
	id = shroud.150
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_prosperity_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.230 }
		}
		launch_cycle_of_prosperity = yes
	}
}

# Cycle of Conflict
country_event = {
	id = shroud.160
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_conflict_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.230 }
		}
		launch_cycle_of_conflict = yes
	}
}

# Cycle of Harmony
country_event = {
	id = shroud.170
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_harmony_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.230 }
		}
		launch_cycle_of_harmony = yes
	}
}

# Cycle of Knowledge
country_event = {
	id = shroud.180
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		clear_cycle_rolled_flags = yes
		set_country_flag = cycle_of_knowledge_rolled
		if = {
			limit = {
				NOT = { has_country_flag = first_cycle_rolled }
			}
			country_event = { id = shroud.230 }
		}
		launch_cycle_of_knowledge = yes
	}
}

# Superstitious Beliefs - Game start event
country_event = {
	id = shroud.200
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		add_resource = { unity = 50 } # Add enough unity to activate edict
		# Give Galactic Dowsing edict
		if = {
			limit = { is_gestalt = yes }
			add_edict = galactic_dowsing_gestalt
		}
		else = {
			add_edict = galactic_dowsing
		}
		# Remove extra unity
		export_resource_stockpile_to_variable = {
			resource = unity
			variable = unity_stockpile_to_clear
		}
		add_resource = {
			unity = -1
			mult = unity_stockpile_to_clear
		}

		set_country_flag = first_cycle_rolled # No event for the first cycle
		country_event = { id = shroud.110 } # Common cycle first
		country_event = { # Start the cycle loop in 13 years
			id = shroud.100
			years = @sb_cycles_duration_years
		}
	}

	after = {
		remove_country_flag = first_cycle_rolled
	}
}

# Cycle of Fortune event roll
country_event = {
	id = shroud.210
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		roll_superstitious_event = {
			POSITIVE = 75
			NEGATIVE = 25
		}
	}
}

# Cycle of Omen event roll
country_event = {
	id = shroud.220
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		roll_superstitious_event = {
			POSITIVE = 25
			NEGATIVE = 75
		}
	}
}

# Common cycle event roll
country_event = {
	id = shroud.230
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		roll_superstitious_event = {
			POSITIVE = 50
			NEGATIVE = 50
		}
	}
}

# Roll Cycle Command - Reroll a new cycle
country_event = {
	id = shroud.240
	hide_window = yes
	is_triggered_only = yes
	is_test_event = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		# Same effects as shroud.100 but without a new roll in 13 years
		random_list = {
			13 = {
				modifier = {
					has_country_flag = cycle_of_fortune_rolled
					has_country_flag = cycle_of_omens_rolled
					factor = 0
				}
				country_event = { id = shroud.105 }
			}
			87 = {
				country_event = { id = shroud.110 }
			}
		}
	}
}

# Update Cycles' bonuses (Leader)
leader_event = {
	id = shroud.300
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			NOT = { has_country_flag = recently_asked_reload_cycles }
			is_superstitious_beliefs_empire = yes
		}
		OR = {
			is_councilor_type = councilor_chief_medium
			is_councilor_type = councilor_executive_astrologist
		}
	}

	immediate = {
		owner = {
			set_country_flag = recently_asked_reload_cycles
			country_event = {
				id = shroud.315
				days = 1
			}
		}
	}
}

# Update Cycles' bonuses (Country)
country_event = {
	id = shroud.305
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = recently_asked_reload_cycles }
		is_superstitious_beliefs_empire = yes
		from = {
			OR = {
				is_councilor_type = councilor_chief_medium
				is_councilor_type = councilor_executive_astrologist
			}
		}
	}

	immediate = {
		set_country_flag = recently_asked_reload_cycles
		country_event = {
			id = shroud.315
			days = 1
		}
	}
}

# Update Cycles: attunement check
country_event = {
	id = shroud.310
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
		has_breached_shroud = yes
	}

	immediate = {
		if = {
			limit = { has_cycle_synergy = yes }
			if = {
				limit = {
					NOT = { has_country_flag = has_recently_cycle_synergy }
				}
				set_country_flag = has_recently_cycle_synergy
				if = {
					limit = {
						NOT = { has_country_flag = recently_asked_reload_cycles }
					}
					set_country_flag = recently_asked_reload_cycles
					country_event = {
						id = shroud.315
						days = 1
					}
				}
			}
		}
		else_if = {
			limit = { has_country_flag = has_recently_cycle_synergy }
			remove_country_flag = has_recently_cycle_synergy
			if = {
				limit = {
					NOT = { has_country_flag = recently_asked_reload_cycles }
				}
				set_country_flag = recently_asked_reload_cycles
				country_event = {
					id = shroud.315
					days = 1
				}
			}
		}
	}
}

# Update Cycles
country_event = {
	id = shroud.315
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = recently_asked_reload_cycles
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		if = {
			limit = { has_cycle_of_fortune = yes }
			launch_cycle_of_fortune = yes
		}
		else_if = {
			limit = { has_cycle_of_omens = yes }
			launch_cycle_of_omens = yes
		}
		else_if = {
			limit = { has_cycle_of_growth = yes }
			launch_cycle_of_growth = yes
		}
		else_if = {
			limit = { has_cycle_of_prosperity = yes }
			launch_cycle_of_prosperity = yes
		}
		else_if = {
			limit = { has_cycle_of_conflict = yes }
			launch_cycle_of_conflict = yes
		}
		else_if = {
			limit = { has_cycle_of_harmony = yes }
			launch_cycle_of_harmony = yes
		}
		else_if = {
			limit = { has_cycle_of_knowledge = yes }
			launch_cycle_of_knowledge = yes
		}
		remove_country_flag = recently_asked_reload_cycles
	}
}

# Pick positive event
country_event = {
	id = shroud.410
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		fire_on_action = {
			on_action = on_superstitious_beliefs_random_positive_events_list
		}
	}
}

# Pick negative event
country_event = {
	id = shroud.415
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_superstitious_beliefs_empire = yes
	}

	immediate = {
		fire_on_action = {
			on_action = on_superstitious_beliefs_random_negative_events_list
		}
	}
}

# Good luck events (500-699)
# Good Luck event 1
country_event = {
	id = shroud.500
	title = shroud.500.title
	desc = shroud.500.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_500_triggered }
	}

	immediate = {
		set_country_flag = shroud_500_triggered
	}

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		custom_tooltip = shroud.500.tt
		hidden_effect = {
			add_random_research_option = {
				add_progress = @good_luck_event_1_insight
				ignore_prereqs = no
				ignore_rare = no
			}
		}
	}
}

# Good Luck event 2
country_event = {
	id = shroud.505
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_505_triggered }
		OR = {
			any_owned_planet = {
				sb_district_event_trigger = {
					CATEGORY = mining
				}
			}
			AND = {
				is_nomadic = yes
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_505_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
						save_event_target_as = mining_planet
					}
				}
			}
			if = {
				limit = { exists = event_target:mining_planet }
				country_event = { id = shroud.508 }
			}
		}
		else = {
			random_owned_planet = {
				limit = {
					sb_district_event_trigger = {
						CATEGORY = mining
					}
				}
				save_event_target_as = mining_planet
				carrier_event = {
					id = shroud.507
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.507
	title = shroud.507.title
	desc = shroud.507.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		add_deposit = d_ore_rich_caverns
	}
}

# Good luck event 2 - Nomads
country_event = {
	id = shroud.508
	title = shroud.507.title
	desc = shroud.507.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		event_target:mining_planet = {
			add_deposit = d_minerals_3
		}
	}
}

# Good Luck event 3
country_event = {
	id = shroud.510
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_510_triggered }
		is_nomadic = no
		any_owned_planet = {
			OR = {
				OR = {
					is_planet_class = pc_gaia
					is_planet_class = pc_ocean
				}
				root = { is_anglers_empire = no }
			}
			sb_district_event_trigger = {
				CATEGORY = farming
			}
		}
	}

	immediate = {
		set_country_flag = shroud_510_triggered
		random_owned_planet = {
			limit = {
				OR = {
					OR = {
						is_planet_class = pc_gaia
						is_planet_class = pc_ocean
					}
					root = { is_anglers_empire = no }
				}
				sb_district_event_trigger = {
					CATEGORY = farming
				}
			}
			carrier_event = {
				id = shroud.512
			}
		}
	}
}

carrier_event = {
	id = shroud.512
	title = shroud.512.title
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			is_anglers_newfound_fertility = yes
		}
		text = shroud.512.desc_anglers
	}
	desc = {
		trigger = {
			is_anglers_newfound_fertility = no
		}
		text = shroud.512.desc
	}

	option = {
		name = HOW_FORTUITOUS
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		if = {
			limit = { is_anglers_newfound_fertility = yes }
			add_modifier = { modifier = lush_planet }
		}
		else = {
			add_deposit = d_fertile_lands
		}
	}
}

# Good Luck event 4
country_event = {
	id = shroud.515
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_515_triggered }
		is_nomadic = no
		any_owned_planet = {
			sb_district_event_trigger = {
				CATEGORY = generator
			}
		}
	}

	immediate = {
		set_country_flag = shroud_515_triggered
		random_owned_planet = {
			limit = {
				sb_district_event_trigger = {
					CATEGORY = generator
				}
			}
			carrier_event = {
				id = shroud.517
			}
		}
	}
}

carrier_event = {
	id = shroud.517
	title = shroud.517.title
	desc = shroud.517.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		add_deposit = d_geothermal_vent
	}
}

# Good Luck event 5
country_event = {
	id = shroud.520
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_520_triggered }
		is_superstitious_beliefs_empire = yes
		OR = {
			any_system_within_border = {
				any_system_planet = {
					has_research_station = yes
					NOT = { has_deposit_for = shipclass_mining_station }
					count_owned_pop_amount = { count <= 0 }
				}
			}
			AND = {
				is_nomadic = yes
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_physics_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_520_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_physics_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							OR = {
								can_have_physics_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
						save_event_target_as = physics_planet
					}
				}
			}
			if = {
				limit = { exists = event_target:physics_planet }
				country_event = { id = shroud.523 }
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					any_system_planet = {
						has_research_station = yes
						NOT = { has_deposit_for = shipclass_mining_station }
						count_owned_pop_amount = { count <= 0 }
					}
				}
				system_event = {
					id = shroud.522
				}
			}
		}
	}
}

system_event = {
	id = shroud.522
	title = shroud.522.title
	desc = shroud.522.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes
	location = this

	immediate = {
		random_system_planet = {
			limit = {
				has_research_station = yes
				NOT = { has_deposit_for = shipclass_mining_station }
				count_owned_pop_amount = { count <= 0 }
			}
			save_event_target_as = physics_planet
		}
	}

	option = {
		name = HOW_FORTUITOUS
		event_target:physics_planet = {
			add_deposit = d_physics_7
		}
	}
}

# Good luck event 5 - Nomads
country_event = {
	id = shroud.523
	title = shroud.522.title
	desc = shroud.522.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		event_target:physics_planet = {
			add_deposit = d_physics_7
		}
	}
}

# Good Luck event 6
country_event = {
	id = shroud.525
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_525_triggered }
		is_superstitious_beliefs_empire = yes
		OR = {
			any_system_within_border = {
				any_system_planet = {
					NOT = { has_deposit_for = shipclass_mining_station }
					count_owned_pop_amount = { count <= 0 }
				}
			}
			AND = {
				is_nomadic = yes
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_society_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_525_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_society_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							OR = {
								can_have_society_deposits = yes
								has_deposit_for = shipclass_research_station
							}
						}
						save_event_target_as = society_planet
					}
				}
			}
			if = {
				limit = { exists = event_target:society_planet }
				country_event = { id = shroud.526 }
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					any_system_planet = {
						NOT = { has_deposit_for = shipclass_mining_station }
						count_owned_pop_amount = { count <= 0 }
					}
				}
				system_event = {
					id = shroud.527
				}
			}
		}
	}
}

# Good luck event 6 - Nomads
country_event = {
	id = shroud.526
	title = shroud.527.title
	desc = shroud.527.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		event_target:society_planet = {
			add_deposit = d_society_7
		}
	}
}

system_event = {
	id = shroud.527
	title = shroud.527.title
	desc = shroud.527.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes
	location = this

	immediate = {
		random_system_planet = {
			limit = {
				NOT = { has_deposit_for = shipclass_mining_station }
				count_owned_pop_amount = { count <= 0 }
			}
			save_event_target_as = society_planet
		}
	}

	option = {
		name = HOW_FORTUITOUS
		event_target:society_planet = {
			add_deposit = d_society_7
		}
	}
}

# Good Luck event 7
country_event = {
	id = shroud.530
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_530_triggered }
		OR = {
			is_nomadic = no
			any_owned_fleet = { is_waystation_ship = yes }
		}
	}

	immediate = {
		set_country_flag = shroud_530_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = { is_waystation_ship = yes }
				solar_system = {
					save_event_target_as = lucky_wreckage_system
				}
			}
		}
		else = {
			random_system_within_border = {
				save_event_target_as = lucky_wreckage_system
			}
		}
		country_event = { id = shroud.532 }
	}
}

country_event = {
	id = shroud.532
	title = shroud.532.title
	desc = shroud.532.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes
	location = event_target:lucky_wreckage_system

	option = {
		name = shroud.532.a
		trigger = {
			is_superstitious_beliefs_empire = yes
		}
		if = {
			limit = {
				has_first_contact_dlc = yes
			}
			gain_superstitious_beliefs_cloaking_tech = yes
		}
		else = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
	}
}

# Good Luck event 8
country_event = {
	id = shroud.535
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_535_triggered }
		OR = {
			any_owned_planet = {
				sb_district_event_trigger = {
					CATEGORY = mining
				}
			}
			AND = {
				is_nomadic = yes
				any_owned_fleet = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_535_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = {
					is_waystation_ship = yes
					solar_system = {
						any_system_planet = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							OR = {
								can_have_mineral_deposits = yes
								has_deposit_for = shipclass_mining_station
							}
						}
						save_event_target_as = mining_planet
					}
				}
			}
			if = {
				limit = { exists = event_target:mining_planet }
				country_event = { id = shroud.536 }
			}
		}
		else = {
			random_owned_planet = {
				limit = {
					sb_district_event_trigger = {
						CATEGORY = mining
					}
				}
				save_event_target_as = mining_planet
				carrier_event = {
					id = shroud.537
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.537
	title = shroud.537.title
	desc = shroud.537.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		add_modifier = {
			modifier = geothermic_metallurgy
			days = -1
		}
	}
}

# Good luck event 8 - Nomads
country_event = {
	id = shroud.536
	title = shroud.537.title
	desc = shroud.537.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		event_target:mining_planet = {
			add_deposit = d_alloys_2
		}
	}
}

# Good Luck event 9
country_event = {
	id = shroud.540
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_540_triggered }
		OR = {
			is_nomadic = no
			any_owned_fleet = { is_waystation_ship = yes }
		}
	}

	immediate = {
		set_country_flag = shroud_540_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_fleet = {
				limit = { is_waystation_ship = yes }
				solar_system = {
					save_event_target_as = lucky_fleet_system
				}
			}
			event_target:lucky_fleet_system = {
				system_event = { id = shroud.542 }
			}
		}
		else = {
			random_system = {
				limit = {
					has_owner = no
					any_country_neighbor_to_system = {
						is_same_value = prevprev
					}
				}
				system_event = {
					id = shroud.542
				}
				prev = {
					set_country_flag = shroud.540_system_found
				}
			}
			if = {
				limit = {
					NOT = {
						has_country_flag = shroud.540_system_found
					}
				}
				random_system_within_border = {
					system_event = {
						id = shroud.542
					}
				}
			}
			remove_country_flag = shroud.540_system_found
		}
	}
}

system_event = {
	id = shroud.542
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			country_event = {
				id = shroud.543
			}
		}
	}
}

country_event = {
	id = shroud.543
	title = shroud.543.title
	desc = shroud.543.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = shroud.543.a
		trigger = { is_superstitious_beliefs_empire = yes }
		custom_tooltip = shroud.543.tt
		create_fleet = {
			effect = {
				set_owner = prev
				create_ship_with_random_graphical_culture = {
					EFFECT_NAME = create_well_found_cruiser_ship
					IGNORE_COUNTRY_GFX = yes
				}
				set_location = from
			}
		}
	}
}

# Good Luck event 10
country_event = {
	id = shroud.545
	title = shroud.545.title
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			is_gestalt = yes
		}
		text = shroud.545.desc_gestalt
	}
	desc = {
		trigger = {
			is_gestalt = no
		}
		text = shroud.545.desc
	}

	trigger = {
		NOT = { has_country_flag = shroud_545_triggered }
	}

	immediate = {
		set_country_flag = shroud_545_triggered
	}

	option = {
		name = shroud.545.a
		trigger = { is_superstitious_beliefs_empire = yes }
		if = {
			limit = {
				is_gestalt = yes
			}
			add_modifier = {
				modifier = unilateral_cohesion
				years = @sb_cycles_duration_years
			}
		}
		else = {
			add_modifier = {
				modifier = a_sense_of_optimism
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Good Luck event 11
country_event = {
	id = shroud.550
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_550_triggered }
		OR = {
			any_system_within_border = { sb_favorable_trine_system_trigger = yes }
			is_nomadic = yes
		}
	}

	immediate = {
		set_country_flag = shroud_550_triggered
		if = {
			limit = { is_nomadic = yes }
			capital_scope = {
				save_event_target_as = favorable_trine_colony
				solar_system = {
					random_system_planet = {
						limit = {
							NOT = { is_same_value = event_target:favorable_trine_colony }
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = favorable_trine_planet_1
					}
					random_system_planet = {
						limit = {
							NOR = {
								is_same_value = event_target:favorable_trine_colony
								is_same_value = event_target:favorable_trine_planet_1
							}
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = favorable_trine_planet_2
					}
					random_system_planet = {
						limit = {
							NOR = {
								is_same_value = event_target:favorable_trine_colony
								is_same_value = event_target:favorable_trine_planet_1
								is_same_value = event_target:favorable_trine_planet_2
							}
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = favorable_trine_planet_3
					}
					event_target:favorable_trine_colony = {
						carrier_event = { id = shroud.553 }
					}
				}
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					sb_favorable_trine_system_trigger = yes
				}
				set_star_flag = favorable_trine
				system_event = {
					id = shroud.552
				}
			}
		}
	}
}

system_event = {
	id = shroud.552
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_system_planet = {
			limit = {
				sb_aligment_colony_trigger = {
					OWNER = from
				}
			}
			save_event_target_as = favorable_trine_colony
		}
		random_system_planet = {
			limit = {
				NOT = {
					is_same_value = event_target:favorable_trine_colony
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = favorable_trine_planet_1
		}
		random_system_planet = {
			limit = {
				NOR = {
					is_same_value = event_target:favorable_trine_colony
					is_same_value = event_target:favorable_trine_planet_1
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = favorable_trine_planet_2
		}
		random_system_planet = {
			limit = {
				NOR = {
					is_same_value = event_target:favorable_trine_colony
					is_same_value = event_target:favorable_trine_planet_1
					is_same_value = event_target:favorable_trine_planet_2
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = favorable_trine_planet_3
		}
		event_target:favorable_trine_colony = {
			carrier_event = {
				id = shroud.553
			}
		}
	}
}

carrier_event = {
	id = shroud.553
	title = shroud.553.title
	desc = shroud.553.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = shroud.553.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		add_modifier = {
			modifier = favorable_trine
			years = @sb_cycles_duration_years
		}
	}
}

# Good Luck event 12
country_event = {
	id = shroud.555
	title = shroud.555.title
	desc = shroud.555.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_555_triggered }
		capital_scope.solar_system? = {
			any_system_planet = {
				NOT = { is_same_value = root.capital_scope }
			}
		}
	}

	immediate = {
		set_country_flag = shroud_555_triggered
		capital_scope.solar_system = {
			random_system_planet = {
				limit = {
					NOT = { is_same_value = root.capital_scope }
				}
				save_event_target_as = auspicious_position_planet
			}
		}
	}

	option = {
		name = HOW_FORTUITOUS
		trigger = { is_superstitious_beliefs_empire = yes }
		add_modifier = {
			modifier = auspicious_planet_alignment
			years = @sb_cycles_duration_years
		}
	}
}

# Good Luck event 13
country_event = {
	id = shroud.560
	title = shroud.560.title
	desc = shroud.560.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_560_triggered }
	}

	immediate = {
		set_country_flag = shroud_560_triggered
	}

	option = {
		name = shroud.560.a
		trigger = { is_superstitious_beliefs_empire = yes }
		add_modifier = {
			modifier = elemental_harmony
			years = @sb_cycles_duration_years
		}
	}
}

# Good Luck event 14
country_event = {
	id = shroud.565
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_565_triggered }
		OR = {
			any_system_within_border = {
				sb_luminary_system_trigger = yes
			}
			any_owned_fleet = {
				is_arkship_fleet = yes
				solar_system? = {
					NOR = {
						is_star_class = sc_black_hole
						any_system_megastructure = {
							OR = {
								is_megastructure_type = dyson_sphere_0
								is_megastructure_type = dyson_sphere_1
								is_megastructure_type = dyson_sphere_2
								is_megastructure_type = dyson_sphere_3
								is_megastructure_type = dyson_sphere_4
								is_megastructure_type = dyson_sphere_5
								is_megastructure_type = dyson_sphere_ruined
								is_megastructure_type = dyson_sphere_restored
								is_megastructure_type = dyson_swarm_1
								is_megastructure_type = dyson_swarm_2
								is_megastructure_type = dyson_swarm_3
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_565_triggered
		if = {
			limit = {
				is_nomadic = no
			}
			random_system_within_border = {
				limit = {
					sb_luminary_system_trigger = yes
					any_system_planet = {
						sb_radiant_luminary_planet_trigger = yes
					}
				}
				system_event = {
					id = shroud.567
				}
				prev = {
					set_country_flag = shroud.565_system_found
				}
			}
			if = {
				limit = {
					NOT = {
						has_country_flag = shroud.565_system_found
					}
				}
				random_system_within_border = {
					limit = {
						sb_luminary_system_trigger = yes
					}
					system_event = {
						id = shroud.542
					}
				}
			}
			remove_country_flag = shroud.565_system_found
		}
		else = {
			random_owned_ship = {
				limit = {
					is_arkship_ship = yes
					solar_system? = {
						NOR = {
							is_star_class = sc_black_hole
							any_system_megastructure = {
								OR = {
									is_megastructure_type = dyson_sphere_0
									is_megastructure_type = dyson_sphere_1
									is_megastructure_type = dyson_sphere_2
									is_megastructure_type = dyson_sphere_3
									is_megastructure_type = dyson_sphere_4
									is_megastructure_type = dyson_sphere_5
									is_megastructure_type = dyson_sphere_ruined
									is_megastructure_type = dyson_sphere_restored
									is_megastructure_type = dyson_swarm_1
									is_megastructure_type = dyson_swarm_2
									is_megastructure_type = dyson_swarm_3
								}
							}
						}
					}
				}
				weights = {
					base = 1
					modifier = {
						factor = 2
						planet_resource_compare = {
							resource = energy
							value >= 10
						}
					}
					modifier = {
						factor = 5
						planet_resource_compare = {
							resource = energy
							value >= 100
						}
					}
				}
				carrier_event = {
					id = shroud.568
					scopes = {
						from = solar_system
					}
				}
			}
		}
	}
}

system_event = {
	id = shroud.567
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_system_planet = {
			limit = {
				sb_radiant_luminary_planet_trigger = yes
			}
			carrier_event = {
				id = shroud.568
			}
			prev = {
				set_star_flag = shroud.567_planet_found
			}
		}
		if = {
			limit = {
				NOT = {
					has_star_flag = shroud.567_planet_found
				}
			}
			random_system_planet = {
				carrier_event = {
					id = shroud.568
				}
			}
		}
		remove_star_flag = shroud.567_planet_found
	}
}

carrier_event = {
	id = shroud.568
	title = shroud.568.title
	desc = shroud.568.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	option = {
		name = shroud.568.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		add_modifier = {
			modifier = radiant_luminary
			years = @sb_cycles_duration_years
		}
	}
}

# Good Luck event 15
country_event = {
	id = shroud.570
	title = shroud.570.title
	desc = shroud.570.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	trigger = {
		is_gestalt = no
		NOT = { has_country_flag = shroud_570_triggered }
		count_owned_leader = {
			limit = {
				sb_councilor_harmony_leader_trigger = yes
			}
			count >= 2
		}
	}

	immediate = {
		set_country_flag = shroud_570_triggered
		random_owned_leader = {
			limit = {
				sb_councilor_harmony_leader_trigger = yes
			}
			set_leader_flag = councilor_harmony
			save_event_target_as = councilor_harmony_leader_1
		}
		random_owned_leader = {
			limit = {
				sb_councilor_harmony_leader_trigger = yes
			}
			set_leader_flag = councilor_harmony
			save_event_target_as = councilor_harmony_leader_2
		}
	}

	option = {
		name = shroud.570.a
		trigger = { is_superstitious_beliefs_empire = yes }
		add_modifier = {
			modifier = councilor_harmony
			years = @sb_cycles_duration_years
		}
	}
}

# Good Luck event 16
country_event = {
	id = shroud.575
	title = shroud.575.title
	desc = shroud.575.desc
	picture = GFX_evt_superstition_good_luck
	show_sound = event_good_luck
	is_triggered_only = yes

	trigger = {
		has_grand_archive_dlc = yes
		NOT = { has_country_flag = shroud_575_triggered }
		has_grand_archive = yes
		count_exhibit = {
			count > 0
		}
		any_exhibit = {
			is_exhibit_active = yes
			is_specimen_category = historical_item
		}
	}

	immediate = {
		set_country_flag = shroud_575_triggered
	}

	option = {
		name = shroud.575.a
		trigger = { is_superstitious_beliefs_empire = yes }
		add_monthly_resource_mult = {
			resource = minor_artifacts
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
	}
}

# Bad luck events (700-899)
# Bad Luck event 1
country_event = {
	id = shroud.700
	title = shroud.700.title
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			is_gestalt = yes
		}
		text = shroud.700.desc_gestalt
	}
	desc = {
		trigger = {
			is_gestalt = no
		}
		text = shroud.700.desc
	}

	trigger = {
		NOT = { has_country_flag = shroud_700_triggered }
	}

	immediate = {
		set_country_flag = shroud_700_triggered
		add_modifier = {
			modifier = discordance
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			add_modifier = {
				modifier = discordance
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad luck event 2
country_event = {
	id = shroud.705
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_705_triggered }
		any_owned_fleet = {
			sb_naval_collision_fleet_trigger = yes
		}
	}

	immediate = {
		set_country_flag = shroud_705_triggered
		random_owned_fleet = {
			limit = {
				sb_naval_collision_fleet_trigger = yes
			}
			fleet_event = {
				id = shroud.707
			}
		}
	}
}

fleet_event = {
	id = shroud.707
	title = shroud.707.title
	desc = shroud.707.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		while = {
			count = 5
			random_owned_ship = {
				limit = {
					sb_naval_collision_ship_trigger = yes
				}
				weights = {
					base = 1
					modifier = {
						factor = 3
						is_designable = yes
					}
				}
				destroy_ship = this
			}
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		custom_tooltip = shroud.707.tt
	}
}

# Bad luck event 3
country_event = {
	id = shroud.710
	title = shroud.710.title
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	desc = {
		text = shroud.710.desc_default
		trigger = {
			exists = event_target:silo_fire_planet_targeted
		}
	}
	desc = {
		text = shroud.710.desc_starbase
		trigger = {
			exists = event_target:silo_fire_starbase_targeted
		}
	}
	desc = {
		text = shroud.710.desc
		trigger = {
			NOR = {
				exists = event_target:silo_fire_planet_targeted
				exists = event_target:silo_fire_starbase_targeted
			}
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_710_triggered }
		OR = {
			any_owned_planet = {
				has_building = building_resource_silo
			}
			any_owned_starbase = {
				has_starbase_building = resource_silo
			}
			any_owned_nonprimary_starbase = {
				is_waystation_starbase = yes
				has_starbase_module = waystation_resource_silo
			}
		}
	}

	immediate = {
		set_country_flag = shroud_710_triggered
		random_list = {
			50 = {
				modifier = {
					factor = 0
					NOT = {
						any_owned_planet = {
							has_building = building_resource_silo
						}
					}
				}
				random_owned_planet = {
					limit = {
						has_building = building_resource_silo
					}
					save_event_target_as = silo_fire_planet_targeted
					ruin_building = building_resource_silo
				}
			}
			50 = {
				modifier = {
					factor = 0
					NOT = {
						any_owned_starbase = {
							has_starbase_building = resource_silo
						}
					}
				}
				random_owned_starbase = {
					limit = {
						has_starbase_building = resource_silo
					}
					save_event_target_as = silo_fire_starbase_targeted
					remove_starbase_building = {
						building = resource_silo
					}
				}
			}
			50 = {
				modifier = {
					factor = 0
					NOT = {
						any_owned_nonprimary_starbase = {
							is_waystation_starbase = yes
							has_starbase_module = waystation_resource_silo
						}
					}
				}
				random_owned_nonprimary_starbase = {
					limit = {
						is_waystation_starbase = yes
						has_starbase_module = waystation_resource_silo
					}
					save_event_target_as = silo_fire_starbase_targeted
					remove_starbase_module = {
						module = waystation_resource_silo
					}
				}
			}
		}
		add_percentage_to_all_resources = {
			PERCENTAGE = @silo_fire_resources_lost
		}
	}
	option = {
		name = shroud.710.a
		custom_tooltip = shroud.710.tt_default
		trigger = {
			is_superstitious_beliefs_empire = yes
			exists = event_target:silo_fire_planet_targeted
		}
	}
	option = {
		name = shroud.710.a
		custom_tooltip = shroud.710.tt_starbase
		trigger = {
			is_superstitious_beliefs_empire = yes
			exists = event_target:silo_fire_starbase_targeted
		}
	}
}

# Bad luck event 4
country_event = {
	id = shroud.715
	title = shroud.715.title
	desc = shroud.715.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_715_triggered }
		is_galactic_community_member = yes
		count_galcom_member = {
			count >= 2
		}
	}

	immediate = {
		set_country_flag = shroud_715_triggered
		random_galcom_member = {
			limit = {
				NOT = {
					is_same_value = prev
				}
			}
			save_event_target_as = diplomatic_faux_pas_victim
		}
		add_modifier = {
			modifier = diplomatic_faux_pas
			years = @sb_cycles_duration_years
		}
		random_owned_leader = {
			limit = {
				has_envoy_task = {
					task = galactic_community
				}
			}
			save_event_target_as = diplomatic_faux_pas_galcom_envoy
			gain_leader_trait_level_max_2 = {
				LEADER_TRAIT = leader_trait_fallible
			}
		}
	}

	option = {
		name = shroud.715.a
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			add_modifier = {
				modifier = diplomatic_faux_pas
				years = @sb_cycles_duration_years
			}
		}
		if = {
			limit = {
				exists = event_target:diplomatic_faux_pas_galcom_envoy
			}
			custom_tooltip = shroud.715.tt
		}
	}
}

# Bad luck event 5
country_event = {
	id = shroud.720
	title = shroud.720.title
	desc = {
		trigger = {
			text = shroud.720.desc
			if = {
				limit = { has_cosmic_storms_dlc = yes }
				text = newline
				text = shroud.720.desc_storm
			}
		}
	}
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_720_triggered }
		any_system_within_border = {
			sb_extreme_solar_flare_system_trigger = yes
		}
	}

	immediate = {
		set_country_flag = shroud_720_triggered
		random_system_within_border = {
			limit = {
				sb_extreme_solar_flare_system_trigger = yes
			}
			weights = {
				base = 1
				modifier = {
					factor = 4
					count_ship_in_system = {
						count >= 4
						limit = {
							sb_extreme_solar_flare_ship_trigger = yes
						}
					}
				}
			}
			save_event_target_as = extreme_solar_flare_system
			every_ship_in_system = {
				limit = {
					sb_extreme_solar_flare_ship_trigger = yes
				}
				destroy_ship = this
			}
			if = {
				limit = {
					has_cosmic_storms_dlc = yes
				}
				spawn_random_storm = {
					type = celestial_storm
					immediate = yes
					cosmic_storm_start_position = this
				}
			}
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		custom_tooltip = shroud.720.tt
		tooltip = {
			if = {
				limit = {
					has_cosmic_storms_dlc = yes
					exists = event_target:extreme_solar_flare_system
				}
				event_target:extreme_solar_flare_system = {
					spawn_random_storm = {
						type = celestial_storm
						immediate = yes
						cosmic_storm_start_position = this
					}
				}
			}
		}
	}
}

# Bad luck event 6
country_event = {
	id = shroud.725
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_725_triggered }
		any_owned_leader = {
			sb_high_profile_traffic_accident_leader_trigger = yes
		}
	}

	immediate = {
		set_country_flag = shroud_725_triggered
		random_owned_planet = {
			save_event_target_as = high_profile_traffic_accident_planet
		}
		random_owned_leader = {
			limit = {
				sb_high_profile_traffic_accident_leader_trigger = yes
			}
			weights = {
				base = 3
				modifier = {
					factor = 3
					is_same_species = root.species
					has_total_skill > 3
				}
				modifier = {
					factor = 0.333
					NOT = { is_leader_tier = leader_tier_default }
				}
			}
			random_list = {
				50 = {
					leader_event = {
						id = shroud.727
					}
				}
				50 = {
					modifier = {
						factor = 0
						NOT = {
							leader_class = scientist
							has_trait = leader_trait_maimed
						}
					}
					leader_event = {
						id = shroud.728
					}
				}
			}
		}
	}
}

leader_event = {
	id = shroud.727
	title = shroud.725.title
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			is_machine_species = yes
		}
		text = shroud.725.desc_killed_machine
	}
	desc = {
		trigger = {
			is_organic_species = yes
		}
		text = shroud.725.desc_killed
	}
	desc = {
		trigger = {
			NOR = {
				is_machine_species = yes
				is_organic_species = yes
			}
		}
		text = shroud.725.desc
	}

	immediate = {
		kill_leader = {
			show_notification = yes
		}
	}

	option = {
		name = shroud.725.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			kill_leader = {
				show_notification = yes
			}
		}
	}
}

leader_event = {
	id = shroud.728
	title = shroud.725.title
	desc = shroud.725.desc_maimed
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		add_trait = { trait = leader_trait_maimed }
	}

	option = {
		name = shroud.725.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			add_trait = { trait = leader_trait_maimed }
		}
	}
}

# Bad luck event 7
country_event = {
	id = shroud.730
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_730_triggered }
		any_owned_planet = {
			sb_massive_sinkholes_planet_trigger = yes
		}
	}

	immediate = {
		set_country_flag = shroud_730_triggered
		random_owned_planet = {
			limit = {
				sb_massive_sinkholes_planet_trigger = yes
			}
			carrier_event = {
				id = shroud.732
			}
		}
	}
}

carrier_event = {
	id = shroud.732
	title = shroud.730.title
	desc = shroud.730.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		ruin_building = random_no_capital
		add_blocker = {
			type = d_deep_sinkhole
		}
		add_blocker = {
			type = d_deep_sinkhole
		}
	}

	option = {
		name = shroud.730.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		custom_tooltip = shroud.730.tt
		tooltip = {
			add_blocker = {
				type = d_deep_sinkhole
			}
			add_blocker = {
				type = d_deep_sinkhole
			}
		}
	}
}

# Bad luck event 8
country_event = {
	id = shroud.735
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_735_triggered }
		any_owned_planet = {
			sb_spontaneous_uproar_planet_trigger = yes
		}
	}

	immediate = {
		set_country_flag = shroud_735_triggered
		random_owned_planet = {
			limit = {
				sb_spontaneous_uproar_planet_trigger = yes
			}
			carrier_event = {
				id = shroud.737
			}
		}
	}
}

carrier_event = {
	id = shroud.737
	title = shroud.735.title
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			from = {
				is_hive_empire = yes
			}
		}
		text = shroud.735.desc_hive
	}
	desc = {
		trigger = {
			from = {
				is_machine_empire = yes
			}
		}
		text = shroud.735.desc_machine
	}
	desc = {
		trigger = {
			from = {
				NOR = {
					is_hive_empire = yes
					is_machine_empire = yes
				}
			}
		}
		text = shroud.735.desc
	}

	immediate = {
		add_planet_devastation = 25
		random_owned_pop_group = {
			kill_single_pop = yes
		}
	}

	option = {
		name = shroud.735.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			add_planet_devastation = 25
			random_owned_pop_group = {
				kill_single_pop = yes
			}
		}
	}
}

# Bad luck event 9
country_event = {
	id = shroud.740
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_machine_species = no
		NOT = { has_country_flag = shroud_740_triggered }
		any_owned_planet = {
			is_homeworld = no
		}
	}

	immediate = {
		set_country_flag = shroud_740_triggered
		random_owned_planet = {
			limit = {
				is_homeworld = no
			}
			carrier_event = {
				id = shroud.742
			}
		}
	}
}

carrier_event = {
	id = shroud.742
	title = shroud.740.title
	desc = shroud.740.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				owner = {
					is_gestalt = yes
				}
			}
			add_modifier = {
				modifier = hypertransmissible_virus_gestalt
				years = @sb_cycles_duration_years
			}
		}
		else = {
			add_modifier = {
				modifier = hypertransmissible_virus
				years = @sb_cycles_duration_years
			}
		}
	}

	option = {
		name = UNFORTUNATE
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			if = {
				limit = {
					owner = {
						is_gestalt = yes
					}
				}
				add_modifier = {
					modifier = hypertransmissible_virus_gestalt
					years = @sb_cycles_duration_years
				}
			}
			else = {
				add_modifier = {
					modifier = hypertransmissible_virus
					years = @sb_cycles_duration_years
				}
			}
		}
	}
}

# Bad luck event 10
country_event = {
	id = shroud.745
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_745_triggered }
		OR = {
			any_system_within_border = { sb_calamitous_quartile_system_trigger = yes }
			any_owned_fleet = {
				is_arkship_fleet = yes
				solar_system? = {
					count_system_planet = {
						count >= 4
						limit = { sb_aligment_planet_trigger = yes }
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_745_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_ship = {
				limit = {
					is_arkship_ship = yes
					solar_system? = {
						count_system_planet = {
							count >= 4
							limit = { sb_aligment_planet_trigger = yes }
						}
					}
				}
				solar_system? = {
					random_system_planet = {
						limit = { sb_aligment_planet_trigger = yes }
						save_event_target_as = calamitous_quartile_planet_1
					}
					random_system_planet = {
						limit = {
							NOT = { is_same_value = event_target:calamitous_quartile_planet_1 }
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = calamitous_quartile_planet_2
					}
					random_system_planet = {
						limit = {
							NOR = {
								is_same_value = event_target:calamitous_quartile_planet_1
								is_same_value = event_target:calamitous_quartile_planet_2
							}
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = calamitous_quartile_planet_3
					}
					random_system_planet = {
						limit = {
							NOR = {
								is_same_value = event_target:calamitous_quartile_planet_1
								is_same_value = event_target:calamitous_quartile_planet_2
								is_same_value = event_target:calamitous_quartile_planet_3
							}
							sb_aligment_planet_trigger = yes
						}
						save_event_target_as = calamitous_quartile_planet_4
					}
				}
				carrier_event = {
					id = shroud.748
					scopes = {
						from = solar_system
						fromfrom = root
					}
				}
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					sb_calamitous_quartile_system_trigger = yes
				}
				system_event = {
					id = shroud.747
				}
			}
		}
	}
}

system_event = {
	id = shroud.747
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		random_system_planet = {
			limit = {
				sb_aligment_colony_trigger = {
					OWNER = from
				}
			}
			save_event_target_as = calamitous_quartile_colony
		}
		random_system_planet = {
			limit = {
				NOT = {
					is_same_value = event_target:calamitous_quartile_colony
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = calamitous_quartile_planet_1
		}
		random_system_planet = {
			limit = {
				NOR = {
					is_same_value = event_target:calamitous_quartile_colony
					is_same_value = event_target:calamitous_quartile_planet_1
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = calamitous_quartile_planet_2
		}
		random_system_planet = {
			limit = {
				NOR = {
					is_same_value = event_target:calamitous_quartile_colony
					is_same_value = event_target:calamitous_quartile_planet_1
					is_same_value = event_target:calamitous_quartile_planet_2
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = calamitous_quartile_planet_3
		}
		random_system_planet = {
			limit = {
				NOR = {
					is_same_value = event_target:calamitous_quartile_colony
					is_same_value = event_target:calamitous_quartile_planet_1
					is_same_value = event_target:calamitous_quartile_planet_2
					is_same_value = event_target:calamitous_quartile_planet_3
				}
				sb_aligment_planet_trigger = yes
			}
			save_event_target_as = calamitous_quartile_planet_4
		}
		event_target:calamitous_quartile_colony = {
			carrier_event = {
				id = shroud.748
			}
		}
	}
}

carrier_event = {
	id = shroud.748
	title = shroud.745.title
	desc = shroud.745.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		add_modifier = {
			modifier = calamitous_quartile
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = shroud.745.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			add_modifier = {
				modifier = calamitous_quartile
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad luck event 11
country_event = {
	id = shroud.750
	title = shroud.750.title
	desc = shroud.750.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_750_triggered }
		capital_scope = {
			exists = owner
			owner = {
				is_same_value = prevprev
			}
			pop_amount > 0
		}
	}

	immediate = {
		set_country_flag = shroud_750_triggered
		capital_scope = {
			save_event_target_as = planet_in_retrograde_home
			solar_system = {
				random_system_planet = {
					limit = {
						NOT = {
							is_same_value = prevprev
						}
						is_star = no
						is_astral_scar = no
						is_asteroid = no
						is_moon = no
					}
					save_event_target_as = planet_in_retrograde_planet
				}
			}
		}
		add_modifier = {
			modifier = planet_in_retrograde
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			add_modifier = {
				modifier = planet_in_retrograde
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad luck event 12
country_event = {
	id = shroud.755
	title = shroud.755.title
	desc = shroud.755.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_755_triggered }
	}

	immediate = {
		set_country_flag = shroud_755_triggered
		add_modifier = {
			modifier = elemental_imbalance
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = shroud.755.a
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			add_modifier = {
				modifier = elemental_imbalance
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad luck event 13
country_event = {
	id = shroud.760
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = shroud_760_triggered }
		OR = {
			any_system_within_border = { sb_luminary_system_trigger = yes }
			any_owned_fleet = {
				is_arkship_fleet = yes
				solar_system? = {
					NOR = {
						is_star_class = sc_black_hole
						any_system_megastructure = {
							OR = {
								is_megastructure_type = dyson_sphere_0
								is_megastructure_type = dyson_sphere_1
								is_megastructure_type = dyson_sphere_2
								is_megastructure_type = dyson_sphere_3
								is_megastructure_type = dyson_sphere_4
								is_megastructure_type = dyson_sphere_5
								is_megastructure_type = dyson_sphere_ruined
								is_megastructure_type = dyson_sphere_restored
								is_megastructure_type = dyson_swarm_1
								is_megastructure_type = dyson_swarm_2
								is_megastructure_type = dyson_swarm_3
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_760_triggered
		if = {
			limit = { is_nomadic = yes }
			random_owned_ship = {
				limit = {
					is_arkship_ship = yes
					solar_system? = {
						NOR = {
							is_star_class = sc_black_hole
							any_system_megastructure = {
								OR = {
									is_megastructure_type = dyson_sphere_0
									is_megastructure_type = dyson_sphere_1
									is_megastructure_type = dyson_sphere_2
									is_megastructure_type = dyson_sphere_3
									is_megastructure_type = dyson_sphere_4
									is_megastructure_type = dyson_sphere_5
									is_megastructure_type = dyson_sphere_ruined
									is_megastructure_type = dyson_sphere_restored
									is_megastructure_type = dyson_swarm_1
									is_megastructure_type = dyson_swarm_2
									is_megastructure_type = dyson_swarm_3
								}
							}
						}
					}
				}
				carrier_event = {
					id = shroud.763
					scopes = { from = solar_system }
				}
			}
		}
		else = {
			random_system_within_border = {
				limit = {
					sb_luminary_system_trigger = yes
				}
				system_event = {
					id = shroud.762
				}
			}
		}
	}
}

system_event = {
	id = shroud.762
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		# pick one planet colony, or fall through to an arkship colony if none exists
		if = {
			limit = { any_system_planet_colony = { always = yes } }
			random_system_planet_colony = {
				carrier_event = {
					id = shroud.763
				}
			}
		}
		else = {
			random_system_ship_colony = {
				carrier_event = {
					id = shroud.763
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.763
	title = shroud.760.title
	desc = shroud.760.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	immediate = {
		add_modifier = {
			modifier = waning_luminary
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = shroud.760.a
		trigger = {
			owner = { is_superstitious_beliefs_empire = yes }
		}
		tooltip = {
			add_modifier = {
				modifier = waning_luminary
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad Luck event 14
country_event = {
	id = shroud.765
	title = shroud.765.title
	desc = shroud.765.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		is_gestalt = no
		NOT = { has_country_flag = shroud_765_triggered }
		count_owned_leader = {
			limit = {
				sb_discordant_council_leader_trigger = yes
			}
			count >= 2
		}
	}

	immediate = {
		set_country_flag = shroud_765_triggered
		random_owned_leader = {
			limit = {
				sb_discordant_council_leader_trigger = yes
			}
			set_leader_flag = discordant_council
			save_event_target_as = discordant_council_leader_1
		}
		random_owned_leader = {
			limit = {
				sb_discordant_council_leader_trigger = yes
			}
			set_leader_flag = discordant_council
			save_event_target_as = discordant_council_leader_2
		}
		add_modifier = {
			modifier = discordant_council
			years = @sb_cycles_duration_years
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			add_modifier = {
				modifier = discordant_council
				years = @sb_cycles_duration_years
			}
		}
	}
}

# Bad Luck event 15
country_event = {
	id = shroud.770
	title = shroud.770.title
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	desc = {
		trigger = {
			is_machine_empire = yes
		}
		text = shroud.770.desc_machine
	}
	desc = {
		trigger = {
			is_hive_empire = yes
		}
		text = shroud.770.desc_hive
	}
	desc = {
		trigger = {
			NOR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
		text = shroud.770.desc_default
	}

	trigger = {
		is_homicidal = no
		NOT = { has_country_flag = shroud_770_triggered }
		count_relation = {
			limit = {
				is_country_type = default
				has_communications = prev
			}
			count >= 1
		}
	}

	immediate = {
		set_country_flag = shroud_770_triggered
		random_relation = {
			limit = {
				is_country_type = default
				has_communications = prev
			}
			save_event_target_as = careless_talk_empire
			add_opinion_modifier = {
				who = prev
				modifier = opinion_careless_talk
			}
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		tooltip = {
			event_target:careless_talk_empire = {
				add_opinion_modifier = {
					who = prev
					modifier = opinion_careless_talk
				}
			}
		}
	}
}

# Bad Luck event 16
country_event = {
	id = shroud.775
	title = shroud.775.title
	desc = shroud.775.desc
	picture = GFX_evt_superstition_bad_luck
	show_sound = event_bad_luck
	is_triggered_only = yes

	trigger = {
		has_grand_archive_dlc = yes
		NOT = { has_country_flag = shroud_775_triggered }
		has_grand_archive = yes
		count_exhibit = {
			count >= 2
			limit = {
				prev = {
					has_specimen = prev
				}
			}
		}
	}

	immediate = {
		set_country_flag = shroud_775_triggered
		random_exhibit = {
			limit = {
				prev = {
					has_specimen = prev
				}
			}
			weights = {
				base = 1
				modifier = {
					factor = 3
					is_specimen_rarity = rare
				}
				modifier = {
					factor = 5
					is_specimen_rarity = epic
				}
				modifier = {
					factor = 7
					is_specimen_rarity = exceptional
				}
			}
			prev = {
				remove_specimen = prev
			}
		}
	}

	option = {
		name = HOW_UNFORTUNATE
		trigger = { is_superstitious_beliefs_empire = yes }
		custom_tooltip = shroud.775.tt
	}
}

country_event = {
	id = shroud.800
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			has_civic = civic_superstitious_beliefs
			has_civic = civic_hive_superstitious_beliefs
			has_civic = civic_machine_superstitious_beliefs
			has_civic = civic_corporate_superstitious_beliefs
		}
	}

	immediate = {
		set_country_flag = was_superstitious_beliefs_empire
	}
}

country_event = {
	id = shroud.805
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = was_superstitious_beliefs_empire
	}

	immediate = {
		if = {
			limit = { is_superstitious_beliefs_empire = no }
			break_cycles = yes
			clear_cycle_flags = yes
		}
		remove_country_flag = was_superstitious_beliefs_empire
	}
}

#==================================
# 1000-1499 Experimental Testing
#==================================

# See shroud_situation_events.txt

#==================================
# 1500-1999 Psionic Auras
#==================================

colony_event = {
	id = shroud.1500
	hide_window = yes
	is_triggered_only = yes

	pre_triggers = {
		has_owner = yes
		has_ground_combat = no
	}

	trigger = {
		exists = owner
		solar_system? = { is_psionic_aura_suppressed = no }
	}

	immediate = {
		if = { # Psionic pops takes priority over Psionic Offices
			limit = {
				owner = { has_technology = tech_psionic_aura }
				any_owned_pop_group = {
					has_psionic_species_trait = yes
				}
			}
			solar_system = {
				natural_spawn_psionic_aura = { OWNER = root.owner }
			}
		}
		else_if = {
			limit = {
				has_branch_office = yes
				has_holding = {
					holding = building_psionic_offices
					owner = branch_office_owner
				}
				solar_system = {
					OR = {
						has_psionic_aura = no
						aura_owner = {
							NOT = { is_same_value = root.owner }
						}
					}
				}
			}
			solar_system = {
				natural_spawn_psionic_aura = { OWNER = root.branch_office_owner }
			}
		}
	}
}

country_event = {
	id = shroud.1505
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_technology = tech_aura_resonation
	}

	immediate = {
		every_owned_starbase = {
			limit = {
				has_starbase_aura_emitter = yes
				solar_system = {
					is_psionic_aura_suppressed = no
				}
			}
			solar_system = {
				natural_spawn_psionic_aura = { OWNER = root }
			}
		}
		every_owned_nonprimary_starbase = {
			limit = {
				has_starbase_aura_emitter = yes
				solar_system = {
					is_psionic_aura_suppressed = no
				}
			}
			solar_system = {
				natural_spawn_psionic_aura = { OWNER = root }
			}
		}
	}
}

country_event = {
	id = shroud.1510
	title = shroud.1510.title
	desc = shroud.1510.desc
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes

	option = {
		name = shroud.1510.a
	}
}

country_event = {
	id = shroud.1550
	title = shroud.1550.title
	desc = {
		trigger = {
			if = {
				limit = { has_country_flag = has_encountered_psionic_auras }
				if = {
					limit = { is_homicidal = yes }
					text = shroud.1550.desc.knows.homicidal
				}
				else = {
					text = shroud.1550.desc.knows
				}
			}
			else = {
				if = {
					limit = { is_homicidal = yes }
					text = shroud.1550.desc.default.homicidal
				}
				else = {
					text = shroud.1550.desc.default
				}
			}
		}
	}
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes

	trigger = {
		attunement >= 0.5
		NOT = { has_country_flag = power_of_will }
		has_country_flag = breached_shroud
	}

	immediate = {
		set_country_flag = power_of_will
	}

	option = {
		name = shroud.1550.a
		if = {
			limit = { NOT = { has_technology = tech_psionic_aura } }
			if = {
				limit = { NOT = { has_tech_option = tech_psionic_aura } }
				add_research_option = tech_psionic_aura
			}
			add_tech_progress = {
				tech = tech_psionic_aura
				progress = 0.1
			}
		}
	}
}

country_event = {
	id = shroud.1560
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_technology = tech_psionic_aura
		NOR = {
			has_technology = tech_aura_intensification
			has_tech_option = tech_aura_intensification
		}
	}

	immediate = {
		add_research_option = tech_aura_intensification
		create_message = {
			type = MESSAGE_TYPE_AURA_INTENSIFICATION_INSIGHT
			localization = MESSAGE_AURA_INTENSIFICATION_INSIGHT_DESC
			days = 30
		}
	}
}

country_event = {
	id = shroud.1565
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		last_increased_tech = tech_psionic_aura
		OR = {
			has_any_covenant = yes
			has_country_flag = forging_our_own_path
		}
	}

	immediate = {
		country_event = { id = shroud.1560 }
	}
}

#==================================
# 2000-2999 Breaching the Shroud
#==================================

# See shroud_situation_events.txt

#==================================
# 3000-3499 Delve Events
#==================================

## Fleeting Impressions
# Eater of Worlds
country_event = {
	id = shroud.3000
	base = shroud.3

	title = shroud.3000.title
	desc_clear = yes
	desc = shroud.3000.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3000_happened
			has_covenant = the_eater_of_worlds
			has_country_flag = the_eater_of_worlds_betrayal
		}
		is_in_domain = the_eater_of_worlds
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_eater_of_worlds
		}
	}

	immediate = {
		set_country_flag = shroud_3000_happened
	}

	option_clear = yes
	option = {
		name = shroud.3000.a # embrace the Eater of Worlds
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3001 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
	option = {
		name = shroud.3000.b # push it back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3002 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_cradle_of_souls
			}
		}
	}
	option = {
		name = shroud.3000.c # Neutral
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3003 }
		}
	}
}

country_event = {
	id = shroud.3001
	base = shroud.3

	title = shroud.3000.title
	desc_clear = yes
	desc = shroud.3000.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_eater_of_worlds = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3002
	base = shroud.3

	title = shroud.3000.title
	desc_clear = yes
	desc = shroud.3000.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_eater_of_worlds = @delve_attunement_large_anti }
	}
}

country_event = {
	id = shroud.3003
	base = shroud.3

	title = shroud.3000.title
	desc_clear = yes
	desc = shroud.3000.c.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Salivating Hunger
# Eater of Worlds
country_event = {
	id = shroud.3005
	base = shroud.3

	title = shroud.3005.title
	desc_clear = yes
	desc = shroud.3005.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3005_happened
			has_covenant = the_eater_of_worlds
			has_country_flag = the_eater_of_worlds_betrayal
		}
		# the player has claims on territories owned by other empires that are weaker than them
		any_country = {
			root = {
				has_claim = prev
				relative_power = {
					who = prev
					category = fleet
					value > equivalent
				}
			}
		}
		is_in_domain = the_eater_of_worlds
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_eater_of_worlds
		}
	}

	immediate = {
		set_country_flag = shroud_3005_happened
	}

	option_clear = yes
	option = {
		name = shroud.3005.a # Embrace Eater
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3006 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
	option = {
		name = shroud.3005.b # Push back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3007 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_cradle_of_souls
			}
		}
	}
}

country_event = {
	id = shroud.3006
	base = shroud.3

	title = shroud.3005.title
	desc_clear = yes
	desc = shroud.3005.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		custom_tooltip = shroud.3005.a.boons.tt
		random_country = {
			limit = {
				root = {
					has_claim = prev
					relative_power = {
						who = prev
						category = fleet
						value > equivalent
					}
				}
			}
			root = {
				declare_war = {
					target = prev
					attacker_war_goal = "wg_conquest"
				}
			}
		}
		add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		hidden_effect = {
			random_list = {
				1 = {
					add_modifier = {
						modifier = shroud_shield_boost
						days = 1800
					}
				}
				1 = {
					add_modifier = {
						modifier = shroud_weapon_boost
						days = 1800
					}
				}
				1 = {
					add_modifier = {
						modifier = shroud_firing_rate
						days = 1800
					}
				}
				1 = {
					add_modifier = {
						modifier = shroud_evasion
						days = 1800
					}
				}
				1 = {
					add_modifier = {
						modifier = shroud_repair
						days = 1800
					}
				}
				1 = {
					add_modifier = {
						modifier = shroud_morale
						days = 1800
					}
				}
			}
		}
	}
}

country_event = {
	id = shroud.3007
	base = shroud.3

	title = shroud.3005.title
	desc_clear = yes
	desc = shroud.3005.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_eater_of_worlds = @delve_attunement_large_anti }
	}
}

## Sacrificial Feast
# Eater of Worlds
country_event = {
	id = shroud.3010
	base = shroud.3

	title = shroud.3010.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3010.desc
			text = newline
			if = {
				limit = {
					OR = {
						is_lithoid_empire = yes
						is_robot_empire = yes
					}
				}
				text = shroud.3010.desc.other
			}
			else = {
				text = shroud.3010.desc.organic
			}
		}
	}

	trigger = {
		NOR = {
			has_country_flag = shroud_3010_happened
			has_covenant = the_eater_of_worlds
			has_country_flag = the_eater_of_worlds_betrayal
		}
		pop_amount >= 1000
		is_in_domain = the_eater_of_worlds
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_eater_of_worlds
		}
	}

	immediate = {
		set_country_flag = shroud_3010_happened
	}

	option_clear = yes
	option = {
		name = shroud.3010.a # embrace the Eater of Worlds
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_high
		if = {
			limit = { pop_amount >= 2000 }
			random_owned_pop_group = {
				sacrifice_single_pop = yes
			}
			random_owned_pop_group = {
				sacrifice_single_pop = yes
			}
		}
		else = {
			random_owned_pop_group = {
				sacrifice_single_pop = yes
			}
		}
		hidden_effect = {
			country_event = { id = shroud.3011 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
	option = {
		name = shroud.3010.b # push it back
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_low
		hidden_effect = {
			country_event = { id = shroud.3012 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_cradle_of_souls
			}
		}
	}
}

country_event = {
	id = shroud.3011
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = high
		DESC = shroud.3010.a.reply
	}

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		custom_bestowed_tooltip = yes
		add_attunement = { the_eater_of_worlds = @delve_attunement_smallest }
	}
}

country_event = {
	id = shroud.3012
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = low
		DESC = shroud.3010.b.reply
	}

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}
		custom_bestowed_tooltip = yes
		add_attunement = { the_eater_of_worlds = @delve_attunement_small_anti }
	}
}

## Transient Visions
# Composer of Strands
country_event = {
	id = shroud.3015
	base = shroud.3

	title = shroud.3015.title
	desc_clear = yes
	desc = shroud.3015.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3015_happened
			has_covenant = the_composer_of_strands
			has_country_flag = the_composer_of_strands_betrayal
		}
		is_in_domain = the_composer_of_strands
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3015_happened
	}

	option_clear = yes
	option = {
		name = shroud.3015.a # embrace the Composer of Strands
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3016 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_composer_of_strands
			}
		}
	}
	option = {
		name = shroud.3015.b # push it back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3017 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_instrument_of_desire
			}
		}
	}
	option = {
		name = shroud.3015.c # Neutral
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3018 }
		}
	}
}

country_event = {
	id = shroud.3016
	base = shroud.3

	title = shroud.3015.title
	desc_clear = yes
	desc = shroud.3015.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_composer_of_strands = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3017
	base = shroud.3

	title = shroud.3015.title
	desc_clear = yes
	desc = shroud.3015.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_composer_of_strands = @delve_attunement_large_anti }
	}
}

country_event = {
	id = shroud.3018
	base = shroud.3

	title = shroud.3015.title
	desc_clear = yes
	desc = shroud.3015.c.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Tempting Conservation
# Composer of Strands
country_event = {
	id = shroud.3020
	base = shroud.3

	title = shroud.3020.title
	desc_clear = yes
	desc = shroud.3020.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3020_happened
			has_covenant = the_composer_of_strands
			has_country_flag = the_composer_of_strands_betrayal
		}
		is_in_domain = the_composer_of_strands
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3020_happened
	}

	option_clear = yes
	option = { # Composer of Strands
		name = shroud.3020.a
		custom_tooltip = attunement_choice_tt
		allow = { is_homicidal = no }
		hidden_effect = {
			country_event = { id = shroud.3021 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_composer_of_strands
			}
		}
	}
	option = { # Instrument of Desire
		name = shroud.3020.b
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3022 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_instrument_of_desire
			}
		}
	}
	option = { # Eater of Worlds
		name = {
			trigger = {
				if = {
					limit = { has_valid_civic = civic_hive_devouring_swarm }
					text = shroud.3020.c.swarm
				}
				else = { text = shroud.3020.c }
			}
		}
		custom_tooltip = attunement_choice_tt
		trigger = { is_homicidal = yes }
		hidden_effect = {
			country_event = { id = shroud.3023 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
}

country_event = {
	id = shroud.3021
	base = shroud.3

	title = shroud.3020.title
	desc_clear = yes
	desc = shroud.3020.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		random_owned_planet = {
			limit = {
				NOR = {
					has_planet_modifier = pm_docile_fauna
					has_planet_modifier = pm_dangerous_wildlife
					has_deposit = d_dangerous_wildlife_blocker
				}
			}
			add_modifier = { modifier = docile_fauna }
		}
		add_attunement = { the_composer_of_strands = @delve_attunement_smallest }
	}
}

country_event = {
	id = shroud.3022
	base = shroud.3

	title = shroud.3020.title
	desc_clear = yes
	desc = shroud.3020.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_attunement = { the_instrument_of_desire = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3023
	base = shroud.3

	title = shroud.3020.title
	desc_clear = yes
	desc = shroud.3020.c.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_attunement = { the_eater_of_worlds = @delve_attunement_smallest }
	}
}

## Morphing Landscapes
# Composer of Strands
country_event = {
	id = shroud.3025
	base = shroud.3

	title = shroud.3025.title
	desc_clear = yes
	desc = shroud.3025.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3025_happened
			has_covenant = the_composer_of_strands
			has_country_flag = the_composer_of_strands_betrayal
		}
		is_in_domain = the_composer_of_strands
		any_planet_within_border = {
			is_terraforming = yes
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3025_happened
	}

	option_clear = yes
	option = {
		name = shroud.3025.a # push back the Composer of Strands
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3026 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_instrument_of_desire
			}
		}
	}
	option = {
		name = shroud.3025.b # embrace it
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3027 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_composer_of_strands
			}
		}
	}
}

country_event = {
	id = shroud.3026
	base = shroud.3

	title = shroud.3025.title
	desc_clear = yes
	desc = shroud.3025.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		random_planet_within_border = {
			limit = {
				is_terraforming = yes
			}
			finish_terraformation = yes
		}
		add_attunement = { the_composer_of_strands = @delve_attunement_large_anti }
	}
}

country_event = {
	id = shroud.3027
	base = shroud.3

	title = shroud.3025.title
	desc_clear = yes
	desc = shroud.3025.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		random_planet_within_border = {
			limit = {
				is_terraforming = yes
			}
			finish_terraformation = yes
			custom_tooltip = shroud.3025.b.reply.tt
			hidden_effect = {
				# Add positive modifier
				random_list = {
					1 = {
						add_modifier = { modifier = ultra_rich }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_ultra_rich
								has_planet_modifier = pm_mineral_poor
							}
						}
					}
					1 = {
						add_modifier = { modifier = lush_planet }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_lush
								has_planet_modifier = pm_bleak
								has_planet_modifier = pm_rich_mircoflora
							}
						}
					}
					1 = {
						add_modifier = { modifier = rich_mircoflora }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_rich_mircoflora
								has_planet_modifier = pm_lush
								has_planet_modifier = pm_bleak
							}
						}
					}
					1 = {
						add_modifier = { modifier = docile_fauna }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_docile_fauna
								has_planet_modifier = pm_dangerous_wildlife
								has_deposit = d_dangerous_wildlife_blocker
							}
						}
					}
					1 = {
						add_modifier = { modifier = natural_beauty }
						modifier = {
							factor = 0
							has_planet_modifier = pm_natural_beauty
						}
					}
					1 = {
						add_modifier = { modifier = strong_magnetic_field }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_strong_magnetic_field
								has_planet_modifier = pm_weak_magnetic_field
								has_planet_modifier = pm_abundant_geothermal_activity
							}
						}
					}
				}
				# Add negative modifier
				random_list = {
					1 = {
						add_modifier = { modifier = mineral_poor }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_mineral_poor
								has_planet_modifier = pm_mineral_rich
								has_planet_modifier = pm_ultra_rich
								has_planet_modifier = pm_low_gravity
							}
						}
					}
					1 = {
						add_modifier = { modifier = bleak_planet }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_bleak
								has_planet_modifier = pm_lush
								has_planet_modifier = pm_rich_mircoflora
							}
						}
					}
					1 = {
						add_modifier = { modifier = dangerous_wildlife }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_dangerous_wildlife
								has_planet_modifier = pm_docile_fauna
								has_planet_modifier = pm_titanic_life
							}
						}
					}
					1 = {
						add_modifier = { modifier = weak_magnetic_field }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_weak_magnetic_field
								has_planet_modifier = pm_strong_magnetic_field
							}
						}
					}
					1 = {
						add_modifier = { modifier = tidal_locked }
						modifier = {
							factor = 0
							has_planet_modifier = pm_tidal_locked
						}
					}
					1 = {
						add_modifier = { modifier = high_gravity }
						modifier = {
							factor = 0
							OR = {
								has_planet_modifier = pm_low_gravity
								has_planet_modifier = pm_high_gravity
								AND = {
									planet_size < 12
									OR = {
										is_planet_class = pc_desert
										is_planet_class = pc_tropical
										is_planet_class = pc_continental
										is_planet_class = pc_ocean
										is_planet_class = pc_arctic
										is_planet_class = pc_tundra
										is_planet_class = pc_arid
										is_planet_class = pc_alpine
										is_planet_class = pc_savannah
										is_planet_class = pc_relic
										is_planet_class = pc_nuked
									}
								}
							}
						}
					}
					1 = {
						add_modifier = { modifier = wild_storms }
						modifier = {
							factor = 0
							has_planet_modifier = pm_wild_storms
						}
					}
				}
			}
		}
		add_attunement = { the_composer_of_strands = @delve_attunement_small }
	}
}

## Prism in the Darkness
# Cradle of Souls
country_event = {
	id = shroud.3030
	base = shroud.3

	title = shroud.3030.title
	desc_clear = yes
	desc = shroud.3030.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3030_happened
			has_covenant = the_cradle_of_souls
			has_country_flag = the_cradle_of_souls_betrayal
		}
		is_in_domain = the_cradle_of_souls
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_cradle_of_souls
		}
	}

	immediate = {
		set_country_flag = shroud_3030_happened
	}

	option_clear = yes
	option = {
		name = shroud.3030.a # embrace the Cradle of Souls
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3031 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_cradle_of_souls
			}
		}
	}
	option = {
		name = shroud.3030.b # push it back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3032 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
	option = {
		name = shroud.3030.c # Neutral
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3033 }
		}
	}
}

country_event = {
	id = shroud.3031
	base = shroud.3

	title = shroud.3030.title
	desc_clear = yes
	desc = shroud.3030.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_cradle_of_souls = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3032
	base = shroud.3

	title = shroud.3030.title
	desc_clear = yes
	desc = shroud.3030.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_cradle_of_souls = @delve_attunement_large_anti }
	}
}

country_event = {
	id = shroud.3033
	base = shroud.3

	title = shroud.3030.title
	desc_clear = yes
	desc = shroud.3030.c.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Shadow Brawl
# Cradle of Souls
country_event = {
	id = shroud.3035
	base = shroud.3

	title = shroud.3035.title
	desc_clear = yes
	desc = shroud.3035.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3035_happened
			has_covenant = the_cradle_of_souls
			has_country_flag = the_cradle_of_souls_betrayal
		}
		is_in_domain = the_cradle_of_souls
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_cradle_of_souls
		}
	}

	immediate = {
		set_country_flag = shroud_3035_happened
	}

	option_clear = yes
	option = {
		name = shroud.3035.a # embrace the Cradle of Souls
		custom_tooltip = attunement_choice_tt
		allow = { is_homicidal = no }
		hidden_effect = {
			country_event = { id = shroud.3036 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_cradle_of_souls
			}
		}
	}
	option = {
		name = shroud.3035.b # push it back
		custom_tooltip = attunement_choice_tt
		trigger = { is_homicidal = no }
		hidden_effect = {
			country_event = { id = shroud.3037 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
	option = {
		name = shroud.3035.b # push it back
		custom_tooltip = attunement_choice_tt
		trigger = { is_homicidal = yes }
		hidden_effect = {
			country_event = { id = shroud.3037 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_eater_of_worlds
			}
		}
	}
}

country_event = {
	id = shroud.3036
	base = shroud.3

	title = shroud.3035.title
	desc_clear = yes
	desc = shroud.3035.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = unity
			value = @tier3unityreward
			min = @tier3unitymin
			max = @tier3unitymax
		}
		add_attunement = { the_cradle_of_souls = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3037
	base = shroud.3

	title = shroud.3035.title
	desc_clear = yes
	desc = shroud.3035.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_cradle_of_souls = @delve_attunement_large_anti }
	}
}

## Sights Unseen
# Instrument of Desire
country_event = {
	id = shroud.3040
	base = shroud.3

	title = shroud.3040.title
	desc_clear = yes
	desc = shroud.3040.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3040_happened
			has_covenant = the_instrument_of_desire
			has_country_flag = the_instrument_of_desire_betrayal
		}
		is_in_domain = the_instrument_of_desire
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3040_happened
	}

	option_clear = yes
	option = {
		name = shroud.3040.a # embrace the Instrument of Desire
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3041 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_instrument_of_desire
			}
		}
	}
	option = {
		name = shroud.3040.b # push it back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3042 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_composer_of_strands
			}
		}
	}
	option = {
		name = shroud.3040.c # Neutral
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3043 }
		}
	}
}

country_event = {
	id = shroud.3041
	base = shroud.3

	title = shroud.3040.title
	desc_clear = yes
	desc = shroud.3040.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_instrument_of_desire = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3042
	base = shroud.3

	title = shroud.3040.title
	desc_clear = yes
	desc = shroud.3040.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_instrument_of_desire = @delve_attunement_large_anti }
	}
}

country_event = {
	id = shroud.3043
	base = shroud.3

	title = shroud.3040.title
	desc_clear = yes
	desc = shroud.3040.c.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Luminous Kernel
# Instrument of Desire
country_event = {
	id = shroud.3045
	base = shroud.3

	title = shroud.3045.title
	desc_clear = yes
	desc = shroud.3045.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3045_happened
			has_covenant = the_instrument_of_desire
			has_country_flag = the_instrument_of_desire_betrayal
		}
		is_in_domain = the_instrument_of_desire
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0.1
			patron_has_all_accords_unlocked = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3045_happened
	}

	option_clear = yes
	option = {
		name = shroud.3045.a # embrace the Instrument of Desire
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3046 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_instrument_of_desire
			}
		}
	}
	option = {
		name = shroud.3045.b # push it back
		custom_tooltip = attunement_choice_tt
		hidden_effect = {
			country_event = { id = shroud.3047 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				is_preferred_patron = the_composer_of_strands
			}
		}
	}
}

country_event = {
	id = shroud.3046
	base = shroud.3

	title = shroud.3045.title
	desc_clear = yes
	desc = shroud.3045.a.reply

	option_clear = yes
	option = {
		name = LEAVE
		if = {
			limit = {
				is_nomadic = no
			}
			random_planet_within_border = {
				limit = {
					OR = {
						has_deposit_for = shipclass_mining_station
						has_deposit = no
					}
				}
				add_deposit = d_minerals_10
			}
		}
		else = {
			random_owned_nonprimary_starbase = {
				limit = {
					is_waystation_starbase = yes
					solar_system = {
						any_system_planet = {
							OR = {
								has_deposit_for = shipclass_mining_station
								has_deposit = no
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							OR = {
								has_deposit_for = shipclass_mining_station
								has_deposit = no
							}
						}
						add_deposit = d_minerals_10
					}
				}
			}
		}
		add_attunement = { the_instrument_of_desire = @delve_attunement_small }
	}
}

country_event = {
	id = shroud.3047
	base = shroud.3

	title = shroud.3045.title
	desc_clear = yes
	desc = shroud.3045.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_attunement = { the_instrument_of_desire = @delve_attunement_large_anti }
	}
}

## Fractious Cacophonies
# Any of the 4 main patrons
country_event = {
	id = shroud.3050
	base = shroud.3

	title = shroud.3050.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3050.desc.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3050.desc.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3050.desc.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3050.desc.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3050.desc.instrument
			}
			text = newline
			text = shroud.3050.desc.outro
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_3050_happened }
		OR = {
			AND = {
				NOR = {
					has_covenant = the_eater_of_worlds
					has_country_flag = shroud_3050_happened_eater
				}
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOR = {
					has_covenant = the_composer_of_strands
					has_country_flag = shroud_3050_happened_composer
				}
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOR = {
					has_covenant = the_cradle_of_souls
					has_country_flag = shroud_3050_happened_cradle
				}
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOR = {
					has_covenant = the_instrument_of_desire
					has_country_flag = shroud_3050_happened_instrument
				}
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = shroud_3050_happened
			days = @delve_retrigger_cooldown # 30 years
		}
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			set_country_flag = shroud_3050_happened_eater
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			set_country_flag = shroud_3050_happened_composer
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			set_country_flag = shroud_3050_happened_cradle
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			set_country_flag = shroud_3050_happened_instrument
		}
	}

	option_clear = yes
	option = {
		name = shroud.3050.a # embrace the Patron
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_medium
		hidden_effect = {
			country_event = { id = shroud.3051 }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					AND = {
						is_preferred_patron = the_eater_of_worlds
						is_in_domain = the_eater_of_worlds
					}
					AND = {
						is_preferred_patron = the_composer_of_strands
						is_in_domain = the_composer_of_strands
					}
					AND = {
						is_preferred_patron = the_cradle_of_souls
						is_in_domain = the_cradle_of_souls
					}
					AND = {
						is_preferred_patron = the_instrument_of_desire
						is_in_domain = the_instrument_of_desire
					}
				}
			}
		}
	}
	option = {
		name = shroud.3050.b # push it back
		hidden_effect = {
			country_event = { id = shroud.3052 }
		}
	}
}

country_event = {
	id = shroud.3051
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = medium
		DESC = shroud.3050.a.reply
	}

	option_clear = yes
	option = {
		name = LEAVE
		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small }
		}
	}
}

country_event = {
	id = shroud.3052
	base = shroud.3

	title = shroud.3050.title
	desc_clear = yes
	desc = shroud.3050.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Prophetic Visions
# Any of the 4 main patrons
country_event = {
	id = shroud.3055
	base = shroud.3

	title = shroud.3055.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3055.desc.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3055.desc.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3055.desc.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3055.desc.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				if = {
					limit = { is_relentless_industrialist_empire = yes }
					text = shroud.3055.desc.instrument.relentless_industrialist
				}
				else = {
					text = shroud.3055.desc.instrument.default
				}
			}
			text = newline
			text = shroud.3055.desc.outro
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_3055_happened }
		OR = {
			AND = {
				NOR = {
					has_covenant = the_eater_of_worlds
					has_country_flag = shroud_3055_happened_eater
				}
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOR = {
					has_covenant = the_composer_of_strands
					has_country_flag = shroud_3055_happened_composer
				}
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOR = {
					has_covenant = the_cradle_of_souls
					has_country_flag = shroud_3055_happened_cradle
				}
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOR = {
					has_covenant = the_instrument_of_desire
					has_country_flag = shroud_3055_happened_instrument
				}
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = shroud_3055_happened
			days = @delve_retrigger_cooldown # 30 years
		}
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			set_country_flag = shroud_3055_happened_eater
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			set_country_flag = shroud_3055_happened_composer
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			set_country_flag = shroud_3055_happened_cradle
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			set_country_flag = shroud_3055_happened_instrument
		}
	}

	option_clear = yes
	option = {
		name = shroud.3055.a # embrace the Patron
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_medium
		hidden_effect = {
			country_event = { id = shroud.3056 }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					AND = {
						is_preferred_patron = the_eater_of_worlds
						is_in_domain = the_eater_of_worlds
					}
					AND = {
						is_preferred_patron = the_composer_of_strands
						is_in_domain = the_composer_of_strands
					}
					AND = {
						is_preferred_patron = the_cradle_of_souls
						is_in_domain = the_cradle_of_souls
					}
					AND = {
						is_preferred_patron = the_instrument_of_desire
						is_in_domain = the_instrument_of_desire
					}
				}
			}
		}
	}
	option = {
		name = {
			trigger = {
				if = {
					limit = { is_robot_empire = yes }
					text = shroud.3055.b.machine
				}
				else = {
					text = shroud.3055.b.organic
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.3057 }
		}
	}
}

country_event = {
	id = shroud.3056
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = medium
		DESC = shroud.3055.a.reply
	}

	option_clear = yes
	option = {
		name = LEAVE
		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small }
		}
	}
}

country_event = {
	id = shroud.3057
	base = shroud.3

	title = shroud.3055.title
	desc_clear = yes
	desc = shroud.3055.b.reply

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
	}
}

## Betwixt the Void
# Any of the 4 main patrons
country_event = {
	id = shroud.3060
	base = shroud.3

	title = shroud.3060.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3060.desc.intro
			text = newline
			if = {
				limit = { is_robot_empire = yes }
				text = shroud.3060.desc.intro.machine
			}
			else = {
				text = shroud.3060.desc.intro.organic
			}
			text = newline
			text = shroud.3060.desc.intro.end
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3060.desc.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3060.desc.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3060.desc.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3060.desc.instrument
			}
			text = newline
			text = shroud.3060.desc.outro
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_3060_happened }
		OR = {
			AND = {
				NOR = {
					has_covenant = the_eater_of_worlds
					has_country_flag = shroud_3060_happened_eater
				}
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOR = {
					has_covenant = the_composer_of_strands
					has_country_flag = shroud_3060_happened_composer
				}
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOR = {
					has_covenant = the_cradle_of_souls
					has_country_flag = shroud_3060_happened_cradle
				}
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOR = {
					has_covenant = the_instrument_of_desire
					has_country_flag = shroud_3060_happened_instrument
				}
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = shroud_3060_happened
			days = @delve_retrigger_cooldown # 30 years
		}
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			set_country_flag = shroud_3060_happened_eater
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			set_country_flag = shroud_3060_happened_composer
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			set_country_flag = shroud_3060_happened_cradle
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			set_country_flag = shroud_3060_happened_instrument
		}
	}

	option_clear = yes
	option = {
		name = shroud.3060.a # embrace the Patron
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_high
		hidden_effect = {
			country_event = { id = shroud.3061 }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					AND = {
						is_preferred_patron = the_eater_of_worlds
						is_in_domain = the_eater_of_worlds
					}
					AND = {
						is_preferred_patron = the_composer_of_strands
						is_in_domain = the_composer_of_strands
					}
					AND = {
						is_preferred_patron = the_cradle_of_souls
						is_in_domain = the_cradle_of_souls
					}
					AND = {
						is_preferred_patron = the_instrument_of_desire
						is_in_domain = the_instrument_of_desire
					}
				}
			}
		}
	}
	option = {
		name = shroud.3060.b
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_low
		hidden_effect = {
			country_event = { id = shroud.3062 }
		}
	}
}

country_event = {
	id = shroud.3061
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = high
		DESC = shroud.3060.a.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3060.a.reply
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3060.a.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3060.a.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3060.a.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3060.a.reply.instrument
			}
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	immediate = {
		random_owned_leader = {
			limit = {
				is_ruler = no
				is_gestalt_node = no
			}
			save_event_target_as = shroud_warped_leader
			exile_leader_as = shroud_warped_leader
		}
		roll_boon_high = yes
	}

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small }
		}
	}

	after = {
		country_event = {
			id = shroud.3063
			years = 5
			scopes = { from = event_target:shroud_warped_leader }
		}
		remove_bestowed_flags = yes
	}
}

country_event = {
	id = shroud.3062
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = low
		DESC = shroud.3060.b.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3060.b.reply
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3060.b.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3060.b.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3060.b.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3060.b.reply.instrument
			}
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	option_clear = yes
	option = {
		name = LEAVE
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_large_anti }
		}
	}
}

# Shroud-Warped follow-up event
country_event = {
	id = shroud.3063
	base = shroud.3
	picture_event_data = {
		portrait = from
	}

	title = shroud.3060.leader_return.title
	desc_clear = yes
	desc = shroud.3060.leader_return.desc

	immediate = {
		return_leader_from_exile = from
		from = {
			add_trait = { trait = leader_trait_shroud_warped }
		}
	}

	option_clear = yes
	option = {
		custom_tooltip = shroud.3060.leader_return_tt
		name = LEAVE
	}
}

# On winning a ground battle.
# This = country, leader attacker
# From = country, planet owner
# FromFrom = planet
country_event = {
	id = shroud.3064
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		FROMFROM = {
			every_ground_combat_attacker = {
				if = {
					limit = { exists = leader }
					leader = {
						# Shroud-Warped
						if = {
							limit = {
								exists = from
								has_trait = leader_trait_shroud_warped
							}
							ROOT = {
								add_intel = {
									who = root.from
									amount = @shroud_warped_intel
								}
							}
						}
					}
				}
			}
		}
	}
}

## A Bidden Chalice
# Any of the 4 main patrons
country_event = {
	id = shroud.3065
	base = shroud.3

	title = shroud.3065.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3065.desc.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3065.desc.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3065.desc.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3065.desc.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3065.desc.instrument
			}
			text = newline
			text = shroud.3065.desc.outro
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_3065_happened }
		OR = {
			AND = {
				NOR = {
					has_covenant = the_eater_of_worlds
					has_country_flag = shroud_3065_happened_eater
				}
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOR = {
					has_covenant = the_composer_of_strands
					has_country_flag = shroud_3065_happened_composer
				}
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOR = {
					has_covenant = the_cradle_of_souls
					has_country_flag = shroud_3065_happened_cradle
				}
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOR = {
					has_covenant = the_instrument_of_desire
					has_country_flag = shroud_3065_happened_instrument
				}
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = shroud_3065_happened
			days = @delve_retrigger_cooldown # 30 years
		}
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			set_country_flag = shroud_3065_happened_eater
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			set_country_flag = shroud_3065_happened_composer
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			set_country_flag = shroud_3065_happened_cradle
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			set_country_flag = shroud_3065_happened_instrument
		}
	}

	option_clear = yes
	option = {
		name = {
			trigger = {
				if = {
					limit = { is_robot_empire = yes }
					text = shroud.3065.a.machine
				}
				else = {
					text = shroud.3065.a.organic
				}
			}
		} # embrace the Patron
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_high
		hidden_effect = {
			country_event = { id = shroud.3066 }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					AND = {
						is_preferred_patron = the_eater_of_worlds
						is_in_domain = the_eater_of_worlds
					}
					AND = {
						is_preferred_patron = the_composer_of_strands
						is_in_domain = the_composer_of_strands
					}
					AND = {
						is_preferred_patron = the_cradle_of_souls
						is_in_domain = the_cradle_of_souls
					}
					AND = {
						is_preferred_patron = the_instrument_of_desire
						is_in_domain = the_instrument_of_desire
					}
				}
			}
		}
	}
	option = {
		name = shroud.3065.b
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_low
		hidden_effect = {
			country_event = { id = shroud.3067 }
		}
	}
}

country_event = {
	id = shroud.3066
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = high
		DESC = shroud.3065.a.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3065.a.reply.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3065.a.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3065.a.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3065.a.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3065.a.reply.instrument
			}
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	option_clear = yes
	option = {
		name = LEAVE

		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}

		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small }
		}
	}
}

country_event = {
	id = shroud.3067
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = low
		DESC = shroud.3065.b.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3065.b.reply.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3065.b.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3065.b.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3065.b.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3065.b.reply.instrument
			}
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	option_clear = yes
	option = {
		name = LEAVE

		add_monthly_resource_mult = {
			resource = unity
			value = @tier4unityreward
			min = @tier4unitymin
			max = @tier4unitymax
		}

		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_large_anti }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_large_anti }
		}
	}
}

## Canvas of changes
# Any of the 4 main patrons
country_event = {
	id = shroud.3070
	base = shroud.3

	title = shroud.3070.title
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3070.desc.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3070.desc.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3070.desc.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3070.desc.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3070.desc.instrument
			}
			text = newline
			text = shroud.3070.desc.outro
		}
	}

	trigger = {
		NOT = { has_country_flag = shroud_3070_happened }
		OR = {
			AND = {
				NOR = {
					has_covenant = the_eater_of_worlds
					has_country_flag = shroud_3070_happened_eater
				}
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOR = {
					has_covenant = the_composer_of_strands
					has_country_flag = shroud_3070_happened_composer
				}
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOR = {
					has_covenant = the_cradle_of_souls
					has_country_flag = shroud_3070_happened_cradle
				}
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOR = {
					has_covenant = the_instrument_of_desire
					has_country_flag = shroud_3070_happened_instrument
				}
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = shroud_3070_happened
			days = @delve_retrigger_cooldown # 30 years
		}
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			set_country_flag = shroud_3070_happened_eater
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			set_country_flag = shroud_3070_happened_composer
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			set_country_flag = shroud_3070_happened_cradle
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			set_country_flag = shroud_3070_happened_instrument
		}
	}

	option_clear = yes
	option = {
		name = {
			trigger = {
				if = {
					limit = { is_in_domain = the_eater_of_worlds }
					text = shroud.3070.a.eater
				}
				else_if = {
					limit = { is_in_domain = the_composer_of_strands }
					text = shroud.3070.a.composer
				}
				else_if = {
					limit = { is_in_domain = the_cradle_of_souls }
					text = shroud.3070.a.cradle
				}
				else_if = {
					limit = { is_in_domain = the_instrument_of_desire }
					text = shroud.3070.a.instrument
				}
			}
		} # embrace the Patron
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_high
		hidden_effect = {
			country_event = { id = shroud.3071 }
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					AND = {
						is_preferred_patron = the_eater_of_worlds
						is_in_domain = the_eater_of_worlds
					}
					AND = {
						is_preferred_patron = the_composer_of_strands
						is_in_domain = the_composer_of_strands
					}
					AND = {
						is_preferred_patron = the_cradle_of_souls
						is_in_domain = the_cradle_of_souls
					}
					AND = {
						is_preferred_patron = the_instrument_of_desire
						is_in_domain = the_instrument_of_desire
					}
				}
			}
		}
	}
	option = {
		name = {
			trigger = {
				if = {
					limit = { is_in_domain = the_eater_of_worlds }
					text = shroud.3070.b.eater
				}
				else_if = {
					limit = { is_in_domain = the_composer_of_strands }
					text = shroud.3070.b.composer
				}
				else_if = {
					limit = { is_in_domain = the_cradle_of_souls }
					text = shroud.3070.b.cradle
				}
				else_if = {
					limit = { is_in_domain = the_instrument_of_desire }
					text = shroud.3070.b.instrument
				}
			}
		}
		custom_tooltip = attunement_choice_tt
		custom_tooltip = random_boon_low
		hidden_effect = {
			country_event = { id = shroud.3072 }
		}
	}
}

country_event = {
	id = shroud.3071
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = high
		DESC = shroud.3070.a.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3070.a.reply.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3070.a.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3070.a.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3070.a.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3070.a.reply.instrument
			}
			text = newline
			text = shroud.3070.a.reply.outro
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	option_clear = yes
	option = {
		name = LEAVE

		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}

		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small }
		}
	}
}

country_event = {
	id = shroud.3072
	base = shroud.3

	inline_script = {
		script = shroud/roll_boon_event
		CHANCE = low
		DESC = shroud.3070.b.reply.default
	}
	desc_clear = yes
	desc = {
		trigger = {
			text = shroud.3070.b.reply.intro
			text = newline
			if = {
				limit = { is_in_domain = the_eater_of_worlds }
				text = shroud.3070.b.reply.eater
			}
			else_if = {
				limit = { is_in_domain = the_composer_of_strands }
				text = shroud.3070.b.reply.composer
			}
			else_if = {
				limit = { is_in_domain = the_cradle_of_souls }
				text = shroud.3070.b.reply.cradle
			}
			else_if = {
				limit = { is_in_domain = the_instrument_of_desire }
				text = shroud.3070.b.reply.instrument
			}
			text = newline
			text = shroud.3070.b.reply.outro
			if = {
				limit = {
					OR = {
						has_country_flag = shroud_bestowed_boon
						has_country_flag = shroud_bestowed_curse
					}
				}
				text = newline
			}
			inline_script = { script = shroud/roll_boon_desc }
		}
	}

	option_clear = yes
	option = {
		name = LEAVE

		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}

		custom_bestowed_tooltip = yes
		if = {
			limit = { is_in_domain = the_eater_of_worlds }
			add_attunement = { the_eater_of_worlds = @delve_attunement_small_anti }
		}
		else_if = {
			limit = { is_in_domain = the_composer_of_strands }
			add_attunement = { the_composer_of_strands = @delve_attunement_small_anti }
		}
		else_if = {
			limit = { is_in_domain = the_cradle_of_souls }
			add_attunement = { the_cradle_of_souls = @delve_attunement_small_anti }
		}
		else_if = {
			limit = { is_in_domain = the_instrument_of_desire }
			add_attunement = { the_instrument_of_desire = @delve_attunement_small_anti }
		}
	}
}

## Psionic Conflict
# Component Delve Event - Zro Launchers
country_event = {
	id = shroud.3100
	base = shroud.3

	title = shroud.3100.title
	desc_clear = yes
	desc = shroud.3100.desc

	trigger = {
		NOT = { has_country_flag = shroud_3100_happened }
		NOR = {
			has_technology = tech_zro_launcher
			has_tech_option = tech_zro_launcher
		}
		OR = {
			AND = {
				NOT = { has_covenant = the_eater_of_worlds }
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOT = { has_covenant = the_composer_of_strands }
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOT = { has_covenant = the_cradle_of_souls }
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOT = { has_covenant = the_instrument_of_desire }
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			add = value:non_component_delve_roll
			check_variable = {
				which = non_component_delve_count
				value > 0
			}
		}
		modifier = {
			add = 1
			has_country_flag = recently_failed_component_delve
		}
	}

	immediate = {
		remove_country_flag = recently_failed_component_delve
		clear_variable = non_component_delve_count
	}

	option_clear = yes
	option = {
		name = shroud.3100.a
		custom_tooltip = shroud.unknown.chances.medium

		hidden_effect = {
			random_list = {
				60 = {
					modifier = { add = value:delve_success_chance_from_techs }
					country_event = { id = shroud.3101 }
				}
				40 = {
					modifier = {
						factor = 0.5
						has_relic = r_zro_crystal
					}
					country_event = { id = shroud.3102 }
				}
			}
		}
	}
	option = {
		name = "exit.shroud"
		custom_tooltip = "exit.shroud.tooltip"
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
		default_hide_option = yes
	}
}

## Psionic Conflict - Success
country_event = {
	id = shroud.3101
	base = shroud.3

	title = shroud.3101.title
	desc_clear = yes
	desc = shroud.3101.desc

	immediate = {
		set_country_flag = shroud_3100_happened
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = {
				NOR = {
					has_technology = tech_zro_launcher
					has_tech_option = tech_zro_launcher
				}
			}
			add_research_option = tech_zro_launcher
		}
		default_hide_option = yes
	}
}

## Psionic Conflict - Fail
country_event = {
	id = shroud.3102
	base = shroud.3

	title = shroud.3102.title
	desc_clear = yes
	desc = shroud.3102.desc

	immediate = {
		set_country_flag = recently_failed_component_delve
		set_timed_country_flag = {
			flag = shroud_3100_happened
			days = 10800 # 30 years
		}
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		custom_tooltip = shroud.3102.a.tt
		hidden_effect = {
			random_owned_planet = {
				ruin_building = random_no_capital
			}
			random_owned_planet = {
				ruin_building = random_no_capital
			}
		}
		default_hide_option = yes
	}
}

## Psychic Pathways
# Component Delve Event - Psionic Lightning
country_event = {
	id = shroud.3105
	base = shroud.3

	title = shroud.3105.title
	desc_clear = yes
	desc = shroud.3105.desc

	trigger = {
		NOT = { has_country_flag = shroud_3105_happened }
		NOR = {
			has_technology = tech_psionic_lightning
			has_tech_option = tech_psionic_lightning
		}
		OR = {
			AND = {
				NOT = { has_covenant = the_eater_of_worlds }
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOT = { has_covenant = the_composer_of_strands }
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOT = { has_covenant = the_cradle_of_souls }
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOT = { has_covenant = the_instrument_of_desire }
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			add = value:non_component_delve_roll
			check_variable = {
				which = non_component_delve_count
				value > 0
			}
		}
		modifier = {
			add = 1
			has_country_flag = recently_failed_component_delve
		}
	}

	immediate = {
		remove_country_flag = recently_failed_component_delve
		clear_variable = non_component_delve_count
	}

	option_clear = yes
	option = {
		name = shroud.3105.a
		custom_tooltip = shroud.unknown.chances.medium

		hidden_effect = {
			random_list = {
				60 = {
					modifier = { add = value:delve_success_chance_from_techs }
					country_event = { id = shroud.3106 }
				}
				40 = {
					modifier = {
						factor = 0.5
						has_relic = r_zro_crystal
					}
					country_event = { id = shroud.3107 }
				}
			}
		}
	}
	option = {
		name = "exit.shroud"
		custom_tooltip = "exit.shroud.tooltip"
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
		default_hide_option = yes
	}
}

## Psychic Pathways - Success
country_event = {
	id = shroud.3106
	base = shroud.3

	title = shroud.3106.title
	desc_clear = yes
	desc = shroud.3106.desc

	immediate = {
		set_country_flag = shroud_3105_happened
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = {
				NOR = {
					has_technology = tech_psionic_lightning
					has_tech_option = tech_psionic_lightning
				}
			}
			add_research_option = tech_psionic_lightning
		}
		random_list = {
			1 = {
				add_monthly_resource_mult = {
					resource = physics_research
					value = @tier2researchreward
					min = @tier2researchmin
					max = @tier2researchmax
				}
			}
			1 = {
				add_monthly_resource_mult = {
					resource = society_research
					value = @tier2researchreward
					min = @tier2researchmin
					max = @tier2researchmax
				}
			}
			1 = {
				add_monthly_resource_mult = {
					resource = engineering_research
					value = @tier2researchreward
					min = @tier2researchmin
					max = @tier2researchmax
				}
			}
		}
		default_hide_option = yes
	}
}

## Psychic Pathways - Fail
country_event = {
	id = shroud.3107
	base = shroud.3

	title = shroud.3107.title
	desc_clear = yes
	desc = shroud.3107.desc

	immediate = {
		set_country_flag = recently_failed_component_delve
		set_timed_country_flag = {
			flag = shroud_3105_happened
			days = 10800 # 30 years
		}
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		add_modifier = {
			modifier = shroud_neg_unity
			days = 1800
		}
		default_hide_option = yes
	}
}
## Psionic Bombers
# Component Delve Event - Psionic Disruptors
country_event = {
	id = shroud.3115
	base = shroud.3

	title = shroud.3115.title
	desc_clear = yes
	desc = shroud.3115.desc

	show_sound_clear = yes
	show_sound = event_ship_explosion

	trigger = {
		NOT = { has_country_flag = shroud_3115_happened }
		NOR = {
			has_technology = tech_psionic_bombers
			has_tech_option = tech_psionic_bombers
		}
		OR = {
			AND = {
				NOT = { has_covenant = the_eater_of_worlds }
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOT = { has_covenant = the_composer_of_strands }
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOT = { has_covenant = the_cradle_of_souls }
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOT = { has_covenant = the_instrument_of_desire }
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			add = value:non_component_delve_roll
			check_variable = {
				which = non_component_delve_count
				value > 0
			}
		}
		modifier = {
			add = 1
			has_country_flag = recently_failed_component_delve
		}
	}

	immediate = {
		remove_country_flag = recently_failed_component_delve
		clear_variable = non_component_delve_count
	}

	option_clear = yes
	option = {
		name = shroud.3115.a
		custom_tooltip = shroud.unknown.chances.medium

		hidden_effect = {
			random_list = {
				60 = {
					modifier = { add = value:delve_success_chance_from_techs }
					country_event = { id = shroud.3116 }
				}
				40 = {
					modifier = {
						factor = 0.5
						has_relic = r_zro_crystal
					}
					country_event = { id = shroud.3117 }
				}
			}
		}
	}
	option = {
		name = "exit.shroud"
		custom_tooltip = "exit.shroud.tooltip"
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
		default_hide_option = yes
	}
}

## Psionic Bombers - Success
country_event = {
	id = shroud.3116
	base = shroud.3

	title = shroud.3116.title
	desc_clear = yes
	desc = shroud.3116.desc

	show_sound_clear = yes
	show_sound = event_ship_explosion

	immediate = {
		set_country_flag = shroud_3115_happened
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = {
				NOR = {
					has_technology = tech_psionic_bombers
					has_tech_option = tech_psionic_bombers
				}
			}
			add_research_option = tech_psionic_bombers
		}
	}
}

## Psionic Bombers - Fail
country_event = {
	id = shroud.3117
	base = shroud.3

	title = shroud.3117.title
	desc_clear = yes
	desc = shroud.3117.desc

	show_sound_clear = yes
	show_sound = event_ship_explosion

	immediate = {
		set_country_flag = recently_failed_component_delve
		set_timed_country_flag = {
			flag = shroud_3115_happened
			days = 10800 # 30 years
		}
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = { is_robot_empire = yes }
			add_modifier = {
				modifier = psionic_shock_robot_modifier
				days = 1800
			}
		}
		else_if = {
			limit = { is_hive_empire = yes }
			add_modifier = {
				modifier = psionic_shock_hive_modifier
				days = 1800
			}
		}
		else = {
			add_modifier = {
				modifier = psionic_shock_modifier
				days = 1800
			}
		}
	}
}

## Psychic Lance
# Component Delve Event - Psionic Disruptors
country_event = {
	id = shroud.3110
	base = shroud.3

	title = shroud.3110.title
	desc_clear = yes
	desc = shroud.3110.desc

	trigger = {
		NOT = { has_country_flag = shroud_3110_happened }
		NOR = {
			has_technology = tech_psionic_disruptor
			has_tech_option = tech_psionic_disruptor
		}
		OR = {
			AND = {
				NOT = { has_covenant = the_eater_of_worlds }
				is_in_domain = the_eater_of_worlds
			}
			AND = {
				NOT = { has_covenant = the_composer_of_strands }
				is_in_domain = the_composer_of_strands
			}
			AND = {
				NOT = { has_covenant = the_cradle_of_souls }
				is_in_domain = the_cradle_of_souls
			}
			AND = {
				NOT = { has_covenant = the_instrument_of_desire }
				is_in_domain = the_instrument_of_desire
			}
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			add = value:non_component_delve_roll
			check_variable = {
				which = non_component_delve_count
				value > 0
			}
		}
		modifier = {
			add = 1
			has_country_flag = recently_failed_component_delve
		}
	}

	immediate = {
		remove_country_flag = recently_failed_component_delve
		clear_variable = non_component_delve_count
	}

	option_clear = yes
	option = {
		name = shroud.3110.a
		custom_tooltip = shroud.unknown.chances.medium

		hidden_effect = {
			random_list = {
				60 = {
					modifier = { add = value:delve_success_chance_from_techs }
					country_event = { id = shroud.3111 }
				}
				40 = {
					modifier = {
						factor = 0.5
						has_relic = r_zro_crystal
					}
					country_event = { id = shroud.3112 }
				}
			}
		}
	}
	option = {
		name = "exit.shroud"
		custom_tooltip = "exit.shroud.tooltip"
		add_modifier = {
			modifier = reduce_next_delve_cooldown
			multiplier = 0.5
		}
		default_hide_option = yes
	}
}

## Psychic Lance - Success
country_event = {
	id = shroud.3111
	base = shroud.3

	title = shroud.3111.title
	desc_clear = yes
	desc = shroud.3111.desc

	immediate = {
		set_country_flag = shroud_3110_happened
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = {
				NOR = {
					has_technology = tech_psionic_disruptor
					has_tech_option = tech_psionic_disruptor
				}
			}
			add_research_option = tech_psionic_disruptor
		}
		default_hide_option = yes
	}
}

## Psychic Lance - Fail
country_event = {
	id = shroud.3112
	base = shroud.3

	title = shroud.3112.title
	desc_clear = yes
	desc = shroud.3112.desc

	immediate = {
		set_country_flag = recently_failed_component_delve
		set_timed_country_flag = {
			flag = shroud_3110_happened
			days = 10800 # 30 years
		}
	}

	option_clear = yes
	option = {
		name = "exit.shroud"
		if = {
			limit = { is_robot_empire = yes }
			add_modifier = {
				modifier = recovering_telepaths_robot
				days = 1800
			}
		}
		else_if = {
			limit = { is_hive_empire = yes }
			add_modifier = {
				modifier = recovering_telepaths_hive
				days = 1800
			}
		}
		else = {
			add_modifier = {
				modifier = recovering_telepaths
				days = 1800
			}
		}
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.3120
	base = shroud.3

	title = shroud.3120.title
	desc_clear = yes
	desc = shroud.3120.desc

	trigger = {
		has_country_flag = has_delved_in_shroud
		has_resource = { type = energy amount >= 2000 }
		has_resource = { type = sr_zro amount >= 500 }
		NOT = { has_country_flag = exclude_distant_echo_delve_event }
		NOT = { has_country_flag = has_recently_seen_distant_echo }
		OR = {
			has_patron_relation = { patron = the_composer_of_strands contact = none }
			has_patron_relation = { patron = the_eater_of_worlds contact = none }
			has_patron_relation = { patron = the_instrument_of_desire contact = none }
			has_patron_relation = { patron = the_cradle_of_souls contact = none }
		}
	}

	immediate = {
		set_country_flag = shroud_diplomacy_engaged
		set_timed_country_flag = {
			flag = has_recently_seen_distant_echo
			years = 20
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = shroud_diplomacy_engaged
		}
	}

	option_clear = yes
	option = {
		name = shroud.3120.a
		custom_tooltip = shroud.3125.tt
		trigger = {
			has_patron_relation = { patron = the_composer_of_strands contact = none }
		}
		allow = {
			has_resource = { type = energy amount >= 2000 }
			has_resource = { type = sr_zro amount >= 500 }
		}
		add_resource = { energy = -2000 }
		add_resource = { sr_zro = -500 }
		set_country_flag = contact_composer
		hidden_effect = {
			add_attunement = { the_composer_of_strands = 400 }
			country_event = { id = shroud.3125 }
		}
	}

	option = {
		name = shroud.3120.b
		custom_tooltip = shroud.3125.tt
		trigger = {
			has_patron_relation = { patron = the_eater_of_worlds contact = none }
		}
		allow = {
			has_resource = { type = energy amount >= 2000 }
			has_resource = { type = sr_zro amount >= 500 }
		}
		add_resource = { energy = -2000 }
		add_resource = { sr_zro = -500 }
		set_country_flag = contact_eater
		hidden_effect = {
			add_attunement = { the_eater_of_worlds = 400 }
			country_event = { id = shroud.3125 }
		}
	}

	option = {
		name = shroud.3120.c
		custom_tooltip = shroud.3125.tt
		trigger = {
			has_patron_relation = { patron = the_instrument_of_desire contact = none }
		}
		allow = {
			has_resource = { type = energy amount >= 2000 }
			has_resource = { type = sr_zro amount >= 500 }
		}
		add_resource = { energy = -2000 }
		add_resource = { sr_zro = -500 }
		set_country_flag = contact_instrument
		hidden_effect = {
			add_attunement = { the_instrument_of_desire = 400 }
			country_event = { id = shroud.3125 }
		}
	}

	option = {
		name = shroud.3120.d
		custom_tooltip = shroud.3125.tt
		trigger = {
			has_patron_relation = { patron = the_cradle_of_souls contact = none }
		}
		allow = {
			has_resource = { type = energy amount >= 2000 }
			has_resource = { type = sr_zro amount >= 500 }
		}
		add_resource = { energy = -2000 }
		add_resource = { sr_zro = -500 }
		set_country_flag = contact_cradle
		hidden_effect = {
			add_attunement = { the_cradle_of_souls = 400 }
			country_event = { id = shroud.3125 }
		}
	}

	option = {
		name = exit.shroud
		custom_tooltip = exit.shroud.tooltip
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.3125
	base = shroud.3

	title = shroud.3125.title
	desc_clear = yes
	desc = shroud.3125.desc

	option_clear = yes
	option = {
		name = exit.shroud
		custom_tooltip = exit.shroud.tooltip
		default_hide_option = yes
	}
}

## Minor Patrons delve events
# The Animator of Clay - Animatus
country_event = {
	id = shroud.3200
	base = shroud.3

	title = shroud.3200.title
	desc_clear = yes
	desc = shroud.3200.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3200_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_animator_of_clay
			contact = completed
		}
		OR = {
			is_in_domain = the_cradle_of_souls
			is_in_domain = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3200_happened
	}

	option_clear = yes
	option = {
		name = shroud.3200.a
		custom_tooltip = shroud.3200.a.tt
	}
}

# The Outsider - Will of Temperance
country_event = {
	id = shroud.3210
	base = shroud.3

	title = shroud.3210.title
	desc_clear = yes
	desc = {
		trigger = {
			if = {
				limit = { has_country_flag = has_left_zroni_to_their_fate }
				text = shroud.3210.desc.left_zroni
			}
			else_if = {
				limit = { has_country_flag = has_met_zroni }
				text = shroud.3210.desc.know_zroni
			}
			else = {
				text = shroud.3210.desc.default
			}
		}
	}

	trigger = {
		NOR = {
			has_country_flag = shroud_3210_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_outsider
			contact = completed
		}
		OR = {
			is_in_domain = the_cradle_of_souls
			is_in_domain = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3210_happened
	}

	option_clear = yes
	option = {
		name = shroud.3210.a
		custom_tooltip = shroud.3210.a.tt
	}
}

# The Golden Dream - Thoughtplay
country_event = {
	id = shroud.3220
	base = shroud.3

	title = shroud.3220.title
	desc_clear = yes
	desc = shroud.3220.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3220_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_golden_dream
			contact = completed
		}
		OR = {
			is_in_domain = the_cradle_of_souls
			is_in_domain = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3220_happened
	}

	option_clear = yes
	option = {
		name = shroud.3220.a
		custom_tooltip = shroud.3220.a.tt
	}
}

# The Endless Tide - Sands of Time
country_event = {
	id = shroud.3230
	base = shroud.3

	title = shroud.3230.title
	desc_clear = yes
	desc = shroud.3230.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3230_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_endless_tide
			contact = completed
		}
		OR = {
			is_in_domain = the_eater_of_worlds
			is_in_domain = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3230_happened
	}

	option_clear = yes
	option = {
		name = shroud.3230.a
		custom_tooltip = shroud.3230.a.tt
	}
}

# The Pale Mountain - Reformed
country_event = {
	id = shroud.3240
	base = shroud.3

	title = shroud.3240.title
	desc_clear = yes
	desc = shroud.3240.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3240_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_pale_mountain
			contact = completed
		}
		OR = {
			is_in_domain = the_eater_of_worlds
			is_in_domain = the_composer_of_strands
		}
	}

	immediate = {
		set_country_flag = shroud_3240_happened
	}

	option_clear = yes
	option = {
		name = shroud.3240.a
		custom_tooltip = shroud.3240.a.tt
	}
}

# The Hollow Point - The Strength of Abstention
country_event = {
	id = shroud.3250
	base = shroud.3

	title = shroud.3250.title
	desc_clear = yes
	desc = shroud.3250.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3250_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_hollow_point
			contact = completed
		}
		OR = {
			is_in_domain = the_cradle_of_souls
			is_in_domain = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3250_happened
	}

	option_clear = yes
	option = {
		name = shroud.3250.a
		custom_tooltip = utopia.3041.tooltip
		hidden_effect = {
			every_owned_leader = {
				limit = {
					has_psionic_leader_trait = yes
				}
				add_trait = {
					trait = leader_trait_shroud_age
					show_message = no
				}
			}
		}
	}
}

# The Vacant Throne - Chaos into Order
country_event = {
	id = shroud.3260
	base = shroud.3

	title = shroud.3260.title
	desc_clear = yes
	desc = shroud.3260.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3260_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_vacant_throne
			contact = completed
		}
		OR = {
			is_in_domain = the_eater_of_worlds
			is_in_domain = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3260_happened
	}

	option_clear = yes
	option = {
		name = shroud.3260.a
		custom_tooltip = shroud.3260.a.tt
	}
}

# The Black River - Infinite Acceleration
country_event = {
	id = shroud.3270
	base = shroud.3

	title = shroud.3270.title
	desc_clear = yes
	desc = shroud.3270.desc

	trigger = {
		NOR = {
			has_country_flag = shroud_3270_happened
			has_country_flag = forging_our_own_path
		}
		has_patron_relation = {
			patron = the_black_river
			contact = completed
		}
		OR = {
			is_in_domain = the_eater_of_worlds
			is_in_domain = the_instrument_of_desire
		}
	}

	immediate = {
		set_country_flag = shroud_3270_happened
	}

	option_clear = yes
	option = {
		name = shroud.3270.a
		custom_tooltip = shroud.3270.a.tt
	}
}

#==================================
# 3500-3599 Forge our own Path
#==================================

country_event = {
	id = shroud.3500
	title = shroud.3500.title
	desc = shroud.3500.desc
	picture = GFX_evt_chosen_leader
	show_sound = event_mystic_reveal
	is_triggered_only = yes

	immediate = {
		set_country_flag = forging_our_own_path
		refresh_accords = yes
		country_event = { id = shroud.1560 }
		country_event = { id = shroud.3510 days = 60 random = 30 }
	}

	option = {
		name = shroud.3500.a
	}
}

country_event = {
	id = shroud.3510
	title = shroud.3510.title
	desc = shroud.3510.desc
	picture = GFX_evt_shroudwalker_enclave
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	immediate = {
		# First leader option.
		random_owned_leader = {
			limit = {
				# If Ruler's class fits, pick it.
				if = {
					limit = { owner = { ruler = { suitable_for_chosen = yes } } }
					is_ruler = yes
				}

				# Else, do regular pick.
				else = {
					suitable_for_chosen = yes
				}
			}
			save_event_target_as = leader_1
		}

		# Second leader option.
		random_owned_leader = {
			limit = {
				NOT = { is_same_value = event_target:leader_1 }
				suitable_for_chosen = yes
			}
			save_event_target_as = leader_2
		}

		# Third leader option.
		random_owned_leader = {
			limit = {
				# If Chosen One exists, pick it.
				if = {
					limit = {
						owner = {
							any_owned_leader = {
								NOR = {
									is_same_value = event_target:leader_1
									is_same_value = event_target:leader_2
								}
								has_trait = leader_trait_chosen
							}
						}
					}
					has_trait = leader_trait_chosen
				}

				# Else, do regular pick.
				else = {
					NOR = {
						is_same_value = event_target:leader_1
						is_same_value = event_target:leader_2
					}
					suitable_for_chosen = yes
				}
			}
			save_event_target_as = leader_3
		}

		# Forth leader option.
		random_owned_leader = {
			limit = {
				NOR = {
					is_same_value = event_target:leader_1
					is_same_value = event_target:leader_2
					is_same_value = event_target:leader_3
				}
				suitable_for_chosen = yes
			}
			save_event_target_as = leader_4
		}
	}

	option = { #Ruler 1
		name = shroud.3510.a
		hidden_effect = {
			event_target:leader_1 = { save_event_target_as = chosen_leader }
			country_event = { id = utopia.2682 }
		}
	}
	option = { #Ruler 2
		name = shroud.3510.b
		hidden_effect = {
			event_target:leader_2 = { save_event_target_as = chosen_leader }
			country_event = { id = utopia.2682 }
		}
	}
	option = { #Ruler 3
		name = shroud.3510.c
		trigger = {
			exists = event_target:leader_3
		}
		hidden_effect = {
			event_target:leader_3 = { save_event_target_as = chosen_leader }
			country_event = { id = utopia.2682 }
		}
	}
	option = { #Ruler 4
		name = shroud.3510.d
		trigger = {
			exists = event_target:leader_4
		}
		hidden_effect = {
			event_target:leader_4 = { save_event_target_as = chosen_leader }
			country_event = { id = utopia.2682 }
		}
	}
}

country_event = {
	id = shroud.3520
	title = shroud.3520.title
	desc = shroud.3520.desc
	picture = GFX_evt_chosen_leader
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	trigger = {
		has_country_flag = forging_our_own_path
		count_unlocked_active_accords = 4
	}

	option = {
		name = shroud.3520.a
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		add_modifier = { modifier = psionic_mastery }
	}
}

#==================================
# 4000-4149 Patrons First Contacts
#==================================

# The Eater of Worlds
inline_script = {
	script = shroud/major_patron_first_contact_start_event
	EVENT_ID = shroud.4000
	SPECIAL_PROJECT_KEY = "THE_EATER_OF_WORLD_FC_PROJECT"
	PATRON_TYPE = the_eater_of_worlds
}

inline_script = {
	script = shroud/major_patron_first_contact_end_event
	EVENT_ID = shroud.4005
	PICTURE = GFX_evt_shroud_eater_of_worlds
	PATRON_TYPE = the_eater_of_worlds
}

# The Cradle of Souls
inline_script = {
	script = shroud/major_patron_first_contact_start_event
	EVENT_ID = shroud.4010
	SPECIAL_PROJECT_KEY = "THE_CRADLE_OF_SOULS_FC_PROJECT"
	PATRON_TYPE = the_cradle_of_souls
}

inline_script = {
	script = shroud/major_patron_first_contact_end_event
	EVENT_ID = shroud.4015
	PICTURE = GFX_evt_shroud_cradle_of_souls
	PATRON_TYPE = the_cradle_of_souls
}

# The Composer of Strands
inline_script = {
	script = shroud/major_patron_first_contact_start_event
	EVENT_ID = shroud.4020
	SPECIAL_PROJECT_KEY = "THE_COMPOSER_OF_STRANDS_FC_PROJECT"
	PATRON_TYPE = the_composer_of_strands
}

inline_script = {
	script = shroud/major_patron_first_contact_end_event
	EVENT_ID = shroud.4025
	PICTURE = GFX_evt_shroud_composer_of_strands
	PATRON_TYPE = the_composer_of_strands
}

# The Instrument of Desire
inline_script = {
	script = shroud/major_patron_first_contact_start_event
	EVENT_ID = shroud.4030
	SPECIAL_PROJECT_KEY = "THE_INSTRUMENT_OF_DESIRE_FC_PROJECT"
	PATRON_TYPE = the_instrument_of_desire
}

inline_script = {
	script = shroud/major_patron_first_contact_end_event
	EVENT_ID = shroud.4035
	PICTURE = GFX_evt_shroud_instrument_of_desire
	PATRON_TYPE = the_instrument_of_desire
}

# The Whisperers in the Void
country_event = {
	id = shroud.4040
	title = shroud.4040.title
	desc = shroud.4040.desc
	picture = GFX_evt_shroud_generic
	is_triggered_only = yes

	immediate = {
		inline_script = {
			script = shroud/patron_start_first_contact_special_project
			PATRON_TYPE = whisperers_in_the_void
			SPECIAL_PROJECT_KEY = WHISPERERS_IN_THE_VOID_FC_PROJECT
		}
	}

	option = {
		name = shroud.4040.a
		tooltip = {
			inline_script = {
				script = shroud/patron_start_first_contact_special_project
				PATRON_TYPE = whisperers_in_the_void
				SPECIAL_PROJECT_KEY = WHISPERERS_IN_THE_VOID_FC_PROJECT
			}
		}
	}
}

country_event = {
	id = shroud.4045
	title = shroud.4045.title
	diplomatic_title = shroud.3.diplo_title
	desc = {
		trigger = {
			if = {
				limit = {
					OR = {
						has_covenant = the_eater_of_worlds
						has_covenant = the_cradle_of_souls
						has_covenant = the_instrument_of_desire
						has_covenant = the_composer_of_strands
					}
				}
				text = shroud.4045.desc.covenant
			}
			else = {
				text = shroud.4045.desc.no_covenant
			}
		}
	}

	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	option = {
		trigger = {
			OR = {
				has_covenant = the_eater_of_worlds
				has_covenant = the_cradle_of_souls
				has_covenant = the_instrument_of_desire
				has_covenant = the_composer_of_strands
			}
		}
		name = shroud.4045.a
		custom_tooltip = shroud.4045.a.covenant.tt
		hidden_effect = {
			set_patron_first_contact_state = { patron = whisperers_in_the_void state = completed }
			country_event = {
				id = shroud.4046
			}
		}
		ai_chance = {
			base = 0
		}
	}

	option = {
		trigger = {
			NOR = {
				has_covenant = the_eater_of_worlds
				has_covenant = the_cradle_of_souls
				has_covenant = the_instrument_of_desire
				has_covenant = the_composer_of_strands
			}
		}
		name = shroud.4045.a
		custom_tooltip = shroud.4045.a.no_covenant.tt
		hidden_effect = {
			set_patron_first_contact_state = { patron = whisperers_in_the_void state = completed }
			country_event = {
				id = shroud.11110
			}
		}
		ai_chance = {
			base = 0
		}
	}

	option = {
		name = shroud.4045.b
		custom_tooltip = shroud.reject_covenant.tt
		default_hide_option = yes
		hidden_effect = {
			refuse_covenant = {
				patron = whisperers_in_the_void
				reset_attunement = yes
			}
			remove_country_flag = contacting_great_patron
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
	}
}

country_event = {
	id = shroud.4046
	title = shroud.4046.title
	diplomatic_title = shroud.3.diplo_title
	desc = {
		trigger = { is_robot_empire = yes }
		text = shroud.4046.desc.robot
	}
	desc = {
		trigger = { is_robot_empire = no }
		text = shroud.4046.desc.organic
	}

	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	option = {
		name = REMARKABLE
		if = {
			limit = {
				has_covenant = the_eater_of_worlds
			}
			whisperers_in_the_void_replace_patron = {
				PATRON = the_eater_of_worlds
				CHAIN = "shroud_eater_covenant_chain"
			}
			set_country_flag = broke_covenant
			country_event = {
				id = shroud.11111
			}
		}
		else_if = {
			limit = {
				has_covenant = the_cradle_of_souls
			}
			whisperers_in_the_void_replace_patron = {
				PATRON = the_cradle_of_souls
				CHAIN = "shroud_cradle_covenant_chain"
			}
			set_country_flag = broke_covenant
			country_event = {
				id = shroud.11112
			}
		}
		else_if = {
			limit = {
				has_covenant = the_instrument_of_desire
			}
			whisperers_in_the_void_replace_patron = {
				PATRON = the_instrument_of_desire
				CHAIN = "shroud_instrument_covenant_chain"
			}
			set_country_flag = broke_covenant
			country_event = {
				id = shroud.11113
			}
		}
		else_if = {
			limit = {
				has_covenant = the_composer_of_strands
			}
			whisperers_in_the_void_replace_patron = {
				PATRON = the_composer_of_strands
				CHAIN = "shroud_composer_covenant_chain"
			}
			set_country_flag = broke_covenant
			country_event = {
				id = shroud.11114
			}
		}
	}
}

# The Animator of Clay
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4050
	SPECIAL_PROJECT_KEY = "THE_ANIMATOR_OF_CLAY_FC_PROJECT"
	PATRON_TYPE = the_animator_of_clay
}

country_event = { #minor_patron_first_contact_end_event
	id = shroud.4055
	title = shroud.4055.title
	desc = {
		trigger = {
			text = shroud.4055.desc

			if = {
				limit = {
					OR = {
						has_country_flag = has_met_animator_of_clay
						has_country_flag = synth_queen_contacted_the_animator_already
					}
				}
				text = newline
				text = shroud.4055.desc.know_animator
			}
		}
	}

	picture = GFX_evt_shroud_generic
	is_triggered_only = yes
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	immediate = {
		set_patron_first_contact_state = { patron = the_animator_of_clay state = completed }
	}

	after = {
		set_country_flag = has_met_animator_of_clay
	}

	option = {
		name = shroud.4055.a
		tooltip = {
			set_patron_first_contact_state = { patron = the_animator_of_clay state = completed }
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}
}

# The Outsider
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4060
	SPECIAL_PROJECT_KEY = "THE_OUTSIDER_FC_PROJECT"
	PATRON_TYPE = the_outsider
}

country_event = { #minor_patron_first_contact_end_event
	id = shroud.4065
	title = shroud.4065.title
	desc = {
		trigger = {
			text = shroud.4065.desc.intro
			text = newline

			if = {
				limit = { has_country_flag = has_left_zroni_to_their_fate }
				text = shroud.4065.desc.outro_left_zroni
			}
			else_if = {
				limit = { has_country_flag = has_met_zroni }
				text = shroud.4065.desc.outro_know_zroni
			}
			else = {
				text = shroud.4065.desc.outro_default
			}
		}
	}

	picture = GFX_evt_shroud_generic
	is_triggered_only = yes
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	immediate = {
		set_patron_first_contact_state = { patron = the_outsider state = completed }
	}

	option = {
		name = {
			trigger = {
				if = {
					limit = { has_country_flag = has_left_zroni_to_their_fate }
					text = shroud.4065.a.left_zroni
				}
				else_if = {
					limit = { has_country_flag = has_met_zroni }
					text = shroud.4065.a.know_zroni
				}
				else = {
					text = shroud.4065.a.default
				}
			}
		}
		tooltip = {
			set_patron_first_contact_state = { patron = the_outsider state = completed }
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}
}

# The Endless Sands
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4070
	SPECIAL_PROJECT_KEY = "THE_ENDLESS_SANDS_FC_PROJECT"
	PATRON_TYPE = the_endless_tide
}

inline_script = {
	script = shroud/minor_patron_first_contact_end_event
	EVENT_ID = shroud.4075
	PATRON_TYPE = the_endless_tide
}

# The Mountain of Bones
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4080
	SPECIAL_PROJECT_KEY = "THE_MOUNTAIN_OF_BONES_FC_PROJECT"
	PATRON_TYPE = the_pale_mountain
}

inline_script = {
	script = shroud/minor_patron_first_contact_end_event
	EVENT_ID = shroud.4085
	PATRON_TYPE = the_pale_mountain
}

# The Golden Dream
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4090
	SPECIAL_PROJECT_KEY = "THE_GOLDEN_DREAM_FC_PROJECT"
	PATRON_TYPE = the_golden_dream
}

inline_script = {
	script = shroud/minor_patron_first_contact_end_event
	EVENT_ID = shroud.4095
	PATRON_TYPE = the_golden_dream
}

# The Bladeless Sword
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4100
	SPECIAL_PROJECT_KEY = "THE_BLADELESS_SWORD_FC_PROJECT"
	PATRON_TYPE = the_hollow_point
}

country_event = { #minor_patron_first_contact_end_event
	id = shroud.4105
	title = shroud.4105.title
	desc = {
		trigger = {
			text = shroud.4105.desc

			if = {
				limit = { is_homicidal = yes }
				text = newline
				text = shroud.4105.desc.outro_homicidal
			}
		}
	}

	picture = GFX_evt_shroud_generic
	is_triggered_only = yes
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	immediate = {
		set_patron_first_contact_state = { patron = the_hollow_point state = completed }
	}

	option = {
		name = {
			trigger = {
				if = {
					limit = { is_homicidal = yes }
					text = shroud.4105.a.homicidal
				}
				else = {
					text = shroud.4105.a.default
				}
			}
		}
		tooltip = {
			set_patron_first_contact_state = { patron = the_hollow_point state = completed }
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}
}

# The Throne's Shadow
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4110
	SPECIAL_PROJECT_KEY = "THE_THRONE_SHADOW_FC_PROJECT"
	PATRON_TYPE = the_vacant_throne
}

inline_script = {
	script = shroud/minor_patron_first_contact_end_event
	EVENT_ID = shroud.4115
	PATRON_TYPE = the_vacant_throne
}

# The Black River
inline_script = {
	script = shroud/minor_patron_first_contact_start_event
	EVENT_ID = shroud.4120
	SPECIAL_PROJECT_KEY = "THE_BLACK_RIVER_FC_PROJECT"
	PATRON_TYPE = the_black_river
}

country_event = { #minor_patron_first_contact_end_event
	id = shroud.4125
	title = shroud.4125.title
	desc = shroud.4125.desc

	picture = GFX_evt_shroud_generic
	is_triggered_only = yes
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	immediate = {
		set_patron_first_contact_state = { patron = the_black_river state = completed }
	}

	option = {
		name = shroud.4125.a
		tooltip = {
			set_patron_first_contact_state = { patron = the_black_river state = completed }
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}
}

# The End of the Cycle
country_event = {
	id = shroud.4135
	title = shroud.4135.title
	diplomatic_title = shroud.3.diplo_title
	desc = shroud.4135.desc

	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	immediate = {
		set_patron_first_contact_state = { patron = end_of_the_cycle state = in_progress }
	}

	option = {
		name = shroud.4135.a
		custom_tooltip = shroud.4135.a.tt
		accept_end_of_the_cycle = yes
		hidden_effect = {
			give_eotc_psionic_component_tech_insight = { TECH = tech_psionic_bombers }
			give_eotc_psionic_component_tech_insight = { TECH = tech_psionic_lightning }
			give_eotc_psionic_component_tech_insight = { TECH = tech_psionic_disruptor }
			give_eotc_psionic_component_tech_insight = { TECH = tech_zro_launcher }
			give_eotc_psionic_component_tech_insight = { TECH = tech_psionic_shield }
			give_eotc_psionic_component_tech_insight = { TECH = tech_precognition_interface }
			give_eotc_psionic_component_tech_insight = { TECH = tech_psi_jump_drive_1 }
			country_event = { id = shroud.4715 } # utopia.3310
		}
		ai_chance = {
			modifier = {
				factor = 0
				NOT = { is_country_type = default }
			}
		}
	}
	option = {
		name = {
			trigger = { NOT = { has_country_flag = forging_our_own_path } }
			text = shroud.4135.b
		}
		name = {
			trigger = { has_country_flag = forging_our_own_path }
			text = shroud.4135.b.forging_our_own_path
		}
		custom_tooltip = shroud.reject_covenant.tt
		default_hide_option = yes
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		hidden_effect = {
			refuse_covenant = {
				patron = end_of_the_cycle
				reset_attunement = yes
			}
			every_owned_leader = {
				limit = { has_trait = leader_trait_disciple_of_the_end }
				root = {
					country_event = {
						id = shroud.12155
						days = 1
						scopes = { from = prev }
					}
				}
			}
			remove_global_flag = end_of_the_cycle_rolled
		}
		ai_chance = {
			modifier = {
				factor = 0
				is_country_type = default # Default AIs should always accept EotC when given the chance
			}
		}
	}

	after = {
		remove_country_flag = contacting_great_patron
	}
}

country_event = {
	id = shroud.4140
	title = shroud.4140.title
	desc = shroud.4140.desc
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle

	is_triggered_only = yes

	immediate = {
		set_country_flag = reached_eotc_situation_stage2
	}

	option = {
		name = shroud.4140.a
		custom_tooltip = shroud.4140.a.tooltip
	}
}

country_event = {
	id = shroud.4145
	title = shroud.4145.title
	desc = {
		trigger = {
			if = {
				limit = { is_homicidal = yes }
				text = shroud.4145.desc_1.homicidal
			}
			else = {
				text = shroud.4145.desc_1.default
			}
			text = newline
			text = shroud.4145.desc_2
		}
	}
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle

	is_triggered_only = yes

	immediate = {
		set_country_flag = reached_eotc_situation_stage3
	}

	option = {
		name = shroud.4145.a
		custom_tooltip = shroud.4145.a.tooltip
	}
}

country_event = {
	id = shroud.4150
	title = shroud.4150.title
	desc = shroud.4150.desc
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle

	is_triggered_only = yes

	option = {
		name = shroud.4150.a
		add_monthly_resource_mult = {
			resource = energy
			value = @tier4materialreward
			min = @tier4materialmin
			max = @tier4materialmax
		}
	}
}

#==================================
# 4150-4499 Mindwarden Enclave
#==================================

# Found a Psionic Aura (not psionic -> contact Mindwardens)
# from = aura system
country_event = {
	id = shroud.4190
	title = shroud.4190.name
	desc = {
		trigger = {
			text = shroud.4190.desc
			if = {
				limit = {
					exists = event_target:mindwarden_enclave_country
					has_communications = event_target:mindwarden_enclave_country
				}
				text = newline
				text = shroud.4190.desc_mindwarden
			}
		}
	}
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes
	location  = from

	option = {
		name = shroud.4190.a
		hidden_effect = {
			if = {
				limit = {
					exists = event_target:mindwarden_enclave_country
					NOT = { has_communications = event_target:mindwarden_enclave_country }
				}
				country_event = {
					id = shroud.4195
					days = 15
				}
			}
		}
	}
}

# Found a Psionic Aura (psionic)
# from = aura system
# fromfrom = aura owner
country_event = {
	id = shroud.4191
	title = shroud.4191.name
	desc = {
		trigger = {
			if = {
				limit = { has_communications = fromfrom }
				text = shroud.4191.desc_1.contact
			}
			else = {
				text = shroud.4191.desc_1.default
			}
			text = newline
			if = {
				limit = { has_country_flag = power_of_will }
				text = shroud.4191.desc_2.knows_aura
			}
			else = {
				text = shroud.4191.desc_2.default
			}
			text = newline
			if = {
				limit = { has_communications = fromfrom }
				text = shroud.4191.desc_3.contact
			}
			else = {
				text = shroud.4191.desc_3.default
			}
		}
	}
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes

	option = {
		name = {
			trigger = {
				if = {
					limit = {
						is_organic_species = yes
						is_gestalt = no
					}
					if = {
						limit = {
							is_hostile_towards_aura = {
								PSIONIC_OWNER = fromfrom
							}
						}
						text = shroud.4191.a.rival_organic
					}
					else = {
						text = shroud.4191.a.organic
					}
				}
				else = {
					if = {
						limit = {
							is_hostile_towards_aura = {
								PSIONIC_OWNER = fromfrom
							}
						}
						text = shroud.4191.a.rival_default
					}
					else = {
						text = shroud.4191.a.default
					}
				}
			}
		}
	}
}

country_event = {
	id = shroud.4195
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:mindwarden_enclave_country
		NOT = { has_communications = event_target:mindwarden_enclave_country }
	}

	immediate = {
		establish_contact = {
			who = event_target:mindwarden_enclave_country
			location = event_target:mindwarden_enclave_system
		}
	}
}

# Post-First Contact setup
# From = First Contact site owner
country_event = {
	id = shroud.4199
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		if = {
			limit = {
				from = {
					NOT = { has_country_flag = mindwarden_enclave_country }
				}
			}
			from = {
				save_event_target_as = target_country
			}
		}
		else = {
			fromfrom = {
				save_event_target_as = target_country
			}
		}
		event_target:target_country = {
			event_target:mindwarden_enclave_country = {
				if = {
					limit = { NOT = { is_same_value = prev } }
					add_trust = {
						who = prev
						amount = prev.value:materiality_engine_trust_gain
					}
				}
			}
			country_event = { id = shroud.4200 }
		}
	}
}

# Mindwarden Enclave Greetings
# Via on_custom_diplomacy | this = target country (player); from = country being contacted
country_event = {
	id = shroud.4200
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			is_country_type = mindwarden_enclave
		}
		NOT = { has_country_flag = in_diplomacy_with@from }
	}

	immediate = {
		ai_trade_facility = {
			offer_hire_mercenary_fleet = yes
			offer_prolong_fleet_contract = yes

			if = {
				limit = {
					NOT = { exists = event_target:mindwarden_enclave_country }
				}
				from = {
					save_event_target_as = mindwarden_enclave_country
				}
			}
			event_target:mindwarden_enclave_country = {
				# Failsafe to catch if fleets are no longer on loan
				remove_loaning_fleet_flag = yes
			}
			country_event = { id = shroud.4201 }
		}
	}
}

country_event = {
	id = shroud.4201
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		ai_trade_facility = {
			offer_hire_mercenary_fleet = yes
			offer_prolong_fleet_contract = yes

			set_country_flag = in_diplomacy_with@event_target:mindwarden_enclave_country
			set_country_flag = mindwarden_diplomacy

			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						is_mercenary_mindwarden_enclave = yes
						has_country_flag = created_by@prev
					}
				}
				country_event = { id = shroud.6850 }
			}
			else_if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						has_country_flag = enclave_destroyed
					}
				}
				country_event = { id = shroud.4350 }
			}
			else_if = {
				limit = { has_country_flag = attacked_mindwardens }
				country_event = { id = shroud.4320 }
			}
			else_if = {
				limit = {
					event_target:shroudwalker_enclave_country = {
						trust = {
							who = root
							value >= 100
						}
					}
				}
				country_event = { id = shroud.4340 }
			}
			else_if = {
				limit = { has_breached_shroud = yes }
				country_event = { id = shroud.4300 }
			}
			else = {
				country_event = { id = shroud.4205 }
			}
		}
	}
}

country_event = {
	id = shroud.4205
	title = shroud.4205.name
	location = event_target:mindwarden_enclave_system
	desc = {
		trigger = {
			if = {
				limit = {
					has_country_flag = mindwarden_return_beginning
				}
				if = {
					limit = {
						has_global_flag = end_of_the_cycle_complete
					}
					text = shroud.4205.desc.return_beginning.eotc
				}
				else = {
					text = shroud.4205.desc.return_beginning
				}
			}
			else_if = {
				limit = {
					has_global_flag = end_of_the_cycle_complete
				}
				text = shroud.4205.desc.eotc
			}
			else_if = {
				limit = {
					NOT = { has_country_flag = closed_mindwarden_diplomacy }
				}
				text = shroud.4205.desc
			}
			else = {
				text = shroud.4205.desc.return
			}
		}
	}

	is_triggered_only = yes
	diplomatic = yes

	custom_gui = "enclave_artist_window"
	custom_gui_option = "enclave_artist_option"
	picture_event_data = {
		portrait = event_target:mindwarden_enclave_country
		room = enclave_mindwarden_room
	}

	option = {
		name = shroud.4205.a
		trigger = {
			NOT = { has_origin = origin_mindwardens }
		}
		response_text = shroud.4210.desc
		is_dialog_only = yes
	}
	option = {
		name = shroud.4205.b
		hidden_effect = {
			country_event = { id = shroud.4250 }
		}
	}
	option = {
		name = shroud.4205.c
		trigger = {
			has_encountered_psionic_auras = yes
			NOR = {
				has_technology = tech_psionic_suppression
				has_country_flag = has_gained_enclave_psionic_suppression_insight
				has_origin = origin_mindwardens
			}
		}
		hidden_effect = {
			country_event = { id = shroud.4230 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				any_system_within_border = {
					any_neighbor_system = {
						has_psionic_aura = yes
						aura_owner = {
							opinion = { who = root value < 0 }
						}
					}
				}
			}
		}
	}
	option = {
		name = shroud.4205.d
		trigger = {
			custom_tooltip = {
				fail_text = mindwarden_raid_cooldown_tt
				NOT = { has_country_flag = mindwarden_raid_cooldown }
			}
		}
		custom_tooltip = mindwarden_encourage_raid
		allow = {
			custom_tooltip = {
				fail_text = shroud.4240.need_psionics
				any_relation = {
					is_psionic = yes
					has_communications = root
				}
			}
			resource_stockpile_compare = { resource = energy value >= @raidhighallow }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		hidden_effect = {
			country_event = { id = shroud.4240 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				any_system_within_border = {
					any_neighbor_system = {
						system_has_hostile_aura = { COUNTRY = root.from }
					}
				}
			}
		}
	}
	option = {
		name = shroud.4205.e
		hidden_effect = {
			country_event = { id = shroud.4260 }
		}
	}
	option = {
		name = shroud.4205.ef
		trigger = {
			event_target:mindwarden_enclave_country = {
				trust = {
					who = root
					value >= 80
				}
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = mindwarden_logistics_cooldown_tt
				NOT = { has_country_flag = mindwarden_logistics_cooldown }
			}
		}
		hidden_effect = {
			country_event = { id = shroud.4265 }
		}
	}
	option = {
		name = shroud.4205.f
		trigger = {
			event_target:mindwarden_enclave_country = {
				trust = {
					who = root
					value >= 80
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.4270 }
		}
	}
	option = {
		name = shroud.4205.g
		trigger = {
			event_target:mindwarden_enclave_country = {
				trust = {
					who = root
					value >= 80
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.4280 }
		}
	}
	option = {
		name = shroud.4205.h
		trigger = {
			has_global_flag = end_of_the_cycle_complete
		}
		hidden_effect = {
			country_event = { id = shroud.4290 }
		}
	}
	option = {
		name = shroud.4205.i
		custom_tooltip = mercenary_tt_patron
		trigger = {
			event_target:mindwarden_enclave_country = {
				is_mercenary_mindwarden_enclave = yes
				has_country_flag = created_by@prev
			}
		}
		ai_trade_facility = {
			offer_hire_mercenary_fleet = yes
			offer_prolong_fleet_contract = yes
			hidden_effect = {
				country_event = { id = shroud.6855 }
			}
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}

	abort_trigger = {
		owner = {
			NOT = { exists = event_target:mindwarden_enclave_country }
		}
	}
}

# About Auras
country_event = {
	id = shroud.4230
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4230.desc
	option_clear = yes

	option = {
		name = shroud.4230.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4230.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = -1000
			influence = -50
		}
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root
					amount = @positive_opinion
				}
				set_timed_country_flag = {
					flag = aura_intel_bought
					years = @mindwardens_dividends_modifier_years
				}
			}
			event_target:shroudwalker_enclave_country = {
				add_trust = {
					who = root
					amount = @negative_opinion
				}
			}
		}
		add_tech_progress = {
			tech = tech_psionic_suppression
			progress = 0.25
		}
		hidden_effect = {
			set_country_flag = has_gained_enclave_psionic_suppression_insight
			country_event = { id = shroud.4231 }
		}
		ai_chance = {
			factor = 100
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Psionic suppression taught
country_event = {
	id = shroud.4231
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4231.desc
}

# Raiding Target
country_event = {
	id = shroud.4240
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4240.desc
	option_clear = yes

	immediate = {
		random_country = {
			limit = {
				is_country_type = default
				is_psionic = yes
				has_communications = root
				is_nomadic = no
			}
			save_event_target_as = raid_target_1
		}
		random_country = {
			limit = {
				is_country_type = default
				is_psionic = yes
				has_communications = root
				is_nomadic = no
				NOT = { is_same_value = event_target:raid_target_1 }
			}
			save_event_target_as = raid_target_2
		}
		random_country = {
			limit = {
				is_country_type = default
				is_psionic = yes
				has_communications = root
				is_nomadic = no
				NOR = {
					is_same_value = event_target:raid_target_1
					is_same_value = event_target:raid_target_2
				}
			}
			save_event_target_as = raid_target_3
		}
		random_country = {
			limit = {
				is_country_type = default
				is_psionic = yes
				has_communications = root
				is_nomadic = no
				NOR = {
					is_same_value = event_target:raid_target_1
					is_same_value = event_target:raid_target_2
					is_same_value = event_target:raid_target_3
				}
			}
			save_event_target_as = raid_target_4
		}
	}

	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}

	option = {
		name = shroud.4240.b
		trigger = {
			exists = event_target:raid_target_1
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= @raidhighallow }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = @raidhighcost
			influence = -50
		}
		custom_tooltip = mindwarden_hire_raid
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:raid_target_1 = { save_event_target_as = preliminary_target }
			country_event = { id = shroud.4241 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				OR = {
					is_at_war_with = event_target:raid_target_1
					is_rival = event_target:raid_target_1
				}
				event_target:raid_target_1 = {
					any_system_with_aura = {
						any_neighbor_system = {
							is_owned_by = root
						}
					}
				}
			}
		}
	}
	option = {
		name = shroud.4240.c
		trigger = {
			exists = event_target:raid_target_2
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= @raidhighallow }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = @raidhighcost
			influence = -50
		}
		custom_tooltip = mindwarden_hire_raid
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:raid_target_2 = { save_event_target_as = preliminary_target }
			country_event = { id = shroud.4241 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				OR = {
					is_at_war_with = event_target:raid_target_1
					is_rival = event_target:raid_target_1
				}
				event_target:raid_target_1 = {
					any_system_with_aura = {
						any_neighbor_system = {
							is_owned_by = root
						}
					}
				}
			}
		}
	}
	option = {
		name = shroud.4240.d
		trigger = {
			exists = event_target:raid_target_3
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= @raidhighallow }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = @raidhighcost
			influence = -50
		}
		custom_tooltip = mindwarden_hire_raid
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:raid_target_3 = { save_event_target_as = preliminary_target }
			country_event = { id = shroud.4241 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				OR = {
					is_at_war_with = event_target:raid_target_1
					is_rival = event_target:raid_target_1
				}
				event_target:raid_target_1 = {
					any_system_with_aura = {
						any_neighbor_system = {
							is_owned_by = root
						}
					}
				}
			}
		}
	}
	option = {
		name = shroud.4240.e
		trigger = {
			exists = event_target:raid_target_4
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= @raidhighallow }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = @raidhighcost
			influence = -50
		}
		custom_tooltip = mindwarden_hire_raid
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:raid_target_4 = { save_event_target_as = preliminary_target }
			country_event = { id = shroud.4241 }
		}
		ai_chance = {
			modifier = {
				factor = 100
				OR = {
					is_at_war_with = event_target:raid_target_1
					is_rival = event_target:raid_target_1
				}
				event_target:raid_target_1 = {
					any_system_with_aura = {
						any_neighbor_system = {
							is_owned_by = root
						}
					}
				}
			}
		}
	}

	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

country_event = {
	id = shroud.4241
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		event_target:mindwarden_enclave_country = {
			add_trust = {
				who = root
				amount = @positive_opinion
			}
			give_mindwarden_dividends_modifiers = {
				FLAG = raid_target_asked
			}
		}
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			event_target:shroudwalker_enclave_country = {
				add_trust = {
					who = root
					amount = @negative_opinion
				}
			}
		}
		set_timed_country_flag = {
			flag = mindwarden_raid_cooldown
			days = 3600
		}
		set_saved_date = {
			key = mindwarden_raid_timer
			days_from_present = 3600
			expires = 3600
		}
		event_target:preliminary_target = {
			country_event = { id = shroud.4242 }
		}
		country_event = { id = shroud.4245 }
	}
}

country_event = {
	id = shroud.4242
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		event_target:mindwarden_enclave_system = {
			random_system_planet = {
				limit = { has_planet_flag = mindwarden_enclave_planet }
				save_event_target_as = raid_source
			}
		}
		save_event_target_as = marauder_target
		from = { save_event_target_as = marauder_employer }
		event_target:mindwarden_enclave_country = {
			set_country_flag = raid_ongoing
		}
		create_country = {
			name = event_target:mindwarden_enclave_country
			type = "marauder_raiders"
			flag = event_target:mindwarden_enclave_country
			effect = {
				save_event_target_as = mindwarden_raiding_country
				set_country_flag = raid_ongoing
			}
		}
		event_target:mindwarden_raiding_country = {
			every_country = { establish_communications_no_message = event_target:mindwarden_raiding_country }
			event_target:mindwarden_enclave_country = {
				set_country_flag = parent_of@event_target:mindwarden_raiding_country
				set_faction_hostility = {
					target = event_target:mindwarden_raiding_country
					set_hostile = no
					set_neutral = no
					set_friendly = yes
				}
			}
			create_mindwarden_raid_fleet = yes
			set_faction_hostility = {
				target = event_target:marauder_target
				set_hostile = yes
				set_neutral = no
				set_friendly = no
			}
		}
		if = {
			limit = { has_communications = event_target:mindwarden_enclave_country }
			country_event = { id = shroud.4246 }
		}
		else = {
			country_event = { id = shroud.4247 }
		}
	}
}

# Mindwarden Raiders Withdraw
fleet_event = {
	id = shroud.4243
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_fleet_flag = raid_accomplished
		event_target:mindwarden_enclave_country = {
			remove_country_flag = raid_ongoing
		}
		event_target:mindwarden_enclave_system = {
			random_system_planet = {
				limit = { has_planet_flag = mindwarden_enclave_planet }
				save_event_target_as = raid_source
			}
		}
		clear_fleet_actions = this
		auto_move_to_planet = {
			target = event_target:raid_source
			destroy_on_arrival = yes
			clear_auto_move_on_arrival = yes
		}
		fleet_event = { id = marauder.118 days = 360 } # Kill fleet after 1 year regardless
	}
}

country_event = {
	id = shroud.4245
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4245.desc
}

# Hired Raiders Approach
country_event = {
	id = shroud.4246
	title = shroud.4246.name
	desc = shroud.4246.desc
	picture = GFX_evt_pirate_armada
	show_sound = event_radio_chatter

	is_triggered_only = yes

	option = {
		name = ONSCREEN
		hidden_effect = {
			country_event = { id = shroud.4300 }
		}
	}
}

# Hired Raiders Approach (previously unknown)
country_event = {
	id = shroud.4247
	title = shroud.4246.name
	desc = shroud.4247.desc
	picture = GFX_evt_pirate_armada
	show_sound = event_radio_chatter

	is_triggered_only = yes

	immediate = {
		establish_communications_no_message = event_target:mindwarden_raiding_country
	}

	option = {
		name = ONSCREEN
		hidden_effect = {
			country_event = { id = shroud.4300 }
		}
	}
}

# Discuss Zro
country_event = {
	id = shroud.4250
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4250.desc
	option_clear = yes

	immediate = {
		set_variable = {
			which = zro_max_value
			value = value:get_resource_value|RESOURCE|sr_zro|MAX|100|
		}
	}

	option = {
		name = shroud.4250.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4250.b
		response_text = shroud.4251.desc
		is_dialog_only = yes
	}
	option = {
		name = shroud.4250.c
		allow = {
			custom_tooltip = {
				fail_text = mindwarden_zro_cooldown_tt
				NOT = { has_country_flag = mindwarden_zro_cooldown }
			}
			resource_stockpile_compare = {
				resource = sr_zro
				value >= 1
			}
		}
		if = {
			limit = {
				resource_stockpile_compare = {
					resource = sr_zro
					value >= 1
				}
			}
			add_resource = {
				sr_zro = -1
				mult = zro_max_value
			}
			add_resource = {
				energy = 1
				mult = value:sell_resource_at_market_value|RESOURCE|sr_zro|VALUE|root.zro_max_value|MULT|5|
			}
		}
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root
					amount = @positive_opinion
				}
				give_mindwarden_dividends_modifiers = {
					FLAG = zro_bought
				}
			}
			if = {
				limit = { exists = event_target:shroudwalker_enclave_country }
				event_target:shroudwalker_enclave_country = {
					add_trust = {
						who = root
						amount = @negative_opinion
					}
				}
			}
			set_timed_country_flag = {
				flag = mindwarden_zro_cooldown
				days = 3600
			}
			set_saved_date = {
				key = mindwarden_zro_timer
				days_from_present = 3600
				expires = 3600
			}
			country_event = { id = shroud.4255 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Donated Zro
country_event = {
	id = shroud.4255
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4255.desc
}

# Help with crime
country_event = {
	id = shroud.4260
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4260.desc
	option_clear = yes

	option = {
		name = shroud.4260.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4260.b
		allow = {
			custom_tooltip = {
				fail_text = mindwarden_decision_cooldown_tt
				NOT = { has_country_flag = mindwarden_decision_cooldown }
			}
			resource_stockpile_compare = { resource = energy value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = -1000
			influence = -50
		}
		custom_tooltip = mindwarden_decision_explanation
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root
					amount = @positive_opinion
				}
				give_mindwarden_dividends_modifiers = {
					FLAG = police_recruited
				}
			}
			if = {
				limit = { exists = event_target:shroudwalker_enclave_country }
				event_target:shroudwalker_enclave_country = {
					add_trust = {
						who = root
						amount = @negative_opinion
					}
				}
			}
			if = {
				limit = {
					NOT = { has_country_flag = thought_police_recruited }
				}
				set_country_flag = thought_police_recruited
				set_variable = {
					which = thought_police_purchased
					value = 1
				}
			}
			else = {
				change_variable = {
					which = thought_police_purchased
					value = 1
				}
			}
			set_timed_country_flag = {
				flag = mindwarden_decision_cooldown
				days = 3600
			}
			set_saved_date = {
				key = mindwarden_decision_timer
				days_from_present = 3600
				expires = 3600
			}
			country_event = { id = shroud.4262 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Thought Police recruited
country_event = {
	id = shroud.4262
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4262.desc
}

# Logistics Assistance
country_event = {
	id = shroud.4265
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4265.desc
	option_clear = yes

	option = {
		name = shroud.4265.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4265.b
		trigger = {
			NOT = {
				has_modifier = mindwarden_logistics
			}
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= value:mindwarden_logistics_assistance_cost }
		}

		mindwarden_give_logistic_assistance = {
			MINDWARDEN_COUNTRY = event_target:mindwarden_enclave_country
		}
		hidden_effect = {
			country_event = { id = shroud.4266 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Logistics given
country_event = {
	id = shroud.4266
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4266.desc
}

# Logistics Assistance Ended
country_event = {
	id = shroud.4267
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4267.desc
	option_clear = yes

	trigger = {
		from = {
			trust = {
				who = root
				value >= 80
			}
		}
		NOT = { has_country_flag = in_diplomacy_with@from }
	}

	option = {
		name = shroud.4267.a
		trigger = {
			NOT = {
				has_modifier = mindwarden_logistics
			}
		}
		allow = {
			resource_stockpile_compare = { resource = energy value >= value:mindwarden_logistics_assistance_cost }
		}

		mindwarden_give_logistic_assistance = {
			MINDWARDEN_COUNTRY = from
		}
	}
	option = {
		name = shroud.4267.b
		default_hide_option = yes
	}

	abort_trigger = {
		has_country_flag = in_diplomacy_with@from
	}
}

# Use your soldiers
country_event = {
	id = shroud.4270
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4270.desc
	option_clear = yes

	option = {
		name = shroud.4270.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4270.b
		allow = {
			custom_tooltip = {
				fail_text = mindwarden_army_cooldown_tt
				NOT = { has_country_flag = mindwarden_army_cooldown }
			}
			resource_stockpile_compare = { resource = energy value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = -1000
			influence = -50
		}
		custom_tooltip = mindwarden_army_explanation
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root
					amount = @positive_opinion
				}
				species = {
					save_event_target_as = mindwarden_enclave_species
				}
				give_mindwarden_dividends_modifiers = {
					FLAG = army_recruited
				}
			}
			if = {
				limit = { exists = event_target:shroudwalker_enclave_country }
				event_target:shroudwalker_enclave_country = {
					add_trust = {
						who = root
						amount = @negative_opinion
					}
				}
			}
			create_fleet = {
				effect = {
					set_owner = root
					while = {
						count = 14
						create_army_transport = {
							army_type = "mindwarden_army"
							army_name = "NAME_Mindwarden_Army"
							species = event_target:mindwarden_enclave_species
							graphical_culture = event_target:mindwarden_enclave_species
						}
					}
					set_location = {
						target = root.capital_scope.solar_system
					}
				}
			}
			set_timed_country_flag = {
				flag = mindwarden_army_cooldown
				days = 3600
			}
			set_saved_date = {
				key = mindwarden_army_timer
				days_from_present = 3600
				expires = 3600
			}
			country_event = { id = shroud.4271 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Army recruited
country_event = {
	id = shroud.4271
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4271.desc
}

# Recruit Commander
country_event = {
	id = shroud.4280
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4280.desc
	option_clear = yes

	option = {
		name = shroud.4280.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4280.b
		allow = {
			custom_tooltip = {
				fail_text = mindwarden_commander_cooldown_tt
				NOT = { has_country_flag = mindwarden_commander_cooldown }
			}
			custom_tooltip = {
				fail_text = mindwarden_commander_already_bought
				NOT = {
					any_owned_leader = {
						has_leader_flag = mindwarden_commander
					}
				}
			}
			custom_tooltip = {
				fail_text = mindwarden_commander_conflicted_leader
				NOT = {
					any_owned_leader = {
						has_leader_flag = shroudwalker_teacher
					}
				}
			}
			resource_stockpile_compare = { resource = energy value >= 4000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			energy = -4000
			influence = -50
		}
		custom_tooltip = mindwarden_commander_explanation
		custom_tooltip = enclave_opinion_tt
		if = {
			limit = { exists = event_target:shroudwalker_enclave_country }
			custom_tooltip = mindwarden_rival_opinion_tt
		}
		custom_tooltip = unlocks_mindwarden_council_position
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				add_trust = {
					who = root
					amount = @positive_opinion
				}
				species = {
					save_event_target_as = mindwarden_enclave_species
				}
				give_mindwarden_dividends_modifiers = {
					FLAG = commander_given
				}
			}
			if = {
				limit = { exists = event_target:shroudwalker_enclave_country }
				event_target:shroudwalker_enclave_country = {
					add_trust = {
						who = root
						amount = @negative_opinion
					}
				}
			}
			create_mindwarden_commander = yes
			set_timed_country_flag = {
				flag = mindwarden_commander_cooldown
				days = 720
			}
			set_saved_date = {
				key = mindwarden_commander_timer
				days_from_present = 720
				expires = 720
			}
			country_event = { id = shroud.4281 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Commander recruited
country_event = {
	id = shroud.4281
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4281.desc
}

# The End of the Cycle
country_event = {
	id = shroud.4290
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4290.desc
	option_clear = yes

	option = {
		name = shroud.4290.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			country_event = { id = shroud.4201 }
		}
	}
	option = {
		name = shroud.4290.b
		response_text = shroud.4290.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.4290.c
		trigger = {
			NOT = { has_modifier = mindwarden_tactics_modifier }
			any_playable_country = {
				exists = event_target:the_end_of_the_cycle@this
			}
		}
		hidden_effect = {
			set_country_flag = mindwarden_learn_about_tactics
			country_event = { id = shroud.4292 }
		}
	}
	option = {
		name = shroud.4290.d
		trigger = {
			NOT = { has_modifier = mindwarden_tactics_modifier }
			any_playable_country = {
				exists = event_target:the_end_of_the_cycle@this
			}
			has_country_flag = mindwarden_learn_about_tactics
		}
		allow = {
			resource_stockpile_compare = {
				resource = energy
				value >= 10000
			}
		}
		add_resource = { energy = -10000 }
		add_modifier = { modifier = mindwarden_tactics_modifier }
		hidden_effect = {
			country_event = { id = shroud.4291 }
			event_target:mindwarden_enclave_country = {
				give_mindwarden_dividends_modifiers = {
					FLAG = reckoning_intel_given
				}
			}
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Modifier against the Reckoning bought
country_event = {
	id = shroud.4291
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4291.desc
}

# Learn about the Mindwarden Tactics
country_event = {
	id = shroud.4292
	base = shroud.4290
	desc_clear = yes
	desc = shroud.4292.desc
}

# Consequences of attacking the Mindwardens
# via on_entering_battle | from = attacked country (Mindwardens)
country_event = {
	id = shroud.4285
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = event_target:mindwarden_enclave_country
		from = { is_same_value = event_target:mindwarden_enclave_country }
		NOT = { has_country_flag = attacked_mindwardens }
	}

	immediate = {
		set_country_flag = attacked_mindwardens
		# Decrease trust
		event_target:mindwarden_enclave_country = {
			add_trust = {
				who = root
				amount = -100
			}
			if = {
				limit = {
					event_target:mindwarden_enclave_system = {
						count_fleet_in_system = {
							limit = { has_fleet_flag = mindwarden_defense_fleet }
							count < 1
						}
					}
				}
				create_mindwarden_defense_fleet = yes
			}
		}
		# Revoke leader upon attacking the Mindwardens
		random_owned_leader = {
			limit = { has_leader_flag = mindwarden_commander }
			leader_event = {
				id = shroud.4286
				days = 5
				scopes = {
					FROM = event_target:mindwarden_enclave_country
				}
			}
		}
	}
}

leader_event = {
	id = shroud.4286
	title = shroud.4286.name
	picture = GFX_evt_shroudwalker_enclave
	desc = {
		text = shroud.4286.desc.councilor
		trigger = { is_councilor = yes }
	}
	desc = {
		text = shroud.4286.desc
		trigger = { is_councilor = no }
	}
	show_sound = event_default
	is_triggered_only = yes

	event_window_type = leader_story
	event_picture_background = "GFX_leader_recruitment_bg_renowned"

	picture_event_data = {
		portrait = root
	}

	option = {
		name = DISAPPOINTING
		custom_tooltip = leader_leaves_tt
		hidden_effect = {
			exile_leader_as = exiled_enclave_leader@root
		}
	}
}

# Materiality Engine built
country_event = {
	id = shroud.4295
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4295.desc
	option_clear = yes

	trigger = {
		NOT = { has_country_flag = mindwarden_enclave_materiality_engine_built }
	}

	immediate = {
		set_country_flag = mindwarden_enclave_materiality_engine_built
	}

	option = {
		name = ACKNOWLEDGED
		custom_tooltip = mindwarden_opinion_materiality_engine_tt
	}
}

# Mindwarden custom_diplomacy if psionic
country_event = {
	id = shroud.4300
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4300.desc
	option_clear = yes

	option = {
		name = shroud.4300.a
		hidden_effect = {
			country_event = { id = shroud.4310 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.4310
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4310.desc
	option_clear = yes

	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Mindwarden custom_diplomacy if at war with them
country_event = {
	id = shroud.4320
	base = shroud.4205
	desc_clear = yes
	desc = {
		trigger = {
			if = {
				limit = { is_psionic = yes }
				text = shroud.4320.desc.psionic
			}
			else = {
				text = shroud.4320.desc.default
			}
			text = newline
			text = shroud.4320.desc.common
		}
	}
	option_clear = yes

	option = {
		name = END_TRANSMISSION
		default_hide_option = yes
	}
}

# Mindwarden custom_diplomacy if Trusted by Shroudwalkers
country_event = {
	id = shroud.4340
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = shroud.4340.desc

	option = {
		name = DOTDOTDOT
		default_hide_option = yes
	}
}

# Mindwarden custom_diplomacy if destroyed
country_event = {
	id = shroud.4350
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4350.desc
	option_clear = yes

	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Mindwarden Enclave Destroyed
country_event = {
	id = shroud.4400
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_country_type = mindwarden_enclave
			fromfrom = {
				is_ship_size = enclave_mindwarden_station
			}
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = event_target:mindwarden_enclave_country }
			}
			save_event_target_as = mindwarden_enclave_country
		}
		if = {
			limit = {
				NOT = { exists = event_target:mindwarden_enclave_system }
			}
			fromfrom.solar_system = {
				save_event_target_as = mindwarden_enclave_system
			}
		}
		event_target:mindwarden_enclave_system = {
			random_megastructure = {
				limit = { is_megastructure_type = shroud_seal }
				remove_megastructure = this
			}
			remove_star_flag = mindwarden_enclave_system
			clear_global_event_target = mindwarden_enclave_system
			save_event_target_as = mindwarden_enclave_system
		}
		set_country_flag = enclave_destroyed

		if = {
			limit = { exists = from }
			from = {
				save_event_target_as = mindwarden_destroyer
				country_event = { id = shroud.4405 }
			}
		}
		every_country = {
			limit = {
				has_communications = ROOT
				NOT = { is_country = event_target:mindwarden_destroyer }
				is_country_type = default
			}
			country_event = { id = shroud.4406 }
		}

		if = {
			limit = { is_mercenary_mindwarden_enclave = no }
			# We have to manually destroy its fleets since we don't fully destroy the country
			every_owned_fleet = {
				destroy_fleet = {
					target = this
					kill_leader = no
					destroy_template = no
				}
			}
			if = {
				limit = { NOT = { has_country_flag = enclave_respawned } }
				country_event = {
					id = shroud.4410
					years = 10
				}
			}
		}
		clear_global_event_target = mindwarden_enclave_system
	}

	after = {
		if = {
			limit = { is_mercenary_mindwarden_enclave = yes }
			destroy_country = yes
			every_country = {
				limit = { has_modifier = country_enclave_capacity_decrease_modifier }
				country_event = { id = enclave.24 days = 2 }
			}
		}
	}
}

country_event = { #Mindwarden Enclave Destroyed (Destroyer)
	id = shroud.4405
	title = shroud.4405.title
	desc = {
		trigger = {
			if = {
				limit = { is_psionic = yes }
				text = shroud.4405.desc.psionic
			}
			else = {
				text = shroud.4405.desc.default
			}
			text = newline
			text = shroud.4405.desc_end
		}
	}
	picture = GFX_evt_space_debris
	location = event_target:mindwarden_enclave_system
	show_sound = event_ship_bridge

	is_triggered_only = yes

	immediate = {
		set_country_flag = destroyed_mindwarden_enclave
	}

	option = {
		name = EXCELLENT
		add_resource = {
			alloys = 2000
			physics_research = 4000
		}
	}
}

country_event = { #Mindwarden Enclave
	id = shroud.4406
	title = shroud.4406.title
	desc = {
		trigger = {
			text = shroud.4406.desc_common
			text = newline
			if = {
				limit = { is_psionic = yes }
				text = shroud.4406.desc.psionic
			}
			else = {
				text = shroud.4406.desc.default
			}
		}
	}
	picture = GFX_evt_space_debris
	location = event_target:mindwarden_enclave_system
	show_sound = event_ship_bridge

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					has_country_flag = created_by@prev
				}
			}
			add_event_chain_counter = {
				event_chain = mindwarden_enclave_chain
				counter = enclaves_built
				amount = -1
			}
			save_event_target_as = enclave_owner
		}
	}

	option = {
		name = {
			trigger = {
				if = {
					limit = { is_psionic = yes }
					text = shroud.4406.a
				}
				else = {
					text = UNFORTUNATE
				}
			}
		}
		trigger = {
			NOT = {
				exists = event_target:enclave_owner
			}
		}
	}
	option = {
		name = enclave.26.a
		trigger = {
			exists = event_target:enclave_owner
		}
	}
}

# Try to spawn Mindwarden Enclave after it was destroyed
country_event = {
	id = shroud.4410
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = enclave_respawned }
		any_system = {
			NOT = { exists = space_owner }
		}
	}

	immediate = {
		random_system = {
			limit = {
				NOT = { exists = space_owner }
			}
			save_global_event_target_as = mindwarden_enclave_system
			random_system_planet = {
				change_pc = pc_shrouded
				save_event_target_as = mindwarden_enclave_planet
			}
			event_target:mindwarden_enclave_country = {
				create_mindwarden_enclave = yes
				set_custom_capital_location = event_target:mindwarden_enclave_planet
			}
		}
		set_country_flag = enclave_respawned
		remove_country_flag = enclave_destroyed
	}
}

#==================================
# 4500 - 4799 Patron Covenants
#==================================

# The Eater Of Worlds Covenant Proposal
# see utopia.3306
inline_script = {
	script = shroud/patron_covenant_proposition_event
	EVENT_ID = shroud.4500
	FORMED_EVENT_ID = shroud.4505
	CONFIRM_EVENT_ID = shroud.4510
	PATRON_TYPE = the_eater_of_worlds
	CHAIN = "shroud_eater_covenant_chain"
}

# The Eater Of Worlds Covenant Formed
country_event = {
	id = shroud.4505
	title = utopia.3310.name
	picture = GFX_evt_shroud_eater_of_worlds
	show_sound = event_the_eater_of_worlds
	is_triggered_only = yes

	desc = {
		trigger = {
			if = {
				limit = {
					is_machine_empire = yes
				}
				text = shroud.4505.desc.gestalt_machine
			}
			else_if = {
				limit = {
					is_robot_empire = yes
				}
				text = shroud.4505.desc.individual_machine
			}
			else_if = {
				limit = {
					is_hive_empire = yes
				}
				text = shroud.4505.desc.hive
			}
			else = {
				text = shroud.4505.desc.default
			}
		}
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	option = {
		name = shroud.4505.a.default
		trigger = {
			is_gestalt = no
		}
		random_owned_planet = {
			random_owned_pop_group = {
				limit = {
					pop_group_size >= 100
				}
				sacrifice_single_pop = yes
			}
		}
	}
	option = {
		name = shroud.4505.a.gestalt
		trigger = {
			hidden_trigger = {
				is_gestalt = yes
			}
		}
		random_owned_planet = {
			random_owned_pop_group = {
				limit = {
					pop_group_size >= 100
				}
				sacrifice_single_pop = yes
			}
		}
	}
}

# The Eater Of Worlds Covenant Confirmation
inline_script = {
	script = shroud/patron_covenant_confirmation_event
	EVENT_ID = shroud.4510
	PATRON_TYPE = the_eater_of_worlds
	MARK_TECH = tech_covenant_eater
	TECH_PATRON = eater
	CHAIN = "shroud_eater_covenant_chain"
}

# The Instrument Of Desire Covenant Proposal
# see utopia.3307
inline_script = {
	script = shroud/patron_covenant_proposition_event
	EVENT_ID = shroud.4550
	FORMED_EVENT_ID = shroud.4555
	CONFIRM_EVENT_ID = shroud.4560
	PATRON_TYPE = the_instrument_of_desire
	CHAIN = "shroud_instrument_covenant_chain"
}

# The Instrument Of Desire Covenant Formed
inline_script = {
	script = shroud/patron_covenant_formed_event
	EVENT_ID = shroud.4555
	PICTURE = GFX_evt_shroud_instrument_of_desire
	SOUND = event_the_instrument_of_desire
}

# The Instrument Of Desire Covenant Confirmation
inline_script = {
	script = shroud/patron_covenant_confirmation_event
	EVENT_ID = shroud.4560
	PATRON_TYPE = the_instrument_of_desire
	MARK_TECH = tech_covenant_instrument
	TECH_PATRON = instrument
	CHAIN = "shroud_instrument_covenant_chain"
}

# The Cradle Of Souls Covenant Proposal
inline_script = {
	script = shroud/patron_covenant_proposition_event
	EVENT_ID = shroud.4600
	FORMED_EVENT_ID = shroud.4605
	CONFIRM_EVENT_ID = shroud.4610
	PATRON_TYPE = the_cradle_of_souls
	CHAIN = "shroud_cradle_covenant_chain"
}

# The Cradle Of Souls Covenant Formed
inline_script = {
	script = shroud/patron_covenant_formed_event
	EVENT_ID = shroud.4605
	PICTURE = GFX_evt_shroud_cradle_of_souls
	SOUND = event_the_cradle_of_souls
}

# The Cradle Of Souls Covenant Confirmation
inline_script = {
	script = shroud/patron_covenant_confirmation_event
	EVENT_ID = shroud.4610
	PATRON_TYPE = the_cradle_of_souls
	MARK_TECH = tech_covenant_cradle
	TECH_PATRON = cradle
	CHAIN = "shroud_cradle_covenant_chain"
}

# The Composer Of Strands Covenant Proposal
# see utopia.3305
inline_script = {
	script = shroud/patron_covenant_proposition_event
	EVENT_ID = shroud.4650
	FORMED_EVENT_ID = shroud.4655
	CONFIRM_EVENT_ID = shroud.4660
	PATRON_TYPE = the_composer_of_strands
	CHAIN = "shroud_composer_covenant_chain"
}

# The Composer Of Strands Covenant Formed
inline_script = {
	script = shroud/patron_covenant_formed_event
	EVENT_ID = shroud.4655
	PICTURE = GFX_evt_shroud_composer_of_strands
	SOUND = event_the_composer_of_strands
}

# The Composer Of Strands Covenant Confirmation
inline_script = {
	script = shroud/patron_covenant_confirmation_event
	EVENT_ID = shroud.4660
	PATRON_TYPE = the_composer_of_strands
	MARK_TECH = tech_covenant_composer
	TECH_PATRON = composer
	CHAIN = "shroud_composer_covenant_chain"
}

# The Whisperers in the Void Covenant Proposal
# see utopia.3304
country_event = {
	id = shroud.4700
	diplomatic_title = shroud.3.diplo_title
	title = shroud.4700.title
	desc = shroud.4700.desc
	picture = GFX_evt_shroud_whisperers_in_the_void
	is_triggered_only = yes

	show_sound = event_whisperers_in_the_void

	is_triggered_only = yes
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	option = {
		name = shroud.4700.a
		custom_tooltip = covenant.tooltip
		custom_tooltip = shroud_whisperers_covenant_chain_begin
		accept_covenant = whisperers_in_the_void

		hidden_effect = {
			if = {
				limit = { is_robot_empire = yes }
				begin_event_chain = {
					event_chain = robot_shroud_whisperers_covenant_chain
					target = this
				}
			}
			else = {
				begin_event_chain = {
					event_chain = shroud_whisperers_covenant_chain
					target = this
				}
			}
			set_country_flag = has_shroud_patron
			country_event = { id = shroud.4705 } # utopia.3310
			country_event = { id = shroud.4710 days = @covenant_confirmation_time_days } # utopia.2658
		}

		if = {
			limit = { is_chosen_empire = yes }
			custom_tooltip = WILL_LOSE_CHOSEN_CIVIC
			hidden_effect = {
				force_remove_chosen_civic = yes
			}
		}
	}
	option = {
		name = shroud.reject_covenant
		custom_tooltip = shroud.reject_covenant.tt
		default_hide_option = yes
		hidden_effect = {
			refuse_covenant = {
				patron = whisperers_in_the_void
				reset_attunement = yes
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
	}
	option = {
		trigger = {
			NOT = { has_country_flag = has_ever_established_covenant }
		}
		allow = {
			NOT = { is_chosen_empire = yes }
		}
		name = shroud.forge_our_own_path
		shroud_forge_your_own_path = yes
	}
}

# The Whisperers in the Void Covenant Formed
inline_script = {
	script = shroud/patron_covenant_formed_event
	EVENT_ID = shroud.4705
	PICTURE = GFX_evt_shroud_whisperers_in_the_void
	SOUND = event_whisperers_in_the_void
}

# The Whisperers in the Void Covenant Confirmation
inline_script = {
	script = shroud/patron_covenant_confirmation_event
	EVENT_ID = shroud.4710
	PATRON_TYPE = whisperers_in_the_void
	MARK_TECH = tech_covenant_whisperers
	TECH_PATRON = whisperers
	CHAIN = "shroud_whisperers_covenant_chain"
}

# The End of the Cycle Covenant Formed
country_event = {
	id = shroud.4715
	title = utopia.3310.name
	picture = GFX_evt_shroud_end_of_the_cycle
	is_triggered_only = yes

	desc = {
		trigger = {
			if = {
				limit = {
					is_machine_empire = yes
				}
				text = shroud.4715.desc.gestalt_machine
			}
			else_if = {
				limit = {
					is_robot_empire = yes
				}
				text = shroud.4715.desc.individual_machine
			}
			else_if = {
				limit = {
					is_hive_empire = yes
				}
				text = shroud.4715.desc.hive
			}
			else = {
				text = shroud.4715.desc.default
			}
		}
	}

	show_sound = event_end_of_the_cycle

	option = {
		name = shroud.4715.a.default
		trigger = {
			is_gestalt = no
			is_spiritualist = no
		}
	}
	option = {
		name = covenant.cycle.option
		trigger = {
			is_gestalt = no
			is_spiritualist = yes
		}
	}
	option = {
		name = shroud.4715.a.gestalt
		trigger = {
			hidden_trigger = {
				is_gestalt = yes
			}
		}
	}
}

#==================================
# 4800 - 4999 Patron Active Accords
#==================================

# The Eater of Worlds - Devour Accord
# country_event = {
# 	id = shroud.4800
# 	hide_window = yes
# 	is_triggered_only = yes

# 	trigger = {
# 		has_shroud_dlc = yes
# 	}

# 	immediate = {
# 		# Find country with worse relation
# 		set_variable = {
# 			which = lowest_relation_score
# 			value = 10000
# 		}
# 		every_neighbor_country = {
# 			limit = {
# 				can_declare_devour_war = yes
# 			}
# 			set_variable = {
# 				which = current_relation_score
# 				value = value:opinion_with_root
# 			}
# 			if = {
# 				limit = {
# 					check_variable = {
# 						which = current_relation_score
# 						value < prev.lowest_relation_score
# 					}
# 				}
# 				prev = {
# 					set_variable = {
# 						which = lowest_relation_score
# 						value = prev.current_relation_score
# 					}
# 				}
# 				save_event_target_as = devour_accord_target@root
# 			}
# 		}
# 		clear_variable = lowest_relation_score

# 		# Declare war
# 		if = {
# 			limit = {
# 				exists = event_target:devour_accord_target@root
# 			}
# 			set_country_flag = devour_war_active
# 			refresh_species_rights = yes
# 			declare_war = {
# 				target = event_target:devour_accord_target@root
# 				attacker_war_goal = wg_devour_total_war
# 			}
# 			event_target:devour_accord_target@root = {
# 				every_owned_species = {
# 					limit = {
# 						NOT = { is_archetype = PRESAPIENT }
# 						root.species = {
# 							NOT = { is_same_species = prevprev }
# 						}
# 					}
# 					if = {
# 						limit = { is_machine_species = yes }
# 						set_citizenship_type = {
# 							country = root
# 							type = citizenship_purge_machine
# 						}
# 					}
# 					else = {
# 						set_citizenship_type = {
# 							country = root
# 							type = citizenship_purge
# 						}
# 					}
# 					set_purge_type = {
# 						type = purge_sacrifice
# 						country = prev
# 					}
# 				}
# 			}
# 		}
# 	}
# }

# # Destroy Eater Fleet
# fleet_event = {
# 	id = shroud.4801
# 	hide_window = yes
# 	is_triggered_only = yes

# 	immediate = {
# 		delete_fleet = this
# 	}
# }

country_event = {
	id = shroud.4802
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_owned_fleet = {
			limit = {
				has_fleet_flag = eater_fleet
			}
			delete_fleet = this
		}
	}
}

# The Eater of Worlds - Digest Accord
country_event = {
	id = shroud.4810
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = { # Modifiers are handled in auras
			flag = digest_accord_active
			years = @accord_duration
		}
		every_system_with_aura = {
			if = {
				limit = {
					exists = owner
					owner = { is_at_war_with = root }
				}
				every_system_planet_colony = {
					add_planet_devastation = @accord_digest_devastation
				}
				every_system_ship_colony = {
					add_planet_devastation = @accord_digest_devastation
				}
				if = {
					limit = {
						owner = {
							is_country_type = default
							NOT = { has_country_flag = recently_got_digest_notification }
						}
					}
					owner = {
						set_timed_country_flag = {
							flag = recently_got_digest_notification
							days = @toast_message_days
						}
						country_event = {
							id = shroud.4811
							scopes = { from = root }
						}
					}
				}
			}
			every_system_ship_colony = {
				limit = {
					exists = owner
					owner = {
						is_at_war_with = root
						is_country_type = default
						is_nomadic = yes
					}
				}
				add_planet_devastation = @accord_digest_devastation
				if = {
					limit = {
						owner = { NOT = { has_country_flag = recently_got_digest_notification } }
					}
					owner = {
						set_timed_country_flag = {
							flag = recently_got_digest_notification
							days = @toast_message_days
						}
						country_event = {
							id = shroud.4812
							scopes = { from = root }
						}
					}
				}
			}
			add_aura_intensity = @accord_aura_intensity_loss
		}
	}
}

# this = victim country
# from = aura owner
# fromfrom = planet
country_event = {
	id = shroud.4811
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = aura_affected_fleets
			value = 0
		}
		every_owned_fleet = {
			limit = {
				is_ship_class = shipclass_military
				exists = solar_system
				solar_system = {
					has_psionic_aura = yes
					aura_owner = { is_same_value = root.from }
				}
			}
			if = {
				limit = {
					NOT = { exists = event_target:target_affected_by_digest }
				}
				save_event_target_as = target_affected_by_digest
			}
			root = {
				change_variable = {
					which = aura_affected_fleets
					value = 1
				}
			}
		}
		set_variable = {
			which = aura_affected_planets
			value = 0
		}
		every_owned_planet = {
			limit = {
				planet_devastation > 0
				exists = solar_system
				solar_system = {
					has_psionic_aura = yes
					aura_owner = { is_same_value = root.from }
				}
			}
			if = {
				limit = {
					NOT = { exists = event_target:target_affected_by_digest }
				}
				save_event_target_as = target_affected_by_digest
			}
			root = {
				change_variable = {
					which = aura_affected_planets
					value = 1
				}
			}
		}
		create_message = {
			type = MESSAGE_DIGEST_EFFECT_VICTIM
			localization = MESSAGE_DIGEST_EFFECT_DESC
			days = @toast_message_days
			target = event_target:target_affected_by_digest
			variable = {
				type = name
				localization = ENEMY
				scope = from
			}
			variable = {
				type = variable
				varname = aura_affected_fleets
				localization = FLEETS
				scope = root
			}
			variable = {
				type = variable
				varname = aura_affected_planets
				localization = COLONIES
				scope = root
			}
		}
		clear_variable = aura_affected_fleets
		clear_variable = aura_affected_planets
	}
}

# this = victim nomad country
# from = aura owner
country_event = {
	id = shroud.4812
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = aura_affected_fleets
			value = 0
		}
		every_owned_fleet = {
			limit = {
				is_ship_class = shipclass_military
				exists = solar_system
				solar_system = {
					has_psionic_aura = yes
					aura_owner = { is_same_value = root.from }
				}
			}
			if = {
				limit = {
					NOT = { exists = event_target:target_affected_by_digest }
				}
				save_event_target_as = target_affected_by_digest
			}
			root = {
				change_variable = {
					which = aura_affected_fleets
					value = 1
				}
			}
		}
		set_variable = {
			which = aura_affected_planets
			value = 0
		}
		every_owned_fleet = {
			limit = {
				is_arkship_fleet = yes
				exists = solar_system
				solar_system = {
					has_psionic_aura = yes
					aura_owner = { is_same_value = root.from }
				}
			}
			solar_system = {
				every_system_ship_colony = {
					limit = {
						planet_devastation > 0
						owner = { is_same_value = root }
					}
					if = {
						limit = {
							NOT = { exists = event_target:target_affected_by_digest }
						}
						save_event_target_as = target_affected_by_digest
					}
					root = {
						change_variable = {
							which = aura_affected_planets
							value = 1
						}
					}
				}
			}
		}
		create_message = {
			type = MESSAGE_DIGEST_EFFECT_VICTIM
			localization = MESSAGE_DIGEST_EFFECT_DESC
			days = @toast_message_days
			target = event_target:target_affected_by_digest
			variable = {
				type = name
				localization = ENEMY
				scope = from
			}
			variable = {
				type = variable
				varname = aura_affected_fleets
				localization = FLEETS
				scope = root
			}
			variable = {
				type = variable
				varname = aura_affected_planets
				localization = COLONIES
				scope = root
			}
		}
		clear_variable = aura_affected_fleets
		clear_variable = aura_affected_planets
	}
}

# The Cradle of Souls - Thoughtbond Accord
country_event = {
	id = shroud.4820
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_gestalt = yes }
			add_modifier = {
				modifier = thoughtbond_accord_gestalt
				years = @accord_duration
			}
		}
		else = {
			add_modifier = {
				modifier = thoughtbond_accord
				years = @accord_duration
			}
		}
	}
}

# The Cradle of Souls - Favor Accord
country_event = {
	id = shroud.4830
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_system_with_aura = {
			limit = {
				aura_owner = {
					is_same_value = root
				}
				has_owner = yes
				owner = {
					NOT = { is_same_value = root }
				}
				root = {
					num_favors = {
						target = prev.owner
						value > 0
					}
				}
			}
			root = {
				add_monthly_resource_mult = {
					resource = unity
					value = @tier1unityreward
					min = @tier1unitymin
					max = @tier1unitymax
					mult = value:get_favor_accord_num_favors
				}
				add_monthly_resource_mult = {
					resource = influence
					value = @tier1influencereward
					min = @tier1influencemin
					max = @tier1influencemax
					mult = value:get_favor_accord_num_favors
				}
				remove_favors = {
					target = prev.owner
					value = value:get_favor_accord_num_favors
				}
			}
			add_aura_intensity = @accord_aura_intensity_loss
		}
	}
}

country_event = {
	id = shroud.4835
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { NOT = { has_technology = tech_federation_code } }
			if = {
				limit = { can_research_technology = tech_federation_code }
				give_technology = { tech = tech_federation_code }
			}
			else = {
				country_event = { id = shroud.4835 days = 30 }
			}
		}
	}
}

# Instrument of Desire - Ascension Accord
country_event = {
	id = shroud.4840
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = free_planetary_ascension
	}
}

# Stop free Planetary Ascension (Ascension Accord)
carrier_event = {
	id = shroud.4845
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		owner = {
			has_country_flag = free_planetary_ascension
		}
	}

	immediate = {
		owner = {
			remove_country_flag = free_planetary_ascension
		}
	}
}

# Instrument of Desire - Exploitation Accord
country_event = {
	id = shroud.4850
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_gestalt = yes }
			add_modifier = {
				modifier = exploitation_accord_gestalt
				years = @accord_duration
			}
		}
		else = {
			add_modifier = {
				modifier = exploitation_accord
				years = @accord_duration
			}
		}
		every_system_with_aura = {
			add_aura_intensity = @accord_aura_intensity_loss
		}
	}
}

# Composer of Strands - Transformation Accord
country_event = {
	id = shroud.4860
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_nomadic = no }
			random_planet_within_border = {
				limit = {
					is_colony = no
					uninhabitable_regular_planet = yes
				}
				root = {
					country_event = {
						id = shroud.4862
						scopes = {
							from = prev
						}
					}
				}
			}
		}
		else = {
			random_owned_colony = {
				limit = {
					is_planet_class = pc_ark
					NOT = {
						has_modifier = transformation_arkship_modifier
					}
				}
				root = {
					country_event = {
						id = shroud.4862
						scopes = {
							from = prev
						}
					}
				}
			}
		}
	}
}

# Turn planet into Gaia (Transformation Covenant)
# From = planet
country_event = {
	id = shroud.4862
	title = shroud.4862.title
	desc = {
		trigger = { is_nomadic = no }
		text = shroud.4862.desc
	}
	desc = {
		trigger = { is_nomadic = yes }
		text = shroud.4862.desc.nomad
	}
	picture = GFX_evt_shroud_composer_of_strands
	show_sound = event_the_composer_of_strands
	location = from
	is_triggered_only = yes

	immediate = {
		from = {
			if = {
				limit = { is_planet_class = pc_ark }
				add_modifier = { modifier = transformation_arkship_modifier }
			}
			else = {
				change_pc = pc_gaia
				set_planet_size = @accord_transformation_gaia_world_size
				reroll_planet = yes
			}
		}
	}

	option = {
		trigger = { is_nomadic = no }
		name = shroud.4862.a
		custom_tooltip = shroud.4862.a.tooltip
	}

	option = {
		trigger = { is_nomadic = yes }
		name = shroud.4862.a
		custom_tooltip = shroud.4862.a.tooltip.nomad
	}
}

# Composer of Strands - Generation Accord
country_event = {
	id = shroud.4870
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_system_with_aura = {
			every_system_planet_colony = {
				limit = {
					has_owner = yes
					is_owned_by = root
				}
				create_pop_group = {
					size = @accord_generation_pop_gain
					species = owner.owner_main_species
				}
			}
			every_system_ship_colony = {
				limit = {
					has_owner = yes
					is_owned_by = root
				}
				create_pop_group = {
					size = @accord_generation_pop_gain
					species = owner.owner_main_species
				}
			}
			add_aura_intensity = @accord_aura_intensity_loss
		}
	}
}

# Whisperers in the Void - Foresight Accord
country_event = {
	id = shroud.4880
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		progress_all_researches = @foresight_tech_progression
	}
}

# Whisperers in the Void - Hindsight Accord
country_event = {
	id = shroud.4890
	title = shroud.4890.title
	desc = {
		trigger = { is_nomadic = no }
		text = shroud.4890.desc
	}
	desc = {
		trigger = { is_nomadic = yes }
		text = shroud.4890.desc.nomad
	}
	picture = GFX_evt_shroud_whisperers_in_the_void
	show_sound = event_whisperers_in_the_void

	is_triggered_only = yes

	immediate = {
		random_owned_colony = {
			limit = {
				can_be_chosen_for_hindsight_any = yes
			}
			save_event_target_as = hindsight_planet_candidate_1
		}
		ordered_owned_colony = {
			limit = {
				can_be_chosen_for_hindsight_any = yes
				NOT = { is_same_value = event_target:hindsight_planet_candidate_1 }
			}
			save_event_target_as = hindsight_planet_candidate_2
		}
		ordered_owned_colony = {
			limit = {
				can_be_chosen_for_hindsight_any = yes
				NOR = {
					is_same_value = event_target:hindsight_planet_candidate_1
					is_same_value = event_target:hindsight_planet_candidate_2
				}
			}
			save_event_target_as = hindsight_planet_candidate_3
		}
		ordered_owned_colony = {
			limit = {
				can_be_chosen_for_hindsight_any = yes
				NOR = {
					is_same_value = event_target:hindsight_planet_candidate_1
					is_same_value = event_target:hindsight_planet_candidate_2
					is_same_value = event_target:hindsight_planet_candidate_3
				}
			}
			save_event_target_as = hindsight_planet_candidate_4
		}
	}

	option = {
		trigger = {
			exists = event_target:hindsight_planet_candidate_1
		}
		name = {
			trigger = {
				if = {
					limit = {
						is_nomadic = yes
					}
					text = shroud.4890.a.nomad
				}
				else = {
					text = shroud.4890.a
				}
			}
		}
		event_target:hindsight_planet_candidate_1 = {
			save_event_target_as = selected_hindsight_planet
		}
		ai_chance = {
			modifier = {
				factor = 2
				event_target:hindsight_planet_candidate_1 = {
					count_owned_pop_amount = { count <= 5000 }
				}
			}
			modifier = {
				factor = 5
				event_target:hindsight_planet_candidate_1 = {
					count_owned_pop_amount = { count <= 2000 }
				}
			}
			modifier = {
				factor = 10
				event_target:hindsight_planet_candidate_1 = {
					count_owned_pop_amount = { count <= 1000 }
				}
			}
		}
	}

	option = {
		trigger = {
			exists = event_target:hindsight_planet_candidate_2
		}
		name = {
			trigger = {
				if = {
					limit = {
						is_nomadic = yes
					}
					text = shroud.4890.b.nomad
				}
				else = {
					text = shroud.4890.b
				}
			}
		}
		event_target:hindsight_planet_candidate_2 = {
			save_event_target_as = selected_hindsight_planet
		}
		ai_chance = {
			modifier = {
				factor = 2
				event_target:hindsight_planet_candidate_2 = {
					count_owned_pop_amount = { count <= 5000 }
				}
			}
			modifier = {
				factor = 5
				event_target:hindsight_planet_candidate_2 = {
					count_owned_pop_amount = { count <= 2000 }
				}
			}
			modifier = {
				factor = 10
				event_target:hindsight_planet_candidate_2 = {
					count_owned_pop_amount = { count <= 1000 }
				}
			}
		}
	}

	option = {
		trigger = {
			exists = event_target:hindsight_planet_candidate_3
		}
		name = {
			trigger = {
				if = {
					limit = {
						is_nomadic = yes
					}
					text = shroud.4890.c.nomad
				}
				else = {
					text = shroud.4890.c
				}
			}
		}
		event_target:hindsight_planet_candidate_3 = {
			save_event_target_as = selected_hindsight_planet
		}
		ai_chance = {
			modifier = {
				factor = 2
				event_target:hindsight_planet_candidate_3 = {
					count_owned_pop_amount = { count <= 5000 }
				}
			}
			modifier = {
				factor = 5
				event_target:hindsight_planet_candidate_3 = {
					count_owned_pop_amount = { count <= 2000 }
				}
			}
			modifier = {
				factor = 10
				event_target:hindsight_planet_candidate_3 = {
					count_owned_pop_amount = { count <= 1000 }
				}
			}
		}
	}

	option = {
		trigger = {
			exists = event_target:hindsight_planet_candidate_4
		}
		name = {
			trigger = {
				if = {
					limit = {
						is_nomadic = yes
					}
					text = shroud.4890.d.nomad
				}
				else = {
					text = shroud.4890.d
				}
			}
		}
		event_target:hindsight_planet_candidate_4 = {
			save_event_target_as = selected_hindsight_planet
		}
		ai_chance = {
			modifier = {
				factor = 2
				event_target:hindsight_planet_candidate_4 = {
					count_owned_pop_amount = { count <= 5000 }
				}
			}
			modifier = {
				factor = 5
				event_target:hindsight_planet_candidate_4 = {
					count_owned_pop_amount = { count <= 2000 }
				}
			}
			modifier = {
				factor = 10
				event_target:hindsight_planet_candidate_4 = {
					count_owned_pop_amount = { count <= 1000 }
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				exists = event_target:selected_hindsight_planet
			}
			if = {
				limit = {
					is_nomadic = yes
				}
				custom_tooltip = shroud.4890.tt.nomad
				hidden_effect = {
					event_target:selected_hindsight_planet = {
						add_deposit = d_relic_arkship
					}
				}
			}
			else = {
				custom_tooltip = shroud.4890.tt
				hidden_effect = {
					event_target:selected_hindsight_planet = {
						change_pc = pc_relic
						relic_world_deposits = yes
						clear_blockers = yes
					}
				}
			}
			hidden_effect = {
				every_system_with_aura = {
					add_aura_intensity = @accord_aura_intensity_loss
				}
			}
		}
	}
}

# End of the Cycle - Annihilation Accord
country_event = {
	id = shroud.4910
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = annihilation_activated
		add_resource = { energy = @[ -annihilation_cost ] }
		add_resource = { minerals = @[ -annihilation_cost ] }
		add_resource = { food = @[ -annihilation_cost ] }
		add_resource = { alloys = @[ -annihilation_cost ] }
		every_situation = {
			limit = { is_situation_type = end_of_the_cycle_endbringers }
			add_situation_progress = -60
			update_eotc_accords = yes
		}
	}
}

# End of the Cycle - Extermination Accord
country_event = {
	id = shroud.4915
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = extermination_activated
		while = {
			count = @extermination_pop_group_loss
			random_owned_pop_group = {
				limit = {
					pop_group_size >= 100
				}
				kill_single_pop = yes
			}
		}
		every_situation = {
			limit = { is_situation_type = end_of_the_cycle_endbringers }
			add_situation_progress = -120
			update_eotc_accords = yes
		}
	}
}

# End of the Cycle - Destruction Accord
country_event = {
	id = shroud.4920
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = destruction_activated
		random_owned_planet = {
			limit = {
				pop_amount >= @destruction_planet_pop_min
				is_capital = no
			}
			save_event_target_as = destroyed_colony
			prev = {
				set_variable = {
					which = destroyed_colony_pop
					value = event_target:destroyed_colony.trigger:pop_amount
				}
			}
			destroy_colony = yes
			change_pc = pc_shrouded
			clear_deposits = yes
			clear_planet_modifiers = yes
		}
		every_situation = {
			limit = { is_situation_type = end_of_the_cycle_endbringers }
			add_situation_progress = -180
			update_eotc_accords = yes
		}
		if = {
			limit = { exists = event_target:destroyed_colony }
			create_message = {
				type = ACCORD_DESTRUCTION_MESSAGE_TYPE
				localization = ACCORD_DESTRUCTION_MESSAGE_DESC
				days = 30
				target = event_target:destroyed_colony
				variable = {
					type = name
					localization = SYSTEM
					scope = event_target:destroyed_colony.solar_system
				}
				variable = {
					type = name
					localization = COLONY
					scope = event_target:destroyed_colony
				}
				variable = {
					type = variable
					localization = POPS
					varname = this.destroyed_colony_pop
					scope = this
				}
			}
		}
		clear_variable = destroyed_colony_pop
	}
}

# End of the Cycle - Eradication Accord
country_event = {
	id = shroud.4925
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = eradication_activated
		every_playable_country = {
			limit = {
				NOT = {
					is_same_value = root
					is_country_type = fallen_empire
					is_at_war_with = root
				}
			}
			root = {
				declare_war = {
					target = prev
					attacker_war_goal = wg_ae_total_war
				}
			}
		}
		every_situation = {
			limit = { is_situation_type = end_of_the_cycle_endbringers }
			add_situation_progress = -240
			update_eotc_accords = yes
		}
	}
}

# End of the Cycle - Fractalization Accord
country_event = {
	id = shroud.4930
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { is_variable_set = fractalization_accord_activation }
			}
			set_variable = {
				which = fractalization_accord_activation
				value = 1
			}
		}
		else = {
			change_variable = {
				which = fractalization_accord_activation
				value = 1
			}
		}
	}
}

# End of the Cycle - Creation Accord
country_event = {
	id = shroud.4935
	title = shroud.4935.title
	desc = {
		trigger = { is_nomadic = no }
		text = shroud.4935.desc
	}
	desc = {
		trigger = { is_nomadic = yes }
		text = shroud.4935.desc.nomad
	}
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle
	location = event_target:accord_creation_world

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_nomadic = no }
			capital_scope.solar_system = {
				spawn_planet = {
					generate_random_name = yes
					check_overlap = yes
					class = pc_gaia
					location = none
					orbit_distance = { min = 60 max = 260 }
					orbit_angle = { min = 0 max = 360 }
					size = 20
					init_effect = {
						clear_planet_modifiers = yes
						save_event_target_as = accord_creation_world
						create_colony = {
							owner = root
						}
						set_controller = root
						prevent_anomaly = yes
						clear_blockers = yes
						reroll_planet = yes
						create_pop_group = {
							size = 1000
							species = owner_main_species
						}
						set_colony_type = col_city
					}
				}
			}
		}
		else = {
			# Existing Arkships are flagged so the newly created one can be identified below.
			capital_scope.solar_system = {
				save_event_target_as = accord_creation_system
				random_system_planet = {
					save_event_target_as = accord_creation_location
				}
			}
			every_owned_planet = {
				limit = { is_planet_class = pc_ark }
				set_carrier_flag = pre_creation_arkship
			}
			random_list = {
				10 = {
					modifier = {
						factor = 0
						NOT = {
							has_technology = tech_civilian_arkship
						}
					}
					create_arkship_effect = {
						TYPE = civilian_arkship
						OWNER = root
						LOCATION = event_target:accord_creation_location
					}
				}
				10 = {
					modifier = {
						factor = 0
						NOT = {
							has_technology = tech_science_arkship
						}
					}
					create_arkship_effect = {
						TYPE = science_arkship
						OWNER = root
						LOCATION = event_target:accord_creation_location
					}
				}
				10 = {
					modifier = {
						factor = 0
						NOT = {
							has_technology = tech_military_arkship
						}
					}
					create_arkship_effect = {
						TYPE = military_arkship
						OWNER = root
						LOCATION = event_target:accord_creation_location
					}
				}
			}
			random_owned_planet = {
				limit = {
					is_planet_class = pc_ark
					NOT = { has_carrier_flag = pre_creation_arkship }
				}
				save_event_target_as = accord_creation_world
			}
			every_owned_planet = {
				limit = { has_carrier_flag = pre_creation_arkship }
				remove_carrier_flag = pre_creation_arkship
			}
		}
	}

	option = {
		trigger = { is_nomadic = no }
		name = OK
		custom_tooltip = shroud.4935.tooltip
	}

	option = {
		trigger = { is_nomadic = yes }
		name = OK
		custom_tooltip = shroud.4935.tooltip.nomad
	}
}

# End of the Cycle - Distortion Accord
country_event = {
	id = shroud.4940
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = {
			flag = disable_jump_drive_cooldown_malus
			years = @distortion_accord_duration
		}
		add_modifier = {
			modifier = distortion_accord
			years = @distortion_accord_duration
		}
	}
}

# End of the Cycle - Intensification Accord
country_event = {
	id = shroud.4945
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_timed_global_flag = {
			flag = shroud_seals_disabled
			years = @intensification_accord_duration
		}
		set_saved_date = {
			key = shroud_seals_disabled_timer
			days_from_present = @[ intensification_accord_duration * 360 ]
			expires = @[ intensification_accord_duration * 360 ]
		}
		add_modifier = {
			modifier = intensification_accord
			years = @intensification_accord_duration
		}
	}
}

# End of the Cycle - Unlock Endbringers accords
situation_event = {
	id = shroud.4946
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		update_eotc_accords = yes
	}
}

# Encountered the EotC Aura
# from = aura system
# fromfrom = aura owner
country_event = {
	id = shroud.4950
	title = shroud.4950.title
	desc = {
		trigger = {
			if = {
				limit = {
					has_country_flag = end_aura_encounter_1
				}
				if = {
					limit = { has_communications = fromfrom }
					text = shroud.4191.desc_1.contact
				}
				else = {
					text = shroud.4191.desc_1.default
				}
				text = newline
				if = {
					limit = { has_country_flag = power_of_will }
					text = shroud.4191.desc_2.knows_aura
				}
				else = {
					text = shroud.4191.desc_2.default
				}
				text = newline
				text = shroud.4950.desc.1
			}
			else_if = {
				limit = {
					has_country_flag = end_aura_encounter_2
				}
				if = {
					limit = { has_communications = fromfrom }
					text = shroud.4950.desc.3.contact
				}
				else = {
					text = shroud.4950.desc.3.default
				}
				text = newline
				text = shroud.4950.desc.1
			}
			else_if = {
				limit = {
					has_country_flag = end_aura_encounter_3
				}
				text = shroud.4950.desc.4
				text = newline
				text = shroud.4950.desc.1
				if = {
					limit = {
						exists = event_target:mindwarden_enclave_country
						has_communications = event_target:mindwarden_enclave_country
					}
					text = newline
					text = shroud.4190.desc_mindwarden
				}
			}
			else_if = {
				limit = {
					has_country_flag = end_aura_encounter_4
				}
				if = {
					limit = { has_communications = fromfrom }
					text = shroud.4950.desc.5.contact
				}
				else = {
					text = shroud.4950.desc.5.default
				}
				text = newline
				text = shroud.4950.desc.1
				if = {
					limit = { has_communications = event_target:mindwarden_enclave_country }
					text = newline
					text = shroud.4190.desc_mindwarden
				}
			}
		}
	}
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle
	is_triggered_only = yes

	immediate = {
		set_country_flag = end_aura_encountered
		if = {
			limit = {
				is_psionic = yes
				has_encountered_psionic_auras = no
			}
			set_country_flag = end_aura_encounter_1
		}
		else_if = {
			limit = {
				is_psionic = yes
				has_encountered_psionic_auras = yes
			}
			set_country_flag = end_aura_encounter_2
		}
		else_if = {
			limit = {
				is_psionic = no
				has_encountered_psionic_auras = no
			}
			set_country_flag = end_aura_encounter_3
		}
		else_if = {
			limit = {
				is_psionic = no
				has_encountered_psionic_auras = yes
			}
			set_country_flag = end_aura_encounter_4
		}
	}

	option = {
		name = shroud.4950.a
	}

	after = {
		remove_country_flag = end_aura_encounter_1
		remove_country_flag = end_aura_encounter_2
		remove_country_flag = end_aura_encounter_3
		remove_country_flag = end_aura_encounter_4
	}
}

situation_event = {
	id = shroud.4954
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		situation_progress >= 590
		NOT = { has_situation_flag = impending_reckoning_sent }
	}

	immediate = {
		set_situation_flag = impending_reckoning_sent
		every_playable_country = {
			country_event = {
				id = shroud.4955
				scopes = {
					from = root.owner
				}
			}
		}
	}
}

country_event = {
	id = shroud.4955
	title = shroud.4955.title
	desc = {
		trigger = {
			if = {
				limit = {
					is_psionic = yes
					is_gestalt = yes
				}
				text = shroud.4955.desc.1.gestalt
			}
			else_if = {
				limit = {
					is_psionic = yes
					is_gestalt = no
				}
				text = shroud.4955.desc.1.non_gestalt
			}
			else = {
				text = shroud.4955.desc.1
			}
			text = newline
			if = {
				limit = {
					has_communications = from
					has_country_flag = has_encountered_end_aura
				}
				text = shroud.4955.desc.2.contact_aura
			}
			else_if = {
				limit = {
					has_communications = from
					NOT = { has_country_flag = has_encountered_end_aura }
				}
				text = shroud.4955.desc.2.contact_no_aura
			}
			else_if = {
				limit = {
					NOT = { has_communications = from }
					has_country_flag = has_encountered_end_aura
				}
				text = shroud.4955.desc.2.no_contact_aura
			}
			else_if = {
				limit = {
					NOR = {
						has_communications = from
						has_country_flag = has_encountered_end_aura
					}
				}
				text = shroud.4955.desc.2.no_contact_no_aura
			}
			text = newline
			text = shroud.4955.desc.3
		}
	}
	picture = GFX_evt_surreal_visions
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	option = {
		name = shroud.4955.a
		custom_tooltip = shroud.4955.a.tt
	}
}

country_event = {
	id = shroud.4960
	title = shroud.4960.title
	desc = {
		trigger = {
			if = {
				limit = {
					has_communications = from
				}
				text = shroud.4960.desc.1.contact
			}
			else = {
				text = shroud.4960.desc.1.no_contact
			}
			text = newline
			text = shroud.4960.desc.2
		}
	}
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes

	immediate = {
		set_country_flag = can_declare_total_war_to_eotc
	}

	option = {
		name = shroud.4960.a
		custom_tooltip = shroud.4960.a.tt
	}
}

country_event = {
	id = shroud.4965
	title = shroud.4965.title
	desc = {
		trigger = {
			if = {
				limit = {
					has_communications = from
				}
				text = shroud.4965.desc.1.contact
			}
			else = {
				text = shroud.4965.desc.1.no_contact
			}
			text = newline
			text = shroud.4965.desc.2
		}
	}
	picture = GFX_evt_shroud_psionic_aura
	show_sound = event_psionic_aura
	is_triggered_only = yes

	option = {
		name = shroud.4965.a
		custom_tooltip = shroud.4955.a.tt
	}
}

# EotC aura win condition
country_event = {
	id = shroud.4970
	title = shroud.4970.title
	desc = shroud.4970.desc
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = eotc_wincon_triggered }
	}

	immediate = {
		set_country_flag = eotc_wincon_triggered
		add_victory_score = {
			source = destroyed_galaxy_score
			score = 500000
		}
		hidden_effect = {
			country_event = { id = timeline.34 } # Milestone Destroyed Galaxy
		}
		country_event = { id = shroud.4972 days = 1 } # win delay
	}

	option = {
		name = shroud.4970.a
		custom_tooltip = shroud.4970.a.tooltip
		tooltip = { win = yes }
	}
}

# Game Over
country_event = {
	id = shroud.4971
	title = shroud.4971.title
	desc = {
		trigger = {
			text = shroud.4971.desc.1
			text = newline
			if = {
				limit = {
					has_communications = from
					is_psionic = yes
				}
				text = shroud.4971.desc.2.contact_psionic
			}
			else_if = {
				limit = {
					has_communications = from
					is_psionic = no
				}
				text = shroud.4971.desc.2.contact_no_psionic
			}
			else_if = {
				limit = {
					NOT = { has_communications = from }
					is_psionic = yes
				}
				text = shroud.4971.desc.2.no_contact_psionic
			}
			else_if = {
				limit = {
					NOT = { has_communications = from }
					is_psionic = no
				}
				text = shroud.4971.desc.2.no_contact_no_psionic
			}
		}
	}
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle

	is_triggered_only = yes

	option = {
		name = shroud.4971.a
		custom_tooltip = shroud.4970.a.tooltip.destroyed
	}
}

# EotC aura win
country_event = {
	id = shroud.4972
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
				is_ai = no
				NOT = { is_same_value = root }
			}
			country_event = { id = shroud.4971 }
		}
		set_update_modifiers_batch = begin
		every_system = {
			set_star_flag = destroyed_by_end_of_the_cycle
			destroy_star_system = yes
		}
		set_update_modifiers_batch = end
		every_country = {
			limit = {
				NOT = { is_country_type = default }
			}
			destroy_country = yes
		}
		win = yes
	}
}

# Proxy War cooldown
country_event = {
	id = shroud.4999
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = {
			flag = proxy_war_cooldown
			days = 30
		}
		set_saved_date = {
			key = proxy_war_cooldown_timer
			days_from_present = 30
			expires = 30
		}
	}
}

#==================================
# 5000 - 5099 Secret Societies
#==================================

# Secret Societies communication effect
country_event = {
	id = shroud.5000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	immediate = {
		closest_system = {
			min_steps = 1
			limit = {
				exists = owner
				owner = { is_candidate_for_early_contact = yes }
			}
			owner = { save_global_event_target_as = first_neighbor@root }
		}
		closest_system = {
			min_steps = 1
			limit = {
				exists = owner
				owner = {
					NOT = { is_same_value = event_target:first_neighbor@root }
					is_candidate_for_early_contact = yes
				}
			}
			owner = { save_global_event_target_as = second_neighbor@root }
		}
		if = {
			limit = { exists = event_target:first_neighbor@root }
			establish_contact = { who = event_target:first_neighbor@root }
		}
		if = {
			limit = { exists = event_target:second_neighbor@root }
			establish_contact = { who = event_target:second_neighbor@root }
		}
	}
}

# Secret Societes infiltration effect
country_event = {
	id = shroud.5010
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			is_secret_societies_empire = yes
			from = { is_secret_societies_empire = yes }
		}
	}

	immediate = {
		if = {
			limit = { is_secret_societies_empire = yes }
			country_event = {
				id = shroud.5011
				scopes = { from = root.from }
			}
		}
		from = {
			if = {
				limit = { is_secret_societies_empire = yes }
				country_event = {
					id = shroud.5011
					scopes = { from = root }
				}
			}
		}
	}
}

# root = secret societies empire
# from = FC empire
country_event = {
	id = shroud.5011
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	immediate = {
		random_spynetwork = {
			limit = {
				owner = { is_same_value = root }
				target = { is_same_value = root.from }
			}
			add_spy_network_level = @secret_society_infiltration_gain
		}
		if = {
			limit = {
				from = {
					OR = {
						AND = {
							exists = event_target:first_neighbor@root
							is_same_value = event_target:first_neighbor@root
						}
						AND = {
							exists = event_target:second_neighbor@root
							is_same_value = event_target:second_neighbor@root
						}
					}
				}
			}
			if = { # FC event when contacting one of the starting empires
				limit = {
					NOT = { has_country_flag = shroud.5013_event_triggered }
				}
				set_country_flag = shroud.5013_event_triggered
				country_event = {
					id = shroud.5013
					days = 10
				}
			}
			else_if = { # FC event when contacting both starting empires
				limit = {
					NOT = { has_country_flag = shroud.5012_event_triggered }
				}
				set_country_flag = shroud.5012_event_triggered
				country_event = {
					id = shroud.5012
					days = 10
				}
			}
		}
	}
}

# FC event when contacting both starting empires
country_event = {
	id = shroud.5012
	title = shroud.5012.title
	desc = shroud.5012.desc
	picture = GFX_evt_bribery
	show_sound = event_dig_site
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	immediate = {
		event_target:first_neighbor@root = {
			save_event_target_as = first_neighbor
		}
		event_target:second_neighbor@root = {
			save_event_target_as = second_neighbor
		}
	}

	option = {
		name = shroud.5012.a
		custom_tooltip = shroud.5012.tt
		hidden_effect = {
			roll_secret_factions = yes
		}
	}

	after = { # we don't need those anymore
		if = {
			limit = { exists = event_target:first_neighbor@root }
			clear_global_event_target = first_neighbor@root
		}
		if = {
			limit = { exists = event_target:second_neighbor@root }
			clear_global_event_target = second_neighbor@root
		}
	}
}

# FC event when contacting one of the starting empires
country_event = {
	id = shroud.5013
	title = shroud.5013.title
	desc = shroud.5013.desc
	picture = GFX_evt_bribery
	show_sound = event_dig_site
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	option = {
		name = shroud.5013.a
	}
}

# Secret Societes Control the Narrative (resolution passed)
country_event = {
	id = shroud.5015
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
		OR = {
			last_resolution_changed = resolution_council_denouncement
			last_resolution_changed = resolution_mutualdefense_castigation_denouncement
		}
		position_on_last_resolution = support
		exists = from
		from = {
			has_modifier = resolution_denounced
		}
	}

	immediate = {
		if = {
			limit = { has_country_flag = narrative_control }
			remove_country_flag = narrative_control
		}
		set_timed_country_flag = {
			flag = narrative_control
			days = 3600
		}
	}
}

# Secret Societes United in Purpose (resolution passed)
country_event = {
	id = shroud.5020
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = {
				is_secret_societies_empire = yes
				position_on_last_resolution = support
				used_favors_on_last_resolution > 0
			}
			if = {
				limit = { has_country_flag = united_in_purpose }
				remove_country_flag = united_in_purpose
			}
			set_timed_country_flag = {
				flag = united_in_purpose
				days = 3600
			}
		}
	}
}

# Secret Societes Behind the Curtain
espionage_operation_event = {
	id = shroud.5025
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		owner = {
			is_secret_societies_empire = yes
		}
	}

	immediate = {
		owner = {
			if = {
				limit = { has_country_flag = behind_the_curtain }
				remove_country_flag = behind_the_curtain
			}
			set_timed_country_flag = {
				flag = behind_the_curtain
				days = 1800
			}
		}
	}
}

# Secret Societes The Right Choice
country_event = {
	id = shroud.5030
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
		exists = ruler
		OR = {
			has_election_type = oligarchic
			ruler = {
				num_candidate_supported > 0
			}
		}
	}

	immediate = {
		set_timed_country_flag = {
			flag = right_choice_demand
			days = 3600
		}
	}
}

# Secret Societes Playing both Sides
country_event = {
	id = shroud.5035
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	immediate = {
		if = {
			limit = { has_country_flag = playing_both_sides_demand }
			remove_country_flag = playing_both_sides_demand
		}
		set_timed_country_flag = {
			flag = playing_both_sides_demand
			days = 3600
		}
	}
}

# Secret Societies proxy war bonus
# Root = instigator
# From = victim
country_event = {
	id = shroud.5040
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_secret_societies_empire = yes
	}

	immediate = {
		if = {
			limit = { has_modifier = secret_societies_proxy_war_bonus }
			remove_modifier = secret_societies_proxy_war_bonus
		}
		export_trigger_value_to_variable = {
			trigger = num_proxy_war
			variable = proxy_wars_variable
		}
		if = {
			limit = {
				check_variable = {
					which = proxy_wars_variable
					value > 0
				}
			}
			add_modifier = {
				modifier = secret_societies_proxy_war_bonus
				mult = proxy_wars_variable
				days = -1
			}
		}
	}
}

# Secret Societies proxy war bonus refresh from war ending
# Root = Loser Warleader
# From = Winner Warleader
# FromFrom = War
country_event = {
	id = shroud.5045
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfrom = {
			is_from_proxy_war = yes
			instigator = {
				is_secret_societies_empire = yes
			}
		}
	}

	immediate = {
		fromfrom.instigator = {
			country_event = { id = shroud.5040 }
		}
	}
}

# Root = Actor
# From = Recipient
# FromFrom = Main Attacker
# FromFromFrom = Main Defender
# FromFromFromFrom = War
country_event = {
	id = shroud.5046
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfromfromfrom = {
			is_from_proxy_war = yes
			instigator = {
				is_secret_societies_empire = yes
			}
		}
	}

	immediate = {
		fromfromfromfrom.instigator = {
			country_event = { id = shroud.5040 }
		}
	}
}

# Proxy War bad opinion modifier trigger
country_event = {
	id = shroud.5050
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		while = {
			count = local_num_attackers
			limit = {
				NOT = { has_country_flag = proxy_war_busted }
			}
			random = {
				chance = 10
				set_country_flag = proxy_war_busted
			}
		}
	}
}

# Root = Country
# From = War
country_event = {
	id = shroud.5051
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			is_from_proxy_war = yes
			instigator = {
				has_country_flag = proxy_war_busted
			}
		}
	}

	immediate = {
		country_event = {
			id = shroud.5054
			days = 7
			scopes = { from = from.instigator }
		}
		from.instigator = {
			if = {
				limit = {
					NOT = { has_country_flag = proxy_war_busted_check }
				}
				set_country_flag = proxy_war_busted_check
				country_event = {
					id = shroud.5059
					days = 7
				}
			}
		}
	}
}

country_event = {
	id = shroud.5054
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { has_country_flag = proxy_war_revealed_event_triggered }
			}
			set_country_flag = proxy_war_revealed_event_triggered
			country_event = {
				id = shroud.5055
				scopes = { from = from }
			}
		}
		else = {
			create_message = {
				type = PROXY_WAR_REVEALED_MESSAGE_TYPE
				localization = PROXY_WAR_REVEALED_MESSAGE_TYPE_DESC
				days = 30
				variable = {
					type = name
					localization = INSTIGATOR
					scope = from
				}
			}
		}
	}
}

country_event = {
	id = shroud.5055
	title = shroud.5055.title
	desc = {
		trigger = {
			if = {
				limit = { is_galactic_community_member = yes }
				text = shroud.5055.desc.galactic
			}
			else = {
				text = shroud.5055.desc.common
			}
		}
	}
	picture = GFX_evt_intelligence_report
	show_sound = event_encrypted_comms
	is_triggered_only = yes

	immediate = {
		add_opinion_modifier = {
			who = from
			modifier = opinion_proxy_war_busted
		}
	}

	option = {
		name = TERRIBLE
		tooltip = {
			add_opinion_modifier = {
				who = from
				modifier = opinion_proxy_war_busted
			}
		}
	}
}

country_event = {
	id = shroud.5059
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = proxy_war_busted
	}

	immediate = {
		remove_country_flag = proxy_war_busted
		if = {
			limit = {
				NOT = { has_country_flag = proxy_war_busted_event_triggered }
			}
			set_country_flag = proxy_war_busted_event_triggered
			country_event = {
				id = shroud.5060
			}
		}
		else = {
			create_message = {
				type = PROXY_WAR_BUSTED_MESSAGE_TYPE
				localization = PROXY_WAR_BUSTED_MESSAGE_TYPE_DESC
				days = 30
			}
		}
		remove_country_flag = proxy_war_busted_check
	}
}

country_event = {
	id = shroud.5060
	title = shroud.5060.title
	desc = {
		trigger = {
			if = {
				limit = { is_galactic_community_member = yes }
				text = shroud.5060.desc.galactic
			}
			else = {
				text = shroud.5060.desc.default
			}
		}
	}
	picture = GFX_evt_intelligence_report
	show_sound = event_encrypted_comms
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_galactic_community_member = yes }
			if = {
				limit = { has_modifier = proxy_war_busted_modifier }
				remove_modifier = proxy_war_busted_modifier
			}
			add_modifier = {
				modifier = proxy_war_busted_modifier
				years = 10
			}
		}
	}

	option = {
		name = UNFORTUNATE
		custom_tooltip = shroud.5060.a.tt
		if = {
			limit = { is_galactic_community_member = yes }
			tooltip = {
				add_modifier = {
					modifier = proxy_war_busted_modifier
					years = 10
				}
			}
		}
	}
}

#==================================
# 5100 - 5199 Chosen
#==================================

country_event = {
	id = shroud.5100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_chosen_empire = yes
	}

	immediate = {
		set_country_flag = can_access_shroud
		give_technology = { tech = tech_psionic_aura message = no }
		country_event = {
			id = shroud.5105
			days = 2
		}
	}
}

country_event = {
	id = shroud.5105
	title = shroud.5105.title
	desc = shroud.5105.desc
	picture = GFX_evt_shroud_generic
	is_triggered_only = yes

	trigger = {
		is_chosen_empire = yes
	}

	option = {
		name = shroud.5105.a
		hidden_effect = {
			set_country_flag = the_composer_of_strands_as_chosen_patron
		}
		set_patron_first_contact_state = { patron = the_composer_of_strands state = completed }
		add_modifier = { modifier = the_composer_of_strands_blessing }
		ai_chance = {
			base = 1
		}
	}

	option = {
		name = shroud.5105.b
		hidden_effect = {
			set_country_flag = the_eater_of_worlds_as_chosen_patron
		}
		set_patron_first_contact_state = { patron = the_eater_of_worlds state = completed }
		add_modifier = { modifier = the_eater_of_worlds_blessing }

		ai_chance = {
			base = 1
			modifier = {
				factor = 2
				is_homicidal = yes
			}
		}
	}

	option = {
		name = shroud.5105.c
		hidden_effect = {
			set_country_flag = the_cradle_of_souls_as_chosen_patron
		}
		set_patron_first_contact_state = { patron = the_cradle_of_souls state = completed }
		add_modifier = { modifier = the_cradle_of_souls_blessing }

		ai_chance = {
			base = 1
			modifier = {
				factor = 0
				is_homicidal = yes
			}
		}
	}

	option = {
		name = shroud.5105.d
		hidden_effect = {
			set_country_flag = the_instrument_of_desire_as_chosen_patron
		}
		set_patron_first_contact_state = { patron = the_instrument_of_desire state = completed }
		add_modifier = { modifier = the_instrument_of_desire_blessing }

		ai_chance = {
			base = 1
		}
	}

	after = {
		hidden_effect = {
			country_event = {
				id = shroud.5110
				days = 30
			}
		}
	}
}

country_event = {
	id = shroud.5110
	title = shroud.5110.title
	desc = {
		trigger = { is_robot_empire = yes }
		text = shroud.5110.desc_robot
	}
	desc = {
		trigger = { is_robot_empire = no }
		text = shroud.5110.desc_organic
	}
	picture = {
		trigger = {
			has_country_flag = the_eater_of_worlds_as_chosen_patron
		}
		picture = GFX_evt_shroud_eater_of_worlds
	}
	picture = {
		trigger = {
			has_country_flag = the_cradle_of_souls_as_chosen_patron
		}
		picture = GFX_evt_shroud_cradle_of_souls
	}
	picture = {
		trigger = {
			has_country_flag = the_instrument_of_desire_as_chosen_patron
		}
		picture = GFX_evt_shroud_instrument_of_desire
	}
	picture = {
		trigger = {
			has_country_flag = the_composer_of_strands_as_chosen_patron
		}
		picture = GFX_evt_shroud_composer_of_strands
	}
	is_triggered_only = yes

	trigger = {
		is_chosen_empire = yes
	}

	immediate = {
		switch = {
			trigger = has_country_flag
			the_composer_of_strands_as_chosen_patron = {
				add_attunement = { the_composer_of_strands = @chosen_patron_attunement_gift }
			}
			the_eater_of_worlds_as_chosen_patron = {
				add_attunement = { the_eater_of_worlds = @chosen_patron_attunement_gift }
			}
			the_cradle_of_souls_as_chosen_patron = {
				add_attunement = { the_cradle_of_souls = @chosen_patron_attunement_gift }
			}
			the_instrument_of_desire_as_chosen_patron = {
				add_attunement = { the_instrument_of_desire = @chosen_patron_attunement_gift }
			}
		}
	}

	option = {
		name = shroud.5110.a
		custom_tooltip = shroud.5110.a.tt
	}
}

country_event = {
	id = shroud.5115
	title = shroud.5115.title
	diplomatic_title = shroud.3.diplo_title
	show_sound = event_psionic

	is_triggered_only = yes
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	trigger = {
		is_chosen_empire = yes
		NOT = { has_country_flag = chosen_passed_first_delve }
	}

	desc = {
		trigger = { has_country_flag = the_composer_of_strands_as_chosen_patron }
		text = shroud.5115.desc.composer
	}
	desc = {
		trigger = { has_country_flag = the_eater_of_worlds_as_chosen_patron }
		text = shroud.5115.desc.eater
	}
	desc = {
		trigger = { has_country_flag = the_cradle_of_souls_as_chosen_patron }
		text = shroud.5115.desc.cradle
	}
	desc = {
		trigger = { has_country_flag = the_instrument_of_desire_as_chosen_patron }
		text = shroud.5115.desc.instrument
	}

	immediate = {
		set_country_flag = chosen_passed_first_delve
	}

	option = {
		name = shroud.5115.a
		add_monthly_resource_mult = {
			resource = unity
			value = @tier3unityreward
			min = @tier3unitymin
			max = @tier3unitymax
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier1materialreward
			min = @tier1materialmin
			max = @tier1materialmax
		}
	}
}

country_event = {
	id = shroud.5120
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_chosen_empire = yes
	}

	immediate = {
		if = {
			limit = { has_modifier = civic_chosen_unity_bonus_modifier }
			remove_modifier = civic_chosen_unity_bonus_modifier
		}
		add_modifier = {
			modifier = civic_chosen_unity_bonus_modifier
			mult = value:get_chosen_attunement_points
		}
	}
}

#==================================
# 5200-5299 Tankbound
#==================================

# Tankbound penalty has been removed as of 4.3.

# country_event = {
# 	id = shroud.5200
# 	hide_window = yes
# 	is_triggered_only = yes
#
# 	trigger = {
# 		is_tankbound_empire = yes
# 	}
#
# 	immediate = {
# 		if = {
# 			limit = { NOT = { has_technology = tech_assembly_pattern } }
# 			add_research_option = tech_assembly_pattern
# 			add_tech_progress = {
# 				tech = tech_assembly_pattern
# 				progress = 0.5
# 			}
# 		}
#
# 		if = {
# 			limit = { is_megacorp = yes }
# 			add_modifier = {
# 				modifier = tankbound_corporate_efficiency_malus
# 				days = -1
# 			}
# 		}
# 		else = {
# 			add_modifier = {
# 				modifier = tankbound_efficiency_malus
# 				days = -1
# 			}
# 		}
# 	}
# }
#
# country_event = {
# 	id = shroud.5210
# 	hide_window = yes
# 	is_triggered_only = yes
#
# 	trigger = {
# 		is_tankbound_empire = yes
# 		OR = {
# 			last_increased_tech = tech_assembly_pattern
# 			last_increased_tech = tech_construction_templates
# 		}
# 	}
#
# 	immediate = {
# 		if = {
# 			limit = { has_modifier = tankbound_efficiency_malus }
# 			remove_modifier = tankbound_efficiency_malus
# 		}
# 		if = {
# 			limit = { has_modifier = tankbound_corporate_efficiency_malus }
# 			remove_modifier = tankbound_corporate_efficiency_malus
# 		}
# 		if = {
# 			limit = {
# 				NAND = {
# 					has_technology = tech_assembly_pattern
# 					has_technology = tech_construction_templates
# 				}
# 			}
# 			if = {
# 				limit = { is_megacorp = yes }
# 				add_modifier = {
# 					modifier = tankbound_corporate_efficiency_malus
# 					days = -1
# 					mult = 0.5 # Both technologies are needed to compensate the malus
# 				}
# 			}
# 			else = {
# 				add_modifier = {
# 					modifier = tankbound_efficiency_malus
# 					days = -1
# 					mult = 0.5
# 				}
# 			}
# 		}
# 	}
# }

#==================================
# 5300-5399 Shroud-Touched Enclave
#==================================

# Shroudwalker Enclave: SotS Options
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5300
	base = enclave.405
	option_clear = yes

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Commune
	option = {
		name = shroud.5300.b
		allow = {
			custom_tooltip = {
				fail_text = shroudwalker_contact_patron_cooldown_tt
				NOT = {
					has_country_flag = shroudwalker_contact_patron_cooldown
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.5305 }
		}
	}
	# Attune
	option = {
		name = shroud.5300.c
		allow = {
			custom_tooltip = {
				fail_text = shroudwalker_attune_patron_cooldown_tt
				NOT = {
					has_country_flag = shroudwalker_attune_patron_cooldown
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.5310 }
		}
	}
	# Delving
	option = {
		name = shroud.5300.d
		allow = {
			if = {
				limit = {
					shroudwalker_can_perform_delving_ritual = yes
				}
				custom_tooltip = {
					fail_text = shroudwalker_delving_ritual_cooldown_tt
					NOT = {
						has_country_flag = shroudwalker_delving_ritual_cooldown
					}
				}
			}
			else = {
				custom_tooltip = {
					always = no
					fail_text = shroud.5315.trigger_failed
				}
			}
		}
		hidden_effect = {
			 country_event = { id = shroud.5315 }
		}
	}
	# Aura infos
	option = {
		name = shroud.5300.e
		hidden_effect = {
			country_event = { id = shroud.5320 }
		}
	}
	# Aura Boosting
	option = {
		name = shroud.5300.f
		allow = {
			has_technology = tech_aura_intensification
		}
		hidden_effect = {
			country_event = { id = shroud.5325 }
		}
	}
	# Aura Emitter
	option = {
		name = shroud.5300.g
		trigger = {
			NOR = {
				has_technology = tech_aura_resonation
				has_tech_option = tech_aura_resonation
			}
		}
		allow = {
			has_technology = tech_psionic_aura
		}
		hidden_effect = {
			country_event = { id = shroud.5330 }
		}
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroudwalker Enclave: PATRON CONTACTING
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5305
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = {
			if = {
				limit = {
					has_contacted_all_major_patrons = yes
					has_contacted_all_minor_patrons = yes
				}
				text = shroud.5305.desc_all_contacted
			}
			else = {
				text = shroud.5305.desc
			}
		}
	}

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Zro
	option = {
		name = shroud.5305.b
		inline_script = {
			script = shroud/shroud_touched_patron_contact
			RESOURCE = sr_zro
			VALUE = 100
		}
	}
	# Astral Threads
	option = {
		name = shroud.5305.c
		inline_script = {
			script = shroud/shroud_touched_patron_contact
			RESOURCE = astral_threads
			VALUE = 500
		}
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroudwalker Enclave: PATRON ATTUNING
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5310
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5310.desc

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Eater of Worlds
	option = {
		name = the_eater_of_worlds_color
		inline_script = {
			script = shroud/shroud_touched_patron_attune
			PATRON = the_eater_of_worlds
		}
	}
	# Cradle of Souls
	option = {
		name = the_cradle_of_souls_color
		inline_script = {
			script = shroud/shroud_touched_patron_attune
			PATRON = the_cradle_of_souls
		}
	}
	# Instrument of Desire
	option = {
		name = the_instrument_of_desire_color
		inline_script = {
			script = shroud/shroud_touched_patron_attune
			PATRON = the_instrument_of_desire
		}
	}
	# Composer of Strands
	option = {
		name = the_composer_of_strands_color
		inline_script = {
			script = shroud/shroud_touched_patron_attune
			PATRON = the_composer_of_strands
		}
	}
	# Whisperers in the Void
	option = {
		name = whisperers_in_the_void_color
		inline_script = {
			script = shroud/shroud_touched_patron_attune
			PATRON = whisperers_in_the_void
		}
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroudwalker Enclave: DELVING RITUAL
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5315
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5315.desc

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Zro
	option = {
		name = shroud.5315.b
		inline_script = {
			script = shroud/shroud_touched_delving_ritual
			RESOURCE = sr_zro
			VALUE = 100
		}
	}
	# Astral Threads
	option = {
		name = shroud.5315.c
		inline_script = {
			script = shroud/shroud_touched_delving_ritual
			RESOURCE = astral_threads
			VALUE = 300
		}
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.5317
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		set_country_flag = delving_ritual
		random_list = {
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_psionic_shield
						has_tech_option = tech_psionic_shield
					}
				}
				country_event = {
					id = utopia.3171
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_precognition_interface
						has_tech_option = tech_precognition_interface
					}
				}
				country_event = {
					id = utopia.3181
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_psi_jump_drive_1
						has_tech_option = tech_psi_jump_drive_1
					}
				}
				country_event = {
					id = utopia.3161
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_zro_launcher
						has_tech_option = tech_zro_launcher
					}
				}
				country_event = {
					id = shroud.3101
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_psionic_lightning
						has_tech_option = tech_psionic_lightning
					}
				}
				country_event = {
					id = shroud.3106
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_psionic_disruptor
						has_tech_option = tech_psionic_disruptor
					}
				}
				country_event = {
					id = shroud.3111
				}
			}
			1 = {
				modifier = {
					factor = 0
					OR = {
						has_technology = tech_psionic_bombers
						has_tech_option = tech_psionic_bombers
					}
				}
				country_event = {
					id = shroud.3116
				}
			}
			0 = {
				modifier = {
					add = 1
					shroudwalker_can_perform_delving_ritual = no
				}
				remove_country_flag = delving_ritual
				country_event = {
					id = shroud.5318
				}
			}
		}
	}
}

country_event = {
	id = shroud.5318
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5318.desc

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.5320
	base = shroud.5300
	desc_clear = yes
	desc = {
		trigger = {
			switch = {
				trigger = has_technology
				tech_aura_intensification = { text = shroud.5320.desc.intensified }
				tech_psionic_aura = {
					if = {
						limit = { has_patron_aura = the_eater_of_worlds }
						text = shroud.5320.desc.aura.eater
					}
					else_if = {
						limit = { has_patron_aura = the_cradle_of_souls }
						text = shroud.5320.desc.aura.cradle
					}
					else_if = {
						limit = { has_patron_aura = the_instrument_of_desire }
						text = shroud.5320.desc.aura.instrument
					}
					else_if = {
						limit = { has_patron_aura = the_composer_of_strands }
						text = shroud.5320.desc.aura.composer
					}
					else_if = {
						limit = { has_patron_aura = whisperers_in_the_void }
						text = shroud.5320.desc.aura.whisperers
					}
					else = {
						text = shroud.5320.desc.aura.outro
					}
				}
				default = { text = shroud.5320.desc.none }
			}

		}
	}
}

country_event = {
	id = shroud.5325
	base = shroud.5300
	desc_clear = yes
	desc = shroud.5325.desc
	option_clear = yes

	option = {
		name = shroud.4230.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	option = {
		name = shroud.5325.zro
		allow = {
			custom_tooltip = {
				fail_text = aura_amplification_cooldown_tt
				NOT = { has_country_flag = aura_amplification_cooldown }
			}
			resource_stockpile_compare = { resource = sr_zro value >= 300 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			sr_zro = -300
			influence = -50
		}
		add_modifier = {
			modifier = aura_amplification_modifier
			years = 10
		}
		custom_tooltip = enclave_opinion_tt
		hidden_effect = {
			country_event = { id = shroud.5326 }
		}
	}
	option = {
		name = shroud.5325.thread
		allow = {
			custom_tooltip = {
				fail_text = aura_amplification_cooldown_tt
				NOT = { has_country_flag = aura_amplification_cooldown }
			}
			resource_stockpile_compare = { resource = astral_threads value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			astral_threads = -1000
			influence = -50
		}
		add_modifier = {
			modifier = aura_amplification_modifier
			years = 10
		}
		custom_tooltip = enclave_opinion_tt
		hidden_effect = {
			country_event = { id = shroud.5326 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.5326
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		event_target:shroudwalker_enclave_country = {
			add_trust = {
				who = root
				amount = @positive_opinion
			}
		}
		set_timed_country_flag = {
			flag = aura_amplification_cooldown
			days = 3600
		}
		set_saved_date = {
			key = aura_amplification_timer
			days_from_present = 3600
			expires = 3600
		}
		country_event = {
			id = shroud.5327
			years = 10
		}
		country_event = { id = shroud.5300 }
	}
}

country_event = {
	id = shroud.5327
	title = enclave.405.name
	location = event_target:shroudwalker_enclave_system
	desc = shroud.5327.desc
	is_triggered_only = yes

	diplomatic = yes
	custom_gui = "enclave_artist_window"
	custom_gui_option = "enclave_artist_option"
	picture_event_data = {
		portrait = event_target:shroudwalker_enclave_country
		room = shroudwalkers_room
	}

	option = {
		name = shroud.5327.a.zro
		allow = {
			resource_stockpile_compare = { resource = sr_zro value >= 300 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_modifier = {
			modifier = aura_amplification_modifier
			years = 10
		}
		add_resource = {
			sr_zro = -300
			influence = -50
		}
		hidden_effect = {
			set_timed_country_flag = {
				flag = aura_amplification_cooldown
				days = 3600
			}
			set_saved_date = {
				key = aura_amplification_timer
				days_from_present = 3600
				expires = 3600
			}
		}
	}

	option = {
		name = shroud.5327.a.thread
		allow = {
			resource_stockpile_compare = { resource = astral_threads value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			astral_threads = -1000
			influence = -50
		}
		add_modifier = {
			modifier = aura_amplification_modifier
			years = 10
		}
		hidden_effect = {
			set_timed_country_flag = {
				flag = aura_amplification_cooldown
				days = 3600
			}
			set_saved_date = {
				key = aura_amplification_timer
				days_from_present = 3600
				expires = 3600
			}
		}
	}

	option = {
		name = shroud.5327.b
		default_hide_option = yes
	}
}

country_event = {
	id = shroud.5330
	base = shroud.5300
	desc_clear = yes
	desc = shroud.5330.desc
	option_clear = yes

	option = {
		name = shroud.4230.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	option = {
		name = shroud.5330.zro
		allow = {
			resource_stockpile_compare = { resource = sr_zro value >= 300 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			sr_zro = -300
			influence = -50
		}
		add_research_option = tech_aura_resonation
		hidden_effect = {
			country_event = { id = shroud.5300 }
		}
	}
	option = {
		name = shroud.5330.thread
		allow = {
			resource_stockpile_compare = { resource = astral_threads value >= 1000 }
			resource_stockpile_compare = { resource = influence value >= 50 }
		}
		add_resource = {
			astral_threads = -1000
			influence = -50
		}
		add_research_option = tech_aura_resonation
		hidden_effect = {
			country_event = { id = shroud.5300 }
		}
	}
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroudwalker Enclave: OPEN MINDS
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5350
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5350.desc

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Pay
	option = {
		name = shroud.5350.b
		allow = {
			if = {
				limit = {
					has_technology = tech_psionic_theory
				}
				custom_tooltip = {
					always = no
					fail_text = shroud.5350.trigger_failed
				}
			}
			else = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
				resource_stockpile_compare = {
					resource = influence
					value >= 50
				}
			}
		}
		add_resource = {
			energy = -1000
		}
		add_resource = {
			influence = -50
		}
		add_tech_progress = {
			tech = tech_psionic_theory
			progress = 0.25
		}
		set_country_flag = psionic_theory_help_received
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroudwalker Enclave: OPEN RIFT
# This = player country; event_target:shroudwalker_enclave_country = enclave country
country_event = {
	id = shroud.5355
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5355.desc

	# Back to menu
	option = {
		name = enclave.410.a
		hidden_effect = {
			country_event = { id = enclave.405 }
		}
	}
	# Open Rift
	option = {
		name = shroud.5355.b
		trigger = {
			is_nomadic = no
		}
		allow = {
			resource_stockpile_compare = {
				resource = astral_threads
				value >= 500
			}
			resource_stockpile_compare = {
				resource = influence
				value >= 50
			}
			custom_tooltip = {
				fail_text = "action_astral_splitting_no_rift_spawning_location_tt"
				any_system_within_border = {
					can_spawn_astral_rift = yes
				}
			}
		}
		shroud_touched_option_cost = {
			RESOURCE = astral_threads
			VALUE = 500
		}
		astral_splitting = yes
		set_country_flag = psionic_rift_help_received
	}
	option = {
		name = shroud.5355.b
		trigger = {
			is_nomadic = yes
		}
		allow = {
			resource_stockpile_compare = {
				resource = astral_threads
				value >= 500
			}
			resource_stockpile_compare = {
				resource = influence
				value >= 50
			}
			custom_tooltip = {
				fail_text = "action_astral_splitting_no_rift_spawning_location_tt"
				any_owned_nonprimary_starbase = {
					is_waystation_starbase = yes
					solar_system? = {
						can_spawn_astral_rift = yes
					}
				}
			}
		}
		shroud_touched_option_cost = {
			RESOURCE = astral_threads
			VALUE = 500
		}
		astral_splitting_nomad = yes
		set_country_flag = psionic_rift_help_received
	}
	# Quit
	option = {
		name = GOODBYE
		default_hide_option = yes
	}
}

# Shroud Seals opinion
country_event = {
	id = shroud.5375
	base = enclave.405
	desc_clear = yes
	option_clear = yes

	desc = shroud.5375.desc

	trigger = {
		exists = event_target:shroudwalker_enclave_country
		has_communications = event_target:shroudwalker_enclave_country
		NOR = {
			has_origin = origin_mindwardens
			has_country_flag = shroudwalkers_warn_shroud_seals
		}
		from = {
			is_megastructure_type = shroud_seal
		}
	}

	immediate = {
		set_country_flag = shroudwalkers_warn_shroud_seals
		event_target:shroudwalker_enclave_country = {
			add_trust = {
				who = root
				amount = @shroudwalkers_opinion_shroud_seals
			}
		}
	}

	# Quit
	option = {
		name = GOODBYE
		custom_tooltip = shroudwalkers_opinion_shroud_seals_tt
	}
}

#==================================
# 6XXX Mindwardens
#==================================

# See origin_events_shadows_shroud.txt

# Mercenary Mindwarden Enclave
country_event = {
	id = shroud.6850
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		ai_trade_facility = {
			offer_hire_mercenary_fleet = yes
			offer_prolong_fleet_contract = yes

			event_target:mindwarden_enclave_country = {
				random_owned_fleet = {
					limit = {
						is_ship_size = enclave_mindwarden_station
					}
					solar_system = {
						save_event_target_as = mindwarden_enclave_system
						random_playable_country = {
							limit = {
								event_target:mindwarden_enclave_country = {
									has_country_flag = created_by@prev
								}
							}
							save_event_target_as = mercenary_patron
						}
					}
				}
			}

			if = {
				limit = {
					has_country_flag = mindwarden_enclave_founded
				}
				if = {
					limit = {
						has_country_flag = first_mindwarden_enclave_founded
					}
					country_event = { id = shroud.6853 }
				}
				else = {
					country_event = { id = shroud.6852 }
				}
			}
			else = {
				country_event = { id = shroud.6851 }
			}
		}
	}
}

country_event = {
	id = shroud.6851
	base = shroud.4205
	desc_clear = yes

	desc = {
		trigger = {
			if = {
				limit = { has_country_flag = mindwarden_return_beginning }
				text = shroud.4205.desc.return_beginning
			}
			else = {
				text = shroud.4205.desc.merc_back
			}
		}
	}

	immediate = {
		run_in_ai_mode = yes # Without this, 'immediate' is not invoked when the event runs in a special mode that allows AI to collect trade data
	}
}

country_event = {
	id = shroud.6852
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4205.desc.merc_first

	immediate = {
		set_country_flag = first_mindwarden_enclave_founded
		remove_country_flag = mindwarden_enclave_founded
		set_country_flag = should_fire_shroud.6830

		run_in_ai_mode = yes
	}
}

country_event = {
	id = shroud.6853
	base = shroud.4205
	desc_clear = yes
	desc = shroud.4205.desc.merc_more

	immediate = {
		remove_country_flag = mindwarden_enclave_founded

		run_in_ai_mode = yes
	}
}

# Patron options
country_event = {
	id = shroud.6855
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = {
			if = {
				limit = { has_country_flag = mindwarden_return_patron_options }
				if = {
					limit = { has_country_flag = mindwarden_return_desc_1 }
					text = shroud.6855.desc.1
				}
				else = {
					text = shroud.6855.desc.2
				}
			}
			else = {
				text = shroud.6855.desc
			}
		}
	}

	immediate = {
		random_list = {
			1 = {}
			1 = { set_country_flag = mindwarden_return_desc_1 }
		}
		event_target:mindwarden_enclave_country = {
			random_owned_fleet = {
				limit = {
					is_ship_class = shipclass_military
					is_leased = yes
				}
				save_event_target_as = loaned_mercenary_fleet
			}
		}
		run_in_ai_mode = yes
	}

	# Back to menu
	option = {
		name = shroud.4230.a
		hidden_effect = {
			set_country_flag = mindwarden_return_beginning
			remove_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.4201 }
		}
	}
	# Upgrade Enclave
	option = {
		name = shroud.6855.b
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_5 }
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = shroud.6855.b.timeout
				event_target:mindwarden_enclave_country = {
					NOT = { has_country_flag = upgraded_station }
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6860 }
		}
	}
	# Give technologies
	option = {
		name = shroud.6855.c
		allow = {
			custom_tooltip = {
				fail_text = shroud.6855.c.timeout
				event_target:mindwarden_enclave_country = {
					NOT = { has_country_flag = updating_databanks }
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6870 }
		}
	}
	# Hire fleet
	option = {
		name = shroud.6855.d
		trigger = {
			NOT = { is_hostile = event_target:mindwarden_enclave_country }
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = fleet_commandeered }
				NOT = {
					any_owned_fleet = {
						is_ship_class = shipclass_military
						is_leased = yes
						controller = {
							is_same_value = root
						}
					}
				}
			}
			if = {
				limit = { is_ai = yes }
				NOT = { has_country_flag = merc_ai_delay }
			}
		}
		allow = {
			custom_tooltip = {
				fail_text = enclave.205.tooltip.a
				event_target:mindwarden_enclave_country = {
					NOT = {
						any_owned_fleet = {
							is_ship_class = shipclass_military
							is_leased = yes
							owner = {
								is_same_value = prev
							}
						}
					}
				}
			}
			custom_tooltip = {
				fail_text = enclave.205.tooltip.b
				event_target:mindwarden_enclave_country = {
					any_owned_fleet = {
						is_ship_class = shipclass_military
						NOT = { any_controlled_ship = { is_damaged = yes } }
						fleet_power >= 500
					}
				}
			}
		}
		ai_trade_facility = {
			custom_tooltip = mindwarden_tt_hirefleet
			offer_hire_mercenary_fleet = yes
			offer_prolong_fleet_contract = yes
			hidden_effect = {
				country_event = { id = shroud.6875 }
			}
		}
	}
	# Manage hired fleet (extend/terminate loan)
	option = {
		name = enclave.205.b
		custom_tooltip = mindwarden_tt_managefleet
		trigger = {
			NOR = {
				is_hostile = event_target:mindwarden_enclave_country
			}
			any_controlled_fleet = {
				is_ship_class = shipclass_military
				is_leased = yes
				owner = {
					is_same_value = event_target:mindwarden_enclave_country
				}
				controller = {
					is_same_value = root
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6880 }
		}
	}
	# Upgrade Enclave Capacity
	option = {
		name = shroud.6855.f
		allow = {
			custom_tooltip = {
				fail_text = shroud.6855.f.timeout
				event_target:mindwarden_enclave_country = {
					NOT = { has_country_flag = bought_mindwarden_enclave_capacity }
				}
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6865 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}

	after = {
		remove_country_flag = mindwarden_return_desc_1
	}
}

# Upgrade Enclave
country_event = {
	id = shroud.6860
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = {
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_1 }
			}
		}
		text = shroud.6860.1.desc
	}
	desc = {
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_2 }
				has_country_flag = mindwardens_upgrade_1
			}
		}
		text = shroud.6860.2.desc
	}
	desc = {
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_3 }
				has_country_flag = mindwardens_upgrade_2
			}
		}
		text = shroud.6860.3.desc
	}
	desc = {
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_4 }
				has_country_flag = mindwardens_upgrade_3
			}
		}
		text = shroud.6860.4.desc
	}
	desc = {
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_5 }
				has_country_flag = mindwardens_upgrade_4
			}
		}
		text = shroud.6860.5.desc
	}

	# Back
	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.6855 }
		}
	}
	# First Upgrade
	option = {
		name = shroud.6860.b
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_1 }
			}
		}
		allow = {
			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						country_uses_bio_ships = yes
					}
				}
				resource_stockpile_compare = { resource = food value >= 1000 }
			}
			else = {
				resource_stockpile_compare = { resource = energy value >= 1000 }
			}
			resource_stockpile_compare = { resource = alloys value >= 500 }
		}
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					country_uses_bio_ships = yes
				}
			}
			add_resource = { food = -1000 }
		}
		else = {
			add_resource = { energy = -1000 }
		}
		add_resource = { alloys = -500 }
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_country_flag = mindwardens_upgrade_1
				upgrade_enclave_starbase = {
					PREFIX = mindwarden
					DESIGN = NAME_Mindwarden_Enclave_Station
					TIER = 1
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# Second Upgrade
	option = {
		name = DEAL
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_2 }
				has_country_flag = mindwardens_upgrade_1
			}
		}
		allow = {
			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						country_uses_bio_ships = yes
					}
				}
				resource_stockpile_compare = { resource = food value >= 2500 }
			}
			else = {
				resource_stockpile_compare = { resource = energy value >= 2500 }
			}
			resource_stockpile_compare = { resource = alloys value >= 1250 }
		}
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					country_uses_bio_ships = yes
				}
			}
			add_resource = { food = -2500 }
		}
		else = {
			add_resource = { energy = -2500 }
		}
		add_resource = { alloys = -1250 }
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_country_flag = mindwardens_upgrade_2
				upgrade_enclave_starbase = {
					PREFIX = mindwarden
					DESIGN = NAME_Mindwarden_Enclave_Station
					TIER = 2
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# Third Upgrade
	option = {
		name = DEAL
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_3 }
				has_country_flag = mindwardens_upgrade_2
			}
		}
		allow = {
			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						country_uses_bio_ships = yes
					}
				}
				resource_stockpile_compare = { resource = food value >= 5500 }
			}
			else = {
				resource_stockpile_compare = { resource = energy value >= 5500 }
			}
			resource_stockpile_compare = { resource = alloys value >= 2750 }
		}
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					country_uses_bio_ships = yes
				}
			}
			add_resource = { food = -5500 }
		}
		else = {
			add_resource = { energy = -5500 }
		}
		add_resource = { alloys = -2750 }
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_country_flag = mindwardens_upgrade_3
				upgrade_enclave_starbase = {
					PREFIX = mindwarden
					DESIGN = NAME_Mindwarden_Enclave_Station
					TIER = 3
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# Fourth Upgrade
	option = {
		name = DEAL
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_4 }
				has_country_flag = mindwardens_upgrade_3
			}
		}
		allow = {
			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						country_uses_bio_ships = yes
					}
				}
				resource_stockpile_compare = { resource = food value >= 10000 }
			}
			else = {
				resource_stockpile_compare = { resource = energy value >= 10000 }
			}
			resource_stockpile_compare = { resource = alloys value >= 5000 }
		}
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					country_uses_bio_ships = yes
				}
			}
			add_resource = { food = -10000 }
		}
		else = {
			add_resource = { energy = -10000 }
		}
		add_resource = { alloys = -5000 }
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_country_flag = mindwardens_upgrade_4
				upgrade_enclave_starbase = {
					PREFIX = mindwarden
					DESIGN = NAME_Mindwarden_Enclave_Station
					TIER = 4
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# Fifth Upgrade
	option = {
		name = DEAL
		trigger = {
			event_target:mindwarden_enclave_country = {
				NOT = { has_country_flag = mindwardens_upgrade_5 }
				has_country_flag = mindwardens_upgrade_4
			}
		}
		allow = {
			if = {
				limit = {
					event_target:mindwarden_enclave_country = {
						country_uses_bio_ships = yes
					}
				}
				resource_stockpile_compare = { resource = food value >= 13000 }
			}
			else = {
				resource_stockpile_compare = { resource = energy value >= 13000 }
			}
			resource_stockpile_compare = { resource = alloys value >= 6500 }
		}
		if = {
			limit = {
				event_target:mindwarden_enclave_country = {
					country_uses_bio_ships = yes
				}
			}
			add_resource = { food = -13000 }
		}
		else = {
			add_resource = { energy = -13000 }
		}
		add_resource = { alloys = -6500 }
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_country_flag = mindwardens_upgrade_5
				upgrade_enclave_starbase = {
					PREFIX = mindwarden
					DESIGN = NAME_Mindwarden_Enclave_Station
					TIER = 5
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Upgrade thank
country_event = {
	id = shroud.6861
	base = shroud.6855
	desc_clear = yes
	desc = shroud.6861.desc
}

# More Enclave Capacity
country_event = {
	id = shroud.6865
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = shroud.6865.desc

	# Back
	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.6855 }
		}
	}
	# Buy Enclave Capacity
	option = {
		name = shroud.6860.b
		allow = {
			resource_stockpile_compare = { resource = energy value >= 1000 }
		}
		add_resource = { energy = -1000 }
		custom_tooltip = shroud.6865.b.tt
		hidden_effect = {
			change_variable = {
				which = mindwarden_enclave_capacity_count
				value = 1
			}
			remove_modifier = mindwarden_enclave_capacity
			add_modifier = {
				modifier = mindwarden_enclave_capacity
				multiplier = mindwarden_enclave_capacity_count
			}
			event_target:mindwarden_enclave_country = {
				set_timed_country_flag = { flag = bought_mindwarden_enclave_capacity days = 360 }
				set_saved_date = {
					key = mindwarden_enclave_capacity_bought_timer
					days_from_present = 360
					expires = 360
				}
			}
			country_event = { id = shroud.6861 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Offer technologies
country_event = {
	id = shroud.6870
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = shroud.6870.desc

	# Back
	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.6855 }
		}
	}
	# Share tech
	option = {
		name = shroud.6860.b
		add_resource = { energy = 1000 }
		custom_tooltip = enclave.2040.a.tt
		hidden_effect = {
			event_target:mindwarden_enclave_country = {
				set_timed_country_flag = { flag = updating_databanks days = @ShareTechTimer }
				set_saved_date = {
					key = updating_databanks_timer
					days_from_present = @ShareTechTimer
					expires = @ShareTechTimer
				}
				copy_techs_from = { target = root }
			}
			country_event = { id = shroud.6861 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Hire Fleet
country_event = {
	id = shroud.6875
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = shroud.6875.desc

	immediate = {
		event_target:mindwarden_enclave_country = {
			if = {
				limit = {
					count_owned_leader = {
						count = 0
						limit = {
							leader_class = commander
							is_councilor = no
							is_ruler = no
						}
					}
				}
				create_mindwarden_fleet_leader = yes
			}
			random_owned_leader = {
				limit = {
					leader_class = commander
					is_councilor = no
					is_ruler = no
				}
				save_event_target_as = mercenary_admiral
				set_immortal = yes
			}
			# Can hire only the main fleet
			ordered_controlled_fleet = {
				limit = {
					is_ship_class = shipclass_military
					is_leased = no
				}
				position = 0
				order_by = trigger:fleet_power
				save_event_target_as = mercenary_fleet
				assign_leader = event_target:mercenary_admiral
				set_name = {
					key = NAME_Mindwarden_Fleet
					variable_string = "[mindwarden_enclave_country.GetName]"
				}
				set_fleet_settings = {
					can_change_leader = no
				}
			}
		}
		run_in_ai_mode = yes
	}

	# Back
	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.6855 }
		}
	}
	# Hire fleet
	option = {
		name = shroud.6860.b
		ai_trade_facility = {
			offer_hire_mercenary_fleet = yes
			info_gathering = {
				get_trade_data = { target = event_target:mindwarden_enclave_country }
			}
			option_selection = {
				if = {
					limit = {
						is_offer_terms_actual = { target = event_target:mindwarden_enclave_country }
					}
					make_special_trade = { target = event_target:mindwarden_enclave_country }
					hidden_effect = {
						set_country_flag = mercenary_enclave_rented_fleet # For tracking returning customers
					}
				}
			}
			allow = {
				can_afford_special_offer = { target = event_target:mindwarden_enclave_country }
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6876 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

# Thank Hire
country_event = {
	id = shroud.6876
	base = shroud.6855
	desc_clear = yes
	desc = shroud.6876.desc
}

# Renew contract?
country_event = {
	id = shroud.6878
	title = enclave.2060.name
	desc = enclave.2060.desc
	picture = GFX_evt_mindwardens
	show_sound = event_mindwarden_enclave
	is_triggered_only = yes

	option = { # Yes, open diplomacy
		name = enclave.2060.b
		hidden_effect = {
			country_event = { id = shroud.4201 }
		}
	}
	option = { # Nope
		name = enclave.2060.a
		default_hide_option = yes
	}
}

# Manage hired fleet
country_event = {
	id = shroud.6880
	base = shroud.4205
	desc_clear = yes
	option_clear = yes

	desc = shroud.6880.desc

	immediate = {
		random_controlled_fleet = {
			limit = {
				is_ship_class = shipclass_military
				is_leased = yes
			}
			save_event_target_as = mercenary_fleet
		}
		run_in_ai_mode = yes
	}

	# Back
	option = {
		name = shroud.4240.a
		hidden_effect = {
			set_country_flag = mindwarden_return_patron_options
			country_event = { id = shroud.6855 }
		}
	}
	# Extend the hire
	option = {
		name = enclave.215.b
		ai_trade_facility = {
			offer_prolong_fleet_contract = yes
			info_gathering = {
				get_trade_data = { target = event_target:mindwarden_enclave_country }
			}
			option_selection = {
				if = {
					limit = {
						is_offer_terms_actual = { target = event_target:mindwarden_enclave_country }
					}
					make_special_trade = { target = event_target:mindwarden_enclave_country }
				}
			}
			allow = {
				can_afford_special_offer = { target = event_target:mindwarden_enclave_country }
			}
		}
		hidden_effect = {
			country_event = { id = shroud.6861 }
		}
	}
	# Terminate Contract
	option = {
		name = enclave.215.c
		hidden_effect = {
			event_target:mercenary_fleet = {
				end_fleet_contract = {
					initiator = root
					reason = cancelled
				}
			}
			country_event = { id = shroud.6881 }
		}
	}
	# End comms
	option = {
		name = GOODBYE
		default_hide_option = yes
		close_mindwarden_diplomacy = yes
	}
}

country_event = {
	id = shroud.6881
	base = shroud.6855
	desc_clear = yes
	desc = shroud.6881.desc
}

#==================================
# 7000 - 7999 Advanced governments
#==================================

# Transcendent Aristocracy post-election modifier
country_event = {
	id = shroud.7005
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		is_oligarchic_authority = yes
		is_transcendent_authority = yes
	}

	immediate = {
		if = {
			limit = { has_modifier = transcendent_oligarchic_election_modifier }
			remove_modifier = transcendent_oligarchic_election_modifier
		}
		add_modifier = {
			modifier = transcendent_oligarchic_election_modifier
			years = 5
		}
	}
}

# Transcendent Ethermind Leader XP bonus
country_event = {
	id = shroud.7010
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		is_hive_empire = yes
		is_transcendent_authority = yes
		has_covenant_with_end_of_the_cycle = no
	}

	immediate = {
		every_owned_leader = {
			limit = { is_gestalt_node = no }
			add_experience = @transcendent_hive_mind_leader_exp
		}
	}
}

# Update Psionic Nexus modifier per attunement points
country_event = {
	id = shroud.7015
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		is_hive_empire = yes
		is_corporeal_authority = yes
	}

	immediate = {
		if = {
			limit = { has_modifier = corporeal_hive_mind_upkeep_modifier }
			remove_modifier = corporeal_hive_mind_upkeep_modifier
		}
		add_modifier = {
			modifier = corporeal_hive_mind_upkeep_modifier
			mult = value:get_attunement_points
		}
	}
}

# Update Transcendent Mainframe modifier per attunement points
country_event = {
	id = shroud.7020
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		is_machine_empire = yes
		is_transcendent_authority = yes
	}

	immediate = {
		if = {
			limit = { has_modifier = transcendent_machine_research_modifier }
			remove_modifier = transcendent_machine_research_modifier
		}
		add_modifier = {
			modifier = transcendent_machine_research_modifier
			mult = value:get_attunement_points
		}
	}
}

# Transcendent Mainframe Research bonus
country_event = {
	id = shroud.7025
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		is_machine_empire = yes
		is_transcendent_authority = yes
		has_covenant_with_end_of_the_cycle = no
	}

	immediate = {
		random_list = {
			1 = {
				add_monthly_resource_mult = {
					resource = physics_research
					value = @tier1researchreward
					min = @tier1researchmin
					max = @tier1researchmax
				}
			}
			1 = {
				add_monthly_resource_mult = {
					resource = society_research
					value = @tier1researchreward
					min = @tier1researchmin
					max = @tier1researchmax
				}
			}
			1 = {
				add_monthly_resource_mult = {
					resource = engineering_research
					value = @tier1researchreward
					min = @tier1researchmin
					max = @tier1researchmax
				}
			}
		}
	}
}

# Transcendent Imperium Unity bonus
country_event = {
	id = shroud.7030
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		from = {
			OR = {
				is_ruler = yes
				is_heir = yes
			}
		}
		is_imperial_authority = yes
		is_transcendent_authority = yes
	}

	immediate = {
		add_monthly_resource_mult = {
			resource = unity
			value = @tier1unityreward
			min = @tier1unitymin
			max = @tier1unitymax
		}
	}
}

# Corporeal Imperium authority: XP bonus when heir is promoted to ruler
# This = Heir
leader_event = {
	id = shroud.7035
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		owner = {
			is_imperial_authority = yes
			is_corporeal_authority = yes
		}
	}

	immediate = {
		add_experience = @corporeal_imperial_heir_xp
	}
}

country_event = {
	id = shroud.7099
	title = shroud.7099.name
	desc = shroud.7099.desc
	picture = GFX_evt_shroud_generic
	show_sound = event_shroud_song
	is_triggered_only = yes

	trigger = {
		is_transcendent_authority = no
		is_corporeal_authority = no
		# EotC cancels advanced authorities
		NOR = {
			has_origin = origin_endbringers
			has_covenant_with_end_of_the_cycle = yes
		}
	}

	option = {
		name = shroud.7099.a
		hidden_effect = {
			country_event = {
				id = shroud.7100
			}
		}
	}
}

country_event = {
	id = shroud.7100
	diplomatic_title = shroud.3.diplo_title
	title = shroud.7100.title
	desc = shroud.7100.desc

	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	immediate = {
		select_shroud_song = yes
	}

	option = {
		name = shroud.7100.a
		hidden_effect = {
			move_towards_advanced_government = { TYPE = transcendent }
		}
	}
	option = {
		name = shroud.7100.b
		hidden_effect = {
			move_towards_advanced_government = { TYPE = corporeal }
		}
	}

	after = {
		custom_tooltip = shroud.7100.tt
		hidden_effect = {
			clear_selected_shroud_song = yes
			country_event = {
				id = shroud.7105
			}
		}
	}
}

country_event = {
	id = shroud.7105
	base = shroud.7100
	desc_clear = yes
	desc = shroud.7105.desc
	option_clear = yes

	option = {
		name = shroud.7100.a
		hidden_effect = {
			move_towards_advanced_government = { TYPE = transcendent }
		}
	}
	option = {
		name = shroud.7100.b
		hidden_effect = {
			move_towards_advanced_government = { TYPE = corporeal }
		}
	}

	after = {
		custom_tooltip = shroud.7105.tt
		hidden_effect = {
			clear_selected_shroud_song = yes
			country_event = {
				id = shroud.7110
			}
		}
	}
}

country_event = {
	id = shroud.7110
	base = shroud.7100
	desc_clear = yes
	desc = shroud.7105.desc
	option_clear = yes

	option = {
		name = shroud.7100.a
		hidden_effect = {
			move_towards_advanced_government = { TYPE = transcendent }
		}
	}
	option = {
		name = shroud.7100.b
		hidden_effect = {
			move_towards_advanced_government = { TYPE = corporeal }
		}
	}

	after = {
		custom_tooltip = shroud.7110.tt
		hidden_effect = {
			clear_selected_shroud_song = yes
			if = {
				limit = { is_eligible_for_advanced_government = { TYPE = transcendent } }
				country_event = {
					id = shroud.7120
					days = 1
				}
			}
			else_if = {
				limit = { is_eligible_for_advanced_government = { TYPE = corporeal } }
				country_event = {
					id = shroud.7121
					days = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.7120
	title = shroud.7120.name
	desc = shroud.7120.desc
	picture = GFX_evt_shroud_generic
	show_sound = event_shroud_song
	is_triggered_only = yes

	option = {
		name = {
			trigger = { is_gestalt = yes }
			text = shroud.7120.a.gestalt
		}
		name = {
			trigger = { is_gestalt = no }
			text = shroud.7120.a.default
		}
		custom_tooltip = shroud.7120.a.tt
		hidden_effect = {
			set_country_flag = transcendent_government
			advanced_authority_refresh = yes
			if = {
				limit = { is_gestalt = yes }
				ruler = {
					if = {
						limit = { has_psionic_leader_trait = no }
						add_trait = { trait = leader_trait_psionic }
					}
				}
			}

			# Transcendent Mainframe modifier setup
			country_event = { id = shroud.7020 }
		}
	}
	option = {
		name = {
			trigger = { is_robot_empire = yes }
			text = shroud.7120.b.machine
		}
		name = {
			trigger = { is_robot_empire = no }
			text = shroud.7120.b.default
		}
	}
}

country_event = {
	id = shroud.7121
	title = shroud.7121.name
	desc = shroud.7121.desc
	picture = GFX_evt_shroud_generic
	show_sound = event_shroud_song
	is_triggered_only = yes

	option = {
		name = shroud.7121.a
		custom_tooltip = shroud.7121.a.tt
		hidden_effect = {
			set_country_flag = corporeal_government
			advanced_authority_refresh = yes
			set_psionic_choir_policy = yes

			# Psionic Nexus modifier setup
			country_event = { id = shroud.7015 }

			# Setup pool leader traits
			if = {
				limit = {
					is_oligarchic_authority = yes
				}
				every_pool_leader = {
					add_trait = {
						trait = random_negative
						show_message = no
					}
				}
			}
		}
	}
	option = {
		name = {
			trigger = { is_robot_empire = yes }
			text = shroud.7120.b.machine
		}
		name = {
			trigger = { is_robot_empire = no }
			text = shroud.7120.b.default
		}
	}
}

#==================================
# 8XXX Endbringers
#==================================

# See origin_events_shadows_shroud.txt

#==================================
# 9000-9999 End of the Cycle
#==================================

carrier_event = {
	id = shroud.9000
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = { last_building_changed = building_psionic_suppressor }
			if = {
				limit = { has_active_building = building_psionic_suppressor }
				add_eotc_aura_psionic_suppressor = yes
			}
			else = {
				remove_eotc_aura_psionic_suppressor = yes
			}
		}
		else_if = {
			limit = { last_building_changed = building_ancient_ward_2 }
			if = {
				limit = { has_active_building = building_ancient_ward_2 }
				add_eotc_aura_grand_ward = yes
			}
			else = {
				remove_eotc_aura_grand_ward = yes
			}
		}
	}
}

#==================================
# 10000-10999 Counters
#==================================

carrier_event = {
	id = shroud.10000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_construct_district
				amount = 1
			}
		}
	}
}

carrier_event = {
	id = shroud.10005
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_establish_colony
				amount = 1
			}
		}

		if = {
			limit = {
				is_planet_class = pc_gaia
			}
			owner = {
				add_patron_objective_counter = {
					counter = po_colonize_gaia_world
					amount = 1
				}
			}
		}
		else_if = {
			limit = {
				is_planet_class = pc_nuked
			}
			owner = {
				add_patron_objective_counter = {
					counter = po_colonize_tomb_world
					amount = 1
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.10010
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		NOT = { has_carrier_flag = terraformed_by@from }
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		set_carrier_flag = terraformed_by@from
		from = {
			add_patron_objective_counter = {
				counter = po_terraform_planet
				amount = 1
			}
		}
	}
}

carrier_event = {
	id = shroud.10015
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_clear_blocker
				amount = 1
			}
		}
	}
}

carrier_event = {
	id = shroud.10020
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_build_army
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10025
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_finish_megastructure
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10030
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_early_launch_agenda
			amount = 1
		}
	}
}

fleet_event = {
	id = shroud.10035
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { can_access_shroud = yes }
	}

	immediate = {
		owner = {
			if = {
				limit = { has_astral_planes_dlc = yes }
				add_patron_objective_counter = {
					counter = po_complete_arc_site_or_rift
					amount = 1
				}
			}
			else = {
				add_patron_objective_counter = {
					counter = po_complete_arc_site
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10036
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_astral_planes_dlc = yes
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_complete_arc_site_or_rift
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10040
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		last_completed_special_project_has_research_cost = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_research_project
			amount = 1
		}
	}
}

fleet_event = {
	id = shroud.10045
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = { can_access_shroud = yes }
	}

	immediate = {
		owner = {
			if = {
				limit = { has_astral_planes_dlc = yes }
				add_patron_objective_counter = {
					counter = po_complete_arc_site_or_rift_stage
					amount = 1
				}
			}
			else = {
				add_patron_objective_counter = {
					counter = po_complete_arc_site_stage
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10046
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_astral_planes_dlc = yes
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_complete_arc_site_or_rift_stage
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10050
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_pick_tradition
			amount = 1
		}

		if = {
			limit = {
				OR = {
					category_last_picked_tradition = tradition_supremacy
					category_last_picked_tradition = tradition_enmity
				}
			}
			add_patron_objective_counter = {
				counter = po_pick_supremacy_or_enmity_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				OR = {
					category_last_picked_tradition = tradition_diplomacy
					category_last_picked_tradition = tradition_politics
				}
			}
			add_patron_objective_counter = {
				counter = po_pick_diplomacy_or_politics_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_domination
			}
			add_patron_objective_counter = {
				counter = po_pick_mercantile_or_domination_tradition
				amount = 1
			}
			add_patron_objective_counter = {
				counter = po_pick_logistics_or_domination_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_mercantile
			}
			add_patron_objective_counter = {
				counter = po_pick_mercantile_or_domination_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_logistics
			}
			add_patron_objective_counter = {
				counter = po_pick_logistics_or_domination_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_adaptability
			}
			add_patron_objective_counter = {
				counter = po_pick_adaptability_or_expansion_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_versatility
			}
			add_patron_objective_counter = {
				counter = po_pick_versatility_or_expansion_tradition
				amount = 1
			}
		}
		else_if = {
			limit = {
				category_last_picked_tradition = tradition_expansion
			}
			add_patron_objective_counter = {
				counter = po_pick_adaptability_or_expansion_tradition
				amount = 1
			}
			add_patron_objective_counter = {
				counter = po_pick_versatility_or_expansion_tradition
				amount = 1
			}
		}
	}
}

carrier_event = {
	id = shroud.10055
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_build_building
				amount = 1
			}
		}
		if = {
			limit = { last_building_changed = building_research_lab_1 }
			owner = {
				add_patron_objective_counter = {
					counter = po_build_research_lab
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10060
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_upgrade_megastructure
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10065
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_activate_relic
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10070
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		from = { leader_class = scientist }
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_scientist_level_up
			amount = 1
		}
	}
}

bypass_event = {
	id = shroud.10075
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			exists = controller
			controller = { can_access_shroud = yes }
		}
	}

	immediate = {
		from.controller = {
			add_patron_objective_counter = {
				counter = po_wormhole_and_locks
				amount = 1
			}
		}
	}
}

bypass_event = {
	id = shroud.10076
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_bypass_type = wormhole
		from = {
			exists = controller
			controller = { can_access_shroud = yes }
		}
	}

	immediate = {
		from.controller = {
			if = {
				limit = { has_astral_planes_dlc = yes }
				add_patron_objective_counter = {
					counter = po_wormhole_and_locks
					amount = 1
				}
			}
			else = {
				add_patron_objective_counter = {
					counter = po_explore_wormhole
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10080
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		if = {
			limit = { is_last_increased_tech_repeatable = yes }
			add_patron_objective_counter = {
				counter = po_research_repeatable_tech
				amount = 1
			}
		}
		if = {
			limit = { is_last_increased_tech_rare = yes }
			add_patron_objective_counter = {
				counter = po_research_rare_tech
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10090
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_change_policy
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = fromfrom
		fromfrom = {
			can_access_shroud = yes
		}
	}

	immediate = {
		fromfrom = {
			add_patron_objective_counter = {
				counter = po_destroy_army
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10110
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_release_sector_as_vassal
				amount = 1
			}
		}
	}
}

carrier_event = {
	id = shroud.10150
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_conquer_planet
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10200
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_pass_resolution_galcom
			amount = 1
		}

		switch = {
			trigger = last_resolution_category_changed
			resolution_category_commerce = {
				add_patron_objective_counter = {
					counter = po_pass_commerce_resolution
					amount = 1
				}
			}
			resolution_category_industry = {
				add_patron_objective_counter = {
					counter = po_pass_industry_resolution
					amount = 1
				}
			}
			resolution_category_ecology = {
				add_patron_objective_counter = {
					counter = po_pass_ecology_resolution
					amount = 1
				}
			}
			resolution_category_divinity = {
				add_patron_objective_counter = {
					counter = po_pass_divinity_resolution
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10300
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_pass_law_federation
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10305
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		has_patron_counter = po_reach_excellent_relations
	}

	immediate = {
		every_playable_country = {
			limit = {
				NOT = { has_country_flag = reached_excellent_relations_with_@root }
				has_communications = root
				opinion_level = {
					who = root
					level = excellent
				}
			}
			set_country_flag = reached_excellent_relations_with_@root
			root = {
				add_patron_objective_counter = {
					counter = po_reach_excellent_relations
					amount = 1
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.10350
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_upgrade_building
				amount = 1
			}
		}
		if = {
			limit = {
				is_last_building_changed_capital = yes
			}
			owner = {
				add_patron_objective_counter = {
					counter = po_upgrade_building_capital
					amount = 1
				}
			}
		}
		else = {
			owner = {
				add_patron_objective_counter = {
					counter = po_upgrade_building_non_capital
					amount = 1
				}
			}
		}
	}
}

country_event = {
	id = shroud.10355
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		exists = from
		from = { is_pirate = yes }
		exists = fromfromfrom
		has_patron_counter = po_destroy_pirates
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_destroy_pirates
			amount = 1
			multiplier = fromfromfrom.trigger:ship_size_multiplier
		}
	}
}

inline_script = {
	script = shroud/objectives/diplomacy_complex_po
	EVENT_ID = shroud.10360
	FLAG_NAME = establish_trade_agreement_with
	PATRON_OBJECTIVE = po_establish_trade_agreement
}

inline_script = {
	script = shroud/objectives/diplomacy_complex_po
	EVENT_ID = shroud.10365
	FLAG_NAME = establish_defensive_pact_with
	PATRON_OBJECTIVE = po_establish_defensive_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_complex_po
	EVENT_ID = shroud.10370
	FLAG_NAME = establish_migration_pact_with
	PATRON_OBJECTIVE = po_establish_migration_treaty
}

inline_script = {
	script = shroud/objectives/diplomacy_po
	EVENT_ID = shroud.10375
	FLAG_NAME = establish_non_agression_pact_with
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_complex_po
	EVENT_ID = shroud.10380
	FLAG_NAME = establish_research_pact_with
	PATRON_OBJECTIVE = po_establish_research_agreement
}

inline_script = {
	script = shroud/objectives/diplomacy_po
	EVENT_ID = shroud.10385
	FLAG_NAME = become_subject_of
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10390
	FLAG_NAME = start_integration_of
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_po
	EVENT_ID = shroud.10395
	FLAG_NAME = establish_embassy_with
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10400
	FLAG_NAME = invite_to_federation_for
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10405
	FLAG_NAME = ask_to_join_federation_to
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10410
	FLAG_NAME = ask_for_association_status_to
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10415
	FLAG_NAME = accept_association_status_offer_of
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10420
	FLAG_NAME = guarantee_independence_of
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10425
	FLAG_NAME = support_independence_of
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10430
	FLAG_NAME = offer_societal_guidance_to
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

inline_script = {
	script = shroud/objectives/diplomacy_simple_po
	EVENT_ID = shroud.10435
	FLAG_NAME = provide_technology_to
	PATRON_OBJECTIVE = po_establish_diplomatic_pact
}

country_event = {
	id = shroud.10440
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_declare_war
			amount = 1
		}
	}
}

carrier_event = {
	id = shroud.10475
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
			has_patron_counter = po_uplift_species
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_uplift_species
				amount = 1
				multiplier = root.value:nb_pop_exact_species_on_planet
			}
		}
	}
}

ship_event = {
	id = shroud.10495
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = controller
		controller = {
			can_access_shroud = yes
			has_patron_counter = po_build_ship_size_mult
		}
	}

	immediate = {
		set_variable = {
			which = ship_naval_cap
			value = value:ship_naval_cap
		}
		controller = {
			add_patron_objective_counter = {
				counter = po_build_ship_size_mult
				amount = prev.ship_naval_cap
			}
		}
		clear_variable = ship_naval_cap
	}
}

ship_event = {
	id = shroud.10500
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_space_fauna = yes
		exists = controller
		controller = {
			can_access_shroud = yes
		}
	}

	immediate = {
		controller = {
			add_patron_objective_counter = {
				counter = po_clone_space_fauna
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10505
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		exists = fromfromfrom
	}

	immediate = {
		if = {
			limit = {
				fromfromfrom = { is_space_fauna = yes }
			}
			if = {
				limit = { has_patron_counter = po_hunt_space_fauna }
				add_patron_objective_counter = {
					counter = po_hunt_space_fauna
					amount = 1
					multiplier = fromfromfrom.trigger:ship_size_multiplier
				}
			}
		}
		else_if = {
			limit = { has_patron_counter = po_destroy_ship }
			add_patron_objective_counter = {
				counter = po_destroy_ship
				amount = 1
				multiplier = fromfromfrom.trigger:ship_size_multiplier
			}
		}
	}
}

carrier_event = {
	id = shroud.10510
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			OR = {
				can_access_shroud = yes
				AND = {
					has_origin = origin_nomadic_purger
					overlord? = { can_access_shroud = yes }
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				from = { has_origin = origin_nomadic_purger }
			}
			from.overlord = {
				add_patron_objective_counter = {
					counter = po_kill_pop
					amount = 1
				}
			}
		}
		else = {
			from = {
				add_patron_objective_counter = {
					counter = po_kill_pop
					amount = 1
				}
			}
		}
	}
}

pop_group_event = {
	id = shroud.10515
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = fromfrom
		fromfrom = { can_access_shroud = yes }
	}

	immediate = {
		fromfrom = {
			add_patron_objective_counter = {
				counter = po_kill_pop
				amount = 1
			}
		}
	}
}

system_event = {
	id = shroud.10520
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		exists = starbase
		NOT = { has_star_flag = conquered_by_@from }
		from = {
			can_access_shroud = yes
			has_patron_counter = po_conquer_system
		}
	}

	immediate = {
		set_star_flag = conquered_by_@from
		from = {
			add_patron_objective_counter = {
				counter = po_conquer_system
				amount = 1
				multiplier = root.starbase.value:starbase_tier
			}
		}
	}
}

country_event = {
	id = shroud.10550
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = prev
		can_access_shroud = yes
		has_patron_counter = po_apply_species_template
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_apply_species_template
			amount = 1
			multiplier = prev.value:nb_pop_exact_species_on_planet
		}
	}
}

country_event = {
	id = shroud.10600
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_claim_system
			amount = 1
		}
	}
}

carrier_event = {
	id = shroud.10650
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_ruin_enemy_building
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10700
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_galcom_member = {
			can_access_shroud = yes
		}
	}

	immediate = {
		every_galcom_member = {
			limit = {
				can_access_shroud = yes
				has_patron_counter = po_galcom_vote
				OR = {
					position_on_last_resolution = support
					position_on_last_resolution = oppose
				}
			}

			add_patron_objective_counter = {
				counter = po_galcom_vote
				amount = 1
			}
		}
	}
}

ship_event = {
	id = shroud.10705
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_ship_size = military_station_small
		exists = controller
		controller = {
			can_access_shroud = yes
		}
	}

	immediate = {
		controller = {
			add_patron_objective_counter = {
				counter = po_build_defense_platform
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10706
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		fromfromfrom = {
			is_ship_size = military_station_small
		}
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_build_defense_platform
			amount = -1
		}
	}
}

country_event = {
	id = shroud.10710
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = { is_ai = yes }
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_earn_favor
			amount = 1
		}
	}
}

espionage_operation_event = {
	id = shroud.10715
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_complete_operation
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10750
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		has_federation = yes
		is_federation_leader = yes
		exists = federation
		federation = {
			num_members = 1
		}
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_form_or_upgrade_federation
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10755
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = federation
	}

	immediate = {
		federation = {
			every_member = {
				limit = {
					can_access_shroud = yes
					has_patron_counter = po_form_or_upgrade_federation
				}
				add_patron_objective_counter = {
					counter = po_form_or_upgrade_federation
					amount = 1
				}
			}
		}
	}
}

carrier_event = {
	id = shroud.10800
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			can_access_shroud = yes
		}
	}

	immediate = {
		owner = {
			add_patron_objective_counter = {
				counter = po_ascend_planet
				amount = 1
			}
		}
	}
}

country_event = {
	id = shroud.10850
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_consecrate_planet
			amount = 1
		}
	}
}

country_event = {
	id = shroud.10855
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_consecrate_planet
			amount = -1
		}
	}
}

country_event = {
	id = shroud.10900
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		can_access_shroud = yes
		exists = from
		count_species = {
			limit = {
				NOT = { is_exact_same_species = from }
				is_same_species = from
			}
			count = 0
		}
	}

	immediate = {
		add_patron_objective_counter = {
			counter = po_host_new_species
			amount = 1
		}
	}
}

# Called from on_pop_grown
# This = planet
# From = country
carrier_event = {
	id = shroud.10910
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
		from = {
			can_access_shroud = yes
			check_variable = {
				which = local_pop_amount
				value > 0
			}
			has_patron_counter = po_grow_pop
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_grow_pop
				amount = local_pop_amount
			}
		}
	}
}

# Called from on_building_starbase_outpost
# This = ship (starbase)
ship_event = {
	id = shroud.10920
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		controller = {
			can_access_shroud = yes
		}
	}

	immediate = {
		controller = {
			add_patron_objective_counter = {
				counter = po_construct_outpost
				amount = 1
			}
		}
	}
}

# Called from on_waystation_built
# this = galactic object/solar system
# from = waystation owner
# fromfrom = waystation starbase
system_event = {
	id = shroud.10922
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = {
			can_access_shroud = yes
		}
	}

	immediate = {
		from = {
			add_patron_objective_counter = {
				counter = po_construct_waystations
				amount = 1
			}
		}
	}
}

# Called from on_modification_complete
# This = Country
# From = Species ( Post Modification )
# FromFrom = Species ( Original )
# Prev = Planet
country_event = {
	id = shroud.10930
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = prev
		can_access_shroud = yes
	}

	immediate = {
		if = {
			limit = {
				NOT = { is_variable_set = po_apply_pop_template_counter }
			}
			set_variable = {
				which = po_apply_pop_template_counter
				value = 0
			}
		}
		change_variable = {
			which = po_apply_pop_template_counter
			value = prev.value:nb_pop_exact_species_on_planet
		}
	}
}

# Called from on_modification_completion
# This = Country
# From = Species ( Post Modification )
country_event = {
	id = shroud.10935
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_variable_set = po_apply_pop_template_counter
	}

	immediate = {
		if = {
			limit = {
				apply_pop_template_pop_check = {
					TIER = 1
				}
			}

			if = {
				limit = {
					apply_pop_template_pop_check = {
						TIER = 2
					}
				}

				if = {
					limit = {
						apply_pop_template_pop_check = {
							TIER = 3
						}
					}

					add_patron_objective_counter = {
						counter = po_apply_pop_template_tier3
						amount = 1
					}
				}

				add_patron_objective_counter = {
					counter = po_apply_pop_template_tier2
					amount = 1
				}
			}

			add_patron_objective_counter = {
				counter = po_apply_pop_template_tier1
				amount = 1
			}
		}
		clear_variable = po_apply_pop_template_counter
	}
}

# Called from on_ship_built
# This = ship
# From = planet
ship_event = {
	id = shroud.10940
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = prev
		is_space_fauna = yes
		exists = controller
		controller = {
			can_access_shroud = yes
			has_patron_counter = po_clone_space_fauna_naval_capacity
		}
	}

	immediate = {
		set_variable = {
			which = ship_naval_cap
			value = value:ship_naval_cap
		}
		controller = {
			add_patron_objective_counter = {
				counter = po_clone_space_fauna_naval_capacity
				amount = prev.ship_naval_cap
			}
		}
		clear_variable = ship_naval_cap
	}
}

#==================================
# 11000-11999 Greater Patrons flow
#==================================

country_event = {
	id = shroud.11000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = greater_patron_chosen }
		mid_game_years_passed >= 0
		has_patron_relation = {
			patron = the_eater_of_worlds
			contact = completed
		}
		has_patron_relation = {
			patron = the_cradle_of_souls
			contact = completed
		}
		has_patron_relation = {
			patron = the_instrument_of_desire
			contact = completed
		}
		has_patron_relation = {
			patron = the_composer_of_strands
			contact = completed
		}
	}

	immediate = {
		random = {
			chance = value:calc_greater_patron_roll_chance
			set_country_flag = greater_patron_chosen
			country_event = { id = shroud.11001 }
		}
	}
}

# Actual Greater Patron roll
country_event = {
	id = shroud.11001
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = contacting_great_patron
		random_list = {
			95 = {
				modifier = {
					factor = 0
					has_origin = origin_endbringers
				}
				country_event = { id = shroud.4040 }
			}
			5 = {
				modifier = {
					factor = 0
					OR = {
						has_global_flag = no_end_of_cycle
						has_global_flag = end_of_the_cycle_rolled
					}
				}
				modifier = {
					factor = 0
					any_country = {
						has_origin = origin_endbringers # If there are endbringers they should be the only country that can roll the EotC
						NOT = { is_same_value = ROOT }
					}
				}
				modifier = {
					factor = 2
					any_country = {
						NOT = { is_same_value = ROOT }
						has_crisis_level = crisis_level_5 # Someone wants to destroy the galaxy? Let's give them a challenge.
					}
				}
				modifier = {
					factor = 5
					has_country_flag = knights_met_end_of_cycle
				}
				set_global_flag = end_of_the_cycle_rolled
				country_event = { id = shroud.4135 }
			}
		}
	}
}

# The Whisperers in the Void Replacement Choice
country_event = {
	id = shroud.11110
	title = shroud.11110.title
	diplomatic_title = shroud.3.diplo_title
	desc = shroud.11110.desc

	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	option = {
		name = shroud.11110.a
		whisperers_in_the_void_replace_patron = {
			PATRON = the_eater_of_worlds
			CHAIN = "shroud_eater_covenant_chain"
		}
		country_event = {
			id = shroud.11111
		}
	}
	option = {
		name = shroud.11110.b
		whisperers_in_the_void_replace_patron = {
			PATRON = the_cradle_of_souls
			CHAIN = "shroud_cradle_covenant_chain"
		}
		country_event = {
			id = shroud.11112
		}
	}
	option = {
		name = shroud.11110.c
		whisperers_in_the_void_replace_patron = {
			PATRON = the_instrument_of_desire
			CHAIN = "shroud_instrument_covenant_chain"
		}
		country_event = {
			id = shroud.11113
		}
	}
	option = {
		name = shroud.11110.d
		whisperers_in_the_void_replace_patron = {
			PATRON = the_composer_of_strands
			CHAIN = "shroud_composer_covenant_chain"
		}
		country_event = {
			id = shroud.11114
		}
	}
}

country_event = {
	id = shroud.11111
	title = shroud.11120.title.eater
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		country_event = {
			id = shroud.11120
		}
	}
}

country_event = {
	id = shroud.11112
	title = shroud.11120.title.cradle
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		country_event = {
			id = shroud.11120
		}
	}
}

country_event = {
	id = shroud.11113
	title = shroud.11120.title.instrument
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		country_event = {
			id = shroud.11120
		}
	}
}

country_event = {
	id = shroud.11114
	title = shroud.11120.title.composer
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		country_event = {
			id = shroud.11120
		}
	}
}

# The Whisperers in the Void Betrayal Event
country_event = {
	id = shroud.11120
	title = shroud.11120.title
	desc = shroud.11120.desc
	is_triggered_only = yes
	location = event_target:selected_planet_for_revenge

	inline_script = {
		script = shroud/patron_revenge_event_picture
		DEFAULT_PICTURE = GFX_evt_shroud_whisperers_in_the_void
	}

	immediate = {
		if = {
			limit = {
				has_country_flag = broke_covenant
			}
			add_modifier = {
				modifier = covenant_broken_modifier
				years = 10
			}
		}
		if = {
			limit = { is_nomadic = no }
			random_planet_within_border = {
				limit = {
					is_colony = no
					potential_shrouded_planet_for_patron_revenge = yes
					OR = {
						is_planet_class = pc_barren
						is_planet_class = pc_barren_cold
					}
				}
				weights = {
					base = 1
					modifier = {
						add = trigger:distance_to_capital
					}
				}

				patron_revenge = yes
			}
		}
		else = {
			random_owned_nonprimary_starbase = {
				limit = {
					is_waystation_starbase = yes
					solar_system = {
						any_system_planet = {
							is_colony = no
							potential_shrouded_planet_for_patron_revenge = yes
							OR = {
								is_planet_class = pc_barren
								is_planet_class = pc_barren_cold
							}
						}
					}
				}
				solar_system = {
					random_system_planet = {
						limit = {
							is_colony = no
							potential_shrouded_planet_for_patron_revenge = yes
							OR = {
								is_planet_class = pc_barren
								is_planet_class = pc_barren_cold
							}
						}
						patron_revenge = yes
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = event_target:selected_planet_for_revenge }
			}
			ordered_planet_within_border = {
				limit = {
					is_star = no
					is_capital = no
					is_asteroid = no
					NOR = {
						is_planet_class = pc_shrouded
					}
				}
				position = 0
				order_by = trigger:distance_to_capital

				patron_revenge = yes
			}
		}
	}

	option = {
		name = shroud.11120.a
		custom_tooltip = shroud.11120.a.tt
		if = {
			limit = {
				has_country_flag = broke_covenant
			}
			tooltip = {
				add_modifier = {
					modifier = covenant_broken_modifier
					years = 10
				}
			}
		}
	}
}

country_event = {
	id = shroud.11130
	title = shroud.11130.title
	desc = {
		trigger = {
			text = shroud.11130.desc_common
			if = {
				limit = { has_country_flag = patron_premature_revenge }
				text = newline
				text = shroud.11130.desc_success
			}
		}
	}
	is_triggered_only = yes
	location = event_target:revenge_avatar

	inline_script = {
		script = shroud/patron_revenge_event_picture
		DEFAULT_PICTURE = GFX_evt_shroud_whisperers_in_the_void
	}

	immediate = {
		event_target:patron_revenge_spawn@root = {
			solar_system = {
				save_event_target_as = spawn_system
			}
		}
		create_country = {
			name = "NAME_Betrayed_Patron_Country"
			type = faction
			effect = {
				set_country_flag = revengeful_patron
				set_policy = {
					policy = orbital_bombardment_accept_surrender
					option = orbital_bombardment_surrender_forbidden
					cooldown = yes
				}
				every_playable_country = {
					establish_communications_no_message = prev
				}
				create_fleet = {
					name = "NAME_Psionic_Avatar"
					settings = {
						can_upgrade = no
						can_change_composition = no
						can_change_leader = no
						uses_naval_capacity = no
						spawn_debris = no
						is_boss = yes
					}
					effect = {
						set_owner = prev
						set_fleet_flag = avatar_fleet
						set_fleet_flag = spawned_for@root
						set_fleet_bombardment_stance = indiscriminate
						create_ship = {
							name = "NAME_Avatar"
							design = "NAME_Shroud_Avatar"
							prefix = no
							upgradable = no
						}
						if = {
							limit = {
								root = {
									has_country_flag = broke_covenant
								}
							}
							add_modifier = {
								modifier = treasoned_revenge_avatar_fleet
							}
						}
						auto_move_to_planet = {
							target = root.capital_scope
							clear_auto_move_on_arrival = no
						}
						set_location = event_target:patron_revenge_spawn@root
						save_event_target_as = revenge_avatar
					}
				}
			}
		}

		if = {
			limit = { has_country_flag = patron_premature_revenge }
			event_target:revenge_avatar = {
				add_modifier = {
					modifier = premature_revenge_avatar_fleet
				}
			}
		}
	}

	option = {
		name = UNFORTUNATE
		if = {
			limit = { has_country_flag = patron_premature_revenge }
			custom_tooltip = shroud.11130.success_tt
		}
	}

	after = {
		remove_country_flag = patron_premature_revenge
	}
}

# This = owner of fleet 1 (combatant)
# From = owner of fleet 2 (destroyed)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
country_event = {
	id = shroud.11135
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = { has_country_flag = revengeful_patron }
	}

	immediate = {
		every_playable_country = {
			limit = {
				fromfromfrom = {
					has_fleet_flag = spawned_for@prev
				}
				exists = event_target:patron_revenge_spawn@this
			}
			event_target:patron_revenge_spawn@this = {
				destroy_ambient_object = this
			}
			clear_global_event_target = event_target:patron_revenge_spawn@this
		}
	}
}

# End of the Cycle marked planet transfer
# This = Planet scope
# From = Country scope (new owner)
# FromFrom = Country scope (previous owner, if any)
carrier_event = {
	id = shroud.11210
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		has_modifier = covenant_shroud_marked
	}

	immediate = {
		remove_modifier = covenant_shroud_marked
	}
}

# The Reckoning has destroyed a ship
# This = owner of ship 1 (combatant)
# From = owner of ship 2 (destroyed)
# FromFrom = ship 1
# FromFromFrom = ship 2
country_event = {
	id = shroud.11220
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		any_playable_country = {
			exists = event_target:the_end_of_the_cycle@this
			root.fromfrom.fleet = {
				is_same_value = event_target:the_end_of_the_cycle@prev
			}
		}
	}

	immediate = {
		root.fromfrom.fleet = {
			change_variable = {
				which = destroyed_ships
				value = 1
			}
		}
		update_reckoning_event_chains = {
			RECKONING = root.fromfrom.fleet
		}
	}
}

# The Reckoning: A Sudden Ending
country_event = {
	id = shroud.11225
	title = shroud.11225.title
	desc = {
		trigger = {
			if = {
				limit = { has_country_flag = eotc_destruction_mitigated }
				text = shroud.11225.desc.mitigated
			}
			else = {
				text = shroud.11225.desc.default
			}
		}
	}
	picture = GFX_evt_shroud_end_of_the_cycle
	show_sound = event_end_of_the_cycle
	is_triggered_only = yes

	option = {
		name = shroud.11225.a
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier3materialreward
			min = @tier3materialmin
			max = @tier3materialmax
		}
		add_modifier = { modifier = survivors_of_the_end_modifier }
	}
}

# The Reckoning integrity update
country_event = {
	id = shroud.11230
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		has_shroud_dlc = yes
		has_event_chain = the_reckoning_chain
		exists = event_target:the_end_of_the_cycle@root
	}

	immediate = {
		# Update own reckoning event chain
		reset_event_chain_counter = {
			event_chain = the_reckoning_chain
			counter = reckoning_integrity
		}
		add_event_chain_counter = {
			event_chain = the_reckoning_chain
			counter = reckoning_integrity
			amount = event_target:the_end_of_the_cycle@root.trigger:fleet_integrity
		}
		# Update other countries observer chains
		every_country = {
			limit = {
				has_event_chain = the_reckoning_observer_chain
				OR = {
					NOT = { exists = event_target:the_end_of_the_cycle@this }
					AND = {
						exists = event_target:the_end_of_the_cycle@this
						event_target:the_end_of_the_cycle@root = {
							NOT = { is_same_value = event_target:the_end_of_the_cycle@prev }
						}
					}
				}
			}
			reset_event_chain_counter = {
				event_chain = the_reckoning_observer_chain
				counter = reckoning_integrity
			}
			add_event_chain_counter = {
				event_chain = the_reckoning_observer_chain
				counter = reckoning_integrity
				amount = event_target:the_end_of_the_cycle@root.trigger:fleet_integrity
			}
		}
	}
}

# The Reckoning has come special project reward
country_event = {
	id = shroud.11235
	title = shroud.11235.title
	desc = shroud.11235.desc
	picture = GFX_evt_unspeakable_horror
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	option = {
		name = shroud.11235.a
		add_modifier = { modifier = reckoning_insight_modifier }
	}
}

# It Must Have a Weakness
country_event = {
	id = shroud.11240
	title = shroud.11240.title
	desc = shroud.11240.desc
	picture = GFX_evt_exploding_ship
	show_sound = event_ship_explosion
	is_triggered_only = yes

	trigger = {
		is_ai = no
		has_shroud_dlc = yes
		exists = event_target:the_reckoning_country
		from = {
			is_same_value = event_target:the_reckoning_country
		}
		NOT = { has_country_flag = battle_lost_against_reckoning }
	}

	immediate = {
		set_country_flag = battle_lost_against_reckoning
	}

	option = {
		name = shroud.11240.a
		enable_special_project = {
			name = "RECKONING_VULNERABILITY_PROJECT"
			location = capital_scope
			owner = ROOT
		}
	}
}

# It Must Have a Weakness special project reward
country_event = {
	id = shroud.11245
	title = shroud.11245.title
	desc = {
		trigger = {
			text = shroud.11245.desc.1
			text = newline
			if = {
				limit = {
					is_psionic = yes
				}
				text = shroud.11245.desc.2.psionic
			}
			else = {
				text = shroud.11245.desc.2.non_psionic
			}
		}
	}
	picture = GFX_evt_ship_travel
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	option = {
		name = {
			trigger = {
				if = {
					limit = {
						is_gestalt = yes
					}
					text = FORTUITOUS
				}
				else = {
					text = BREAKTHROUGH
				}
			}
		}
		add_modifier = { modifier = reckoning_vulnerability_modifier }
	}
}

# The End of the Cycle - Exiled event
country_event = {
	id = shroud.11250
	title = shroud.11250.title
	diplomatic_title = shroud.3.diplo_title
	desc = shroud.11250.desc

	is_triggered_only = yes
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = no_video_feed_room
	}

	trigger = {
		has_covenant = end_of_the_cycle
		OR = {
			NOT = { has_origin = origin_endbringers }
			check_variable = {
				which = endbringers_delve_count_variable
				value > 3
			}
		}
	}

	option = {
		name = shroud.11250.a
		custom_tooltip = exit.shroud.tooltip
		hidden_effect = {
			add_modifier = { modifier = reduce_next_delve_cooldown }
		}
	}
}

# The End of the Cycle - Exile outpost rebuilt
carrier_event = {
	id = shroud.11255
	title = shroud.11255.title
	desc = shroud.11255.desc
	picture = GFX_evt_megastructure_construction
	show_sound = event_construction
	location = root

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		tooltip = {
			solar_system = {
				create_starbase = {
					size = starbase_outpost
					owner = root.owner
				}
			}
		}
	}

	after = {
		hidden_effect = {
			solar_system = {
				create_starbase = {
					size = starbase_outpost
					owner = root.owner
				}
				if = {
					limit = { root.owner = { is_specialist_subject_type = { TYPE = bulwark } } }
					starbase = {
						add_starbase_component = {
							component = "STARBASE_AURA_BULWARK_ARRAY"
						}
					}
				}
			}
		}
	}
}

# The End of the Cycle - Nomad Capital Arkship rebuilt
country_event = {
	id = shroud.11260
	title = shroud.11260.title
	desc = shroud.11260.desc
	picture = GFX_evt_arkship_in_orbit
	show_sound = event_construction
	location = root

	is_triggered_only = yes

	# The Arkship is built here rather than in reckoning_spawn because firing an event restarts the scripted effect post-init pass count, and reckoning_spawn is already at the engine limit of 5.
	immediate = {
		if = {
			limit = { has_country_flag = starting_science_arkship }
			reckoning_spawn_rebirth_arkship_effect = { ARKSHIP_TYPE = science }
		}
		else_if = {
			limit = { has_country_flag = starting_military_arkship }
			reckoning_spawn_rebirth_arkship_effect = { ARKSHIP_TYPE = military }
		}
		else = {
			if = {
				limit = { NOT = { has_technology = tech_civilian_arkship } }
				give_technology = { tech = tech_civilian_arkship message = no }
				refresh_auto_generated_ship_designs = yes
			}
			reckoning_spawn_rebirth_arkship_effect = { ARKSHIP_TYPE = civilian }
		}
	}

	option = {
		name = EXCELLENT
	}
}

#==================================
# 12000-13000 Shroud Leaders
#==================================

# Roll for shroud leader acquisition
country_event = {
	id = shroud.12000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		has_breached_shroud = yes
	}

	immediate = {
		if = {
			limit = { has_covenant_with_end_of_the_cycle = yes }
			if = {
				limit = {
					NOR = {
						has_global_flag = eotc_leader_found
						has_country_flag = eotc_leader_found
					}
				}
				random = {
					chance = 3
					set_global_flag = eotc_leader_found
					country_event = { id = shroud.12060 }
					set_country_flag = eotc_leader_found
				}
			}
		}
		else = {
			if = {
				limit = {
					NOR = {
						has_global_flag = cradle_leader_found
						has_country_flag = cradle_leader_found
					}
					has_patron_relation = { patron = the_cradle_of_souls }
					is_in_domain = the_cradle_of_souls
					has_covenant_with_the_composer_of_strands = no
					has_covenant_with_the_eater_of_worlds = no
					has_covenant_with_the_instrument_of_desire = no
					has_covenant_with_whisperers_in_the_void = no
					is_homicidal = no
				}
				random = {
					chance = value:calc_patron_paragon_roll_chance|PATRON|the_cradle_of_souls|
					set_global_flag = cradle_leader_found
					country_event = { id = shroud.12010 }
					set_country_flag = cradle_leader_found
					break = yes
				}
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = eater_leader_found
						has_country_flag = eater_leader_found
					}
					has_patron_relation = { patron = the_eater_of_worlds }
					is_in_domain = the_eater_of_worlds
					has_covenant_with_the_composer_of_strands = no
					has_covenant_with_the_cradle_of_souls = no
					has_covenant_with_the_instrument_of_desire = no
					has_covenant_with_whisperers_in_the_void = no
					NOT = { has_valid_civic = civic_hive_devouring_swarm }
				}
				random = {
					chance = value:calc_patron_paragon_roll_chance|PATRON|the_eater_of_worlds|
					set_global_flag = eater_leader_found
					country_event = { id = shroud.12020 }
					set_country_flag = eater_leader_found
					break = yes
				}
			}
			if = {
				limit = {
					NOT = {
						has_global_flag = instrument_leader_found
						has_country_flag = instrument_leader_found
					}
					has_patron_relation = { patron = the_instrument_of_desire }
					is_in_domain = the_instrument_of_desire
					has_covenant_with_the_composer_of_strands = no
					has_covenant_with_the_cradle_of_souls = no
					has_covenant_with_the_eater_of_worlds = no
					has_covenant_with_whisperers_in_the_void = no
					is_homicidal = no
				}
				random = {
					chance = value:calc_patron_paragon_roll_chance|PATRON|the_instrument_of_desire|
					set_global_flag = instrument_leader_found
					country_event = { id = shroud.12030 }
					set_country_flag = instrument_leader_found
					break = yes
				}
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = composer_leader_found
						has_country_flag = composer_leader_found
					}
					has_patron_relation = { patron = the_composer_of_strands }
					is_in_domain = the_composer_of_strands
					has_covenant_with_the_instrument_of_desire = no
					has_covenant_with_the_cradle_of_souls = no
					has_covenant_with_the_eater_of_worlds = no
					has_covenant_with_whisperers_in_the_void = no
					is_homicidal = no
				}
				random = {
					chance = value:calc_patron_paragon_roll_chance|PATRON|the_composer_of_strands|
					set_global_flag = composer_leader_found
					country_event = { id = shroud.12040 }
					set_country_flag = composer_leader_found
					break = yes
				}
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = whisperers_leader_found
						has_country_flag = whisperers_leader_found
					}
					has_patron_relation = { patron = whisperers_in_the_void }
					is_in_domain = whisperers_in_the_void
					has_covenant_with_the_instrument_of_desire = no
					has_covenant_with_the_cradle_of_souls = no
					has_covenant_with_the_eater_of_worlds = no
					has_covenant_with_the_composer_of_strands = no
					is_homicidal = no
					is_gestalt = no
				}
				random = {
					chance = value:calc_patron_paragon_roll_chance|PATRON|whisperers_in_the_void|
					set_global_flag = whisperers_leader_found
					country_event = { id = shroud.12050 }
					set_country_flag = whisperers_leader_found
					break = yes
				}
			}
		}
	}
}

# Ganthuata
country_event = {
	id = shroud.12010
	title = shroud.12010.name
	desc = shroud.12010.desc
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_05
			SPECIES_CLASS = ART
			CLASS = official
			NAME = ganthuata
			LEVEL = 8
			AGE = 40
			GENDER = male
			ETHIC = xenophile
			DESC = ganthuata_desc
			CATCH_PHRASE = ganthuata_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_official_diplomacy_councilor consume_selection = yes }
			add_trait = { trait = leader_trait_principled_2 consume_selection = yes }
			add_trait = { trait = leader_trait_spycraft consume_selection = yes }
			add_trait = { trait = leader_trait_ambassador_ear_to_the_ground_2 consume_selection = yes }
			add_trait = { trait = leader_trait_ambassador_extra_envoys_2 consume_selection = yes }
			add_trait = { trait = leader_trait_overseer consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_cradle consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = cradle_leader_found
			event_target:shroud_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}
	option = {
		name = shroud.12010.a
		response_text = shroud.12010.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12010.b
		response_text = shroud.12010.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12010.c
		response_text = shroud.12010.c.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12010.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = ganthuata
			}
		}
	}
}

# Koborok'Ra
country_event = {
	id = shroud.12020
	title = shroud.12020.name
	desc = {
		trigger = { has_covenant_with_the_eater_of_worlds = yes }
		text = shroud.12020.desc.covenant
	}
	desc = {
		trigger = { has_covenant_with_the_eater_of_worlds = no }
		text = shroud.12020.desc.no_covenant
	}
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_10
			SPECIES_CLASS = HUM
			CLASS = commander
			NAME = koborokra
			LEVEL = 8
			AGE = 35
			GENDER = male
			ETHIC = militarist
			DESC = koborokra_desc
			CATCH_PHRASE = koborokra_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_commander_admiral consume_selection = yes }
			add_trait = { trait = leader_trait_butcher consume_selection = yes }
			add_trait = { trait = leader_trait_aggressive consume_selection = yes }
			add_trait = { trait = leader_trait_commanding_presence_2 consume_selection = yes }
			add_trait = { trait = leader_trait_juryrigger consume_selection = yes }
			add_trait = { trait = leader_trait_corsair_2 consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_eater consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = eater_leader_found
			event_target:shroud_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}
	option = {
		name = shroud.12020.a
		response_text = shroud.12020.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12020.b
		response_text = shroud.12020.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12020.c
		response_text = shroud.12020.c.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12020.d
		response_text = shroud.12020.d.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12020.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = koborokra
			}
		}
	}
}

# Morr
country_event = {
	id = shroud.12030
	title = shroud.12030.name
	desc = shroud.12030.desc
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_04
			SPECIES_CLASS = AQUATIC
			CLASS = official
			NAME = morr
			LEVEL = 8
			AGE = 32
			GENDER = female
			ETHIC = authoritarian
			DESC = morr_desc
			CATCH_PHRASE = morr_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_official_governor consume_selection = yes }
			add_trait = { trait = leader_trait_intellectual consume_selection = yes }
			add_trait = { trait = leader_trait_trade_focus_2 consume_selection = yes }
			add_trait = { trait = leader_trait_pop_focused consume_selection = yes }
			add_trait = { trait = leader_trait_distribution_lines_2 consume_selection = yes }
			add_trait = { trait = leader_trait_refinement_focus_2 consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_instrument consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = instrument_leader_found
			event_target:shroud_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}
	option = {
		name = shroud.12030.a
		response_text = shroud.12030.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12030.b
		response_text = shroud.12030.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12030.c
		response_text = shroud.12030.c.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12030.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = morr
			}
		}
	}
}

# Kronen the Afflicted
country_event = {
	id = shroud.12040
	title = shroud.12040.name
	desc = shroud.12040.desc
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_01
			SPECIES_CLASS = MOL
			CLASS = scientist
			NAME = kronen
			LEVEL = 8
			AGE = 32
			GENDER = indeterminable
			ETHIC = materialist
			DESC = kronen_desc
			CATCH_PHRASE = kronen_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_scientist_governor consume_selection = yes }
			add_trait = { trait = leader_trait_traumatized consume_selection = yes }
			add_trait = { trait = leader_trait_melancholic_2 consume_selection = yes }
			add_trait = { trait = leader_trait_society_focus_3 consume_selection = yes }
			add_trait = { trait = leader_trait_expertise_psionics_2 consume_selection = yes }
			add_trait = { trait = leader_trait_environmental_engineer consume_selection = yes }
			add_trait = { trait = leader_trait_bureaucrat consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_composer consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = composer_leader_found
			event_target:shroud_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}
	option = {
		name = shroud.12040.a
		response_text = shroud.12040.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12040.b
		response_text = shroud.12040.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12040.c
		response_text = shroud.12040.c.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12040.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = kronen
			}
		}
	}
}

# from = kronen leader
country_event = {
	id = shroud.12045
	title = leader_trait_disciple_of_the_composer
	diplomatic_title = kronen
	desc = shroud.12045.desc
	picture = GFX_leader_recruitment_bg_renowned

	diplomatic = yes
	is_triggered_only = yes
	event_window_type = leader_conversation
	force_open = yes

	picture_event_data = {
		portrait = from
		room = root
		planet_background = root
		graphical_culture = root
		city_level = root
	}

	trigger = {
		from = {
			has_trait = leader_trait_disciple_of_the_composer
		}
	}

	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}

	option = {
		name = shroud.12045.a
		trigger = {
			from = {
				NAND = {
					has_leader_flag = leader_second_dialogue_option_selected
					has_leader_flag = leader_third_dialogue_option_selected
				}
			}
		}
		response_text = shroud.12045.a.response
		is_dialog_only = yes
		from = { set_leader_flag = leader_first_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.a
		trigger = {
			from = {
				has_leader_flag = leader_second_dialogue_option_selected
				has_leader_flag = leader_third_dialogue_option_selected
			}
		}
		response_text = shroud.12045.a.response_2
		is_dialog_only = yes
		from = { set_leader_flag = leader_first_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.b
		trigger = {
			from = {
				NAND = {
					has_leader_flag = leader_first_dialogue_option_selected
					has_leader_flag = leader_third_dialogue_option_selected
				}
			}
		}
		response_text = shroud.12045.b.response
		is_dialog_only = yes
		from = { set_leader_flag = leader_second_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.b
		trigger = {
			from = {
				has_leader_flag = leader_first_dialogue_option_selected
				has_leader_flag = leader_third_dialogue_option_selected
			}
		}
		response_text = shroud.12045.b.response_2
		is_dialog_only = yes
		from = { set_leader_flag = leader_second_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.c
		trigger = {
			from = {
				NAND = {
					has_leader_flag = leader_first_dialogue_option_selected
					has_leader_flag = leader_second_dialogue_option_selected
				}
			}
		}
		response_text = shroud.12045.c.response
		is_dialog_only = yes
		from = { set_leader_flag = leader_third_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.c
		trigger = {
			from = {
				has_leader_flag = leader_first_dialogue_option_selected
				has_leader_flag = leader_second_dialogue_option_selected
			}
		}
		response_text = shroud.12045.c.response_2
		is_dialog_only = yes
		from = { set_leader_flag = leader_third_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.d
		trigger = {
			from = {
				has_leader_flag = leader_first_dialogue_option_selected
				has_leader_flag = leader_second_dialogue_option_selected
				has_leader_flag = leader_third_dialogue_option_selected
			}
		}
		response_text = shroud.12045.d.response
		is_dialog_only = yes
		from = { set_leader_flag = leader_last_dialogue_option_selected }
	}
	option = {
		name = shroud.12045.end
		trigger = {
			from = { has_leader_flag = leader_last_dialogue_option_selected }
		}
		default_hide_option = yes
		from = {
			add_trait = {
				trait = leader_trait_disciple_of_the_composer_2
			}
		}
	}
	option = { # Permanent exit option
		name = GOODBYE
		trigger = {
			from = { NOT = { has_leader_flag = leader_last_dialogue_option_selected } }
		}
		default_hide_option = yes
		from = {
			add_trait = {
				trait = leader_trait_disciple_of_the_composer_2
			}
		}
	}

	after = {
		from = {
			remove_leader_flag = leader_first_dialogue_option_selected
			remove_leader_flag = leader_second_dialogue_option_selected
			remove_leader_flag = leader_third_dialogue_option_selected
			remove_leader_flag = leader_last_dialogue_option_selected
		}
	}
}

# Zulyn the Listener
country_event = {
	id = shroud.12050
	title = shroud.12050.name
	desc = shroud.12050.desc
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_02
			SPECIES_CLASS = FUN
			CLASS = scientist
			NAME = zulyn
			LEVEL = 8
			AGE = 38
			GENDER = indeterminable
			ETHIC = xenophile
			DESC = zulyn_desc
			CATCH_PHRASE = zulyn_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_scientist_scholar consume_selection = yes }
			add_trait = { trait = leader_trait_carefree_2 consume_selection = yes }
			add_trait = { trait = leader_trait_spark_of_genius_2 consume_selection = yes }
			add_trait = { trait = leader_trait_academic_dig_site_expert_2 consume_selection = yes }
			add_trait = { trait = leader_trait_academic_astral_rift_expert consume_selection = yes }
			add_trait = { trait = leader_trait_expertise_psionics_2 consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_whisperers consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = whisperers_leader_found
			event_target:shroud_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}
	option = {
		name = shroud.12050.a
		response_text = shroud.12050.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12050.b
		response_text = shroud.12050.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12050.c
		response_text = shroud.12050.c.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12050.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = zulyn
			}
		}
	}
}

# Ouw'ron
country_event = {
	id = shroud.12060
	title = shroud.12060.name
	desc = {
		trigger = {
			text = shroud.12060.desc_1
			if = {
				limit = {
					any_owned_leader = {
						has_trait = leader_trait_blinded
					}
				}
				text = shroud.12060.desc_blind
			}
			text = shroud.12060.desc_default
			text = shroud.12060.desc_2
		}
	}
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned

	event_window_type = leader_recruit
	auto_opens = yes

	immediate = {
		shroud_leader_creator = {
			LEADER_PORTRAIT = psionic_08
			SPECIES_CLASS = AVI
			CLASS = commander
			NAME = ouwron
			LEVEL = 8
			AGE = 25
			GENDER = male
			ETHIC = militarist
			DESC = ouwron_desc
			CATCH_PHRASE = ouwron_catch_phrase
		}
		last_created_leader = {
			add_trait = { trait = subclass_commander_admiral consume_selection = yes }
			add_trait = { trait = leader_trait_aggressive consume_selection = yes }
			add_trait = { trait = leader_trait_trickster consume_selection = yes }
			add_trait = { trait = leader_trait_artillerist_2 consume_selection = yes }
			add_trait = { trait = leader_trait_wrecker_2 consume_selection = yes }
			add_trait = { trait = leader_trait_crusader consume_selection = yes }
			add_trait = { trait = leader_trait_disciple_of_the_end consume_selection = yes }
			add_trait = { trait = leader_trait_psionic consume_selection = yes }
		}
	}

	picture_event_data = {
		portrait = event_target:shroud_leader
		room = shroud_room
	}

	option = {
		name = DISMISS
		tag = dismiss_leader
		hidden_effect = {
			remove_global_flag = eotc_leader_found
			country_event = {
				id = shroud.12155
				days = 1
				scopes = { from = event_target:shroud_leader }
			}
		}
	}
	option = {
		name = shroud.12060.a
		response_text = shroud.12060.a.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12060.b
		response_text = shroud.12060.b.response
		is_dialog_only = yes
	}
	option = {
		name = shroud.12060.c
		response_text = shroud.12060.c.response
		is_dialog_only = yes
	}
	option = {
		name = HIRE
		tag = hire_leader
		custom_tooltip = shroud.12060.hire_custom_tooltip
		hidden_effect = {
			shroud_leader_hire_effect = {
				GLOBAL_EVENT_TARGET = ouwron
			}
		}
	}
}

# Disciple of the Eater attunement per combat won
# This = owner of fleet 1 (winner)
# From = owner of fleet 2 (loser)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
country_event = {
	id = shroud.12100
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		fromfrom = {
			exists = leader
			leader = {
				has_trait = leader_trait_disciple_of_the_eater
			}
		}
	}

	immediate = {
		add_attunement = {
			the_eater_of_worlds = @disciple_of_the_eater_combat_attunement
		}
	}
}

# Disciple of the Eater zro per devastation through orbital bombardment
# This = Planet
# From = Bombarder (country)
# local_devastation = variable of daily devastation
carrier_event = {
	id = shroud.12110
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		any_fleet_in_orbit = {
			exists = leader
			leader = {
				has_trait = leader_trait_disciple_of_the_eater
			}
			exists = owner
			owner = { is_same_value = root.from }
		}
	}

	immediate = {
		every_fleet_in_orbit = {
			limit = {
				exists = leader
				leader = {
					has_trait = leader_trait_disciple_of_the_eater
				}
				exists = owner
				owner = { is_same_value = root.from }
			}
			leader = {
				if = {
					limit = {
						NOT = { is_variable_set = eater_fleet_devastation }
					}
					set_variable = {
						which = eater_fleet_devastation
						value = 0
					}
				}
				change_variable = {
					which = eater_fleet_devastation
					value = root.local_devastation
				}
				while = {
					limit = {
						check_variable = {
							which = eater_fleet_devastation
							value >= 1
						}
					}
					owner = {
						add_resource = { sr_zro = @disciple_of_the_eater_zro_fleet_attack }
					}
					subtract_variable = { which = eater_fleet_devastation value = 1 }
				}
			}
		}
	}
}

# Disciple of the Eater zro per devastation through ground combat
# This = Planet
# From = damaging country
# local_devastation = variable of daily devastation
carrier_event = {
	id = shroud.12120
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		any_ground_combat_attacker = {
			exists = leader
			leader = {
				has_trait = leader_trait_disciple_of_the_eater
			}
			exists = owner
			owner = { is_same_value = root.from }
		}
	}

	immediate = {
		every_ground_combat_attacker = {
			limit = {
				exists = leader
				leader = {
					has_trait = leader_trait_disciple_of_the_eater
				}
				exists = owner
				owner = { is_same_value = root.from }
			}
			leader = {
				if = {
					limit = {
						NOT = { is_variable_set = eater_ground_combat_devastation }
					}
					set_variable = {
						which = eater_ground_combat_devastation
						value = 0
					}
				}
				change_variable = {
					which = eater_ground_combat_devastation
					value = root.local_devastation
				}
				while = {
					limit = {
						check_variable = {
							which = eater_ground_combat_devastation
							value >= 1
						}
					}
					owner = {
						add_resource = { sr_zro = @disciple_of_the_eater_zro_army_attack }
					}
					subtract_variable = { which = eater_ground_combat_devastation value = 1 }
				}
			}
		}
	}
}

# Strand Afflicted upgrade
# Root = pop
# From = planet
pop_group_event = {
	id = shroud.12130
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_shroud_dlc = yes
		from = {
			exists = leader
			leader = {
				has_trait = leader_trait_disciple_of_the_composer
				OR = {
					NOT = { is_variable_set = disciple_of_the_composer_pop_growth }
					check_variable = {
						which = disciple_of_the_composer_pop_growth
						value > 0
					}
				}
			}
		}
	}

	immediate = {
		from.leader = {
			if = {
				limit = {
					NOT = { is_variable_set = disciple_of_the_composer_pop_growth }
				}
				set_variable = {
					which = disciple_of_the_composer_pop_growth
					value = @disciple_of_the_composer_pop_threshold
				}
			}
			subtract_variable = {
				which = disciple_of_the_composer_pop_growth
				value = local_pop_amount
			}
			if = {
				limit = {
					check_variable = {
						which = disciple_of_the_composer_pop_growth
						value <= 0
					}
				}
				owner = {
					country_event = {
						id = shroud.12045
						scopes = { from = prev }
					}
				}
			}
		}
	}
}

# Shrouded Whispers zro reward on rare and psionics tech
country_event = {
	id = shroud.12140
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			has_trait = leader_trait_disciple_of_the_whisperers
			is_councilor = yes
		}
	}

	immediate = {
		if = {
			limit = { is_last_increased_tech_rare = yes }
			add_resource = { sr_zro = @disciple_of_the_whisperers_tech_zro }
		}
		if = {
			limit = { is_last_increased_tech_category = psionics }
			add_resource = { sr_zro = @disciple_of_the_whisperers_tech_zro }
		}
	}
}

# Apostle of the End aura intensity reward on ship destroyed in EotC aura
# This = owner of ship 1 (combatant)
# From = owner of ship 2 (destroyed)
# FromFrom = ship 1
# FromFromFrom = ship 2
country_event = {
	id = shroud.12150
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfrom.fleet = {
			exists = leader
			leader = { has_trait = leader_trait_disciple_of_the_end }
			solar_system = {
				has_psionic_aura = end_aura
				aura_owner = { is_same_value = root }
			}
		}
	}

	immediate = {
		fromfrom.fleet.solar_system = {
			add_aura_intensity = @disciple_of_the_end_aura_intensity
		}
	}
}

# from = leader
country_event = {
	id = shroud.12155
	title = shroud.12155.name
	desc = shroud.12155.desc
	show_sound = {
		trigger = { is_robot_empire = yes }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { is_robot_empire = no }
		sound = event_psionic
	}
	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = event_target:apostle_leader
		room = root
		planet_background = root
		graphical_culture = root
		city_level = root
	}

	immediate = {
		from = {
			if = {
				limit = { exists = fleet }
				fleet = { save_event_target_as = spawn_location }
			}
			else = {
				root.capital_scope = { save_event_target_as = spawn_location }
			}
		}
		create_country = {
			name = "name_eotc"
			type = faction
			effect = {
				root = { establish_communications_no_message = prev }
				create_fleet = {
					name = "leader_trait_disciple_of_the_end"
					settings = {
						can_upgrade = no
						can_change_composition = no
						can_change_leader = no
						uses_naval_capacity = no
						spawn_debris = no
					}
					effect = {
						set_owner = prev
						create_ship_design = {
							design = "NAME_Ouwron_Battleship"
						}
						create_ship = {
							design = last_created_design
							graphical_culture = "psionic_01"
						}
						create_ship_design = {
							design = "NAME_Ouwron_Destroyer"
						}
						while = {
							count = 5
							create_ship = {
								design = last_created_design
								graphical_culture = "psionic_01"
							}
						}
						set_location = {
							target = event_target:spawn_location
							distance = 20
							angle = random
						}
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 800
						save_event_target_as = apostle_fleet
						prev = {
							clone_leader = {
								target = root.from
								skip_background_generation = yes
								effect = {
									save_event_target_as = apostle_leader
									event_target:apostle_fleet = {
										assign_leader = prev
									}
									root.from = {
										kill_leader = { show_notification = no }
									}
								}
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = DISMISS
		custom_tooltip = shroud.12155.tt
	}
}

# Galactic community resolution to wage war on a psionic aura
country_event = {
	id = shroud.12160
	title = shroud.12160.title
	desc = shroud.12160.desc
	picture = GFX_evt_galactic_senate
	show_sound = event_announcement
	is_triggered_only = yes

	option = {
		name = shroud.12160.a
	}
}

# Shroud Incursion
country_event = {
	id = shroud.13000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_deficit = sr_zro
		NOT = {
			has_country_flag = shroud_incursion
		}
	}

	immediate = {
		random = {
			chance = 2
			set_timed_country_flag = {
				flag = shroud_incursion
				days = 720 # 2 years
			}
			country_event = { id = utopia.3024 }
		}
	}
}
