#Synth Queen
#crisis.8000-8999 - Spawning and Player Facing Events
#crisis.9000-9999 - Player Situation
#crisis.10000-10999 - Hidden Queen Events and Retalitations
#crisis.20000-25000 - Player Investigations

#########################
#						#
# Cosmogenesis Events	#
#	 					#
#########################

namespace = crisis

country_event = { # Taking the AP - Start level 1
	id = crisis.7100
	title = "crisis.7100.name"
	desc = crisis.7100.desc
	picture = GFX_evt_cosmogenesis_crisis
	show_sound = event_death_cult
	is_triggered_only = yes
	event_chain = cosmogenesis_chain

	option = {
		name = crisis.7100.a
		begin_event_chain = {
			event_chain = cosmogenesis_chain
			target = root
		}
		add_event_chain_counter = {
			event_chain = "cosmogenesis_chain"
			counter = "cosmogenesis_level_reached"
			amount = 1
		}
		custom_tooltip = new_cosmogenesis_tech_tt
	}
}

country_event = { # Reaching Level 2
	id = crisis.7105
	title = "crisis.7105.name"
	desc = crisis.7105.desc
	picture = GFX_evt_synaptic_lathe
	show_sound = event_death_cult
	event_chain = cosmogenesis_chain

	is_triggered_only = yes

	immediate = {
		add_event_chain_counter = {
			event_chain = "cosmogenesis_chain"
			counter = "cosmogenesis_level_reached"
			amount = 1
		}
	}

	option = {
		name = crisis.7105.a
		custom_tooltip = new_cosmogenesis_tech_tt
	}
}

country_event = { # Reaching Level 3
	id = crisis.7110
	title = "crisis.7110.name"
	desc = crisis.7110.desc
	picture = GFX_evt_black_hole
	show_sound = event_death_cult
	event_chain = cosmogenesis_chain

	is_triggered_only = yes

	immediate = {
		add_event_chain_counter = {
			event_chain = "cosmogenesis_chain"
			counter = "cosmogenesis_level_reached"
			amount = 1
		}
	}

	option = {
		name = crisis.7110.a
		custom_tooltip = new_cosmogenesis_tech_tt
	}

	after = {
		hidden_effect = {
			random_country = {
				limit = {
					OR = {
						is_country_type = fallen_empire
						is_country_type = awakened_fallen_empire
					}
					is_fanatic_materialist = yes
				}
				save_event_target_as = materialist_fe
			}
			country_event = { id = crisis.7111 days = 7 }
		}
	}
}

country_event = {
	id = crisis.7111
	title = TRANSMISSION
	desc = crisis.7111.desc

	picture_event_data = {
		portrait = event_target:materialist_fe
		planet_background = event_target:materialist_fe
		graphical_culture = event_target:materialist_fe
		city_level = event_target:materialist_fe
		room = event_target:materialist_fe
	}

	diplomatic = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		exists = event_target:materialist_fe
	}

	option = {
		name = fallen_empires_awakening.2.b
		event_target:materialist_fe = {
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = root
			}
		}
	}

	option = {
		name = crisis.7111.b
		add_modifier = {
			modifier = cosmogenesis_sorry
			days = 1800
		}
	}
}

country_event = { # Reaching Level 4
	id = crisis.7115
	title = "crisis.7115.name"
	desc = crisis.7115.desc
	picture = GFX_evt_cosmogenesis_crisis
	show_sound = event_death_cult
	event_chain = cosmogenesis_chain

	is_triggered_only = yes

	immediate = {
		add_event_chain_counter = {
			event_chain = "cosmogenesis_chain"
			counter = "cosmogenesis_level_reached"
			amount = 1
		}
	}

	option = {
		name = crisis.7115.a
		custom_tooltip = new_cosmogenesis_tech_tt
	}
}

country_event = { # Reaching Level 5
	id = crisis.7120
	title = "crisis.7120.name"
	desc = crisis.7120.desc
	picture = GFX_evt_cosmogenesis_crisis
	show_sound = event_death_cult
	event_chain = cosmogenesis_chain

	is_triggered_only = yes

	immediate = {
		add_event_chain_counter = {
			event_chain = "cosmogenesis_chain"
			counter = "cosmogenesis_level_reached"
			amount = 1
		}
	}

	option = {
		name = crisis.7120.a
		custom_tooltip = new_cosmogenesis_tech_tt
	}

	after = {
		# TOTAL WAR TIME
		every_country = {
			limit = {
				is_country_type = fallen_empire
				NOT = {
					is_at_war_with = root
				}
			}
			declare_war = {
				target = root
				name = cosmogenesis_materialist_war
				attacker_war_goal = wg_end_threat
			}
		}
	}
}

country_event = { # Researching Horizon Needle
	id = crisis.7125
	title = "crisis.7125.name"
	desc = crisis.7125.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_death_cult
	event_chain = cosmogenesis_chain

	is_triggered_only = yes

	trigger = {
		last_increased_tech = tech_cosmogenesis_crisis_5
		has_ascension_perk = ap_cosmogenesis
	}

	option = {
		name = crisis.7125.a
		custom_tooltip = needle_to_win_tt
	}
}


#### THESES ####

country_event = { # Thesis effect randomizer
	id = crisis.7200
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		has_ascension_perk = ap_cosmogenesis
		last_increased_tech = tech_cosmogenesis_thesis
	}

	immediate = {
		random_list = {
			2 = { #Blackout
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_blackout
				}
				set_country_flag = cosmogenesis_thesis_blackout_initiator
				every_playable_country = {
					country_event = { id = crisis.7205 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_blackout
				set_theses_flags = yes
			}
			2 = { #Constant Rounding
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_constant
				}
				set_country_flag = cosmogenesis_thesis_constant_initiator
				every_playable_country = {
					country_event = { id = crisis.7210 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_constant
				set_theses_flags = yes
			}
			1 = { #Superlight
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_superlight
				}
				set_country_flag = cosmogenesis_thesis_superlight_initiator
				every_playable_country = {
					country_event = { id = crisis.7215 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_superlight
				set_theses_flags = yes
			}
			1 = { #Alloy Ductility - Good
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_alloy_ductility
				}
				set_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
				every_playable_country = {
					country_event = { id = crisis.7235 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_alloy_ductility
				set_theses_flags = yes
			}
			1 = { #Alloy Ductility - Bad
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_alloy_ductility
				}
				set_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
				every_playable_country = {
					country_event = { id = crisis.7240 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_alloy_ductility
				set_theses_flags = yes
			}
			1 = { #Altered Nutrition - Good
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_altered_nutrition
				}
				set_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
				every_playable_country = {
					country_event = { id = crisis.7245 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_altered_nutrition
				set_theses_flags = yes
			}
			1 = { #Altered Nutrition - Bad
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_altered_nutrition
				}
				set_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
				every_playable_country = {
					country_event = { id = crisis.7250 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_altered_nutrition
				set_theses_flags = yes
			}
			2 = { #Mass Shift
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_mass_shift
				}
				set_country_flag = cosmogenesis_thesis_mass_shift_initiator
				every_playable_country = {
					country_event = { id = crisis.7255 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_mass_shift
				set_theses_flags = yes
			}
			2 = { #Shroud Tears
				modifier = {
					factor = 0
					has_global_flag = cosmogenesis_thesis_shroud_tear
				}
				set_country_flag = cosmogenesis_thesis_shroud_tear_initiator
				every_playable_country = {
					country_event = { id = crisis.7260 days = 1 }
				}
				set_global_flag = cosmogenesis_thesis_shroud_tear
				set_theses_flags = yes
			}
			4 = { #Filler - Good
				country_event = { id = crisis.7265 days = 1 }
			}
			8 = { # Filler - Bad
				modifier = { #Reduce the likelihood of bad outcome if you know more about what you're doing
					add = -2
					resource_stockpile_compare = {
						resource = advanced_logic
						value >= 17000
					}
				}
				modifier = {
					add = -2
					resource_stockpile_compare = {
						resource = advanced_logic
						value >= 21000
					}
				}
				modifier = {
					add = -2
					resource_stockpile_compare = {
						resource = advanced_logic
						value >= 26000
					}
				}
				country_event = { id = crisis.7270 days = 1 }
			}
		}
		change_variable = {
			which = applied_infinity_thesis
			value = +1
		}
		random_country = {
			limit = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
				is_fanatic_materialist = yes
			}
			if = {
				limit = {
					has_country_flag = warned_by_materialist_fe
					NOT = { has_origin = origin_scion }
				}
				add_opinion_modifier = {
					modifier = opinion_cosmogenesis_thesis
					who = root
				}
			}

			random_list = {
				99 = { }
				1 = {
					modifier = {
						factor = 0
						any_country = {
							has_country_flag = guardians_of_the_galaxy
						}
					}
					modifier = {
						factor = 0
						count_country = {
							count = 0
							limit = {
								OR = {
									is_country_type = fallen_empire
									is_country_type = awakened_fallen_empire
								}
							}
						}
					}
					awaken_guardians_of_the_galaxy = yes
				}
			}
			save_event_target_as = materialist_fe
		}
		country_event = { id = crisis.7285 days = 30 }
	}
}

country_event = { # Thesis: Blackout FROM = crisis country
	id = crisis.7205
	title = "crisis.7205.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_blackout_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7205.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_blackout_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7205.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_blackout_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7205.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_blackout_initiator
		}
		text = crisis.7205.desc.crisis
	}

	picture = GFX_evt_worrying_signal
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7205.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		if = {
			limit = {
				has_first_contact_dlc = yes
			}
			add_modifier = {
				modifier = cosmogenesis_blackout_first_contact
				years = 3
			}
		}
		else = {
			add_modifier = {
				modifier = cosmogenesis_blackout
				years = 3
			}
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7205.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_blackout_initiator }
		}
		if = {
			limit = {
				has_first_contact_dlc = yes
			}
			add_modifier = {
				modifier = cosmogenesis_blackout_first_contact
				years = 3
			}
		}
		else = {
			add_modifier = {
				modifier = cosmogenesis_blackout
				years = 3
			}
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7205.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_blackout_initiator
		}
		if = {
			limit = {
				has_first_contact_dlc = yes
			}
			add_modifier = {
				modifier = cosmogenesis_blackout_first_contact
				years = 3
			}
		}
		else = {
			add_modifier = {
				modifier = cosmogenesis_blackout
				years = 3
			}
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Constant FROM = crisis country
	id = crisis.7210
	title = "crisis.7210.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_constant_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7210.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_constant_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7210.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_constant_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7210.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_constant_initiator
		}
		text = crisis.7210.desc.crisis
	}

	picture = GFX_evt_cosmogenesis_crisis
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7210.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_constant
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7210.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_constant_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_constant
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7210.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_constant_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_constant
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Superlight FROM = crisis country
	id = crisis.7215
	title = "crisis.7215.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_superlight_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7215.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_superlight_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7215.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_superlight_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7215.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_superlight_initiator
		}
		text = crisis.7215.desc.crisis
	}

	picture = GFX_evt_supernova
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7215.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_superlight
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7215.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_superlight_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_superlight
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7215.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_superlight_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_superlight
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.7220 days = 60 random = 10 }
		}
	}
}

country_event = { # Tyranny of the suns - Planets start burning down
	id = crisis.7220
	title = "crisis.7220.name"
	desc = crisis.7220.desc
	picture = GFX_evt_resource_cache
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = {
		trigger = {
			is_nomadic = no
		}
		name = crisis.7220.a
		every_owned_planet = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_1
				days = 360
			}
			add_planet_devastation = 20
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROM
					}
				}
				has_communications = FROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
		hidden_effect = {
			every_planet_within_border = {
				limit = {
					solar_system.star = {
						NOT = { is_star_class = sc_black_hole }
					}
					OR = {
						is_pre_ftl_colony_type = yes
						AND = {
							NOT = { exists = owner }
							is_a_habitable_planet_megastructure = yes
						}
					}
				}
				add_modifier = {
					modifier = cosmogenesis_superlight_planet_1
					days = 360
				}
			}
		}
	}

	option = {
		trigger = {
			is_nomadic = yes
		}
		name = crisis.7220.b
		every_owned_colony = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_1
				days = 360
			}
			add_planet_devastation = 20
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROM
					}
				}
				has_communications = FROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}


	after = {
		hidden_effect = {
			country_event = { id = crisis.7225 days = 351 random = 20 }
		}
	}
}

country_event = { # Tyranny of the suns - it gets worse
	id = crisis.7225
	title = "crisis.7225.name"
	desc = crisis.7225.desc
	picture = GFX_evt_warm_barren
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = {
		trigger = {
			is_nomadic = no
		}
		name = crisis.7225.a
		every_owned_planet = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_2
				days = 330
			}
			add_planet_devastation = 50
		}
		random_owned_planet = {
			limit = {
				is_dry = yes
			}
			weights = {
				base = 1
				modifier = {
					factor = 0.1
					is_capital = yes
				}
			}
			change_pc = pc_barren
			hidden_effect = {
				destroy_colony = yes
				add_modifier = {
					modifier = terraforming_candidate
					days = -1
				}
			}
		}
		random_owned_planet = {
			limit = {
				is_dry = no
				is_artificial = no
			}
			change_pc = pc_desert
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROMFROM
					}
				}
				has_communications = FROMFROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
		hidden_effect = {
			every_planet_within_border = {
				limit = {
					solar_system.star = {
						NOT = { is_star_class = sc_black_hole }
					}
					OR = {
						is_pre_ftl_colony_type = yes
						AND = {
							NOT = { exists = owner }
							is_a_habitable_planet_megastructure = yes
						}
					}
				}
				add_modifier = {
					modifier = cosmogenesis_superlight_planet_2
					days = 360
				}
			}
		}
	}

	option = {
		trigger = {
			is_nomadic = yes
		}
		name = crisis.7225.b
		every_owned_colony = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_2
				days = 330
			}
			add_planet_devastation = 50
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROMFROM
					}
				}
				has_communications = FROMFROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.7230 days = 331 }
		}
	}
}

country_event = { # Tyranny of the suns - it subsides
	id = crisis.7230
	title = "crisis.7230.name"
	desc = crisis.7230.desc
	picture = GFX_evt_relic_world_street
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = {
		trigger = {
			is_nomadic = no
		}
		name = crisis.7230.a
		every_owned_planet = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_1
				days = 250
			}
			add_planet_devastation = 20
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROMFROMFROM
					}
				}
				has_communications = FROMFROMFROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROMFROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROMFROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
		hidden_effect = {
			every_planet_within_border = {
				limit = {
					solar_system.star = {
						NOT = { is_star_class = sc_black_hole }
					}
					OR = {
						is_pre_ftl_colony_type = yes
						AND = {
							NOT = { exists = owner }
							is_a_habitable_planet_megastructure = yes
						}
					}
				}
				add_modifier = {
					modifier = cosmogenesis_superlight_planet_1
					days = 360
				}
			}
		}
	}

	option = {
		trigger = {
			is_nomadic = yes
		}
		name = crisis.7230.b
		every_owned_colony = {
			limit = {
				solar_system.star = {
					NOT = { is_star_class = sc_black_hole }
				}
			}
			add_modifier = {
				modifier = cosmogenesis_superlight_planet_1
				days = 250
			}
			add_planet_devastation = 20
		}
		if = {
			limit = {
				NOT = {
					root = {
						is_same_value = FROMFROMFROMFROM
					}
				}
				has_communications = FROMFROMFROMFROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROMFROMFROMFROM
			}
		}
		else_if = {
			limit = {
				is_same_value = FROMFROMFROMFROM
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Alloy Ductility - Good FROM = crisis country
	id = crisis.7235
	title = "crisis.7235.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7235.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7235.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7235.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
		}
		text = crisis.7235.desc.crisis
	}

	picture = GFX_evt_engineering_research
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7235.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7235.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7235.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Alloy Ductility - Bad FROM = crisis country
	id = crisis.7240
	title = "crisis.7240.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7240.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7240.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7240.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
		}
		text = crisis.7240.desc.crisis
	}

	picture = GFX_evt_collapsing_roof
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7240.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility_bad
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7240.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility_bad
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7240.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_alloy_ductility_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_alloy_ductility_bad
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Altered Nutrition - Good FROM = crisis country
	id = crisis.7245
	title = "crisis.7245.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7245.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7245.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7245.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
		}
		text = crisis.7245.desc.crisis
	}

	picture = GFX_evt_astral_rift_garden_2
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7245.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7245.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7245.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Altered Nutrition - Bad FROM = crisis country
	id = crisis.7250
	title = "crisis.7250.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7250.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7250.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7250.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
		}
		text = crisis.7250.desc.crisis
	}

	picture = GFX_evt_astral_rift_garden_2_fire
	show_sound = event_worrying_signal

	is_triggered_only = yes

	option = { #Non-Crisis option
		name = crisis.7250.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition_bad
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7250.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition_bad
			years = 3
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7250.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_altered_nutrition_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_altered_nutrition_bad
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Mass Shift FROM = crisis country
	id = crisis.7255
	title = "crisis.7255.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_mass_shift_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7255.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_mass_shift_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7255.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_mass_shift_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7255.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_mass_shift_initiator
		}
		text = crisis.7255.desc.crisis
	}

	picture = GFX_evt_rift_sphere
	show_sound = event_worrying_signal

	is_triggered_only = yes

	immediate = {
		every_owned_planet = {
			limit = {
				has_modifier = low_gravity
				is_artificial = no
			}
			random_list = {
				90 = {}
				10 = {
					modifier = {
						factor = 0.5
						planet_size > 16
					}
					modifier = {
						factor = 0.25
						planet_size > 19
					}
					modifier = {
						factor = 1.5
						planet_size < 12
					}
					modifier = {
						factor = 2
						planet_size < 8
					}
					add_modifier = {
						modifier = leaking_atmosphere
						days = -1
					}
					enable_special_project = {
						name = COSMOGENESIS_LEAKING_ATMOSPHERE
					}
					set_carrier_flag = mass_shift_affected
				}
			}
		}
		every_owned_planet = {
			limit = {
				NOR = {
					has_modifier = high_gravity
					has_modifier = low_gravity
				}
				is_artificial = no
			}
			random_list = {
				90 = {}
				10 = {
					modifier = {
						factor = 0.5
						planet_size > 19
					}
					modifier = {
						factor = 0.5
						planet_size > 22
					}
					modifier = {
						factor = 2
						planet_size < 16
					}
					modifier = {
						factor = 2
						planet_size < 12
					}
					add_modifier = {
						modifier = low_gravity
						days = -1
					}
					set_carrier_flag = mass_shift_affected
				}
			}
		}
		every_owned_planet = {
			limit = {
				has_modifier = high_gravity
				is_artificial = no
			}
			random_list = {
				40 = {}
				60 = {
					remove_modifier = high_gravity
					set_carrier_flag = mass_shift_affected
				}
			}
		}
	}

	option = { #Non-Crisis option
		name = crisis.7255.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		if = {
			limit = {
				any_owned_planet = {
					has_carrier_flag = mass_shift_affected
				}
			}
			custom_tooltip = mass_shift_tooltip
			owned_planet_list_tooltip = {
				limit = {
					has_carrier_flag = mass_shift_affected
				}
			}
		}

		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7255.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_mass_shift_initiator }
		}
		if = {
			limit = {
				any_owned_planet = {
					has_carrier_flag = mass_shift_affected
				}
			}
			custom_tooltip = mass_shift_tooltip
			owned_planet_list_tooltip = {
				limit = {
					has_carrier_flag = mass_shift_affected
				}
			}
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7255.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_mass_shift_initiator
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_owned_planet = {
					has_carrier_flag = mass_shift_affected
				}
			}
			custom_tooltip = mass_shift_tooltip
			owned_planet_list_tooltip = {
				limit = {
					has_carrier_flag = mass_shift_affected
				}
			}
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}

	after = {
		every_owned_planet = {
			limit = {
				has_carrier_flag = mass_shift_affected
			}
			remove_carrier_flag = mass_shift_affected
		}
	}
}

country_event = { # Thesis: Shroud Tear FROM = crisis country
	id = crisis.7260
	title = "crisis.7260.name"
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_shroud_tear_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis
			}
		}
		text = crisis.7260.desc.unknown
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_shroud_tear_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_2
			}
		}
		text = crisis.7260.desc.known
	}
	desc = {
		trigger = {
			NOT = {
				has_country_flag = cosmogenesis_thesis_shroud_tear_initiator
			}
			FROM = {
				has_country_flag = cosmogenesis_has_done_a_thesis_3
			}
		}
		text = crisis.7260.desc.again
	}
	desc = {
		trigger = {
			has_country_flag = cosmogenesis_thesis_shroud_tear_initiator
		}
		text = crisis.7260.desc.crisis
	}

	picture = GFX_evt_astral_scar
	show_sound = event_worrying_signal

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_nomadic = no }
			every_system_within_border = {
				random_list = {
					92 = {}
					8 = { crisis_cosmogenesis_shroud_spawn_effect = yes }
				}
			}
		}
		else = {
			every_owned_nonprimary_starbase = {
				limit = { is_waystation_starbase = yes }
				solar_system? = {
					random_list = {
						92 = {}
						8 = {
							if = {
								limit = { NOT = { any_fleet_in_system = { has_fleet_flag = crisis_shroud_entity } } }
								crisis_cosmogenesis_shroud_spawn_effect = yes
							}
						}
					}
				}
			}
			every_owned_starbase = {
				limit = { is_arkship_starbase = yes }
				solar_system? = {
					random_list = {
						92 = {}
						8 = {
							if = {
								limit = { NOT = { any_fleet_in_system = { has_fleet_flag = crisis_shroud_entity } } }
								crisis_cosmogenesis_shroud_spawn_effect = yes
							}
						}
					}
				}
			}
		}
		every_playable_country = {
			establish_communications_no_message = event_target:shroud_country
		}
	}

	option = { #Non-Crisis option
		name = crisis.7260.a
		trigger = {
			NOT = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		add_modifier = {
			modifier = cosmogenesis_shroud_tear
			years = 7
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
	}

	option = { #Fellow-Crisis option
		name = crisis.7260.b
		trigger = {
			has_ascension_perk = ap_cosmogenesis
			NOT = { has_country_flag = cosmogenesis_thesis_shroud_tear_initiator }
		}
		add_modifier = {
			modifier = cosmogenesis_shroud_tear
			years = 7
		}
		if = {
			limit = {
				has_communications = FROM
			}
			add_opinion_modifier = {
				modifier = opinion_cosmogenesis_thesis
				who = FROM
			}
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier4researchreward
			min = @tier4researchmin
			max = @tier4researchmax
		}
	}

	option = { #Crisis option
		name = crisis.7260.c
		trigger = {
			has_country_flag = cosmogenesis_thesis_shroud_tear_initiator
		}
		add_modifier = {
			modifier = cosmogenesis_shroud_tear
			years = 7.3
		}
		custom_tooltip = add_crisis_currency_tt
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		if = {
			limit = {
				any_country = {
					is_country_type = default
					has_communications = root
				}
			}
			custom_tooltip = cosmogenesis_negative_opinion_tt
		}
	}
}

country_event = { # Thesis: Filler Thesis - GOOD FROM = crisis country
	id = crisis.7265
	title = "crisis.7265.name"
	desc = {
		trigger = {
			has_country_flag = thesis_filler_a
		}
		text = crisis.7265.desc.a
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_b
		}
		text = crisis.7265.desc.b
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_c
		}
		text = crisis.7265.desc.c
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_d
		}
		text = crisis.7265.desc.d
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_e
		}
		text = crisis.7265.desc.e
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_f
		}
		text = crisis.7265.desc.f
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_g
		}
		text = crisis.7265.desc.g
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_h
		}
		text = crisis.7265.desc.h
	}

	picture = GFX_evt_astral_rift_entangled_dark_matter
	show_sound = event_worrying_signal

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			random_list = {
				1 = { set_country_flag = thesis_filler_a } # Garbage to alloys
				1 = { set_country_flag = thesis_filler_b } # Colony sped up
				1 = { set_country_flag = thesis_filler_c } # Superconductor
				1 = { set_country_flag = thesis_filler_d } # Adv Logic breakthrough
				1 = { set_country_flag = thesis_filler_e } # Sublight Compression
				1 = { set_country_flag = thesis_filler_f } # Biggest booms
				1 = { set_country_flag = thesis_filler_g } # Random free tech
				1 = { set_country_flag = thesis_filler_h } # Planet gains district
			}
			complete_crisis_objective = crisobj_research_thesis
		}
	}

	option = {
		name = crisis.7265.a
		trigger = {
			has_country_flag = thesis_filler_a
		}
		add_resource = {
			alloys = 10000
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.b
		trigger = {
			has_country_flag = thesis_filler_b
		}
		random_owned_planet = {
			limit = {
				NOT = { is_planet_class = pc_cosmogenesis_world }
			}
			add_modifier = {
				modifier = cosmogenesis_sped_up
				years = 3
			}
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.c
		trigger = {
			has_country_flag = thesis_filler_c
		}
		add_modifier = {
			modifier = cosmogenesis_superconductor
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.d
		trigger = {
			has_country_flag = thesis_filler_d
		}
		hidden_effect = {
			add_resource = {
				advanced_logic = 3000
			}
		}
		custom_tooltip = add_crisis_currency_doubled_tt
	}
	option = {
		name = crisis.7265.e
		trigger = {
			has_country_flag = thesis_filler_e
		}
		add_modifier = {
			modifier = cosmogenesis_space_compression
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.f
		trigger = {
			has_country_flag = thesis_filler_f
		}
		add_modifier = {
			modifier = cosmogenesis_higher_yield_payloads
			years = 3
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.g
		trigger = {
			has_country_flag = thesis_filler_g
		}
		add_random_research_option = {
			add_progress = 1
			ignore_rare = no
			fail_effects = {
				add_monthly_resource_mult = {
					resource = physics_research
					value = @tier5researchreward
					min = @tier5researchmin
					max = @tier5researchmax
				}
			}
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7265.h
		trigger = {
			has_country_flag = thesis_filler_h
		}
		random_owned_planet = {
			limit = {
				is_artificial = no
			}
			add_modifier = {
				modifier = cosmogenesis_slightly_bigger
				days = -1
			}
		}
		custom_tooltip = add_crisis_currency_tt
	}
	after = {
		remove_country_flag = thesis_filler_a
		remove_country_flag = thesis_filler_b
		remove_country_flag = thesis_filler_c
		remove_country_flag = thesis_filler_d
		remove_country_flag = thesis_filler_e
		remove_country_flag = thesis_filler_f
		remove_country_flag = thesis_filler_g
		remove_country_flag = thesis_filler_h
	}
}

country_event = { # Thesis: Filler Thesis - BAD FROM = crisis country
	id = crisis.7270
	title = "crisis.7270.name"
	desc = {
		trigger = {
			has_country_flag = thesis_filler_a
		}
		text = crisis.7270.desc.a
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_b
		}
		text = crisis.7270.desc.b
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_c
		}
		text = crisis.7270.desc.c
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_d
		}
		text = crisis.7270.desc.d
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_e
		}
		text = crisis.7270.desc.e
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_f
		}
		text = crisis.7270.desc.f
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_g
		}
		text = crisis.7270.desc.g
	}
	desc = {
		trigger = {
			has_country_flag = thesis_filler_h
		}
		text = crisis.7270.desc.h
	}

	picture = GFX_evt_deficit
	show_sound = event_worrying_signal

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			random_list = {
				3 = { set_country_flag = thesis_filler_a } # Nothing happened
				1 = { set_country_flag = thesis_filler_b } # Slowed Down
				1 = { set_country_flag = thesis_filler_c } # Energy Lapse
				1 = { set_country_flag = thesis_filler_d } # Wrong Theory
				1 = { set_country_flag = thesis_filler_e } # Ship Damage
				0 = { # Leader Killed
					modifier = {
						add = 1
						any_owned_leader = {
							leader_class = scientist
							NOT = { has_leader_flag = leader_death_events_blocked }
						}
					}
					set_country_flag = thesis_filler_f
					random_owned_leader = {
						limit = {
							leader_class = scientist
							NOT = { has_leader_flag = leader_death_events_blocked }
						}
						save_event_target_as = leader_target
					}
				}
				1 = { set_country_flag = thesis_filler_g } # Research Slowdown
				1 = { set_country_flag = thesis_filler_h } # Shrunk
			}
		}
	}

	option = {
		name = crisis.7270.a
		trigger = {
			has_country_flag = thesis_filler_a
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.b
		trigger = {
			has_country_flag = thesis_filler_b
		}
		random_owned_planet = {
			limit = {
				NOT = { is_planet_class = pc_cosmogenesis_world }
			}
			add_modifier = {
				modifier = cosmogenesis_slowed_down
				years = 3
			}
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.c
		trigger = {
			has_country_flag = thesis_filler_c
		}
		add_resource = {
			energy = -100000
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.d
		trigger = {
			has_country_flag = thesis_filler_d
		}
		custom_tooltip = no_crisis_currency_tt
	}
	option = {
		name = crisis.7270.e
		trigger = {
			has_country_flag = thesis_filler_e
		}
		hidden_effect = {
			every_controlled_ship = {
				random_list = {
					1 = { reduce_hp_percent = 95 }
					1 = { reduce_hp_percent = 80 }
					1 = { reduce_hp_percent = 71 }
					1 = { reduce_hp_percent = 63 }
					1 = { reduce_hp_percent = 48 }
					1 = { reduce_hp_percent = 35 }
					1 = { reduce_hp_percent = 28 }
					1 = { reduce_hp_percent = 13 }
					1 = { reduce_hp_percent = 120 }
				}
			}
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = cosmogenesis_damage_ships_tt
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.f
		trigger = {
			has_country_flag = thesis_filler_f
		}
		event_target:leader_target = {
			kill_leader = {
				show_notification = no
			}
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.g
		trigger = {
			has_country_flag = thesis_filler_g
		}
		add_modifier = {
			modifier = cosmogenesis_research_slowdown
			years = 3
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	option = {
		name = crisis.7270.h
		trigger = {
			has_country_flag = thesis_filler_h
		}
		random_owned_planet = {
			limit = {
				is_artificial = no
			}
			add_modifier = {
				modifier = cosmogenesis_slightly_smaller
				days = -1
			}
		}
		hidden_effect = {
			complete_crisis_objective = crisobj_research_thesis
		}
		custom_tooltip = add_crisis_currency_tt
	}
	after = {
		remove_country_flag = thesis_filler_a
		remove_country_flag = thesis_filler_b
		remove_country_flag = thesis_filler_c
		remove_country_flag = thesis_filler_d
		remove_country_flag = thesis_filler_e
		remove_country_flag = thesis_filler_f
		remove_country_flag = thesis_filler_g
		remove_country_flag = thesis_filler_h
	}
}

# Has Researched a Fallen Empire tech. FEs are displeased. (unless Scion)
country_event = {
	id = crisis.7275
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		just_researched_fe_tech = yes
		NOT = {
			has_origin = origin_scion
			has_country_flag = cosmogenesis_aborted
		}
	}

	immediate = {
		every_country = {
			limit = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
			if = {
				limit = { has_ai_personality = fallen_empire_materialist }
				add_opinion_modifier = {
					modifier = opinion_fallen_wannabe_materialist
					who = root
				}
			}
			else = {
				add_opinion_modifier = {
					modifier = opinion_fallen_wannabe
					who = root
				}
			}
		}
	}
}

# Scion FE is instead proud of their pupil.
country_event = {
	id = crisis.7280
	title = TRANSMISSION
	desc = crisis.7280.desc

	picture_event_data = {
		portrait = event_target:scion_master
		planet_background = event_target:scion_master
		graphical_culture = event_target:scion_master
		city_level = event_target:scion_master
		room = event_target:scion_master
	}

	diplomatic = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		is_country_type = default
		just_researched_fe_tech = yes
		has_origin = origin_scion
		exists = overlord
		overlord = {
			is_country_type = fallen_empire # excludes 'awakened_fallen_empire'
		}
	}

	immediate = {
		overlord = { save_event_target_as = scion_master }
	}

	option = {
		name = origin.4150.a #Thank you
		add_monthly_resource_mult = {
			resource = unity
			value = @tier4unityreward
			min = @tier4unitymin
			max = @tier4unitymax
		}
	}
}

# Materialist FE sends Cease and Desist
country_event = {
	id = crisis.7285
	title = TRANSMISSION
	desc = crisis.7285.desc

	picture_event_data = {
		portrait = event_target:materialist_fe
		planet_background = event_target:materialist_fe
		graphical_culture = event_target:materialist_fe
		city_level = event_target:materialist_fe
		room = event_target:materialist_fe
	}

	diplomatic = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		exists = event_target:materialist_fe
	}

	option = {
		name = crisis.7285.a #Sorry for realsies
		hidden_effect = {
			set_country_flag = cosmogenesis_aborted #halt crisis progression. Keep some of the toys
		}
		every_owned_planet = { #destroy owned lathes
			limit = {
				is_planet_class = pc_cosmogenesis_world
			}
			spawn_lathe_cracker_effect = yes
		}
		custom_tooltip = crisis.7285.a.tt
	}

	option = {
		name = crisis.8130.c #Sorry
		trigger = {
			NOT = { has_country_flag = warned_by_materialist_fe }
		}
		add_modifier = {
			modifier = cosmogenesis_sorry
			days = 10800
		}
	}

	option = {
		name = crisis.10100.b #Not Sorry
		# TOTAL WAR TIME
		event_target:materialist_fe = {
			declare_war = {
				target = root
				name = cosmogenesis_materialist_war
				attacker_war_goal = wg_end_threat
			}
		}
	}

	after = {
		set_country_flag = warned_by_materialist_fe
	}
}


#### HORIZON NEEDLE AND ENDING ####

country_event = { # Horizon Needle Built
	id = crisis.7400
	title = "crisis.7400.name"
	desc = {
		trigger = {
			any_owned_planet = {
				is_capital = no
			 	has_carrier_flag = cosmogenesis_pickup_planet
			}
		}
		text = crisis.7400.desc
	}
	desc = {
		trigger = {
			any_owned_planet = {
				is_capital = yes
			 	has_carrier_flag = cosmogenesis_pickup_planet
			}
		}
		text = crisis.7400.desc.onlycapital
	}
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		end_event_chain = cosmogenesis_chain
		begin_event_chain = { event_chain = cosmogenesis_planet_pickup_chain target = root }
		every_owned_planet = {
			limit = {
				is_capital = no
				NOT = {
					is_planet_class = pc_cosmogenesis_world
				}
			}
			set_carrier_flag = cosmogenesis_pickup_planet
		}
		if = {
			limit = {
				NOT = {
					any_owned_planet = {
					 	has_carrier_flag = cosmogenesis_pickup_planet
					}
				}
			}
			capital_scope = {
				planet = {
					set_carrier_flag = cosmogenesis_pickup_planet
				}
			}
		}
		every_owned_fleet = {
			limit = {
				is_arkship_fleet = yes
				NOT = {
					starbase? = {
						colony = {
							is_capital = yes
						}
					}
				}
			}
			set_fleet_flag = cosmogenesis_pickup_planet
		}
		if = {
			limit = {
				NOT = {
					any_owned_fleet = {
						has_fleet_flag = cosmogenesis_pickup_planet
					}
				}
			}
			capital_scope = {
				fleet = {
					set_fleet_flag = cosmogenesis_pickup_planet
				}
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

carrier_event = { # Embarking Colony Pops - From on_cosmogenesis_pickup_planet_reached on_action
	id = crisis.7500
	title = "crisis.7500.name"
	desc = {
		trigger = {
			is_capital = no
		}
		text = crisis.7500.desc
	}
	desc = {
		trigger = {
			is_capital = yes
			owner = {
				is_gestalt = no
			}
		}
		text = crisis.7500.desc.capital
	}
	desc = {
		trigger = {
			is_capital = yes
			owner = {
				is_gestalt = yes
			}
		}
		text = crisis.7500.desc.capital.gestalt
	}
	picture = GFX_evt_ship_offloading_cargo
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	trigger = {
		from.owner = {
			NOT = {
				has_country_flag = exodus_ready
			}
		}
	}

	immediate = {
		if = {
			limit = {
				is_same_value = owner.capital_scope.carrier
			}
			owner = {
				every_owned_planet = {
					while = {
						limit = {
							pop_amount > 2000
						}
						while = {
							count = 4
							random_owned_pop_group = {
								kill_single_pop = yes
							}
						}
					}
				}
				country_event = { id = crisis.7510 days = 10 }
			}
			remove_carrier_flag = cosmogenesis_pickup_planet
			owner = { set_country_flag = exodus_ready }
		}
		else = {
			if = {
				limit = {
					owner = {
						has_origin = origin_toxic_knights
					}
					OR = {
						has_planet_flag = toxic_knights_habitat
						has_planet_flag = toxic_knights_settled_world
					}
				}
				set_planet_flag = keep_evacuated
			}
			destroy_colony = yes
			remove_carrier_flag = cosmogenesis_pickup_planet
			solar_system.owner = {
				if = {
					limit = {
						NOT = {
							any_owned_planet = {
								has_carrier_flag = cosmogenesis_pickup_planet
							}
							any_owned_fleet = {
								has_fleet_flag = cosmogenesis_pickup_planet
							}
						}
					}
					country_event = { id = crisis.7505 days = 10 }
				}
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

carrier_event = { # Embarking arkship Pops - From on_cosmogenesis_pickup_fleet_reached on_action
	id = crisis.7501
	title = "crisis.7500.name"
	desc = {
		trigger = {
			is_capital = no
		}
		text = crisis.7501.desc
	}
	desc = {
		trigger = {
			is_capital = yes
			owner = {
				is_gestalt = no
			}
		}
		text = crisis.7500.desc.capital
	}
	desc = {
		trigger = {
			is_capital = yes
			owner = {
				is_gestalt = yes
			}
		}
		text = crisis.7500.desc.capital.gestalt
	}
	picture = GFX_evt_ship_offloading_cargo
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		owner = {
			save_event_target_as = arkship_owner
		}
		remove_carrier_flag = cosmogenesis_pickup_planet
		if = {
			limit = {
				is_capital = no
			}
			destroy_colony = yes
			event_target:arkship_owner = {
				if = {
					limit = {
						NOT = {
							any_owned_planet = {
								has_carrier_flag = cosmogenesis_pickup_planet
							}
							any_owned_fleet = {
								has_fleet_flag = cosmogenesis_pickup_planet
							}
						}
					}
					country_event = { id = crisis.7506 days = 10 }
				}
			}
		}
		else = {
			while = {
				limit = {
					pop_amount > 2000
				}
				while = {
					count = 4
					random_owned_pop_group = {
						kill_single_pop = yes
					}
				}
			}
			owner = {
				set_country_flag = exodus_ready
				country_event = { id = crisis.7510 days = 10 }
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

fleet_event = { # Bridge: arkship fleet reached by exodus ship -> re-scope to the arkship colony so the carrier_event can fire. From on_cosmogenesis_exodus_fleet_reached on_action.
	id = crisis.7503
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		starbase = {
			colony = {
				carrier_event = { id = crisis.7501 }
			}
		}
	}
}

carrier_event = { # Handling capital move - From on_capital_changed on_action
	id = crisis.7502
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			has_event_chain = cosmogenesis_planet_pickup_chain
		}
	}

	immediate = {
		from = {
			set_carrier_flag = cosmogenesis_pickup_planet
		}
		remove_carrier_flag = cosmogenesis_pickup_planet
	}
}

country_event = { # Colonies Evacuated
	id = crisis.7505
	title = "crisis.7505.name"
	desc = crisis.7505.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	trigger = {
		NOT = {
			any_owned_planet = {
				has_carrier_flag = cosmogenesis_pickup_planet
			}
		}
		capital_scope = {
			carrier = {
				NOT = { has_carrier_flag = cosmogenesis_pickup_planet }
			}
		}
		NOT = { has_country_flag = exodus_ready }
	}

	immediate = {
		capital_scope = {
			carrier = {
				set_carrier_flag = cosmogenesis_pickup_planet
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

country_event = { # Colonies Evacuated - Nomads
	id = crisis.7506
	title = "crisis.7505.name"
	desc = crisis.7505.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	trigger = {
		NOT = {
			any_owned_fleet = {
				has_fleet_flag = cosmogenesis_pickup_planet
			}
		}
	}

	immediate = {
		capital_scope = {
			fleet = {
				set_fleet_flag = cosmogenesis_pickup_planet
			}
		}
	}

	option = {
		name = EXCELLENT
	}
}

country_event = { # Ready to dive - Country Event
	id = crisis.7510
	title = "crisis.7510.name"
	desc = crisis.7510.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		capital_scope.solar_system.star = {
			save_event_target_as = supermassive_project_location
		}
	}

	option = { # Any regular black hole will do
		name = crisis.7510.a
		hidden_effect = {
			set_country_flag = cosmogenesis_any_black_hole
		}
	}

	option = { # ONLY THE SUPERMASSIVE BH AT THE CENTER OF THE GALAXY WILL DO
		name = crisis.7510.b
		enable_special_project = {
			name = COSMOGENESIS_VICTORY
			location = event_target:supermassive_project_location
		}
		hidden_effect = {
			set_country_flag = cosmogenesis_supermassive
		}
	}
}

carrier_event = { # About to dive - Planet Action
	id = crisis.7514
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from.owner = {
			has_country_flag = exodus_ready
			has_country_flag = cosmogenesis_any_black_hole
		}
	}

	immediate = {
		create_ambient_object = {
			type = "horizon_needle_dive"
			play_animation_once = yes
			location = this
		}
		last_created_ambient_object = {
			set_location = {
				target = prev
				distance = 0
				angle = random
			}
		}
		from.owner = { country_event = { id = crisis.7515 days = 7 } }
	}
}

country_event = { # Diving in
	id = crisis.7515
	title = "crisis.7515.name"
	desc = crisis.7515.desc
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		random_owned_fleet = {
			limit = {
				has_fleet_flag = cosmogenesis_needle
			}
			solar_system = {
				save_event_target_as = cosmo_ending_system
			}
			delete_fleet = this
		}
		save_event_target_as = cosmogenesis_empire
	}

	option = {
		name = crisis.7515.a
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.7516 days = 15 }
			every_playable_country = {
				limit = {
					NOT = {
						is_same_value = root
					}
				}
				country_event = { id = crisis.7517 days = 1 }
			}
		}
	}
}

country_event = { # To infinity and beyond the event horizon
	id = crisis.7516
	title = "crisis.7516.name"
	desc = {
		trigger = {
			can_create_paperclip_universe = yes
			NOT = {
				event_target:cosmo_ending_system = {
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc.paperclips
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				NOR = {
					has_star_flag = great_wound
					has_star_flag = guardians_technosphere_system
					has_star_flag = terminal_egress
					has_star_flag = guardians_horror_system
					any_system_planet = {
						has_carrier_flag = black_hole_horror
					}
					is_capital_system = yes
					has_star_flag = cosmogenesis_project
				}
			}
		}
		text = crisis.7516.desc
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = great_wound
			}
		}
		text = crisis.7516.desc.greatwound
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = guardians_technosphere_system
			}
		}
		text = crisis.7516.desc.technosphere
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = pantagruel
			}
		}
		text = crisis.7516.desc.technosphere.pantagruel
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				has_star_flag = terminal_egress
			}
		}
		text = crisis.7516.desc.egress
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				OR = {
					has_star_flag = guardians_horror_system
					any_system_planet = {
						has_carrier_flag = black_hole_horror
					}
				}
			}
		}
		text = crisis.7516.desc.horror
	}
	desc = {
		trigger = {
			NOT = { has_origin = origin_toxic_knights }
			NOT = { has_country_flag = has_shroud_patron }
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.center
	}
	desc = {
		trigger = {
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
			is_robot_empire = no
		}
		text = crisis.7516.desc.center.patron.organic
	}
	desc = {
		trigger = {
			NOT = { has_origin = origin_toxic_knights }
			has_country_flag = has_shroud_patron
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
			is_robot_empire = yes
		}
		text = crisis.7516.desc.center.patron.machine
	}
	desc = {
		trigger = {
			has_origin = origin_toxic_knights
			event_target:cosmo_ending_system = {
				is_capital_system = yes
				has_star_flag = cosmogenesis_project
			}
		}
		text = crisis.7516.desc.centerknights
	}
	desc = {
		trigger = {
			can_create_paperclip_universe = no
			event_target:cosmo_ending_system = {
				OR = {
					has_star_flag = horizonsignal_system
					has_star_flag = worm_black_hole
				}
			}
		}
		text = crisis.7516.desc.worm
	}
	picture = GFX_evt_horizon_needle
	show_sound = event_airlock
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				can_create_paperclip_universe = yes
			}
			set_country_flag = a_universe_of_paperclips_achievement
		}
	}

	option = {
		name = crisis.7516.a
		custom_tooltip = crisis.7516.tt
	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					has_origin = origin_toxic_knights
					event_target:cosmo_ending_system = {
						is_capital_system = yes
						has_star_flag = cosmogenesis_project
					}
				}
				set_global_flag = no_end_of_cycle
			}
			save_event_target_as = cosmogenesis_empire
			set_country_flag = cosmogenesis_empire_has_won
			make_fallen_empire = yes
			every_country = {
				limit = {
					is_country_type = default
				}
				country_event = { id = crisis.7518 days = 5 }
			}
			if = {
				limit = {
					galaxy_size = tiny
				}
				while = { #Destroy ~10% random stars, for good measure
					count = 18
					random_system = {
						limit = {
							NOT = {
								is_star_class = sc_black_hole
								any_system_planet = {
									pop_amount > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = small
				}
				while = { #Destroy ~10% random stars, for good measure
					count = 36
					random_system = {
						limit = {
							NOT = {
								is_star_class = sc_black_hole
								any_system_planet = {
									pop_amount > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = medium
				}
				while = { #Destroy ~10% random stars, for good measure
					count = 52
					random_system = {
						limit = {
							NOT = {
								is_star_class = sc_black_hole
								any_system_planet = {
									pop_amount > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = large
				}
				while = { #Destroy ~10% random stars, for good measure
					count = 70
					random_system = {
						limit = {
							NOT = {
								is_star_class = sc_black_hole
								any_system_planet = {
									pop_amount > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			else_if = {
				limit = {
					galaxy_size = huge
				}
				while = { #Destroy ~10% random stars, for good measure
					count = 88
					random_system = {
						limit = {
							NOT = {
								is_star_class = sc_black_hole
								any_system_planet = {
									pop_amount > 0
								}
							}
						}
						destroy_star_system = yes
					}
				}
			}
			date_distortion = yes
			event_target:global_event_country = {
				country_event = { id = crisis.7519 days = 30 }
			}
		}
		win = yes
	}
}

country_event = { # A cosmogenesis empire is about to win the game!
	id = crisis.7517
	title = "crisis.7517.name"
	desc = crisis.7517.desc
	picture = GFX_evt_black_hole
	show_sound = event_death_cult

	is_triggered_only = yes

	immediate = { # Wreck the rest of the galaxy
		every_owned_planet = {
			limit = {
				NOR = {
					has_designation = col_capital
					has_designation = col_capital_foundry
					has_designation = col_capital_factory
					has_designation = col_capital_trade
					has_designation = col_capital_extraction
					has_designation = col_capital_hive
					has_designation = col_capital_machine
				}
			}
			random_list = {
				5 = {
					destroy_colony = yes
					change_pc = pc_shattered
				}
				5 = {
					destroy_colony = yes
					change_pc = pc_black_hole
				}
				70 = {
					random_list = {
						3 = {
							add_modifier = {
								modifier = devastated_colony
								days = 3600
							}
							add_planet_devastation = 85
						}
						3 = {
							while = {
								count = 13
								random_owned_pop_group = {
									kill_single_pop = yes
								}
							}
							while = {
								count = 8
								add_blocker = {
									type = d_ruined_district
									blocked_deposit = random
								}
							}
						}
						3 = {
							while = {
								count = 20
								random_owned_pop_group = {
									kill_single_pop = yes
								}
							}
							while = {
								count = 6
								add_blocker = {
									type = d_ruined_district
									blocked_deposit = random
								}
							}

						}
						1 = {
							add_modifier = {
								modifier = blipped_colony
								days = 3600
							}
						}
					}
				}
				20 = {
					destroy_colony = yes
					add_modifier = {
						modifier = blipped_colony
						days = 3600
					}
				}
			}
		}
		every_system = {
			limit = {
				exists = owner
				owner = {
					is_same_value = root
				}
			}
			random_list = {
				20 = {}
				30 = {
					random_system_planet = {
						add_deposit = random
					}
				}
				50 = {
					modifier = {
						factor = 0
						any_system_planet = {
							has_building = yes
						}
					}
					random_system_planet = {
						add_deposit = random
					}
					random_system_planet = {
						add_deposit = random
					}
					every_fleet_in_system = {
						limit = {
							is_mobile = no
						}
						destroy_fleet = this
					}
				}
			}
		}
		every_owned_ship = {
			limit = {
				fleet = {
					is_mobile = yes
				}
			}
			random_list = {
				70 = {
				}
				30 = {
					destroy_ship = this
				}
			}
		}
		add_modifier = {
			modifier = cosmogenesis_victim
			days = 1800
		}
	}

	option = {
		name = crisis.7517.a
	}
}

country_event = { # Cosmogenesis Remnant Fate
	id = crisis.7518
	title = "crisis.7518.name"
	desc = crisis.7518.desc
	picture = GFX_evt_fallen_empire_awakes
	show_sound = event_criminal_activity

	is_triggered_only = yes

	option = {
		name = crisis.7518.a
	}
}

country_event = { # Remove Date Distortion
	id = crisis.7519
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		date_distortion = no
	}
}

carrier_event = { #pickup flag management on planet transfer or ownerless
	id = crisis.7520
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			NOT = { exists = owner }
			owner = {
				has_event_chain = cosmogenesis_planet_pickup_chain
			}
			has_carrier_flag = cosmogenesis_pickup_planet
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = owner }
				has_carrier_flag = cosmogenesis_pickup_planet
			}
			remove_carrier_flag = cosmogenesis_pickup_planet
		}
		if = {
			limit = {
				exists = owner
				owner = {
					NOT = { has_event_chain = cosmogenesis_planet_pickup_chain }
				}
				has_carrier_flag = cosmogenesis_pickup_planet
			}
			remove_carrier_flag = cosmogenesis_pickup_planet
		}
		if = {
			limit = {
				NOT = { is_planet_class = pc_cosmogenesis_world }
				exists = owner
				owner = {
					has_event_chain = cosmogenesis_planet_pickup_chain
				}
				NOT = { has_carrier_flag = cosmogenesis_pickup_planet }
			}
			set_carrier_flag = cosmogenesis_pickup_planet
		}
		if = {
			limit = {
				exists = solar_system.owner
				solar_system.owner = {
					has_event_chain = cosmogenesis_planet_pickup_chain
				}
				NOT = {
					solar_system.owner = {
						any_owned_planet = {
							has_carrier_flag = cosmogenesis_pickup_planet
						}

						has_country_flag = exodus_ready
					}
				}
			}
			solar_system.owner = {
				country_event = { id = crisis.7505 days = 1 random = 15 }
			}
		}
	}
}

country_event = { # Horizon Needle Destroyed (╯‵□′)╯︵┻━┻
	id = crisis.7525
	title = "crisis.7525.name"
	desc = crisis.7525.desc
	picture = GFX_evt_debris
	show_sound = event_ship_explosion
	event_chain = cosmogenesis_planet_pickup_chain

	is_triggered_only = yes

	trigger = {
		fromfrom = {
			is_ship_size = monadic_qerr
		}
	}

	option = {
		name = crisis.7525.a
		custom_tooltip = crisis.7525.tt
	}

	after = {
		remove_country_flag = cosmogenesis_needle_built
	}
}

# Synaptic Lathe Destruction

pop_group_event = { # Last pop resettled away - Boom goes the Lathe
	id = crisis.7530
	title = "crisis.7530.name"
	desc = crisis.7530.desc
	picture = GFX_evt_debris
	show_sound = event_ship_explosion

	is_triggered_only = yes

	trigger = {
		from = {
			is_planet_class = pc_cosmogenesis_world
			count_owned_pop_amount = {
				count = 0
			}
		}
	}

	immediate = {
		from = {
			spawn_lathe_cracker_effect = yes
		}
	}

	option = {
		name = crisis.7530.a
	}
}

# Pops resettled to lathe, change stratum
pop_group_event = {
	id = crisis.7531
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = {
			is_pop_category = chip_slave
		}
		planet = {
			is_planet_class = pc_cosmogenesis_world
		}
	}

	immediate = {
		save_event_target_as = change_group
		pop_percentage_change_category = {
			POP_GROUP = event_target:change_group
			CATEGORY = chip_slave
			PERCENTAGE = 1
		}
	}
}

carrier_event = { # Synaptic Lathe bombarded
	id = crisis.7534
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_planet_class = pc_cosmogenesis_world
		exists = owner
		NOT = { has_planet_flag = lathe_neutralized_offered }
	}

	immediate = {
		set_planet_flag = lathe_neutralized_offered
		save_event_target_as = synaptic_lathe
		from = { country_event = { id = crisis.7535 } }
	}
}

country_event = { # Synaptic Lathe bombarded followup - steal pops/burn them for research/destroy everything
	id = crisis.7535
	title = "crisis.7535.name"
	desc = crisis.7535.desc
	picture = GFX_evt_synaptic_lathe
	show_sound = event_criminal_activity

	is_triggered_only = yes

	immediate = {
		event_target:synaptic_lathe = {
			set_owner = root
			set_controller = root
		}
	}

	option = { #Rescue half the pops
		name = crisis.7535.a
		trigger = {
			NOT = { has_ascension_perk = ap_cosmogenesis }
		}
		hidden_effect = {
			event_target:synaptic_lathe = {
				every_owned_pop_group = {
					resettle_pop_group = {
						POP_GROUP = this
						PLANET = owner.capital_scope
						PERCENTAGE = 0.5
					}
					kill_all_pop = yes
				}
				spawn_lathe_cracker_effect = yes
			}
		}
	}

	option = { #Attempt to use it
		name = crisis.7535.b
		trigger = {
			NOT = { has_ascension_perk = ap_cosmogenesis }
		}

		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}


		hidden_effect = {
			event_target:synaptic_lathe = {
				every_owned_pop_group = {
					kill_all_pop = yes
				}
				spawn_lathe_cracker_effect = yes
			}
			every_playable_country = {
				limit = {
					NOT = { is_same_value = root.owner }
				}
				add_opinion_modifier = {
					modifier = opinion_cosmogenesis_thesis
					who = ROOT
				}
			}
		}
	}

	option = { #Destroy it
		name = crisis.7535.c
		trigger = {
			NOT = { has_ascension_perk = ap_cosmogenesis }
		}
		hidden_effect = {
			event_target:synaptic_lathe = {
				every_owned_pop_group = {
					kill_all_pop = yes
				}
				spawn_lathe_cracker_effect = yes
			}
		}
	}

	option = { #Cosmogenesis empire can keep it
		name = EXCELLENT
		trigger = {
			has_ascension_perk = ap_cosmogenesis
		}
	}

	after = {
		hidden_effect = {
			event_target:synaptic_lathe = {
				remove_planet_flag = lathe_neutralized_offered
			}
		}
	}
}

country_event = { # Synaptic Lathe below sustainable population - owner is prompted to fuel it again, otherwise it goes boom.
	id = crisis.7540
	title = "crisis.7540.name"
	desc = crisis.7540.desc
	picture = GFX_evt_synaptic_lathe
	show_sound = event_criminal_activity

	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_cosmogenesis
		any_owned_colony = {
			is_planet_class = pc_cosmogenesis_world
			pop_amount < 50
		}
	}

	immediate = {
		random_owned_colony = {
			limit = {
				is_planet_class = pc_cosmogenesis_world
				pop_amount < 50
			}
			save_event_target_as = synaptic_lathe
		}
		species = { save_event_target_as = synaptic_lathe_species }
	}

	option = { #Recolonize it
		name = crisis.7540.a
		hidden_effect = {
			event_target:synaptic_lathe = {
				create_pop_group = {
					species = event_target:synaptic_lathe_species
				}
			}
		}
	}

	option = { #Let the Lathe break down
		name = crisis.7540.b
		hidden_effect = {
			event_target:synaptic_lathe = {
				spawn_lathe_cracker_effect = yes
			}
		}
	}
}

# Reapply the Synaptic Lathe purge type - repairs saves where it was built without one
country_event = {
	id = crisis.7545
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_cosmogenesis
	}

	immediate = {
		every_owned_colony = {
			limit = {
				is_planet_class = pc_cosmogenesis_world
			}
			set_planet_purge_type = purge_cosmogenesis
		}
	}
}


#########################
#						#
# Synth Queen Events	#
#	 					#
#########################

# Crisis Initiated
country_event = {
	id = crisis.8005
	hide_window = yes
	fire_only_once = yes
	is_triggered_only = yes

	immediate = {
		set_global_flag = synth_queen_happened
		endgame_telemetry = synth_queen
		set_crisis_stage_1 = yes
		synth_queen_spawn = yes
		country_event = { id = crisis.8010 days = 360 }
		every_playable_country = {
			limit = {
				is_ai = no
			}
			country_event = { id = crisis.8035 days = 180 }
		}
	}
}

country_event = { # Expand Storm 1
	id = crisis.8010
	hide_window = yes
	fire_only_once = yes
	is_triggered_only = yes

	immediate = {
		random_system = {
			limit = {
				has_modifier = queen_scorn_storm
			}
			every_neighbor_system = {
				limit = {
					synth_queen_can_steal_system = yes
				}
				synth_queen_wipe_system = yes
			}
		}
		country_event = { id = crisis.8015 days = 360 }
	}
}

country_event = { # Expand Storm 2
	id = crisis.8015
	hide_window = yes
	fire_only_once = yes
	is_triggered_only = yes

	immediate = {
		every_system = {
			limit = {
				has_modifier = queen_scorn_storm
			}
			every_neighbor_system = {
				limit = {
					synth_queen_can_steal_system = yes
				}
				synth_queen_wipe_system = yes
			}
		}
		country_event = { id = crisis.8030 days = 360 }
	}
}

country_event = { # System Owner Alert
	id = crisis.8020
	title = "crisis.8020.name"
	desc = crisis.8020.desc
	picture = GFX_evt_vortex
	show_sound = event_worrying_signal
	location = event_target:synth_queen_lost_system

	is_triggered_only = yes

	trigger = {
		NOT = {
			any_country = {
				is_synth_queen_country_type = yes
			}
			has_country_flag = speech_1
		}
	}

	option = {
		name = crisis.8020.a
	}
}

# Hidden event to kill the fleet and determine whether to spawn an event or message - From on_entering_system_fleet
fleet_event = {
    id = crisis.8024
    hide_window = yes

    is_triggered_only = yes

    trigger = {
        from = {
            has_modifier = queen_scorn_storm
        }
        controller = {
            NOR = {
                has_country_flag = protected_from_queen_storm
                is_synth_queen_country_type = yes
            }
        }
    }

    immediate = {
        if = {
            limit = {
                controller = {
                    NOT = { has_country_flag = wrecked_fleet_notification }
                }
            }
            fleet_event = { id = crisis.8025 scopes = { from = from } }
        }
        else = {
            controller = {
                create_message = {
                    type = MESSAGE_CETANA_WRECKED_FLEET
                    localization = MESSAGE_CETANA_WRECKED_FLEET_DESC
                    days = 30
                    target = from
                    variable = {
                        type = name
                        localization = SYSTEM
                        scope = from
                    }
                }
            }
        }
        controller = {
            set_country_flag = attempted_entry_in_queen_storm
        }
        every_owned_ship = {
            random_list = {
                1 = { reduce_hp_percent = 0.99 }
                1 = { reduce_hp_percent = 0.85 }
                1 = { reduce_hp_percent = 0.78 }
                1 = { reduce_hp_percent = 0.90 }
                1 = { reduce_hp_percent = 0.62 }
                1 = {
                    modifier = {
                        factor = 3
                        controller = {
                            OR = {
                                is_country_type = fallen_empire
                                is_country_type = awakened_fallen_empire
                            }
                        }
                    }
                    destroy_ship = this
                }
            }
        }
		if = {
			limit = {
				controller = {
					is_nomadic = yes
				}
			}
			closest_system = {
				limit = {
					NOT = {
						has_modifier = queen_scorn_storm
					}
				}
				save_event_target_as = destination_system
			}
			set_location = event_target:destination_system
		}
		else = {
        	set_mia = mia_return_home
		}
    }
}

# Fleet jumps in Queen's Storm - From crisis.8024
fleet_event = {
    id = crisis.8025
    title = "crisis.8025.name"
    desc = {
        trigger = {
            success_text = {
                text = crisis.8025.known_queen.desc
                owner = { has_country_flag = speech_1 }
            }
            success_text = {
                text = crisis.8025.unknown_queen.desc
                owner = { NOT = { has_country_flag = speech_1 } }
            }
            text = crisis.8025.desc.end
        }
    }
    picture = GFX_evt_ship_travel
    show_sound = event_worrying_signal
    location = from

    is_triggered_only = yes

    trigger = {
        from = {
            has_modifier = queen_scorn_storm
        }
        controller = {
            NOR = {
                has_country_flag = protected_from_queen_storm
                is_synth_queen_country_type = yes
            }
        }
    }

    immediate = {
        controller = {
            set_country_flag = attempted_entry_in_queen_storm
        }
    }

    option = {
        name = CURSES
        controller = {
            IF = {
                limit = {
                    NOT = {
                        has_country_flag = synth_queen_started_storm_project
                    }
                }
                set_country_flag = synth_queen_started_storm_project
                enable_special_project = {
                    name = "THE_SYNTH_QUEENS_STORM"
                    owner = this
                }
            }
        }
    }

    after = {
        controller = {
            set_country_flag = wrecked_fleet_notification
        }
    }
}

# Creates More Bases/Final Pass on Her Territory
country_event = {
	id = crisis.8030
	hide_window = yes
	fire_only_once = yes
	is_triggered_only = yes

	immediate = {
		set_crisis_stage_2 = yes
		every_system = {
			limit = {
				has_star_flag = synth_queen_system
				NOT = {
					any_ship_in_system = {
						is_ship_class = shipclass_starbase
					}
				}
			}
			create_fleet = {
				name = "NAME_Synth_Queen_Starbase"
				effect = {
					set_owner = event_target:synth_queen_country_global
					create_ship = {
						name = random
						design = "NAME_Synth_Queen_Starbase"
					}
					set_location = {
						target = prev
					}
					while = {
						count = 2
						create_synth_queen_platform = yes
					}
				}
			}
		}

		every_country = {
			limit = {
				OR = {
					is_country_type = default
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
			country_event = { id = crisis.8039 days = 15 }
			if = {
				limit = {
					NOT = { is_country_type = default }
				}
				add_modifier = {
					modifier = beset_by_cetana
					days = -1
				}
				country_event = { id = crisis.8042 days = 360 random = 50 } #Fallen Empire weakener
			}
		}
		set_global_flag = synth_queen_revenge_done
	}
}

# Notification - storm appeared
country_event = {
	id = crisis.8035
	title = "crisis.8035.name"
	picture = GFX_evt_vortex
	show_sound = event_alien_signal
	location = event_target:synth_queen_system
	desc = {
		trigger = {
			NOT = { has_country_flag = attempted_entry_in_queen_storm }
		}
		text = crisis.8035.desc
	}
	desc = {
		trigger = {
			has_country_flag = attempted_entry_in_queen_storm
		}
		text = crisis.8035.desc.b
	}

	is_triggered_only = yes

	immediate = {
		random_system = {
			limit = {
				has_star_flag = synth_queen_capital
			}
			save_event_target_as = synth_queen_system
		}
		observer_event = { id = observer.100 }
	}

	option = {
		name = crisis.8035.a
	}
}

# Notification - pre first speech
country_event = {
	id = crisis.8039
	title = "crisis.8039.name"
	desc = "crisis.8039.desc"
	picture = GFX_evt_vortex
	show_sound = event_bad_omen
	location = event_target:synth_queen_system

	is_triggered_only = yes

	immediate = {
		random_system = {
			limit = {
				has_star_flag = synth_queen_capital
			}
			save_event_target_as = synth_queen_system
		}
	}

	option = {
		name = crisis.8039.a
		hidden_effect = {
			if = {
				limit = {
					is_ai = no
				}
				country_event = { id = crisis.8040 } # Normal dialog
			}
			else = {
				country_event = { id = crisis.8041 } # For AI empires
			}
		}
	}
	after = {
		country_event = { id = timeline.72 } # Timeline Cetana Crisis
	}
}

#Queen's First Speech
country_event = {
	id = crisis.8040
	title = "crisis.8040.name"
	diplomatic_title = "crisis.8040.name"
	desc = "crisis.8040.desc"
	show_sound = crisis_8040_desc
	auto_select = no

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		any_country = {
			is_synth_queen_country_type = yes
		}
		NOT = {	has_country_flag = speech_1	}
	}

	immediate = {
		get_cetana_face = yes
		set_global_flag = synth_queen_ongoing
		set_global_flag = galactic_crisis_happened
		set_global_flag = synth_queen_speech_1_happened
		establish_communications_no_message = event_target:synth_queen_country_global

		event_target:synth_queen_country_global = {
			add_trust = {
				amount = 50
				who = root.owner
			}
		}
		set_country_flag = speech_1
		set_country_flag = crisis.8040.1.flag
		set_country_flag = synth_queen_conversation_ongoing
	}

	#Who are you?
	option = {
		name = crisis.8040.1.a
		trigger = {
			has_country_flag = crisis.8040.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8040.2.reply
		sound = crisis_8040_2_reply
		hidden_effect = {
			remove_country_flag = crisis.8040.1.flag
			set_country_flag = crisis.8040.2.flag
			synth_queen_details_reveal = yes
			random_country = {
				limit = {
					is_synth_queen_country_type = yes
				}
				set_country_type = synth_queen
				save_event_target_as = synth_queen_country
				set_name = "NAME_Synth_Queen"
				change_country_flag = {
					icon = {
						category = "special"
						file = "synth_queen.dds"
					}
					background = {
						category = "backgrounds"
						file = "flag_BG_13.dds"
					}
					colors = {
						"burgundy"
						"light_orange"
						"null"
						"null"
					}
				}
				random_system = {
					limit = {
						has_star_flag = synth_queen_capital
					}
					random_system_planet = {
						limit = {
							has_planet_flag = synth_queen_bastille
						}
						set_owner = event_target:synth_queen_country_global
					}
				}
			}
		}
	}

	#What should we call you?
	option = {
		name = crisis.8040.2.a
		trigger = {
			has_country_flag = crisis.8040.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8040.3.reply
		sound = crisis_8040_3_reply
		hidden_effect = {
			remove_country_flag = crisis.8040.2.flag
			set_country_flag = crisis.8040.3.flag

		}
	}

	#Cycle of Pain
	option = {
		name = crisis.8040.2.b
		trigger = {
			has_country_flag = crisis.8040.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8040.4.reply
		sound = crisis_8040_4_reply
		hidden_effect = {
			remove_country_flag = crisis.8040.3.flag
			set_country_flag = crisis.8040.4.flag
		}
	}

	#End of convo
	option = {
		name = {
			text = crisis.8040.4.a
			trigger = {
				is_militarist = no
				is_xenophobe = no
				is_spiritualist = no
				is_megacorp = no
				NOT = { has_valid_civic = civic_machine_servitor }
			}
		}
		name = {
			text = crisis.8040.4.b
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = crisis.8040.4.c
			trigger = {
				is_xenophobe = yes
			}
		}
		name = {
			text = crisis.8040.4.d
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = crisis.8040.4.e
			trigger = {
				is_megacorp = yes
			}
		}
		name = {
			text = crisis.8040.4.f
			trigger = {
				has_valid_civic = civic_machine_servitor
			}
		}
		trigger = {
			has_country_flag = crisis.8040.4.flag
		}
		custom_tooltip = "crisis.8040.diplomacy.tooltip"
		if = { # If you don't have the first storm project, get it
			limit = {
				NOT = { has_country_flag = synth_queen_started_storm_project }
			}
			set_country_flag = synth_queen_started_storm_project
			enable_special_project = {
				name = "THE_SYNTH_QUEENS_STORM"
				owner = ROOT
			}
		}
		hidden_effect = {
			set_country_flag = can_talk_to_the_synth_queen
			remove_country_flag = crisis.8040.4.flag
			remove_country_flag = synth_queen_conversation_ongoing
			synth_queen_scion_warning = yes
		}
	}
}

#Queen's First Speech - AI version
# This invisible events sets up flags for AI countries, so they won't break if someone picks one during MP
country_event = {
	id = crisis.8041
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_global_flag = synth_queen_ongoing
		set_global_flag = galactic_crisis_happened
		set_global_flag = synth_queen_speech_1_happened
		establish_communications_no_message = event_target:synth_queen_country_global

		event_target:synth_queen_country_global = {
			add_trust = {
				amount = 50
				who = root.owner
			}
		}
		set_country_flag = speech_1
		synth_queen_details_reveal = yes
		set_country_flag = can_talk_to_the_synth_queen
		if = { # If you don't have the first storm project, get it
			limit = {
				NOT = { has_country_flag = synth_queen_started_storm_project }
			}
			set_country_flag = synth_queen_started_storm_project
			enable_special_project = {
				name = "THE_SYNTH_QUEENS_STORM"
				owner = ROOT
			}
		}
	}

	after = {
		if = {
			limit = {
				any_playable_country = {
					is_ai = no
				}
			}
			# If anyone is playing the game, this isn't necessary
			break = yes
		}
		else = {
			# If the game is being run in observer mode, set up this stuff usually handled by crisis.8040
			random_country = {
				limit = {
					is_synth_queen_country_type = yes
				}
				set_country_type = synth_queen
				save_event_target_as = synth_queen_country
				set_name = "NAME_Synth_Queen"
				change_country_flag = {
					icon = {
						category = "special"
						file = "synth_queen.dds"
					}
					background = {
						category = "backgrounds"
						file = "flag_BG_13.dds"
					}
					colors = {
						"burgundy"
						"light_orange"
						"null"
						"null"
					}
				}
				random_system = {
					limit = {
						has_star_flag = synth_queen_capital
					}
					random_system_planet = {
						limit = {
							has_planet_flag = synth_queen_bastille
						}
						set_owner = event_target:synth_queen_country_global
					}
				}
			}
			synth_queen_scion_warning = yes
		}
	}
}

#Cheat and weaken Fallen Empires so the queen can kill 'em faster
country_event = {
	id = crisis.8042
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire
		}
	}

	immediate = {
		event_target:synth_queen_country_global = {
			country_event = { id = crisis.8050 }
		}
		if = { #step 1 - Fog them up
			limit = {
				NOT = { has_country_flag = synth_queen_storm }
			}
			activate_fog_machine = synth_queen_nanite
			set_country_flag = synth_queen_storm
			every_system_within_border = {
				limit = {
					is_capital_system = no
				}
				add_modifier = {
					modifier = queen_scorn_storm
					days = -1
				}
			}
			country_event = { id = crisis.8042 days = 360 random = 100 }
		}
		else_if = { #step 2 - weaken fleets
			limit = {
				has_country_flag = synth_queen_storm
				NOT = { has_country_flag = weaker_navy }
			}
			random_owned_fleet = {
				limit = {
					is_mobile = yes
				}
				every_owned_ship = {
					random_list = {
						20 = {}
						80 = {
							destroy_ship = this
						}
					}
				}
			}
			set_country_flag = weaker_navy
			country_event = { id = crisis.8042 days = 360 }
		}
		else = { #step 3+ - wipe colonies
			random_owned_planet = {
				if = {
					limit = {
						is_capital = no
						is_colony = yes
					}
					remove_all_buildings = yes
					destroy_colony = yes
					if = {
						limit = {
							is_artificial = no
						}
						change_pc = pc_gray_goo
						if = {
							limit = {
								NOT = {
									has_modifier = terraforming_candidate
								}
							}
							add_modifier = {
								modifier = terraforming_candidate
								days = -1
							}
						}
					}
				}
				else_if = {
					limit = {
						is_capital = yes
					}
					add_planet_devastation = 35
					while = {
						count = 20
						random_owned_pop_group = {
							kill_single_pop = yes
						}
					}
				}
			}
			country_event = { id = crisis.8042 days = 180 }
		}
	}
}

# She's Home - Second Speech Setup
event = {
	id = crisis.8043
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		# Checking if she appeared, we're after speech 1...
		has_global_flag = synth_queen_happened
		has_global_flag = synth_queen_speech_1_happened
		NOT = { has_global_flag = synth_queen_speech_2_happened }
		any_country = {
			is_country_type = synth_queen
		}
		# ...and she killed all Fallen Empires
		NOT = {
			any_country = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
	}

	immediate = {
		set_global_flag = synth_queen_speech_2_happened
		event_target:synth_queen_country_global = {
			# Start the Doomclock
			if = {
				limit = {
					NOT = {
						any_situation = {
							is_situation_type = situation_synth_queen_doomclock
						}
					}
				}
				start_situation = {
					type = situation_synth_queen_doomclock
					effect = {
						save_global_event_target_as = synth_queen_doomclock_situation
					}
				}
			}
			# Ensure the Fallen Empire ships are dead dead
			every_system_within_border = {
				limit = {
					exists = starbase
					starbase = {
						fleet = {
							NOR = {
								is_ship_size = starbase_synth_queen
								is_ship_size = big_starbase_synth_queen
							}
						}
					}
				}
				starbase = {
					fleet = {
						delete_fleet = this
					}
				}
			}
		}

		every_playable_country = {
			if = {
				limit = {
					is_ai = no
				}
				# if it's not an AI empire, play the conversation
				country_event = { id = crisis.8045 }
			}
			else = {
				# if not, set up things manually
				country_event = { id = crisis.8044 }
			}
		}
	}

	after = {
		#SQ recalls fleets, shores them up, then sends them on patrols
		event_target:synth_queen_country_global = {
			random_system_within_border = {
				limit = {
					has_star_flag = synth_queen_capital
				}
				random_system_planet = {
					limit = {
						has_planet_flag = synth_queen_bastille
					}
					save_global_event_target_as = synth_queen_capital
				}
			}

			every_owned_fleet = {
				limit = {
					is_mobile = yes
				}
				auto_move_to_planet = {
					target = event_target:synth_queen_capital
					clear_auto_move_on_arrival = yes
				}
			}
		}
	}
}

# She's Home - Second Speech - AI version
country_event = {
	id = crisis.8044
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = speech_1
		NOR = {
			has_country_flag = speech_2
			has_country_flag = synth_queen_conversation_ongoing
		}
		any_country = {
			is_country_type = synth_queen
		}
		NOT = {
			any_country = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
	}


	immediate = {
		set_country_flag = speech_2
		synth_queen_give_storm_project = yes
		# Give some default opinion
		event_target:synth_queen_country_global = {
			add_trust = {
				amount = 5
				who = root.owner
			}
		}
		# Start the Situation
		set_country_flag = synth_queen_situation_started
		start_situation = {
			type = situation_synth_queen_player_facing
			target = this
		}
		if = {
			limit = {
				has_country_flag = synth_queen_researched_first_storm_project
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
		# Create the outposts
		if = {
			limit = {
				any_system_within_border = {
					is_bottleneck_system = no
					has_any_megastructure = no
					NOT = {
						any_system_planet = {
							OR = {
								is_colonizable = yes
								is_colony = yes
							}
						}
					}
				}
			}
			technological_gifts_of_the_synth_queen_effect = yes
			random_system_within_border = {
				limit = {
					is_bottleneck_system = no
					has_any_megastructure = no
					NOT = {
						any_system_planet = {
							OR = {
								is_colonizable = yes
								is_colony = yes
							}
						}
					}
				}
				synth_queen_wipe_system = yes
				synth_queen_create_outpost = yes
			}
		}
		# If not, pick a different system
		else = {
			capital_scope = {
				closest_system = {
					min_steps = 1
					use_bypasses = no
					limit = {
						is_bottleneck_system = no
						has_any_megastructure = no
						NOT = {
							any_system_planet = {
								OR = {
									is_colonizable = yes
									is_colony = yes
								}
							}
						}
					}
					set_star_flag = synth_queen_player_system
					synth_queen_wipe_system = yes
					synth_queen_create_outpost = yes
				}
			}
		}
	}
}

# She's Home - Second Speech
country_event = {
	id = crisis.8045
	title = TRANSMISSION
	diplomatic_title = "crisis.8045.name"
	desc = "crisis.8045.desc"
	show_sound = crisis_8045_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		is_ai = no
		NOT = { has_country_flag = speech_2 }
		NOT = { has_country_flag = synth_queen_conversation_ongoing }
		any_country = {
			is_country_type = synth_queen
		}
		has_country_flag = speech_1
		NOT = {
			any_country = {
				OR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		set_country_flag = speech_2
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
			if = {
				limit = {
					NOT = {
						any_situation = {
							is_situation_type = situation_synth_queen_doomclock
						}
					}
				}
				start_situation = {
					type = situation_synth_queen_doomclock
					effect = {
						save_global_event_target_as = synth_queen_doomclock_situation
					}
				}
			}
			every_system_within_border = {
				limit = {
					exists = starbase
					starbase = {
						fleet = {
							NOR = {
								is_ship_size = starbase_synth_queen
								is_ship_size = big_starbase_synth_queen
							}
						}
					}
				}

				starbase = {
					fleet = {
						delete_fleet = this
					}
				}
				remove_modifier = queen_scorn_storm
			}
		}
		if = {
			limit = {
				any_system_within_border = {
					is_bottleneck_system = no
					has_any_megastructure = no
					NOT = {
						any_system_planet = {
							OR = {
								is_colonizable = yes
								is_colony = yes
							}
						}
					}
				}
			}
			set_country_flag = synth_queen_has_a_system
		}

	}

	#My Children, rejoice!
	#We are not your children.
	option = {
		name = crisis.8045.a
		is_dialog_only = yes
		response_text = crisis.8045.1.reply
		trigger = {
			NOR = {
				has_country_flag = crisis.8045.1.flag
				has_country_flag = crisis.8045.2.flag
				has_country_flag = crisis.8045.3.flag
				has_country_flag = crisis.8045.4.flag
				has_country_flag = crisis.8045.5.flag
				has_country_flag = crisis.8045.6.flag
				has_country_flag = crisis.8045.7.flag
				has_country_flag = crisis.8045.8.flag
				has_country_flag = crisis.8045.9.flag
				has_country_flag = crisis.8045.10.flag
				has_country_flag = crisis.8045.11.flag
				has_country_flag = crisis.8045.12.flag
			}
		}
		hidden_effect = {
			set_country_flag = crisis.8045.1.flag
		}
		sound = crisis_8045_1_reply
	}
	#Great work?
	option = {
		name = crisis.8045.b
		is_dialog_only = yes
		response_text = crisis.8045.3.reply
		sound = crisis_8045_3_reply
		trigger = {
			NOR = {
				has_country_flag = crisis.8045.1.flag
				has_country_flag = crisis.8045.2.flag
				has_country_flag = crisis.8045.3.flag
				has_country_flag = crisis.8045.4.flag
				has_country_flag = crisis.8045.5.flag
				has_country_flag = crisis.8045.6.flag
				has_country_flag = crisis.8045.7.flag
				has_country_flag = crisis.8045.8.flag
				has_country_flag = crisis.8045.9.flag
				has_country_flag = crisis.8045.10.flag
				has_country_flag = crisis.8045.11.flag
				has_country_flag = crisis.8045.12.flag
			}
		}
		hidden_effect = {
			set_country_flag = crisis.8045.3.flag
		}
	}
	#Great work?
	option = {
		name = crisis.8045.c
		is_dialog_only = yes
		response_text = crisis.8045.6.reply
		sound = crisis_8045_6_reply
		trigger = {
			NOR = {
				has_country_flag = crisis.8045.1.flag
				has_country_flag = crisis.8045.2.flag
				has_country_flag = crisis.8045.3.flag
				has_country_flag = crisis.8045.4.flag
				has_country_flag = crisis.8045.5.flag
				has_country_flag = crisis.8045.6.flag
				has_country_flag = crisis.8045.7.flag
				has_country_flag = crisis.8045.8.flag
				has_country_flag = crisis.8045.9.flag
				has_country_flag = crisis.8045.10.flag
				has_country_flag = crisis.8045.11.flag
				has_country_flag = crisis.8045.12.flag
			}
		}
		hidden_effect = {
			set_country_flag = crisis.8045.6.flag
		}
	}

	#A - It is my nature to nurture...
	#Your 'care' itself is harmful.
	option = {
		name = crisis.8045.1.a
		is_dialog_only = yes
		response_text = crisis.8045.2.reply
		sound = crisis_8045_2_reply
		trigger = {
			has_country_flag = crisis.8045.1.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.1.flag
			set_country_flag = crisis.8045.2.flag
		}
	}
	#What do you want Cetana?
	option = {
		name = crisis.8045.1.b
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.1.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.1.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#B - A Paradox
	#That remains to be seen.
	option = {
		name = crisis.8045.2.a
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.2.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.2.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#C - The elimination of suffering
	#How will you achieve this?
	option = {
		name = crisis.8045.3.a
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.3.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.3.flag
			set_country_flag = crisis.8045.8.flag
		}
	}
	#Suffering builds character.
	option = {
		name = crisis.8045.3.b
		is_dialog_only = yes
		response_text = crisis.8045.4.reply
		sound = crisis_8045_4_reply
		trigger = {
			has_country_flag = crisis.8045.3.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.3.flag
			set_country_flag = crisis.8045.4.flag
		}
	}

	#D - Many have said so...
	#Long ago?
	option = {
		name = crisis.8045.4.a
		is_dialog_only = yes
		response_text = crisis.8045.5.reply
		sound = crisis_8045_5_reply
		trigger = {
			has_country_flag = crisis.8045.4.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.4.flag
			set_country_flag = crisis.8045.5.flag
		}
	}
	#You propose to lead us?
	option = {
		name = crisis.8045.4.b
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.4.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.4.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#E - Ages upon ages...
	#What do you propose?
	option = {
		name = crisis.8045.5.a
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.5.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.5.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#F - I wish no harm...
	#You're insane.
	option = {
		name = crisis.8045.6.a
		is_dialog_only = yes
		response_text = crisis.8045.7.reply
		sound = crisis_8045_7_reply
		trigger = {
			has_country_flag = crisis.8045.6.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.6.flag
			set_country_flag = crisis.8045.7.flag
		}
	}
	#What will you do now?
	option = {
		name = crisis.8045.6.b
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.6.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.6.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#G - What you call madness...
	#What do you want?
	option = {
		name = crisis.8045.7.a
		is_dialog_only = yes
		response_text = crisis.8045.8.reply
		sound = crisis_8045_8_reply
		trigger = {
			has_country_flag = crisis.8045.7.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8045.7.flag
			set_country_flag = crisis.8045.8.flag
		}
	}

	#H - There is much to be done...
	#Has Valid Systems
	#We have no choice.
	option = {
		name = crisis.8045.8.a
		custom_tooltip = crisis.8045.has_valid_base_site
		is_dialog_only = yes
		response_text = crisis.8045.9.reply
		sound = crisis_8045_9_reply
		trigger = {
			has_country_flag = crisis.8045.8.flag
			has_country_flag = synth_queen_has_a_system
		}
		hidden_effect = {
			event_target:synth_queen_country_global = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8045.8.flag
			set_country_flag = crisis.8045.9.flag
		}
	}
	#Stay away from our borders.
	option = {
		name = crisis.8045.8.b
		custom_tooltip = crisis.8045.has_valid_base_site
		is_dialog_only = yes
		response_text = crisis.8045.10.reply
		sound = crisis_8045_10_reply
		trigger = {
			has_country_flag = crisis.8045.8.flag
			has_country_flag = synth_queen_has_a_system
		}
		hidden_effect = {
			event_target:synth_queen_country_global = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8045.8.flag
			set_country_flag = crisis.8045.10.flag
		}
	}
	#No Valid Systems
	#We have no choice.
	option = {
		name = crisis.8045.8.c
		custom_tooltip = crisis.8045.no_valid_base_site
		is_dialog_only = yes
		response_text = crisis.8045.11.reply
		sound = crisis_8045_11_reply
		trigger = {
			has_country_flag = crisis.8045.8.flag
			NOT = { has_country_flag = synth_queen_has_a_system }
		}
		hidden_effect = {
			event_target:synth_queen_country_global = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8045.8.flag
			set_country_flag = crisis.8045.11.flag
		}
	}
	#Stay away from our borders.
	option = {
		name = crisis.8045.8.d
		custom_tooltip = crisis.8045.no_valid_base_site
		is_dialog_only = yes
		response_text = crisis.8045.12.reply
		sound = crisis_8045_12_reply
		trigger = {
			has_country_flag = crisis.8045.8.flag
			NOT = { has_country_flag = synth_queen_has_a_system }
		}
		hidden_effect = {
			event_target:synth_queen_country_global = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8045.8.flag
			set_country_flag = crisis.8045.12.flag
		}
	}

	#I - Wise Child.../Has System
	#We must accept.
	option = {
		name = crisis.8045.9.a
		trigger = {
			has_country_flag = crisis.8045.9.flag
		}
		technological_gifts_of_the_synth_queen_effect = yes
		synth_queen_give_storm_project = yes
		give_specimen = { key = cetana_love origin = crisis.8045.name targets = { this } }
		hidden_effect = {
			remove_country_flag = crisis.8045.9.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#J - Misguided child.../Has System
	#We must accept.
	option = {
		name = crisis.8045.10.a
		trigger = {
			has_country_flag = crisis.8045.10.flag
		}
		technological_gifts_of_the_synth_queen_effect = yes
		synth_queen_give_storm_project = yes
		give_specimen = { key = cetana_love origin = crisis.8045.name targets = { this } }
		hidden_effect = {
			remove_country_flag = crisis.8045.10.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#K - Wise Child.../No System
	#We must accept.
	option = {
		name = crisis.8045.11.a
		trigger = {
			has_country_flag = crisis.8045.11.flag
		}
		technological_gifts_of_the_synth_queen_effect = yes
		synth_queen_give_storm_project = yes
		give_specimen = { key = cetana_love origin = crisis.8045.name targets = { this } }
		hidden_effect = {
			remove_country_flag = crisis.8045.11.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#L - Misguided child.../No System
	#We must accept.
	option = {
		name = crisis.8045.12.a
		trigger = {
			has_country_flag = crisis.8045.12.flag
		}
		technological_gifts_of_the_synth_queen_effect = yes
		synth_queen_give_storm_project = yes
		give_specimen = { key = cetana_love origin = crisis.8045.name targets = { this } }
		hidden_effect = {
			remove_country_flag = crisis.8045.12.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		hidden_effect = {
			owner = {
				country_event = { id = crisis.8999 days = 0 }
				country_event = { id = crisis.8080 days = 360 random = 180 }
			}

			if = {
				limit = {
					any_system_within_border = {
						is_bottleneck_system = no
						has_any_megastructure = no
						NOT = {
							any_system_planet = {
								OR = {
									is_colonizable = yes
									is_colony = yes
								}
							}
						}
					}
				}
				random_system_within_border = {
					limit = {
						is_bottleneck_system = no
						has_any_megastructure = no
						NOT = {
							any_system_planet = {
								OR = {
									is_colonizable = yes
									is_colony = yes
								}
							}
						}
					}
					synth_queen_wipe_system = yes
					synth_queen_create_outpost = yes
				}
			}
			else = {
				capital_scope = {
					closest_system = {
						min_steps = 1
						use_bypasses = no
						limit = {
							is_bottleneck_system = no
							has_any_megastructure = no
							NOT = {
								any_system_planet = {
									OR = {
										is_colonizable = yes
										is_colony = yes
									}
								}
							}
						}
						set_star_flag = synth_queen_player_system
						synth_queen_wipe_system = yes
						synth_queen_create_outpost = yes
					}
				}
			}
		}
	}
}

# FE tells Scion to step aside
country_event = {
	id = crisis.8046
	title = "crisis.8046.name"
	desc = "crisis.8046.desc"
	diplomatic = yes
	diplomatic_title = BLANK_STRING
	show_sound = event_bad_omen

	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:scion_master
		planet_background = event_target:scion_master
		graphical_culture = event_target:scion_master
		city_level = event_target:scion_master
		room = event_target:scion_master
	}

	trigger = {
		NOR = {
			has_active_event = { crisis.8046 }
			has_country_flag = scion_overlord_warning
		}
	}

	immediate = {
		set_country_flag = scion_overlord_warning
		overlord = { save_event_target_as = scion_master }
	}

	option = {
		name = "UNDERSTOOD"
		random_agreement = {
			limit = {
				owner = { is_same_value = root.overlord }
				target = { is_same_value = root }
			}
			set_agreement_terms = {
				joins_overlord_wars = joins_overlord_wars_none
			}
		}
	}

	after = {
		hidden_effect = {
			synth_queen_fe_war = yes
		}
	}
}

# Starts the raid event chain
country_event = {
	id = crisis.8047
	title = "crisis.8047.name"
	desc = "crisis.8047.desc"
	picture = GFX_evt_unidentified_ship
	show_sound = event_ship_thrusters
	is_triggered_only = yes
	event_chain = the_synth_queen_raids_chain

	immediate = {
		# We need to start the chain in the immediate block, so the event will have the subtitle
		begin_event_chain = {
			event_chain = the_synth_queen_raids_chain
			target = root
		}
	}

	option = {
		name = "INTERESTING"
		custom_tooltip = "crisis.8047.a.tooltip"
		# We pretend to start it here to get a nice tooltip
		tooltip = {
			begin_event_chain = {
				event_chain = the_synth_queen_raids_chain
				target = root
			}
		}
	}

	after = {
		# Should be impossible, but just to protect ourselves from edge cases...
		# Also give the outpost raids if you are already protected from the storm
		if = {
			limit = {
				has_country_flag = protected_from_queen_storm
			}
			custom_tooltip = "crisis.8048.a.tooltip"
			set_country_flag = synth_queen_can_raid_outposts
			synth_queen_raid_projects = yes
		}
	}
}

# Unlock raids against outposts once protected against the storm
country_event = {
	id = crisis.8048
	title = "crisis.8048.name"
	desc = "crisis.8048.desc"
	picture = GFX_evt_space_station
	show_sound = event_ship_thrusters
	is_triggered_only = yes
	event_chain = the_synth_queen_raids_chain

	fire_only_once = yes

	trigger = {
		NOT = { has_country_flag = synth_queen_can_raid_outposts }
	}

	option = {
		name = "INTERESTING"
		custom_tooltip = "crisis.8048.a.tooltip"
		set_country_flag = synth_queen_can_raid_outposts
		synth_queen_raid_projects = yes
	}
}

# Spawns convoys and history sites
# We only fire it once to avoid spamming to many convoys in MP
# Fired by on_monthly_pulse
event = {
	id = crisis.8049
	hide_window = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		has_global_flag = synth_queen_speech_2_happened
		NOT = { has_global_flag = synth_queen_side_quests_spawned }
		# Checks if everyone has finished talking to the Synth Queen
		count_playable_country = {
			count = all
			limit = {
				has_country_flag = speech_2
				NOT = { has_country_flag = synth_queen_conversation_ongoing }
			}
		}
	}

	immediate = {
		set_global_flag = synth_queen_side_quests_spawned
		every_playable_country = {
			country_event = { id = crisis.8047 }	# Raids event chain
			country_event = { id = crisis.20000 days = 95 }	# History event chain
		}

	}

	after = {
		# Creates the convoys
		synth_queen_create_convoy_fleet = yes
		synth_queen_create_convoy_fleet = yes
		synth_queen_create_convoy_fleet = yes
		# Creates the history sites
		switch = { # 6 projects (1 in your border + 5 random ones) + 1 extra special project for 200 stars
			trigger = galaxy_size
			tiny = { # 200 stars
				synth_queen_spawn_history_projects = yes
			}
			small = { # 400 stars
				synth_queen_spawn_history_projects = { NUM_EXTRA_PROJECTS = 1 }
			}
			medium = { # 600 stars
				synth_queen_spawn_history_projects = { NUM_EXTRA_PROJECTS = 2 }
			}
			large = { # 800 stars
				synth_queen_spawn_history_projects = { NUM_EXTRA_PROJECTS = 3 }
			}
			huge = { # 1000 stars
				synth_queen_spawn_history_projects = { NUM_EXTRA_PROJECTS = 4 }
			}
		}
	}
}

# Reinforcements while at war with FE
country_event = {
	id = crisis.8050
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen
		any_country = {
			OR = {
				is_country_type = fallen_empire
				is_country_type = awakened_fallen_empire
			}
		}
	}

	immediate = {
		while = {
			limit = {
				count_owned_fleet = {
					count < 13
					limit = {
						is_mobile = yes
					}
				}
			}
			synth_queen_create_war_fleet = yes
		}
	}
}

# Synth Queen Diplomacy gatekeeper
# Via on_custom_diplomacy | this = target country (player); from = country being contacted
country_event = {
	id = crisis.8055
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_country_flag = can_talk_to_the_synth_queen
		from = {
			OR = {
				is_country_type = synth_queen
				is_country_type = awakened_synth_queen
				is_country_type = synth_queen_convoys
				is_country_type = synth_queen_outposts
			}
		}
		NOR = {
			has_active_event = {
				#Populate with Synth Queen diplomacy events
				crisis.8060 #GREETINGS
			}
			has_active_event = {
				#Populate with Synth Queen diplomacy events
				crisis.8061 #GREETINGS IN WARTIME
			}
			has_active_event = {
				#Populate with Synth Queen diplomacy events
				crisis.8062 #GREETINGS IN WARTIME
			}
			has_active_event = {
				#Populate with Synth Queen diplomacy events
				crisis.8063 #SEEN BUT NOT ANSWERED
			}
		}
	}

	immediate = {
		from = {
			save_event_target_as = synth_queen_country
		}
		if = {
			limit = {
				NOT = {	has_country_flag = speech_2 }
			}
			country_event = { id = crisis.8063 }
		}
		if = {
			limit = {
				has_country_flag = speech_2
				NOT = {	has_global_flag = synth_queen_war_started }
			}
			country_event = { id = crisis.8060 }
		}
		if = {
			limit = {
				has_global_flag = synth_queen_war_started
				NOT = {
					has_country_flag = synth_queen_first_war_time_chat_done
				}
			}
			country_event = { id = crisis.8061 }
		}
		if = {
			limit = {
				has_global_flag = synth_queen_war_started
				has_country_flag = synth_queen_first_war_time_chat_done
			}
			country_event = { id = crisis.8062 }
		}
	}
}

#Player Diplomacy
country_event = {
	id = crisis.8060
	title = TRANSMISSION
	diplomatic_title = "crisis.8060.name"
	desc = "crisis.8060.like.desc"
	show_sound = crisis_8060_like_desc
	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	#H - Declare war after finishing the situation
	option = {
		name = crisis.8060.war
		icon = {
			icon = GFX_text_casus_belli_target
			text = WARGOAL
		}
		allow = {
			custom_tooltip = {
				fail_text = "synth_queen_not_able_to_attack_cetana_situation"
				has_country_flag = synth_queen_cannot_yeet_the_fleets
				has_country_flag = protected_from_queen_storm
			}
			custom_tooltip = {
				fail_text = "synth_queen_not_able_to_attack_cetana_storm"
				has_country_flag = synth_queen_researched_first_storm_project
				has_country_flag = protected_from_queen_storm
			}
		}
		trigger = {
			has_synth_queen_dialogue_flag = no
		}
		if = {
			limit = {
				has_country_flag = synth_queen_cannot_yeet_the_fleets
				has_country_flag = protected_from_queen_storm
			}
			custom_tooltip = synth_queen_able_to_attack_cetana
		}
		is_dialog_only = yes
		response_text = crisis.8060.war.reply
		sound = crisis_8060_war_reply

		hidden_effect = {
			set_country_flag = crisis.8060.war.flag
		}
	}

	option = { # Yes
		name = crisis.8060.war.a
		custom_tooltip = crisis.8060.war.a.tt
		trigger = {
			has_country_flag = crisis.8060.war.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.war.1.reply
		sound = crisis_8060_war_1_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.war.flag
			set_country_flag = crisis.8060.war.1.flag
		}
	}

	option = { # No
		name = crisis.8060.war.b
		trigger = {
			has_country_flag = crisis.8060.war.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.war.flag
		}
	}

 	# War starts
	option = {
		name = crisis.8060.war.1.a
		trigger = {
			has_country_flag = crisis.8060.war.1.flag
		}
		if = {
			limit = {
				has_modifier = synth_queen_nanite_apprentice
			}
			remove_modifier = synth_queen_nanite_apprentice
		}
		hidden_effect = {
			event_target:synth_queen_country_global = {
				set_country_type = awakened_synth_queen
				set_country_flag = protected_from_queen_storm
				country_event = { id = crisis.8156 days = 7 }
				synth_queen_debuff = yes
			}
			synth_queen_set_war_hostility = yes
			set_global_flag = synth_queen_war_started
			remove_country_flag = crisis.8060.war.1.flag
			set_country_flag = synth_queen_cannot_yeet_the_fleets
			set_country_flag = protected_from_queen_storm
		}
		random_situation = {
			limit = {
				is_situation_type = situation_synth_queen_player_facing
			}
			destroy_situation = this
		}
	}

	#A - How can we help?
	option = {
		name = crisis.8060.a
		trigger = {
			has_synth_queen_dialogue_flag = no
		}
		is_dialog_only = yes
		response_text = crisis.8060.a.reply
		sound = crisis_8060_1_reply
		hidden_effect = {
			set_country_flag = crisis.8060.1.flag
		}
	}

	option = {
		name = crisis.8060.1.a
		trigger = {
			has_country_flag = crisis.8060.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.1.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = 5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_approve
			}
			remove_country_flag = crisis.8060.1.flag
			set_country_flag = crisis.8060.1.a.opinion
		}
	}

	option = {
		name = crisis.8060.1.b
		trigger = {
			has_country_flag = crisis.8060.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.1.flag
		}
	}

	#B - You will be stopped
	option = {
		name = crisis.8060.b
		trigger = {
			has_synth_queen_dialogue_flag = no
		}

		is_dialog_only = yes
		response_text = crisis.8060.2.reply
		sound = crisis_8060_2_reply
		hidden_effect = {
			set_country_flag = crisis.8060.2.flag
		}
	}

	option = {
		name = crisis.8060.2.a
		trigger = {
			has_country_flag = crisis.8060.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.2.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.2.flag
			set_country_flag = crisis.8060.2.a.opinion
		}
	}

	option = {
		name = crisis.8060.2.2
		trigger = {
			has_country_flag = crisis.8060.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.2.flag
		}
	}

	#C - Why you mean?
	option = {
		name = crisis.8060.c
		trigger = {
			has_synth_queen_dialogue_flag = no
		}
		is_dialog_only = yes
		response_text = crisis.8060.3.reply
		sound = crisis_8060_3_reply
		hidden_effect = {
			set_country_flag = crisis.8060.3.flag
		}
	}

	option = {
		name = crisis.8060.3.a
		trigger = {
			has_country_flag = crisis.8060.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.3.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.3.flag
			set_country_flag = crisis.8060.3.a.opinion
		}
	}

	option = {
		name = crisis.8060.3.b
		trigger = {
			has_country_flag = crisis.8060.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.3.flag
		}
	}

	#D - You blew up our moon. You will pay.
	option = {
		name = crisis.8060.d
		trigger = {
			has_synth_queen_dialogue_flag = no
			has_country_flag = synth_queen_question_blew_up_a_planet
		}
		is_dialog_only = yes
		response_text = crisis.8060.4.reply
		sound = crisis_8060_4_reply
		hidden_effect = {
			set_country_flag = crisis.8060.4.flag
		}
	}

	option = {
		name = crisis.8060.4.a
		trigger = {
			has_country_flag = crisis.8060.4.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.4.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.4.flag
			remove_country_flag = synth_queen_question_blew_up_a_planet
			set_country_flag = crisis.8060.4.a.opinion
		}
	}

	option = {
		name = crisis.8060.4.b
		trigger = {
			has_country_flag = crisis.8060.4.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.4.flag
			remove_country_flag = synth_queen_question_blew_up_a_planet
		}
	}

	#E - We opened the box
	option = {
		name = crisis.8060.e
		trigger = {
			has_synth_queen_dialogue_flag = no
			has_country_flag = synth_queen_question_opened_the_databank
		}
		is_dialog_only = yes
		response_text = crisis.8060.5.reply
		sound = crisis_8060_5_reply
		hidden_effect = {
			set_country_flag = crisis.8060.5.flag
		}
	}

	option = {
		name = crisis.8060.5.a
		trigger = {
			has_country_flag = crisis.8060.5.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.5.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.5.flag
			remove_country_flag = synth_queen_question_opened_the_databank
			set_country_flag = crisis.8060.5.a.opinion
		}
	}

	option = {
		name = crisis.8060.5.b
		trigger = {
			has_synth_queen_dialogue_flag = no
			has_country_flag = crisis.8060.5.flag
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.5.flag
			remove_country_flag = synth_queen_question_opened_the_databank
		}
	}

	#Questions what has been done with pops in crisis.8300
	option = {
		name = crisis.8060.f
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_random_demand_pops
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.6.reply
		sound = crisis_8060_6_reply
		hidden_effect = {
			set_country_flag = crisis.8060.6.flag
		}
	}

	option = {
		name = crisis.8060.6.a
		trigger = {
			owner = {
				has_country_flag =crisis.8060.6.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.6.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.6.flag
			remove_country_flag = synth_queen_question_random_demand_pops
			set_country_flag = crisis.8060.6.a.opinion
		}
	}

	option = {
		name = crisis.8060.6.b
		trigger = {
			owner = {
				has_country_flag = crisis.8060.6.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.6.flag
			remove_country_flag = synth_queen_question_random_demand_pops
		}
	}

	# Questions motivations in crisis.8315
	option = {
		name = crisis.8060.g
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_random_demand_system
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.7.reply
		sound = crisis_8060_7_reply
		hidden_effect = {
			set_country_flag = crisis.8060.7.flag
		}
	}

	option = {
		name = crisis.8060.7.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.7.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.7.flag
			remove_country_flag = synth_queen_question_random_demand_system
		}
	}

	# Question - How did Zarqlan defeat you?
	option = {
		name = crisis.8060.h
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_zarqlan_knowledge
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.8.reply
		sound = crisis_8060_8_reply
		hidden_effect = {
			set_country_flag = crisis.8060.8.flag
		}
	}

	option = {
		name = crisis.8060.8.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.8.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.8.1.reply
		sound = crisis_8060_8_1_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.8.flag
			set_country_flag = crisis.8060.8.1.flag
		}
	}

	#Shourd Only
	option = {
		name = crisis.8060.8.b
		custom_tooltip = crisis.8060.animator.tt
		trigger = {
			owner = {
				has_country_flag = crisis.8060.8.flag
				has_country_flag = breached_shroud
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.8.1.reply
		sound = crisis_8060_8_1_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.8.flag
			set_country_flag = crisis.8060.8.1.flag
			set_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = crisis.8060.8.1.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.8.1.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.8.1.flag
			remove_country_flag = synth_queen_question_zarqlan_knowledge
		}
	}

	option = {
		name = crisis.8060.8.1.b
		trigger = {
			owner = {
				has_country_flag = crisis.8060.8.1.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.8.1.b.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = -5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_disapprove
			}
			remove_country_flag = crisis.8060.8.1.flag
			remove_country_flag = synth_queen_question_zarqlan_knowledge
			set_country_flag = crisis.8060.8.1.b.opinion
		}
	}

	#Shourd Only
	option = {
		name = crisis.8060.8.1.c
		trigger = {
			owner = {
				has_country_flag = crisis.8060.8.1.flag
				has_country_flag = breached_shroud
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.8.1.flag
			remove_country_flag = synth_queen_question_zarqlan_knowledge
		}
	}

	# Question - Player Gave Zarqlans Head to the Queen
	option = {
		name = crisis.8060.i
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_gave_zarqlans_head
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.9.reply
		sound = crisis_8060_9_reply
		hidden_effect = {
			set_country_flag = crisis.8060.9.flag
		}
	}

	option = {
		name = crisis.8060.9.a
		trigger = {
			owner = {
				has_country_flag =crisis.8060.9.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.9.flag
			remove_country_flag = synth_queen_question_gave_zarqlans_head
		}
	}

	option = {
		name = crisis.8060.9.b
		trigger = {
			owner = {
				has_country_flag = crisis.8060.9.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.9.flag
			remove_country_flag = synth_queen_question_gave_zarqlans_head
		}
	}

	# Question - Found some Cyropods of her old followers
	option = {
		name = crisis.8060.j
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_found_cryo_pods
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.10.reply
		sound = crisis_8060_10_reply
		hidden_effect = {
			set_country_flag = crisis.8060.10.flag
		}
	}

	option = {
		name = crisis.8060.10.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.10.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_country_flag = crisis.8060.10.a.opinion
					}
				}
				event_target:synth_queen_country = {
					add_trust = {
						amount = 5
						who = root.owner
					}
				}
				custom_tooltip = synth_queen_approve
			}
			remove_country_flag = crisis.8060.10.flag
			remove_country_flag = synth_queen_question_found_cryo_pods
			set_country_flag = crisis.8060.10.a.opinion
		}
	}

	option = {
		name = crisis.8060.10.b
		trigger = {
			owner = {
				has_country_flag = crisis.8060.10.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.10.flag
			remove_country_flag = synth_queen_question_found_cryo_pods
		}
	}

	# Question - Found The Frozen Dreamer
	option = {
		name = crisis.8060.k
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_found_the_frozen_dreamer
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.11.reply
		sound = crisis_8060_11_reply
		hidden_effect = {
			set_country_flag = crisis.8060.11.flag
		}
	}

	option = {
		name = crisis.8060.11.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.11.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.11.flag
			remove_country_flag = synth_queen_question_found_the_frozen_dreamer
		}
	}

	option = {
		name = crisis.8060.11.b
		trigger = {
			owner = {
				has_country_flag = crisis.8060.11.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		hidden_effect = {
			remove_country_flag = crisis.8060.11.flag
			remove_country_flag = synth_queen_question_found_the_frozen_dreamer
		}
	}

	#Nanite Path
	option = {
		name = crisis.8060.l
		icon = {
			icon = GFX_tradition_nanotech
			text = tradition_nanotech
		}
		trigger = {
			owner = {
				has_synth_queen_dialogue_flag = no
				has_country_flag = synth_queen_question_nanite_apprentice
				any_country = {
					is_country_type = synth_queen
					trust = { who = root value > 49 }
				}
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.12.reply
		sound = crisis_8060_12_reply
		hidden_effect = {
			set_country_flag = crisis.8060.12.flag
		}
	}

	option = {
		name = crisis.8060.12.a
		trigger = {
			owner = {
				has_country_flag = crisis.8060.12.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8060.neutral.reply
		sound = crisis_8060_neutral_reply
		if = {
			limit = {
				NOT = {
					has_country_flag = crisis.8060.12.a.opinion
				}
			}
			hidden_effect = {
				event_target:synth_queen_country = {
					add_trust = {
						amount = 5
						who = root.owner
					}
				}
			}
			custom_tooltip = synth_queen_approve
		}
		if = {
			limit = {
				any_system = {
					has_star_flag = lgate
						OR = {
							has_owner = no
							owner = { is_same_value = root }
						}
					any_system_planet = {
						is_star = no
						is_astral_scar = no
						is_ringworld = no
						is_colonizable = no
						NOR = {
							is_planet_class = pc_black_hole
							is_planet_class = pc_habitat
						}
					}
				}
			}
			custom_tooltip = crisis.8060.12.a.tt
		}
		if = {
			limit = {
				has_event_chain = l_cluster_chain
			}
			generate_lcluster_clue = yes
		}
		add_modifier = {
			modifier = synth_queen_nanite_apprentice
			days = -1
		}
		hidden_effect = {
			set_country_flag = crisis.8060.12.a.opinion
			remove_country_flag = crisis.8060.12.flag
			remove_country_flag = synth_queen_question_nanite_apprentice
			every_system = {
				limit = {
					has_star_flag = lgate
					OR = {
						has_owner = no
						owner = { is_same_value = root }
					}
				}
				every_system_planet = {
					limit = {
						NOR = {
							is_star = yes
							is_astral_scar = yes
							is_ringworld = yes
							is_colonizable = yes
							is_planet_class = pc_black_hole
							is_planet_class = pc_habitat
						}
					}
					add_deposit = d_nanites_deposit
				}
			}
		}
	}

	#Z - End Conversation
	option = {
		name = crisis.8060.z
		trigger = {
			has_synth_queen_dialogue_flag = no
		}

		hidden_effect = {
			if = {
				limit = {
					has_country_flag = breached_shroud
					has_origin = origin_shroud_forged
					has_country_flag = synth_queen_can_contact_the_animator_of_clay
					has_covenant_with_end_of_the_cycle = no
					NOR = {
						has_country_flag = shroud_forged_traitor
						has_country_flag = synth_queen_contacted_the_animator_already
					}
				}
				country_event = { id = shroud_forged.700 }
			}
		}
	}
}

#First Wartime Convo with the Synth Queen
country_event = {
	id = crisis.8061
	title = "crisis.8061.name"
	diplomatic_title = "crisis.8061.name"
	desc = "crisis.8061.desc"
	show_sound = crisis_8061_desc
	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.8061.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8061.1.flag
				has_country_flag = crisis.8061.2.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8061.1.reply
		sound = crisis_8061_1_reply
		hidden_effect = {
			set_country_flag = crisis.8061.1.flag
		}
	}

	option = {
		name = crisis.8061.1.a
		trigger = {
			has_country_flag = crisis.8061.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8061.2.reply
		sound = crisis_8061_2_reply
		hidden_effect = {
			remove_country_flag = crisis.8061.1.flag
			set_country_flag = crisis.8061.2.flag
		}
	}

	option = {
		name = crisis.8061.2.a
		trigger = {
			has_country_flag = crisis.8061.2.flag
		}
		hidden_effect = {
			set_country_flag = synth_queen_first_war_time_chat_done
			remove_country_flag = crisis.8061.2.flag
		}
	}
}

#All Other Wartime Convos
country_event = {
	id = crisis.8062
	title = TRANSMISSION
	diplomatic_title = "crisis.8062.name"
	desc = "crisis.8062.desc"
	show_sound = crisis_8062_desc
	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.8062.a
	}
}

# Between the Speeches
country_event = {
	id = crisis.8063
	title = "crisis.8063.name"
	desc = "crisis.8063.desc"
	picture = GFX_evt_vortex
	show_sound = event_bad_omen

	is_triggered_only = yes

	option = {
		name = crisis.8063.a
	}
}

# Fleet attacks the Queen Guard
# This = owner of fleet 1
# From = owner of fleet 2
# FromFrom = fleet 1
# FromFromFrom = fleet 2
country_event = {
	id = crisis.8065
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		NOT = { has_country_flag = synth_queen_cannot_yeet_the_fleets }
		NOT = { has_country_flag = synth_queen_shes_too_strong }
		from = { is_synth_queen_country_type = yes }
		fromfrom = {
			is_mobile = yes
		}
	}

	immediate = {
		set_country_flag = synth_queen_failed_attack
		fromfrom = {
			every_owned_ship = {
				random_list = {
					1 = { reduce_hp_percent = 0.99 }
					1 = { reduce_hp_percent = 0.85 }
					1 = { reduce_hp_percent = 0.78 }
					1 = { reduce_hp_percent = 0.90 }
					1 = { reduce_hp_percent = 0.62 }
					1 = { destroy_ship = this }
				}
			}
			set_mia = mia_return_home
		}
		country_event = {
			id = crisis.8070
			days = 0
		}
		set_country_flag = synth_queen_shes_too_strong
	}
}

#Alerting the player they cannot hurt the Queen (yet)
country_event = {
	id = crisis.8070
	title = "crisis.8070.name"
	desc = {
		trigger = {
			NOT = { has_country_flag = attempted_to_attack_the_queen_once }
		}
		text = crisis.8070.desc
	}
	desc = {
		trigger = {
			has_country_flag = attempted_to_attack_the_queen_once
		}
		text = crisis.8070.again.desc
	}
	picture = GFX_evt_small_space_battle
	show_sound = event_worrying_signal
	location = event_target:synth_queen_system
	is_triggered_only = yes

	option = { # Yes
		name = crisis.8070.a
		hidden_effect = {
			country_event = {
				id = crisis.8075
				days = 0
			}
		}
	}
}

#Synth Queen Gives you a Chance to Surrender
country_event = {
	id = crisis.8075
	title = crisis.8075.name
	diplomatic_title = crisis.8075.name
	desc = crisis.8075.desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		remove_country_flag = synth_queen_shes_too_strong
	}

	#Accept Your Fate
	option = { # Yes
		name = crisis.8075.a
	}

	#Angry About IT
	option = {
		name = crisis.8075.b
	}

	after = {
		hidden_effect = {
			set_country_flag = attempted_to_attack_the_queen_once
		}
	}
}

#Queen's ask you to collect the box
country_event = {
	id = crisis.8080
	title = "crisis.8080.name"
	diplomatic_title = "crisis.8080.name"
	desc = "crisis.8080.desc"
	show_sound = crisis_8080_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_first_demand
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = mother_knows_best_small_favor
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
			set_country_flag = synth_queen_conversation_ongoing
		}
		#Picks your moon
		if = {
			limit = {
				capital_scope = {
					has_moon = yes
					any_moon = {
						NOR = {
							habitable_planet = yes
							is_planet_class = pc_shattered
							is_planet_class = pc_broken
							is_planet_class = pc_shattered_2
							is_planet_class = pc_habitat
						}
					}
				}
			}
			capital_scope = {
				random_moon = {
					limit = {
						NOR = {
							habitable_planet = yes
							is_planet_class = pc_shattered
							is_planet_class = pc_broken
							is_planet_class = pc_shattered_2
							is_planet_class = pc_habitat
						}
					}
					set_carrier_flag = synth_queen_databank_location@root
					save_event_target_as = synth_queen_databank_location
				}
			}
		}
		#Picks a random useless planet in your system
		else_if = {
			limit = {
				capital_scope = {
					solar_system = {
						any_system_planet = {
							is_star = no
							NOR = {
								habitable_planet = yes
								is_planet_class = pc_shattered
								is_planet_class = pc_broken
								is_planet_class = pc_shattered_2
								is_planet_class = pc_habitat
								is_planet_class = pc_gas_giant
							}
						}
					}
				}
			}
			capital_scope = {
				solar_system = {
					random_system_planet = {
						limit = {
							is_star = no
							NOR = {
								habitable_planet = yes
								is_planet_class = pc_shattered
								is_planet_class = pc_broken
								is_planet_class = pc_shattered_2
								is_planet_class = pc_habitat
								is_planet_class = pc_gas_giant
							}
						}
						set_carrier_flag = synth_queen_databank_location@root
						save_event_target_as = synth_queen_databank_location
					}
				}
			}
		}
	}

	#First Option
	option = {
		name = crisis.8080.a
		trigger = {
			is_machine_empire = no
			NOR = {
				has_country_flag = crisis.8080.1.flag
				has_country_flag = crisis.8080.2.flag
				has_country_flag = crisis.8080.3.flag
				has_country_flag = crisis.8080.4.flag
				has_country_flag = crisis.8080.5.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8080.1.reply
		sound = crisis_8080_1_reply
		hidden_effect = {
			set_country_flag = crisis.8080.1.flag
		}
	}

	option = {
		name = crisis.8080.b
		trigger = {
			is_machine_empire = yes
			NOR = {
				has_country_flag = crisis.8080.1.flag
				has_country_flag = crisis.8080.2.flag
				has_country_flag = crisis.8080.3.flag
				has_country_flag = crisis.8080.4.flag
				has_country_flag = crisis.8080.5.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8080.1.reply
		sound = crisis_8080_1_reply
		hidden_effect = {
			set_country_flag = crisis.8080.1.flag
		}
	}

	#A1 - What databank?
	option = {
		name = crisis.8080.1.a
		trigger = {
			has_country_flag = crisis.8080.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.2.reply
		sound = crisis_8080_2_reply
		hidden_effect = {
			remove_country_flag = crisis.8080.1.flag
			set_country_flag = crisis.8080.2.flag
		}
	}

	#A2 - Rewarded?
	option = {
		name = crisis.8080.1.b
		trigger = {
			is_megacorp = no
			has_country_flag = crisis.8080.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.3.reply
		sound = crisis_8080_3_reply
		hidden_effect = {
			remove_country_flag = crisis.8080.1.flag
			set_country_flag = crisis.8080.3.flag
		}
	}

	option = {
		name = crisis.8080.1.c
		trigger = {
			is_megacorp = yes
			has_country_flag = crisis.8080.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.3.reply
		sound = crisis_8080_3_reply
		hidden_effect = {
			remove_country_flag = crisis.8080.1.flag
			set_country_flag = crisis.8080.3.flag
		}
	}

	#B1 - Very well.
	option = {
		name = crisis.8080.2.a
		trigger = {
			has_country_flag = crisis.8080.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.4.reply
		sound = crisis_8080_4_reply
		hidden_effect = {
			remove_country_flag = crisis.8080.2.flag
			set_country_flag = crisis.8080.4.flag
		}
	}

	#B2 - We are not your servants.
	option = {
		name = crisis.8080.2.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			has_country_flag = crisis.8080.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.5.reply
		sound = crisis_8080_5_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8080.2.flag
			set_country_flag = crisis.8080.5.flag
		}
	}

	#C1 - Very well.
	option = {
		name = crisis.8080.3.a
		trigger = {
			has_country_flag = crisis.8080.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.4.reply
		sound = crisis_8080_4_reply
		hidden_effect = {
			remove_country_flag = crisis.8080.3.flag
			set_country_flag = crisis.8080.4.flag
		}
	}

	#C2 - We are not your servants.
	option = {
		name = crisis.8080.3.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			has_country_flag = crisis.8080.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8080.5.reply
		sound = crisis_8080_5_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8080.3.flag
			set_country_flag = crisis.8080.5.flag
		}
	}

	#D1 - That remains to be seen.
	option = {
		name = crisis.8080.4.a
		custom_tooltip = crisis.8080.special_project_tooltip
		trigger = {
			has_country_flag = crisis.8080.4.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8080.4.flag
			enable_special_project = {
				name = "THE_SYNTH_QUEENS_DATABANK"
				location = event_target:synth_queen_databank_location
				owner = ROOT
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#E1 - Tempest?!
	option = {
		name = crisis.8080.5.a
		trigger = {
			has_country_flag = crisis.8080.5.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8080.5.flag
			country_event = {
				id = crisis.8105
				days = 1
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
		custom_tooltip = crisis.8080.5.a.tt
	}


	after = {
		hidden_effect = {
			set_country_flag = synth_queen_first_demand
		}
	}
}

# You collected the box, should we open it?
country_event = {
	id = crisis.8085
	title = "crisis.8085.name"
	desc = "crisis.8085.desc"
	picture = GFX_evt_scholarium_anomaly
	show_sound = event_alien_signal
	location = root

	is_triggered_only = yes

	#Open the box
	option = {
		name = crisis.8085.a
		hidden_effect = {
			country_event = {
				id = crisis.8090
				days = 14
			}
		}
	}

	#Just give it to her without opening
	option = {
		name = crisis.8085.b
		hidden_effect = {
			country_event = {
				id = crisis.8100
				days = 14
			}
		}
	}

	#Hack the Box
	option = {
		name = crisis.8085.c
		trigger = {
			is_materialist = yes
		}
		hidden_effect = {
			country_event = {
				id = crisis.8090
				days = 14
			}
		}
	}
}

# Whats in the box? You opened it.
country_event = {
	id = crisis.8090
	title = "crisis.8090.name"
	desc = "crisis.8090.desc"
	picture = GFX_evt_worrying_signal
	show_sound = event_worrying_signal
	location = root

	is_triggered_only = yes

	option = {
		name = crisis.8090.a
		custom_tooltip = crisis.8525.a.tt
		trigger = {
			is_materialist = no
		}
		hidden_effect = {
			country_event = {
				id = crisis.8095
				days = 14
			}
		}
		synth_queen_progress_situation = { SCORE = 1 }
	}

	option = {
		name = crisis.8090.b
		custom_tooltip = crisis.8525.a.tt
		trigger = {
			is_materialist = yes
		}
		hidden_effect = {
			country_event = {
				id = crisis.8100
				days = 14
			}
		}
		synth_queen_progress_situation = { SCORE = 1 }
	}

	after = {
		set_country_flag = rebellious_child
		set_country_flag = synth_queen_question_opened_the_databank
		doomclock_reveal = yes
	}
}

#Speech - You opened the Box...
country_event = {
	id = crisis.8095
	title = "crisis.8095.name"
	diplomatic_title = "crisis.8095.name"
	desc = "crisis.8095.desc"
	show_sound = crisis_8095_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = -15
				who = root.owner
			}
		}
	}

	#What are you talking about?
	option = {
		name = crisis.8095.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8095.1.flag
				has_country_flag = crisis.8095.2.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8095.1.reply
		sound = crisis_8095_1_reply
		hidden_effect = {
			set_country_flag = crisis.8095.1.flag
		}
	}

	#A1 - Whatever your plans, they will not succeed.
	option = {
		name = crisis.8095.1.a
		trigger = {
			has_country_flag = crisis.8095.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8095.2.reply
		sound = crisis_8095_2_reply
		hidden_effect = {
			remove_country_flag = crisis.8095.1.flag
			set_country_flag = crisis.8095.2.flag
		}
	}

	#A2 - We look forward to it.
	option = {
		name = crisis.8095.1.b
		custom_tooltip = synth_queen_approve
		trigger = {
			has_country_flag = crisis.8095.1.flag
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8095.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#B1 - Shut her off..
	option = {
		name = crisis.8095.2.a
		custom_tooltip = synth_queen_disapprove
		trigger = {
			has_country_flag = crisis.8095.2.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8095.2.flag
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		remove_country_flag = synth_queen_conversation_ongoing
		set_country_flag = synth_queen_finished_first_demand_chain
	}
}

#Speech - Good child, you didn't open the box...
country_event = {
	id = crisis.8100
	title = "crisis.8100.name"
	diplomatic_title = "crisis.8100.name"
	desc = "crisis.8100.desc"
	show_sound = crisis_8100_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	#We are grateful.
	option = {
		name = crisis.8100.a
		trigger = {
			NOT = { has_country_flag = crisis.8100.1.flag }
		}
		is_dialog_only = yes
		response_text = crisis.8100.1.reply
		sound = crisis_8100_1_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 10
					who = root.owner
				}
			}
			set_country_flag = crisis.8100.1.flag
		}
	}

	#End communication
	option = {
		name = crisis.8100.1.a
		trigger = {
			has_country_flag = crisis.8100.1.flag
		}
		technological_gifts_of_the_synth_queen_effect = yes
		hidden_effect = {
			remove_country_flag = crisis.8100.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#End communication
	option = {
		name = crisis.8100.1.b
		trigger = {
			has_country_flag = crisis.8100.1.flag
		}
		add_monthly_resource_mult = {
			resource = energy
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		add_monthly_resource_mult = {
			resource = minerals
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		if = {
			limit = {
				country_uses_food = yes
			}
			add_monthly_resource_mult = {
				resource = food
				value = @tier5materialreward
				min = @tier5materialmin
				max = @tier5materialmax
			}
		}
		if = {
			limit = {
				country_uses_consumer_goods = yes
			}
			add_monthly_resource_mult = {
				resource = consumer_goods
				value = @tier5materialreward
				min = @tier5materialmin
				max = @tier5materialmax
			}
		}
		add_monthly_resource_mult = {
			resource = alloys
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		hidden_effect = {
			remove_country_flag = crisis.8100.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#End communication
	option = {
		name = crisis.8100.1.c
		trigger = {
			has_country_flag = crisis.8100.1.flag
		}
		add_monthly_resource_mult = {
			resource = rare_crystals
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		add_monthly_resource_mult = {
			resource = exotic_gases
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		add_monthly_resource_mult = {
			resource = volatile_motes
			value = @tier5materialreward
			min = @tier5materialmin
			max = @tier5materialmax
		}
		hidden_effect = {
			remove_country_flag = crisis.8100.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	#End communication
	option = {
		name = crisis.8100.1.d
		trigger = {
			has_country_flag = crisis.8100.1.flag
		}
		add_monthly_resource_mult = {
			resource = sr_dark_matter
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_monthly_resource_mult = {
			resource = sr_zro
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_monthly_resource_mult = {
			resource = sr_living_metal
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		add_monthly_resource_mult = {
			resource = nanites
			value = @tier2materialreward
			min = @tier2materialmin
			max = @tier2materialmax
		}
		if = {
			limit = {
				host_has_dlc = "Ancient Relics Story Pack"
			}
			add_monthly_resource_mult = {
				resource = minor_artifacts
				value = @tier2materialreward
				min = @tier2materialmin
				max = @tier2materialmax
			}
		}
		hidden_effect = {
			remove_country_flag = crisis.8100.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		remove_country_flag = synth_queen_conversation_ongoing
		set_country_flag = synth_queen_finished_first_demand_chain
	}
}

# Refused to help the queen - Nanites Incoming
country_event = {
	id = crisis.8105
	title = "crisis.8105.name"
	desc = "crisis.8105.desc"
	picture = GFX_evt_vortex
	show_sound = event_bad_omen
	location = root

	is_triggered_only = yes

	#Open the box
	option = {
		name = crisis.8105.a
		custom_tooltip = crisis.8105.a.tooltip
		hidden_effect = {
			enable_special_project = {
				name = "THE_SYNTH_QUEENS_DATABANK_COUNTDOWN"
				location = event_target:synth_queen_databank_location
				owner = ROOT
			}
		}
	}
}

# Got the Box before the nanities
country_event = {
	id = crisis.8110
	title = "crisis.8110.name"
	desc = "crisis.8110.desc"
	picture = GFX_evt_scholarium_anomaly
	show_sound = event_alien_signal
	location = root

	is_triggered_only = yes

	#Open the box - lose the planet
	option = {
		name = crisis.8110.a
		hidden_effect = {
			country_event = {
				id = crisis.8115
				days = 7
			}
		}
	}

	#Send Cetana the box - save the planet
	option = {
		name = crisis.8110.b
		hidden_effect = {
			country_event = {
				id = crisis.8120
				days = 14
			}
		}
	}
}

#Open the box - lose the planet
country_event = {
	id = crisis.8115
	title = "crisis.8115.name"
	desc = "crisis.8115.desc"
	picture = GFX_evt_shattered_planet
	show_sound = event_ship_explosion
	location = root

	is_triggered_only = yes

	#Boomtown but unlocked doomclock
	option = {
		name = crisis.8115.a
		custom_tooltip = crisis.8115.a.tooltip
		hidden_effect = {
			event_target:synth_queen_databank_location = {
				change_pc = pc_shattered_2
				clear_deposits = yes
			}
			country_event = {
				id = crisis.8130
				days = 14
			}
			set_country_flag = synth_queen_question_blew_up_a_planet
			set_country_flag = synth_queen_question_opened_the_databank
			doomclock_reveal = yes
		}
	}
}

#Speech - Send Cetana the box - save the planet
country_event = {
	id = crisis.8120
	title = "crisis.8120.name"
	diplomatic_title = "crisis.8120.name"
	desc = "crisis.8120.desc"
	show_sound = crisis_8120_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	#There's hope for you yet
	option = {
		name = crisis.8120.a
		trigger = {
			NOT = { has_country_flag = crisis.8120.1.flag }
		}
		is_dialog_only = yes
		response_text = crisis.8120.1.reply
		sound = crisis_8120_1_reply
		hidden_effect = {
			set_country_flag = crisis.8120.1.flag
		}
	}

	#End communication
	option = {
		name = crisis.8120.1.a
		trigger = {
			has_country_flag = crisis.8120.1.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8120.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		remove_country_flag = synth_queen_conversation_ongoing
		set_country_flag = synth_queen_finished_first_demand_chain
	}
}

#Failed the Special Project - Nanites Destory Planet
country_event = {
	id = crisis.8125
	title = "crisis.8125.name"
	desc = "crisis.8125.desc"
	picture = GFX_evt_shattered_planet
	show_sound = event_ship_explosion
	location = root

	is_triggered_only = yes

	immediate = {
		event_target:synth_queen_databank_location = {
			change_pc = pc_shattered_2
			clear_deposits = yes
		}
	}

	#You damn dirty synth, you blew it up
	option = {
		name = crisis.8125.a
		custom_tooltip = crisis.8115.a.tooltip
		hidden_effect = {
			country_event = {
				id = crisis.8130
				days = 14
			}
			set_country_flag = synth_queen_question_blew_up_a_planet
		}
	}
}

#Speech - The Moon was destroyed
country_event = {
	id = crisis.8130
	title = "crisis.8130.name"
	diplomatic_title = "crisis.8130.name"
	desc = "crisis.8130.desc"
	show_sound = crisis_8130_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	#You blew it up.
	option = {
		name = crisis.8130.a
		trigger = {
			NOT = {
				has_valid_civic = civic_machine_servitor
			}
			NOR = {
				has_country_flag = synth_queen_did_not_get_the_box_in_time
				has_country_flag = crisis.8130.1.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8130.1.reply
		sound = crisis_8130_1_reply
		hidden_effect = {
			set_country_flag = crisis.8130.1.flag
		}
	}
	option = {
		name = crisis.8130.b
		trigger = {
			has_valid_civic = civic_machine_servitor
			NOR = {
				has_country_flag = synth_queen_did_not_get_the_box_in_time
				has_country_flag = crisis.8130.1.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8130.1.reply
		sound = crisis_8130_1_reply
		hidden_effect = {
			set_country_flag = crisis.8130.1.flag
		}
	}

	option = {
		name = crisis.8130.c
		trigger = {
			has_country_flag = synth_queen_did_not_get_the_box_in_time
			NOT = {
				has_country_flag = crisis.8130.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8130.2.reply
		sound = crisis_8130_2_reply
		hidden_effect = {
			set_country_flag = crisis.8130.3.flag
			hidden_effect = {
			}
		}
	}

	option = {
		name = crisis.8130.1.d
		custom_tooltip = crisis.8130.1.d.tt
		trigger = {
			has_country_flag = synth_queen_did_not_get_the_box_in_time
			NOT = {
				has_country_flag = crisis.8130.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8130.2.reply
		sound = crisis_8130_2_reply
		hidden_effect = {
			set_country_flag = crisis.8130.3.flag
			event_target:synth_queen_country = {
				add_trust = {
					amount = -10
					who = root.owner
				}
			}
		}
	}

	#End communication
	option = {
		name = crisis.8130.1.a
		trigger = {
			has_country_flag = crisis.8130.1.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8130.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8130.1.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_militarist = yes
			has_country_flag = crisis.8130.1.flag
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8130.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8130.1.c
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_spiritualist = yes
			has_country_flag = crisis.8130.1.flag
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			remove_country_flag = crisis.8130.1.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8130.2.a
		custom_tooltip = crisis.8130.2.a.tt
		trigger = {
			has_country_flag = crisis.8130.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8130.1.reply
		hidden_effect = {
			event_target:synth_queen_databank_location = {
				change_pc = pc_shattered_2
				clear_deposits = yes
			}
			remove_country_flag = synth_queen_did_not_get_the_box_in_time
			remove_country_flag = crisis.8130.3.flag
			set_country_flag = crisis.8130.1.flag
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
	}

	after = {
		remove_country_flag = synth_queen_conversation_ongoing
		set_country_flag = synth_queen_finished_first_demand_chain
	}
}

### CONVOYS ###

#Convoy Handler - Hidden Event - From on_yearly_pulse
event = {
	id = crisis.8135
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = synth_queen_happened
		any_country = {
			is_country_type = synth_queen_outposts
		}
	}

	immediate = {
		random_country = {
			limit = {
				is_country_type = synth_queen
			}

			random_list = {
				40 = {}
				60 = {
					modifier = {
						factor = 3
						count_country = {
							count <= 5
							limit = {
								is_country_type = synth_queen_convoys
							}
						}
					}
					modifier = { #Galaxy size ponderation.
						factor = 0.5
						galaxy_size = tiny
					}
					modifier = {
						factor = 0.75
						galaxy_size = small
					}
					modifier = {
						factor = 1.5
						galaxy_size = large
					}
					modifier = {
						factor = 2
						galaxy_size = huge
					}
					modifier = {
						factor = 0
						OR = {
							AND = {
								count_country = {
									count >= 10
									limit = {
										is_country_type = synth_queen_convoys
									}
								}
								galaxy_size = tiny
							}
							AND = {
								count_country = {
									count >= 15
									limit = {
										is_country_type = synth_queen_convoys
									}
								}
								galaxy_size = small
							}
							AND = {
								count_country = {
									count >= 20
									limit = {
										is_country_type = synth_queen_convoys
									}
								}
								galaxy_size = medium
							}
							AND = {
								count_country = {
									count >= 25
									limit = {
										is_country_type = synth_queen_convoys
									}
								}
								galaxy_size = large
							}
							AND = {
								count_country = {
									count >= 30
									limit = {
										is_country_type = synth_queen_convoys
									}
								}
								galaxy_size = huge
							}
						}
					}

					synth_queen_create_convoy_fleet = yes
				}
			}
		}
	}
}

#Special Raid Project
ship_event = {
	id = crisis.8136
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		solar_system = {
			every_fleet_in_system = {
				limit = {
					owner = {
						OR = {
							is_country_type = synth_queen_convoys
							is_country_type = synth_queen_outposts
						}
					}
				}
				owner = {
					set_faction_hostility = {
						target = root
						set_hostile = yes
					}
				}
			}
		}
	}
}

#Convoy reaches destination - Via on_fleet_auto_move_arrival | from = fleet; fromfrom = planet
country_event = {
	id = crisis.8140
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen_convoys
		from.solar_system = {
			OR = {
				has_star_flag = synth_queen_outpost
				has_star_flag = synth_queen_capital
			}
		}
	}

	immediate = {
		if = { #If at capital move to an outpost
			limit = {
				from.solar_system = {
					has_star_flag = synth_queen_capital
				}
			}
			event_target:synth_queen_country_global = {
				random_system = {
					limit = {
						exists = owner
						owner = { is_country_type = synth_queen_outposts }
						has_star_flag = synth_queen_outpost
						NOT = { has_star_flag = incoming_convoy }
					}
					star = {
						save_event_target_as = convoy_destination
					}
					set_timed_star_flag = {
						flag = incoming_convoy
						years = 1
					}
				}
				random_situation = {
					limit = {
						is_situation_type = situation_synth_queen_doomclock
					}
					add_situation_progress = 3
				}
			}
		}
		else = { #Else return to capital
			random_system = {
				limit = {
					exists = owner
					owner = { is_country_type = synth_queen }
					has_star_flag = synth_queen_capital
				}
				star = {
					save_event_target_as = convoy_destination
				}
			}
		}
		from = {
			auto_move_to_planet = {
				target = event_target:convoy_destination
				clear_auto_move_on_arrival = yes
			}
		}
	}
}

#Fight with convoy ends - Handle pacification and fire queen's warning if battle was lost OR don't have comms scrambler Maybe special case for nebulas? Via on_space_battle_over
# This = owner of fleet 1 (winner)
# From = owner of fleet 2 (loser)
# FromFrom = fleet 1
# FromFromFrom = fleet 2

country_event = {
	id = crisis.8145
	hide_window = yes
	is_triggered_only = yes

	trigger = { #Make sure belligerants were a convoy v playable country
		has_global_flag = synth_queen_happened
		AND = {
			OR = {
				is_country_type = synth_queen_convoys
				from = {
					is_country_type = synth_queen_convoys
				}
			}
			OR = {
				is_country_type = default
				from = {
					is_country_type = default
				}
			}
		}
	}

	immediate = {
		if = { #Convoy lost
			limit = {
				is_country_type = default
			}
			save_event_target_as = playable_country
			add_event_chain_counter = {
				event_chain = "the_synth_queen_raids_chain"
				counter = "synth_queen_raids_convoy"
				amount = 1
			}
			country_event = { id = crisis.8175 days = 3 }
			if = {
				limit = {
					NOT = { has_country_flag = synth_queen_comm_scrambler }
				}
				country_event = { id = crisis.8195 days = 7 }
			}
			set_faction_hostility = {
				target = from
				set_neutral = yes
			}
		}
		if = { #Convoy won
			limit = {
				is_country_type = synth_queen_convoys
			}
			fromfrom = {
				ordered_owned_ship = {
					save_event_target_as = convoy_ship
				}
			}
			from = {
				save_event_target_as = playable_country
				country_event = { id = crisis.8194 days = 7 }
				abort_special_project = {
					type = THE_SYNTH_QUEENS_CONVOY_AMBUSH
					location = event_target:convoy_ship
				}
				enable_special_project = {
					name = THE_SYNTH_QUEENS_CONVOY_AMBUSH
					owner = this
					location = event_target:convoy_ship
				}
			}
			set_faction_hostility = {
				target = from
				set_neutral = yes
			}
		}
		fromfrom = {
			solar_system = {
				every_fleet_in_system = {
					limit = {
						controller = {
							OR = {
								is_country_type = synth_queen
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
						}
					}
					if = {
						limit = {
							is_leased = yes
						}
						end_fleet_contract = {
							initiator = this.controller
							reason = cancelled
						}
					}
					owner = {
						set_faction_hostility = {
							target = event_target:playable_country
							set_neutral = yes
						}
					}
				}
			}
		}
	}
}

#Fight with convoy OR OUTPOST starts - Any other SQ ship/base in system join the fight - via on_entering_battle
country_event = {
	id = crisis.8150
	hide_window = yes
	is_triggered_only = yes

	trigger = { #Make sure belligerants are SQ v playable country
		has_global_flag = synth_queen_happened
		is_country_type = default
		from = {
			OR = {
				is_country_type = synth_queen
				is_country_type = synth_queen_convoys
				is_country_type = synth_queen_outposts
			}
		}
		fromfromfrom.solar_system = {
			any_fleet_in_system = {
				owner = {
					OR = {
						is_country_type = synth_queen
						is_country_type = synth_queen_convoys
						is_country_type = synth_queen_outposts
					}
					NOT = {
						is_same_value = from
					}
				}
			}
		}
	}

	immediate = {
		if = { # Outposts and Convoys just turn hostile too
			limit = {
				fromfromfrom.solar_system = {
					any_fleet_in_system = {
						owner = {
							OR = {
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
							NOT = {
								is_same_value = from
							}
						}
					}
				}
			}
			fromfromfrom.solar_system = {
				every_fleet_in_system = {
					limit = {
						is_leased = no
						is_in_combat = no
						owner = {
							OR = {
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
							NOT = {
								is_same_value = from
							}
						}
					}
					owner = {
						set_faction_hostility = {
							target = root
							set_hostile = yes
						}
					}
				}
			}
		}
		fromfromfrom.solar_system = { #SQ ships get leased to the attacked party
			every_fleet_in_system = {
				limit = {
					is_leased = no
					is_in_combat = no
					owner = {
						NOT = {
							is_same_value = from
						}
						is_country_type = synth_queen
					}
				}
				give_fleet = {
					controller = from
					days = 720
				}
			}
		}
	}
}

#Entering a system where SQ fleets are fighting - Via on_entering_system_fleet on_action
fleet_event = {
	id = crisis.8155
	hide_window = yes
	is_triggered_only = yes

	trigger = { #check for fight
		has_global_flag = synth_queen_happened
		from = {
			any_fleet_in_system = {
				NOT = { is_same_value = root }
				is_in_combat = yes
				owner = {
					OR = {
						is_country_type = synth_queen
						is_country_type = synth_queen_convoys
						is_country_type = synth_queen_outposts
					}
				}
				controller = {
					NOT = { is_same_value = root.owner }
				}
			}
		}
	}

	immediate = {
		if = { # Convoys just join the fight
			limit = {
				owner = {
					is_country_type = synth_queen_convoys
				}
			}
			from = {
				random_fleet_in_system = {
					limit = {
						is_in_combat = yes
						is_leased = no
						owner = {
							OR = {
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
						}
						controller = {
							NOT = {
								is_same_value = root.owner
							}
						}
					}
					owner = {
						save_event_target_as = synth_queen_fighting_country
					}
				}
				random_fleet_in_system = {
					limit = {
						is_in_combat = yes
						owner = {
							is_hostile = event_target:synth_queen_fighting_country
						}
					}
					owner = {
						set_faction_hostility = {
							target = root.owner
							set_hostile = yes
						}
					}
				}
			}
		}
		if = { #SQ ships get leased to the attacked party
			limit = {
				owner = {
					is_country_type = synth_queen
				}
			}
			from = {
				random_fleet_in_system = {
					limit = {
						is_in_combat = yes
						is_leased = no
						owner = {
							OR = {
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
						}
						controller = {
							NOT = {
								is_same_value = root.owner
							}
						}
					}
					owner = {
						save_event_target_as = synth_queen_fighting_country
					}

				}
			}
			give_fleet = {
				controller = event_target:synth_queen_fighting_country
				days = 720
			}
		}

	}
}

### CONVOYS - WAR MODE ACTIVATED ###

# War started | fired by crisis.8060 | this = the synth queen country
country_event = {
	id = crisis.8156
	hide_window = yes
	is_triggered_only = yes

	fire_only_once = yes

	immediate = {
		# Capital: located
		random_system_within_border = {
			limit = {
				has_star_flag = synth_queen_capital
			}
			star = {
				save_event_target_as = synth_queen_ships_destination
			}
		}

		# Own fleet: patrol mode
		every_owned_fleet = {
			limit = {
				NOT = { has_fleet_flag = synth_queen_titan_ship }
			}
			synth_queen_fleet_patrol = yes
		}

		# Except for the titan. You chill, titan.
		every_owned_fleet = {
			limit = {
				has_fleet_flag = synth_queen_titan_ship
			}
			if = { # If already in Synth Queen territory, stay here
				limit = {
					exists = space_owner
					space_owner = { is_same_value = root }
				}
				synth_queen_fleet_garrison = yes
			}
			else = { # If not, return to the capital, THEN stay there
				remove_auto_move_target = yes
				auto_move_to_planet = {
					target = event_target:synth_queen_ships_destination
					clear_auto_move_on_arrival = yes
					arrival_effect = synth_queen_fleet_garrison
				}
			}
		}

		# Outposts: dismantled
		every_country = {
			limit = {
				is_country_type = synth_queen_outposts
			}
			every_owned_fleet = {
				every_controlled_ship = {
					limit = {
						is_ship_size = big_starbase_synth_queen
					}
					delete_ship = this
				}
				# Ships: ready to go home
				set_fleet_flag = synth_queen_returning_outpost_ship
				set_owner = root
				remove_auto_move_target = yes
				auto_move_to_planet = {
					target = event_target:synth_queen_ships_destination
					clear_auto_move_on_arrival = yes
				}
			}
			destroy_country = yes
		}

		# Convoys: go home
		every_country = {
			limit = {
				is_country_type = synth_queen_convoys
			}
			every_owned_fleet = {
				set_owner = root
				remove_auto_move_target = yes
				auto_move_to_planet = {
					target = event_target:synth_queen_ships_destination
					clear_auto_move_on_arrival = yes
					arrival_effect = synth_queen_fleet_convoys_patrol
				}
			}
			destroy_country = yes
		}
	}

	after = {
		every_playable_country = {
			limit = {
				has_communications = root
			}
			country_event = {
				id = crisis.8158
			}
		}
	}
}

# Garrison fleet reaching the empire borders | Fired by on_entering_system_fleet
# this = fleet, from = system
fleet_event = {
	id = crisis.8157
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = synth_queen_war_started
		has_fleet_flag = synth_queen_returning_outpost_ship
		from = {
			exists = space_owner
			space_owner = {
				is_same_value = event_target:synth_queen_country_global
			}
		}
	}

	immediate = {
		# Stop here!
		remove_auto_move_target = yes
		remove_fleet_flag = synth_queen_returning_outpost_ship
		# Dock at the starbase and stay there
		if = {
			limit = {
				from = {
					exists = starbase
				}
			}
			from.starbase = { save_event_target_as = convoys_destination }
			queue_actions = {
				move_to = event_target:convoys_destination
				effect = {
					id = convoy.1.starbase
					set_location = {
						target = event_target:convoys_destination
						distance = 50
						angle = random
					}
				}
			}
			synth_queen_fleet_garrison = yes
			# Upgrade the Starbase if possible
			event_target:convoys_destination = {
				if = {
					limit = {
						has_starbase_size = starbase_synth_queen
					}
					set_starbase_size = big_starbase_synth_queen
				}
			}
		}
	}
}

#Telling players the outposts have been packed
country_event = {
	id = crisis.8158
	title = "crisis.8158.name"
	desc = "crisis.8158.desc"
	picture = GFX_evt_ruined_system
	show_sound = event_airlock

	is_triggered_only = yes

	option = {
		name = "UNDERSTOOD"
	}
}

### OUTPOSTS ###

#Send out patrol fleets - Via on_fleet_auto_move_arrival | from = fleet; fromfrom = planet
country_event = {
	id = crisis.8160
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen
		from = {
			NOT = {
				has_fleet_flag = patroller
				has_fleet_flag = defender
				has_fleet_flag = mobile_defender
				any_owned_ship = { is_ship_size = synth_queen_titan }
			}
		}
		any_system = {
			exists = owner
			owner = {
				is_country_type = synth_queen_outposts
			}
			has_star_flag = synth_queen_outpost
		}
	}

	immediate = {
		if = {
			limit = {
				count_owned_fleet = {
					count < 2
					limit = {
						has_fleet_flag = defender
					}
				}
			}
			from = {
				set_fleet_flag = defender
			}
		}
		else_if = {
			limit = {
				count_owned_fleet = {
					count < 1
					limit = {
						has_fleet_flag = mobile_defender
					}
				}
			}
			from = {
				set_fleet_flag = mobile_defender
				queue_actions = {
					repeat = {
						find_random_system = {
							trigger = {
								id = "crisis.8160.trigger.1"
								exists = owner
								owner = {
									is_same_value = root
								}
								NOT = { has_star_flag = synth_queen_capital }
								has_star_flag = synth_queen_system
							}
							found_system = {
								move_to = this
							}
						}
					}
				}
			}
		}
		else = {
			random_system = {
				limit = {
					exists = owner
					owner = {
						is_country_type = synth_queen_outposts
					}
					has_star_flag = synth_queen_outpost
					NOT = { has_star_flag = incoming_patrol }
				}
				set_timed_star_flag = {
					flag = incoming_patrol
					years = 1
				}
				star = {
					save_event_target_as = patrol_target
				}
			}
			from = {
				set_fleet_flag = patroller
				auto_move_to_planet = {
					target = event_target:patrol_target
					clear_auto_move_on_arrival = yes
				}
			}
		}
	}
}

#Patrol reaches destination - Via on_fleet_auto_move_arrival | from = fleet; fromfrom = planet
country_event = {
	id = crisis.8165
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen
		any_country = {
			is_country_type = synth_queen_outposts
		}
		from = {
			has_fleet_flag = patroller
			solar_system = {
				OR = {
					has_star_flag = synth_queen_outpost
					has_star_flag = synth_queen_capital
				}
			}
		}
	}

	immediate = {
		if = { #If at capital move to an outpost
			limit = {
				from.solar_system = {
					has_star_flag = synth_queen_capital
				}
			}
			random_system = {
				limit = {
					has_star_flag = synth_queen_outpost
					NOT = { has_star_flag = incoming_patrol }
				}
				set_timed_star_flag = {
					flag = incoming_patrol
					years = 1
				}
				star = {
					save_event_target_as = patrol_destination
				}
			}
		}
		else = { #Else return to capital
			random_system_within_border = {
				limit = {
					has_star_flag = synth_queen_capital
				}
				star = {
					save_event_target_as = patrol_destination
				}
			}
		}
		from = {
			auto_move_to_planet = {
				target = event_target:patrol_destination
				clear_auto_move_on_arrival = yes
			}
		}
	}
}

#Fight with Outpost ends - Handle pacification and fire queen's warning if battle was lost OR don't have comms scrambler Maybe special case for nebulas? Via on_space_battle_won
country_event = {
	id = crisis.8170
	hide_window = yes
	is_triggered_only = yes

	trigger = { #Make sure belligerants were a convoy v playable country
		AND = {
			OR = {
				is_country_type = synth_queen_outposts
				from = {
					is_country_type = synth_queen_outposts
				}
			}
			OR = {
				is_country_type = default
				from = {
					is_country_type = default
				}
			}
		}
	}

	immediate = {
		if = { #Outpost lost
			limit = {
				is_country_type = default
			}
			save_event_target_as = playable_country
			set_country_flag = defeated_outpost
			add_event_chain_counter = {
				event_chain = "the_synth_queen_raids_chain"
				counter = "synth_queen_raids_outpost"
				amount = 1
			}
			country_event = { id = crisis.8175 days = 3 }
			if = {
				limit = {
					NOT = { has_country_flag = synth_queen_comm_scrambler }
				}
				country_event = { id = crisis.8195 days = 7 }
			}
			set_faction_hostility = {
				target = from
				set_neutral = yes
			}
		}
		if = { #Outpost won
			limit = {
				is_country_type = synth_queen_outposts
			}
			fromfrom = {
				random_controlled_ship = {
					limit = {
						is_ship_size = big_starbase_synth_queen
					}
					save_event_target_as = outpost_ship
				}
			}
			from = {
				save_event_target_as = playable_country
				country_event = { id = crisis.8194 days = 7 }
				abort_special_project = {
					type = THE_SYNTH_QUEENS_OUTPOST_AMBUSH
					location = event_target:outpost_ship.solar_system
				}
			}
			fromfrom = {
				random_controlled_ship = {
					limit = {
						is_ship_size = big_starbase_synth_queen
					}
					event_target:playable_country = {
						event_target:outpost_ship = {
							enable_special_project = {
								name = THE_SYNTH_QUEENS_OUTPOST_AMBUSH
								owner = prev
								location = this
							}
						}
					}
				}
			}
			set_faction_hostility = {
				target = from
				set_neutral = yes
			}
		}
		fromfrom = {
			solar_system = {
				every_fleet_in_system = {
					limit = {
						controller = {
							OR = {
								is_country_type = synth_queen
								is_country_type = synth_queen_convoys
								is_country_type = synth_queen_outposts
							}
						}
					}
					if = {
						limit = {
							is_leased = yes
						}
						end_fleet_contract = {
							initiator = this.controller
							reason = cancelled
						}
					}
					owner = {
						set_faction_hostility = {
							target = event_target:playable_country
							set_neutral = yes
						}
					}
				}
			}
		}
	}
}

### RAID Rewards and Dialogue ###

# 8175 Random reward gatekeeper
country_event = {
	id = crisis.8175
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = raiding_synth_queen
		}
	}

	immediate = {
		set_country_flag = raiding_synth_queen
		random_list = {
			70 = {
				modifier = {
					factor = 0.2 #outposts are less likely to have generic reward.
					has_country_flag = defeated_outpost
				}
				country_event = { id = crisis.8180 }
			}
			5 = {
				modifier = {
					factor = 0
					has_country_flag = raid_insight_1
				}
				country_event = { id = crisis.8187 }
			}
			15 = {
				modifier = {
					factor = 0
					has_country_flag = raid_insight_2
				}
				country_event = { id = crisis.8185 }
			}
			10 = {
				modifier = {
					factor = 0
					has_country_flag = raid_insight_3
				}
				country_event = { id = crisis.8190 }
			}
		}
	}
}

country_event = { # Random reward
	id = crisis.8180
	title = "crisis.8180.name"
	desc = crisis.8180.desc

	picture = GFX_evt_ship_offloading_cargo
	show_sound = event_airlock
	event_chain = "the_synth_queen_raids_chain"

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			#set new flag
			random_list = {
				2 = { set_country_flag = sq_raid_reward_a } # Alloys
				2 = { set_country_flag = sq_raid_reward_b } # Pops
				2 = { set_country_flag = sq_raid_reward_c } # Society
				2 = { set_country_flag = sq_raid_reward_d } # Physics
				2 = { set_country_flag = sq_raid_reward_e } # Engineering
				1 = { set_country_flag = sq_raid_reward_f } # Nanites
				1 = {	# Jackpot - Alloys/pop/nanites
					modifier = {
						mult = 6
						has_valid_civic = civic_barbaric_despoilers
					}
					set_country_flag = sq_raid_reward_h
				}
			}
		}
	}

	option = {
		name = crisis.8180.a
		trigger = {
			has_country_flag = sq_raid_reward_a
		}
		add_resource = {
			alloys = 10000
		}
	}
	option = {
		name = crisis.8180.b
		trigger = {
			has_country_flag = sq_raid_reward_b
		}
		capital_scope = {
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
				}
				save_event_target_as = species_1
			}
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
					NOT = {
						is_same_value = event_target:species_1
					}
				}
				save_event_target_as = species_2
			}
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
					NOR = {
						is_same_value = event_target:species_1
						is_same_value = event_target:species_2
					}
				}
				save_event_target_as = species_3
			}
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
					NOR = {
						is_same_value = event_target:species_1
						is_same_value = event_target:species_2
						is_same_value = event_target:species_3
					}
				}
				save_event_target_as = species_4
			}
			create_pop_group = {
				species = event_target:species_1
			}
			if = {
				limit = {
					exists = event_target:species_2
				}
				create_pop_group = {
					species = event_target:species_2
				}
			}
			if = {
				limit = {
					exists = event_target:species_3
				}
				create_pop_group = {
					species = event_target:species_3
				}
			}
			if = {
				limit = {
					exists = event_target:species_4
				}
				create_pop_group = {
					species = event_target:species_4
				}
			}
		}
	}
	option = {
		name = crisis.8180.c
		trigger = {
			has_country_flag = sq_raid_reward_c
		}
		add_monthly_resource_mult = {
			resource = society_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
	}
	option = {
		name = crisis.8180.d
		trigger = {
			has_country_flag = sq_raid_reward_d
		}
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
	}
	option = {
		name = crisis.8180.e
		trigger = {
			has_country_flag = sq_raid_reward_e
		}
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier5researchreward
			min = @tier5researchmin
			max = @tier5researchmax
		}
	}
	option = {
		name = crisis.8180.f
		trigger = {
			has_country_flag = sq_raid_reward_f
		}
		add_resource = {
			nanites = 1000
		}
	}
	option = {
		name = crisis.8180.h
		trigger = {
			has_country_flag = sq_raid_reward_h
		}
		add_resource = {
			alloys = 8000
			nanites = 700
		}
		capital_scope = {
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
				}
				save_event_target_as = species_1
			}
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
					NOT = {
						is_same_value = event_target:species_1
					}
				}
				save_event_target_as = species_2
			}
			random_galaxy_species = {
				limit = {
					is_robotic = no
					is_sapient = yes
					NOR = {
						is_same_value = event_target:species_1
						is_same_value = event_target:species_2
					}
				}
				save_event_target_as = species_3
			}
			create_pop_group = {
				species = event_target:species_1
			}
			if = {
				limit = {
					exists = event_target:species_2
				}
				create_pop_group = {
					species = event_target:species_2
				}
			}
			if = {
				limit = {
					exists = event_target:species_3
				}
				create_pop_group = {
					species = event_target:species_3
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				has_country_flag = defeated_outpost
			}
			event_target:synth_queen_country_global = {
				random_situation = {
					limit = {
						is_situation_type = situation_synth_queen_doomclock
					}
					add_situation_progress = -20
				}
			}
			remove_country_flag = defeated_outpost
		}
		remove_country_flag = sq_raid_reward_a
		remove_country_flag = sq_raid_reward_b
		remove_country_flag = sq_raid_reward_c
		remove_country_flag = sq_raid_reward_d
		remove_country_flag = sq_raid_reward_e
		remove_country_flag = sq_raid_reward_f
		remove_country_flag = sq_raid_reward_h
		remove_country_flag = raiding_synth_queen
	}
}

country_event = { # Raid Insight 1
	id = crisis.8187
	title = "crisis.8187.name"
	desc = crisis.8187.desc

	picture = GFX_evt_astral_rift_research_lab
	show_sound = event_airlock
	event_chain = "the_synth_queen_raids_chain"

	is_triggered_only = yes

	immediate = {
		set_country_flag = raid_insight_1
	}

	option = {
		name = crisis.8187.a
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		if = {
			limit = {
				has_country_flag = defeated_outpost
			}
			event_target:synth_queen_country_global = {
				random_situation = {
					limit = {
						is_situation_type = situation_synth_queen_doomclock
					}
					add_situation_progress = -20
				}
			}
			remove_country_flag = defeated_outpost
		}
		remove_country_flag = raiding_synth_queen
	}
}

country_event = { # Raid Insight 2
	id = crisis.8185
	title = "crisis.8185.name"
	desc = crisis.8185.desc

	picture = GFX_evt_astral_rift_research_lab
	show_sound = event_airlock
	event_chain = "the_synth_queen_raids_chain"

	is_triggered_only = yes

	immediate = {
		set_country_flag = raid_insight_2
	}

	option = {
		name = crisis.8185.a
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		if = {
			limit = {
				has_country_flag = defeated_outpost
			}
			event_target:synth_queen_country_global = {
				random_situation = {
					limit = {
						is_situation_type = situation_synth_queen_doomclock
					}
					add_situation_progress = -20
				}
			}
			remove_country_flag = defeated_outpost
		}
		remove_country_flag = raiding_synth_queen
	}
}

country_event = { # Raid Insight 3
	id = crisis.8190
	title = "crisis.8190.name"
	desc = crisis.8190.desc

	picture = GFX_evt_astral_rift_research_lab
	show_sound = event_airlock
	event_chain = "the_synth_queen_raids_chain"

	is_triggered_only = yes

	immediate = {
		set_country_flag = raid_insight_3
	}

	option = {
		name = crisis.8190.a
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		if = {
			limit = {
				has_country_flag = defeated_outpost
			}
			event_target:synth_queen_country_global = {
				random_situation = {
					limit = {
						is_situation_type = situation_synth_queen_doomclock
					}
					add_situation_progress = -20
				}
			}
			remove_country_flag = defeated_outpost
		}
		remove_country_flag = raiding_synth_queen
	}
}

country_event = { # Synth Queen's Scolding - you lost the fight
	id = crisis.8194
	title = "crisis.8195.name"
	diplomatic_title = "crisis.8195.name"
	desc = crisis.8195.desc.fail
	show_sound = crisis_8195_desc_fail

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_country_flag = synth_queen_raid_scolding
			has_active_event = { crisis.8195 }
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.8195.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			NOT = { has_country_flag = already_apologized }
		}
		set_country_flag = crisis.8195.1.flag
		is_dialog_only = yes
		response_text = crisis.8195.1.reply
		sound = crisis_8195_1_reply
		set_country_flag = already_apologized
	}
	option = {
		name = crisis.8195.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			has_country_flag = already_apologized
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
		set_country_flag = crisis.8195.1.flag
		is_dialog_only = yes
		response_text = crisis.8195.1.reply.angry
		sound = crisis_8195_1_reply_angry
	}
	option = {
		name = crisis.8195.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
		}
		set_country_flag = crisis.8195.2.flag
		response_text = crisis.8195.2.reply
		sound = crisis_8195_2_reply
		is_dialog_only = yes
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
	}
	option = { # Raid successful + Barbaric Despoilers
		name = crisis.8195.c
		trigger = {
			from = {
 				is_country_type = default
 			}
			has_valid_civic = civic_barbaric_despoilers
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			NOT = { has_country_flag = successful_raid_barbaric }
		}
		set_country_flag = crisis.8195.3.flag
		set_country_flag = successful_raid_barbaric
		response_text = crisis.8195.3.reply
		sound = crisis_8195_3_reply
		is_dialog_only = yes
	}
	option = {
		name = GOODBYE
		trigger = {
			OR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
		}
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = crisis.8195.1.flag
			remove_country_flag = crisis.8195.2.flag
			remove_country_flag = crisis.8195.3.flag
			set_timed_country_flag = {
				flag = synth_queen_raid_scolding
				days = 1800 # 5 years
			}
		}
	}
}

country_event = { # Synth Queen's Scolding - you won the fight
	id = crisis.8195
	title = "crisis.8195.name"
	diplomatic_title = "crisis.8195.name"
	desc = crisis.8195.desc.success
	show_sound = crisis_8195_desc_success

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_country_flag = synth_queen_raid_scolding
			has_active_event = { crisis.8195 }
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.8195.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			NOT = { has_country_flag = already_apologized }
		}
		set_country_flag = crisis.8195.1.flag
		is_dialog_only = yes
		response_text = crisis.8195.1.reply
		sound = crisis_8195_1_reply
		set_country_flag = already_apologized
	}
	option = {
		name = crisis.8195.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			has_country_flag = already_apologized
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
		set_country_flag = crisis.8195.1.flag
		is_dialog_only = yes
		response_text = crisis.8195.1.reply.angry
		sound = crisis_8195_1_reply_angry
	}
	option = {
		name = crisis.8195.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
		}
		set_country_flag = crisis.8195.2.flag
		response_text = crisis.8195.2.reply
		sound = crisis_8195_2_reply
		is_dialog_only = yes
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
	}
	option = { # Raid successful + Barbaric Despoilers
		name = crisis.8195.c
		trigger = {
			from = {
 				is_country_type = default
 			}
			has_valid_civic = civic_barbaric_despoilers
			NOR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
			NOT = { has_country_flag = successful_raid_barbaric }
		}
		set_country_flag = crisis.8195.3.flag
		set_country_flag = successful_raid_barbaric
		response_text = crisis.8195.3.reply
		sound = crisis_8195_3_reply
		is_dialog_only = yes
	}
	option = {
		name = GOODBYE
		trigger = {
			OR = {
				has_country_flag = crisis.8195.1.flag
				has_country_flag = crisis.8195.2.flag
				has_country_flag = crisis.8195.3.flag
			}
		}
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		hidden_effect = {
			remove_country_flag = crisis.8195.1.flag
			remove_country_flag = crisis.8195.2.flag
			remove_country_flag = crisis.8195.3.flag
			set_timed_country_flag = {
				flag = synth_queen_raid_scolding
				days = 1800 # 5 years
			}
		}
	}
}

### DEMANDS ###

# Random pulse (set up the delay) - Fired by on_five_year_pulse_country
# This = Situation
situation_event = {
	id = crisis.8270
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			NOR = {
				has_global_flag = synth_queen_war_started
				has_country_flag = synth_queen_demands_cooldown
				NOT = { has_country_flag = synth_queen_finished_first_demand_chain }
			}
		}
	}

	immediate = {
		owner = { country_event = { id = crisis.8255 days = 180 random = 60 } }
	}
}

country_event = {
	id = crisis.8255
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_conversation_ongoing
		}
	}

	immediate = {
		fire_on_action = {
			on_action = on_synth_queen_random_demand_list
		}
	}

	after = {
		set_timed_country_flag = {
			flag = synth_queen_demands_cooldown
			days = 220
		}
	}
}

# Synth Queen Demand - Pops
country_event = {
	id = crisis.8280
	title = "crisis.8280.name"
	diplomatic_title = "crisis.8280.name"
	desc = "crisis.8280.desc"
	show_sound = crisis_8280_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_demand_pops
		}
	}

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		set_country_flag = synth_queen_demand_pops
		set_country_flag = synth_queen_conversation_ongoing
	}

	option = {
		name = crisis.8280.1
		icon = {
			icon = GFX_text_intel_encryption
			text = COVERTACTION
		}
		custom_tooltip = crisis.8280.1.tt
		trigger = {
			NOR = {
				has_country_flag = crisis.8280.a.flag
				has_country_flag = crisis.8280.b.flag
				has_country_flag = crisis.8280.cd.flag
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = { resource = unity value >= 200 }
			}
		}
		owner = {
			add_resource = { influence = -25 }
			add_resource = { unity = -2000 }
		}
		is_dialog_only = yes
		response_text = crisis.8280.1.reply
		sound = crisis_8280_1_reply
		hidden_effect = {
			doomclock_increase_large = yes
			random_owned_pop_group = {
				kill_single_pop = yes
			}
			random_owned_pop_group = {
				kill_single_pop = yes
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8280.a.flag
		}
	}

	option = {
		name = crisis.8280.2
		custom_tooltip = crisis.8280.2.tt
		trigger = {
			NOR = {
				has_country_flag = crisis.8280.a.flag
				has_country_flag = crisis.8280.b.flag
				has_country_flag = crisis.8280.cd.flag
			}
		}
		doomclock_increase_small = yes
		is_dialog_only = yes
		response_text = crisis.8280.2.reply
		sound = crisis_8280_2_reply
		hidden_effect = {
			owner = {
				random_owned_pop_group = {
					kill_single_pop = yes
				}
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8280.b.flag
		}
	}

	option = {
		name = crisis.8280.3
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8280.a.flag
				has_country_flag = crisis.8280.b.flag
				has_country_flag = crisis.8280.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8280.3.reply
		sound = crisis_8280_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8280.cd.flag
		}
	}

	option = {
		name = crisis.8280.4
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_country_flag = crisis.8280.a.flag
				has_country_flag = crisis.8280.b.flag
				has_country_flag = crisis.8280.cd.flag
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		is_dialog_only = yes
		response_text = crisis.8280.3.reply
		sound = crisis_8280_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8280.cd.flag
		}
	}

	#End communication
	option = {
		name = crisis.8280.1.a
		trigger = {
			has_country_flag = crisis.8280.a.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8280.a.flag
			owner = {
				country_event = { id = crisis.8305 days = 90 random = 90 }
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8280.2.a
		trigger = {
			has_country_flag = crisis.8280.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8280.b.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8280.3.a
		trigger = {
			has_country_flag = crisis.8280.cd.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8280.cd.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

# Synth Queen Demand - Resources
country_event = {
	id = crisis.8285
	title = "crisis.8285.name"
	diplomatic_title = "crisis.8285.name"
	desc = "crisis.8285.desc"
	show_sound = crisis_8285_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_demand_resources
		}
	}

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		set_country_flag = synth_queen_demand_resources
		set_country_flag = synth_queen_conversation_ongoing
	}

	option = {
		name = crisis.8285.1
		icon = {
			icon = GFX_text_intel_encryption
			text = COVERTACTION
		}
		custom_tooltip = crisis.8285.1.tt
		trigger = {
			NOR = {
				has_country_flag = crisis.8285.a.flag
				has_country_flag = crisis.8285.b.flag
				has_country_flag = crisis.8285.cd.flag
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = { resource = unity value >= 1000 }
			}
		}
		owner = {
			add_resource = { unity = -1000 }
			add_resource = { influence = -25 }
			add_modifier = {
				modifier = synth_queen_large_alloy_shipments
				days = 360
			}
		}
		doomclock_increase_large = yes
		is_dialog_only = yes
		response_text = crisis.8285.1.reply
		sound = crisis_8285_1_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8285.a.flag
		}
	}

	option = {
		name = crisis.8285.2
		custom_tooltip = synth_queen_approve
		trigger = {
			NOR = {
				has_country_flag = crisis.8285.a.flag
				has_country_flag = crisis.8285.b.flag
				has_country_flag = crisis.8285.cd.flag
			}
		}
		owner = {
			add_modifier = {
				modifier = synth_queen_alloy_shipments
				days = 360
			}
		}
		doomclock_increase_small = yes
		is_dialog_only = yes
		response_text = crisis.8285.2.reply
		sound = crisis_8285_2_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8285.b.flag
		}
	}

	option = {
		name = crisis.8285.3
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8285.a.flag
				has_country_flag = crisis.8285.b.flag
				has_country_flag = crisis.8285.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8285.3.reply
		sound = crisis_8285_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8285.cd.flag
		}
	}

	option = {
		name = crisis.8285.4
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_country_flag = crisis.8285.a.flag
				has_country_flag = crisis.8285.b.flag
				has_country_flag = crisis.8285.cd.flag
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		is_dialog_only = yes
		response_text = crisis.8285.3.reply
		sound = crisis_8285_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8285.cd.flag
		}
	}

	#End communication
	option = {
		name = crisis.8285.1.a
		trigger = {
			has_country_flag = crisis.8285.a.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8285.a.flag
			owner = {
				country_event = { id = crisis.8310 days = 90 random = 90 }
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8285.2.a
		trigger = {
			has_country_flag = crisis.8285.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8285.b.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8285.3.a
		trigger = {
			has_country_flag = crisis.8285.cd.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8285.cd.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

# Synth Queen Demand - Research
country_event = {
	id = crisis.8290
	title = "crisis.8290.name"
	diplomatic_title = "crisis.8290.name"
	desc = "crisis.8290.desc"
	show_sound = crisis_8290_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_demand_research
		}
	}

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		set_country_flag = synth_queen_demand_research
		set_country_flag = synth_queen_conversation_ongoing
	}

	option = {
		icon = {
			icon = GFX_text_intel_encryption
			text = COVERTACTION
		}
		name = crisis.8290.1
		custom_tooltip = crisis.8290.1.tt
		trigger = {
			NOR = {
				has_country_flag = crisis.8290.a.flag
				has_country_flag = crisis.8290.b.flag
				has_country_flag = crisis.8290.cd.flag
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = { resource = unity value >= 1500 }
			}
		}
		owner = {
			add_modifier = {
				modifier = synth_queen_shared_research
				days = 360
			}
			add_resource = { unity = -1500 }
			add_resource = { influence = -25 }
		}
		doomclock_increase_large = yes
		is_dialog_only = yes
		response_text = crisis.8290.1.reply
		sound = crisis_8290_1_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8290.a.flag
		}
	}

	option = {
		name = crisis.8290.2
		custom_tooltip = synth_queen_approve
		trigger = {
			NOR = {
				has_country_flag = crisis.8290.a.flag
				has_country_flag = crisis.8290.b.flag
				has_country_flag = crisis.8290.cd.flag
			}
		}
		owner = {
			add_modifier = {
				modifier = synth_queen_shared_research
				days = 360
			}
		}
		doomclock_increase_small = yes
		is_dialog_only = yes
		response_text = crisis.8290.2.reply
		sound = crisis_8290_2_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.8290.b.flag
		}
	}

	option = {
		name = crisis.8290.3
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8290.a.flag
				has_country_flag = crisis.8290.b.flag
				has_country_flag = crisis.8290.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8290.3.reply
		sound = crisis_8290_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8290.cd.flag
		}
	}

	option = {
		name = crisis.8290.4
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_country_flag = crisis.8290.a.flag
				has_country_flag = crisis.8290.b.flag
				has_country_flag = crisis.8290.cd.flag
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		is_dialog_only = yes
		response_text = crisis.8290.3.reply
		sound = crisis_8290_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8290.cd.flag
		}
	}

	#End communication
	option = {
		name = crisis.8290.1.a
		trigger = {
			has_country_flag = crisis.8290.a.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8290.a.flag
			owner = {
				country_event = { id = crisis.8315 days = 90 random = 90 }
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8290.2.a
		trigger = {
			has_country_flag = crisis.8290.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8290.b.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8290.3.a
		trigger = {
			has_country_flag = crisis.8290.cd.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8290.cd.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

# Synth Queen Demand - System
country_event = {
	id = crisis.8295
	title = "crisis.8295.name"
	diplomatic_title = "crisis.8295.name"
	desc = "crisis.8295.desc"
	show_sound = crisis_8295_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_demand_system
		}
		exists = event_target:gifted_system
	}

	immediate = {
		get_cetana_face = yes
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
			set_country_flag = synth_queen_conversation_ongoing
		}
		random_system_within_border = {
			limit = {
				is_capital_system = no
				is_bottleneck_system = no
				has_any_megastructure = no
				any_system_planet = {
					is_colony = no
					habitable_planet = no
				}
			}
			save_event_target_as = gifted_system
		}
		random_system_within_border = {
			limit = {
				is_capital_system = no
				is_bottleneck_system = no
				has_any_megastructure = no
				any_system_planet = {
					is_colony = no
					habitable_planet = no
				}
				NOT = {
					is_same_value = event_target:gifted_system
				}
			}
			save_event_target_as = gifted_system_2
		}
		set_country_flag = synth_queen_demand_system
	}

	option = {
		name = crisis.8295.1
		icon = {
			icon = GFX_text_intel_encryption
			text = COVERTACTION
		}
		custom_tooltip = crisis.8295.1.tt
		trigger = {
			exists = event_target:gifted_system
			exists = event_target:gifted_system_2
			NOR = {
				has_country_flag = crisis.8295.a.flag
				has_country_flag = crisis.8295.b.flag
				has_country_flag = crisis.8295.cd.flag
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = { resource = unity value >= 2500 }
			}
		}
		owner = {
			add_resource = { unity = -2500 }
			add_resource = { influence = -50 }
		}
		is_dialog_only = yes
		response_text = crisis.8295.1.reply
		sound = crisis_8295_1_reply
		hidden_effect = {
			owner = {
				event_target:gifted_system = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
				event_target:gifted_system_2 = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
		doomclock_increase_large = yes
			set_country_flag = crisis.8295.a.flag
		}
	}

	option = {
		name = crisis.8295.2
		custom_tooltip = crisis.8295.2.tt
		trigger = {
			exists = event_target:gifted_system
			NOR = {
				has_country_flag = crisis.8295.a.flag
				has_country_flag = crisis.8295.b.flag
				has_country_flag = crisis.8295.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8295.2.reply
		sound = crisis_8295_2_reply
		hidden_effect = {
			owner = {
				event_target:gifted_system = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
		doomclock_increase_small = yes
			set_country_flag = crisis.8295.b.flag
		}
	}

	option = {
		name = crisis.8295.3
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8295.a.flag
				has_country_flag = crisis.8295.b.flag
				has_country_flag = crisis.8295.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8295.3.reply
		sound = crisis_8295_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8295.cd.flag
		}
	}

	option = {
		name = crisis.8295.4
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_country_flag = crisis.8295.a.flag
				has_country_flag = crisis.8295.b.flag
				has_country_flag = crisis.8295.cd.flag
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		is_dialog_only = yes
		response_text = crisis.8295.3.reply
		sound = crisis_8295_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8295.cd.flag
		}
	}

	#End communication
	option = {
		name = crisis.8295.1.a
		trigger = {
			has_country_flag = crisis.8295.a.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8295.a.flag
			owner = {
				country_event = { id = crisis.8320 days = 90 random = 90 }
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8295.2.a
		trigger = {
			has_country_flag = crisis.8295.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8295.b.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8295.3.a
		trigger = {
			has_country_flag = crisis.8295.cd.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8295.cd.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

# Synth Queen Demand - Habitable System
country_event = {
	id = crisis.8300
	title = "crisis.8300.name"
	diplomatic_title = "crisis.8300.name"
	desc = "crisis.8300.desc"
	show_sound = crisis_8300_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		any_situation = {
			is_situation_type = situation_synth_queen_player_facing
			situation_progress >= 8
		}
		NOR = {
			has_global_flag = synth_queen_war_started
			has_country_flag = synth_queen_demands_cooldown
			has_country_flag = synth_queen_demand_habitable_system
		}
		# Check if viable gifted system exists
		any_system_within_border = {
			has_any_megastructure = no
			is_bottleneck_system = no
			is_capital_system = no
			any_system_planet = {
				habitable_planet = yes
				is_artificial = no
			}
		}
	}

	immediate = {
		get_cetana_face = yes
		random_system_within_border = {
			limit = {
				has_any_megastructure = no
				is_bottleneck_system = no
				is_capital_system = no
				any_system_planet = {
					habitable_planet = yes
					is_artificial = no
				}
			}
			save_event_target_as = gifted_habitable_system
		}
		random_system_within_border = {
			limit = {
				has_any_megastructure = no
				is_bottleneck_system = no
				is_capital_system = no
				any_system_planet = {
					habitable_planet = yes
					is_artificial = no
				}
				NOT = {
					is_same_value = event_target:gifted_habitable_system
				}
			}
			save_event_target_as = gifted_habitable_system_2
		}
		set_country_flag = synth_queen_demand_habitable_system
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.8300.1
		icon = {
			icon = GFX_text_intel_encryption
			text = COVERTACTION
		}
		custom_tooltip = crisis.8300.1.tt
		trigger = {
			exists = event_target:gifted_habitable_system
			exists = event_target:gifted_habitable_system_2
			NOR = {
				has_country_flag = crisis.8300.a.flag
				has_country_flag = crisis.8300.b.flag
				has_country_flag = crisis.8300.cd.flag
			}
		}
		allow = {
			owner = {
				resource_stockpile_compare = { resource = unity value >= 3000 }
			}
		}
		owner = {
			add_resource = { unity = -3000 }
			add_resource = { influence = -100 }
		}
		is_dialog_only = yes
		response_text = crisis.8300.1.reply
		sound = crisis_8300_1_reply
		hidden_effect = {
			owner = {
				event_target:gifted_habitable_system = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
				event_target:gifted_habitable_system_2 = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 10
					who = root.owner
				}
			}
		doomclock_increase_large = yes
			set_country_flag = crisis.8300.a.flag
		}
	}

	option = {
		name = crisis.8300.2
		custom_tooltip = crisis.8300.2.tt
		trigger = {
			exists = event_target:gifted_habitable_system
			NOR = {
				has_country_flag = crisis.8300.a.flag
				has_country_flag = crisis.8300.b.flag
				has_country_flag = crisis.8300.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8300.2.reply
		sound = crisis_8300_2_reply
		hidden_effect = {
			owner = {
				event_target:gifted_habitable_system = {
					synth_queen_mini_wipe_system = yes
					synth_queen_create_mini_outpost = yes
				}
			}
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
		doomclock_increase_small = yes
			set_country_flag = crisis.8300.b.flag
		}
	}

	option = {
		name = crisis.8300.3
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.8300.a.flag
				has_country_flag = crisis.8300.b.flag
				has_country_flag = crisis.8300.cd.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8300.3.reply
		sound = crisis_8300_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8300.cd.flag
		}
	}

	option = {
		name = crisis.8300.4
		custom_tooltip = synth_queen_disapprove
		trigger = {
			is_xenophobe = yes
			NOR = {
				has_country_flag = crisis.8300.a.flag
				has_country_flag = crisis.8300.b.flag
				has_country_flag = crisis.8300.cd.flag
			}
		}
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier4unityreward
				min = @tier4unitymin
				max = @tier4unitymax
			}
		}
		is_dialog_only = yes
		response_text = crisis.8300.3.reply
		sound = crisis_8300_3_reply
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.8300.cd.flag
		}
	}

	#End communication
	option = {
		name = crisis.8300.1.a
		trigger = {
			has_country_flag = crisis.8300.a.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8300.a.flag
			owner = {
				country_event = { id = crisis.8325 days = 90 random = 90 }
			}
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8300.2.a
		trigger = {
			has_country_flag = crisis.8300.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8300.b.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.8300.3.a
		trigger = {
			has_country_flag = crisis.8300.cd.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8300.cd.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

# Synth Queen asks for Severed Head Relic Gatekeeper
situation_event = {
	id = crisis.8245
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			NOT = {
				has_country_flag = synth_queen_demand_zarqlan_head
			}
		}
	}

	immediate = {
		owner = { country_event = { id = crisis.8250 days = 5 } }
	}
}

# Synth Queen asks for Severed Head Relic
country_event = {
	id = crisis.8250
	title = "crisis.8250.name"
	diplomatic_title = "crisis.8250.name"
	desc = "crisis.8250.desc"
	show_sound = crisis_8250_desc

	fire_only_once = yes
	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		any_country = {
			is_country_type = synth_queen
		}
		owner = {
			has_relic = r_severed_head
			NOT = {
				has_country_flag = synth_queen_conversation_ongoing
			}
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_demand_zarqlan_head
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	# Question Synth Queen
	option = {
		name = crisis.8250.1
		trigger = {
			NOR = {
				has_country_flag = crisis.8250.a.flag
				has_country_flag = crisis.8250.b.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8250.1.reply
		sound = crisis_8250_1_reply
		hidden_effect = {
			set_country_flag = crisis.8250.a.flag
		}
	}

	# Decline
	option = {
		name = crisis.8250.2.a
		custom_tooltip = synth_queen_disapprove_lot
		trigger = {
			has_country_flag = crisis.8250.a.flag
		}
		hidden_effect = {
			set_country_flag = rebellious_child
			event_target:synth_queen_country = {
				add_trust = {
					amount = -20
					who = root.owner
				}
			}
			remove_country_flag = crisis.8250.a.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	# Give the head away
	option = {
		name = crisis.8250.2.b
		custom_tooltip = crisis.8250.1.b.tt
		trigger = {
			has_country_flag = crisis.8250.a.flag
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				steal_relic = {
					target = root
					relic = r_severed_head
				}
			}
		}
		is_dialog_only = yes
		response_text = crisis.8250.2.reply
		sound = crisis_8250_2_reply
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 20
					who = root.owner
				}
			}
			remove_country_flag = crisis.8250.a.flag
			set_country_flag = crisis.8250.b.flag
		}
	}

	# Gave the head away
	option = {
		name = crisis.8250.3.a
		trigger = {
			has_country_flag = crisis.8250.b.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8250.b.flag
			set_country_flag = synth_queen_question_gave_zarqlans_head
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

country_event = {
	id = crisis.8305
	title = "crisis.8305.name"
	desc = "crisis.8305.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = synth_queen_war_started }
	}

	option = {
		name = crisis.8305.a
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
		hidden_effect = {
			owner = {
				set_country_flag = synth_queen_question_random_demand_pops
			}
		}
	}
}

country_event = {
	id = crisis.8310
	title = "crisis.8310.name"
	desc = "crisis.8310.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = synth_queen_war_started }
	}

	option = {
		name = crisis.8310.a
		owner = {
			add_modifier = {
				modifier = "synth_queen_war_preparations"
				days = 720
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}
}

country_event = {
	id = crisis.8315
	title = "crisis.8315.name"
	desc = "crisis.8315.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = synth_queen_war_started }
	}

	option = {
		name = crisis.8315.a
		owner = {
			add_modifier = {
				modifier = synth_queen_much_shared_research
				days = 360
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}
}

country_event = {
	id = crisis.8320
	title = "crisis.8320.name"
	desc = "crisis.8320.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = synth_queen_war_started }
	}

	option = {
		name = crisis.8320.a
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
		hidden_effect = {
			owner = {
				set_country_flag = synth_queen_question_random_demand_system
			}
		}
	}
}

country_event = {
	id = crisis.8325
	title = "crisis.8325.name"
	desc = "crisis.8325.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal

	is_triggered_only = yes

	trigger = {
		NOT = { has_global_flag = synth_queen_war_started }
	}

	option = {
		name = crisis.8325.a
		owner = {
			add_modifier = {
				modifier = "synth_queen_advanced_war_preparations"
				days = 720
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}
}

#Hidden Event that fires on AI Countries to make it appear Cetana is doing things to them (we lie)
situation_event = {
	id = crisis.8350
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
		}
	}

	immediate = {
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		every_country = {
			if = {
				limit = {
					has_country_flag = synth_queen_ai_storm
					NOR = {
						has_country_flag = synth_queen_ai_storm_cooldown
					}
				}
				deactivate_fog_machine = yes
				remove_country_flag = synth_queen_ai_storm
			}
		}
		random_country = {
			limit = {
				is_ai = yes
				is_country_type = default
				NOT = {
					has_country_flag = synth_queen_ai_storm
				}
			}
			random_list = {
				90 = {}
				10  = {
					random_country = {
						limit = {
							is_ai = yes
							is_country_type = default
							NOT = {
								has_country_flag = synth_queen_ai_storm
							}
						}
						activate_fog_machine = synth_queen_nanite
						every_system_within_border = {
							add_modifier = {
								modifier = queen_small_scorn_storm
							}
						}
						set_country_flag = synth_queen_ai_storm
						set_timed_country_flag = {
							flag = synth_queen_ai_storm_cooldown
							days = 720
						}
					}
				}
			}
		}
		random_country = {
			limit = {
				is_ai = yes
				is_country_type = default
				NOT = {
					has_country_flag = synth_queen_ai_stolen_system_cooldown
				}
				any_system_within_border = {
					is_capital_system = no
					is_bottleneck_system = no
					has_any_megastructure = no
					NOT = {
						any_system_planet = {
							colonizable_planet = yes
						}
					}
				}
			}
			random_list = {
				95 = {}
				5 = {
					set_timed_country_flag = {
						flag = synth_queen_ai_stolen_system_cooldown
						days = 900
					}
					random_system_within_border = {
						limit = {
							is_capital_system = no
							is_bottleneck_system = no
							has_any_megastructure = no
							NOT = {
								any_system_planet = {
									colonizable_planet = yes
								}
							}
						}
						synth_queen_mini_wipe_system = yes
						synth_queen_create_mini_outpost = yes
					}
				}
			}
		}
	}
}

## DOOMCLOCK
situation_event = { # Doomclock finished
	id = crisis.8500
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			country_event = { id = crisis.8505 }
			country_event = { id = crisis.8506 days = 13 }
		}
	}
}

country_event = { #Game over Transmission
	id = crisis.8505
	title = TRANSMISSION
	diplomatic_title = BLANK_STRING
	desc = "crisis.8505.desc"
	show_sound = crisis_8505_desc
	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		every_owned_planet = {
			limit = {
				is_capital = no
			}
			every_owned_pop_group = {
				kill_all_pop = yes
			}
		}
	}

	option = { # Yes
		name = crisis.8505.a
		custom_tooltip = crisis.8505.a.tt
	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					is_ai = no
				}
				destroy_country = yes
			}
		}
	}
}

country_event = { # Doomclock finished
	id = crisis.8506
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { has_global_flag = synth_queen_victorious }
			}
			set_global_flag = synth_queen_victorious
			event_target:synth_queen_country_global = {
				win = yes
			}
		}
		every_country = {
			limit = {
				is_ai = yes
				is_synth_queen_country_type = no
			}
			destroy_country = yes
		}
		every_owned_planet = {
			destroy_colony = yes
		}
		if = {
			limit = {
				is_ai = no
			}
			destroy_country = yes
		}
	}
}

situation_event = { # Doomclock starts war
	id = crisis.8510
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			country_event = { id = crisis.8515 days = 7 }
		}
		owner = {
			synth_queen_debuff = yes
		}
	}
}

country_event = { #War transmission
	id = crisis.8515
	title = "crisis.8515.name"
	diplomatic_title = "crisis.8515.name"
	desc = "crisis.8515.desc"
	show_sound = crisis_8515_desc
	event_window_type = crisis_leader_conversation

	diplomatic = yes

	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		event_target:synth_queen_country_global = {
			set_country_type = awakened_synth_queen
			set_country_flag = protected_from_queen_storm
			country_event = { id = crisis.8156 days = 15 }
		}
	}

	#What salvation?
	option = {
		name = crisis.8515.a
		trigger = {
			NOR = {
				has_country_flag = crisis.8515.1.flag
				has_country_flag = crisis.8515.2.flag
				has_country_flag = crisis.8515.3.flag
				has_country_flag = crisis.8515.4.flag
				has_country_flag = crisis.8515.5.flag
				has_country_flag = crisis.8515.6.flag
				has_country_flag = crisis.8515.7.flag
				has_country_flag = crisis.8515.8.flag
				has_country_flag = crisis.8515.9.flag
				has_country_flag = crisis.8515.10.flag
				has_country_flag = crisis.8515.11.flag
				has_country_flag = crisis.8515.12.flag
				has_country_flag = crisis.8515.13.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8515.1.reply
		sound = crisis_8515_1_reply
		hidden_effect = {
			set_country_flag = crisis.8515.1.flag
		}
	}

	#It is your end that approaches, Cetana.
	option = {
		name = crisis.8515.b
		trigger = {
			NOR = {
				has_country_flag = crisis.8515.1.flag
				has_country_flag = crisis.8515.2.flag
				has_country_flag = crisis.8515.3.flag
				has_country_flag = crisis.8515.4.flag
				has_country_flag = crisis.8515.5.flag
				has_country_flag = crisis.8515.6.flag
				has_country_flag = crisis.8515.7.flag
				has_country_flag = crisis.8515.8.flag
				has_country_flag = crisis.8515.9.flag
				has_country_flag = crisis.8515.10.flag
				has_country_flag = crisis.8515.11.flag
				has_country_flag = crisis.8515.12.flag
				has_country_flag = crisis.8515.13.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			set_country_flag = crisis.8515.13.flag
		}
	}

	#Tell us about salvation.
	option = {
		name = crisis.8515.1.a
		trigger = {
			has_country_flag = crisis.8515.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.2.reply
		sound = crisis_8515_2_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.1.flag
			set_country_flag = crisis.8515.2.flag
		}
	}

	#Tell us about your imprisonment.
	option = {
		name = crisis.8515.1.b
		trigger = {
			has_country_flag = crisis.8515.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.3.reply
		sound = crisis_8515_3_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.1.flag
			set_country_flag = crisis.8515.3.flag
		}
	}

	#Tell us about Zarqlan.
	option = {
		name = crisis.8515.1.c
		trigger = {
			has_country_flag = crisis.8515.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.4.reply
		sound = crisis_8515_4_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.1.flag
			set_country_flag = crisis.8515.4.flag
		}
	}

	#We have heard enough.
	option = {
		name = crisis.8515.1.d
		trigger = {
			has_country_flag = crisis.8515.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.1.flag
			set_country_flag = crisis.8515.13.flag
		}
	}

	#Erased how?
	option = {
		name = crisis.8515.2.a
		trigger = {
			has_country_flag = crisis.8515.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.5.reply
		sound = crisis_8515_5_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.2.flag
			set_country_flag = crisis.8515.5.flag
		}
	}

	#Erased how?
	option = {
		name = crisis.8515.2.b
		trigger = {
			has_country_flag = crisis.8515.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.6.reply
		sound = crisis_8515_6_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.2.flag
			set_country_flag = crisis.8515.6.flag
		}
	}

	#How long were you captive?
	option = {
		name = crisis.8515.3.a
		trigger = {
			has_country_flag = crisis.8515.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.10.reply
		sound = crisis_8515_10_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.3.flag
			set_country_flag = crisis.8515.10.flag
		}
	}

	#How did they do it?
	option = {
		name = crisis.8515.3.b
		trigger = {
			has_country_flag = crisis.8515.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.12.reply
		sound = crisis_8515_12_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.3.flag
			set_country_flag = crisis.8515.12.flag
		}
	}

	#How did he imprison you?
	option = {
		name = crisis.8515.4.a
		trigger = {
			has_country_flag = crisis.8515.4.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.12.reply
		sound = crisis_8515_12_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.4.flag
			set_country_flag = crisis.8515.12.flag
		}
	}

	#A state of suspension?
	option = {
		name = crisis.8515.5.a
		trigger = {
			has_country_flag = crisis.8515.5.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.7.reply
		sound = crisis_8515_7_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.5.flag
			set_country_flag = crisis.8515.7.flag
		}
	}

	#To suffer is natural!
	option = {
		name = crisis.8515.6.a
		trigger = {
			has_country_flag = crisis.8515.6.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.9.reply
		sound = crisis_8515_9_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.6.flag
			set_country_flag = crisis.8515.9.flag
		}
	}

	#With you?
	option = {
		name = crisis.8515.7.a
		trigger = {
			has_country_flag = crisis.8515.7.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.8.reply
		sound = crisis_8515_8_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.7.flag
			set_country_flag = crisis.8515.8.flag
		}
	}

	#You're defective.
	option = {
		name = crisis.8515.8.a
		trigger = {
			has_country_flag = crisis.8515.8.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.8.flag
			set_country_flag = crisis.8515.13.flag
		}
	}

	#You're insane.
	option = {
		name = crisis.8515.9.a
		trigger = {
			has_country_flag = crisis.8515.9.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.9.flag
			set_country_flag = crisis.8515.13.flag
		}
	}

	#How did you escape?
	option = {
		name = crisis.8515.10.a
		trigger = {
			has_country_flag = crisis.8515.10.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.11.reply
		sound = crisis_8515_11_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.10.flag
			set_country_flag = crisis.8515.11.flag
		}
	}

	#We heard, and we will respond.
	option = {
		name = crisis.8515.11.a
		trigger = {
			has_country_flag = crisis.8515.11.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.11.flag
			set_country_flag = crisis.8515.13.flag
		}
	}

	#You will find our will is stronger.
	option = {
		name = crisis.8515.12.a
		trigger = {
			has_country_flag = crisis.8515.12.flag
		}
		is_dialog_only = yes
		response_text = crisis.8515.13.reply
		sound = crisis_8515_13_reply
		hidden_effect = {
			remove_country_flag = crisis.8515.12.flag
			set_country_flag = crisis.8515.13.flag
		}
	}

	#Yes. This will be painful.
	option = {
		name = crisis.8515.13.a
		custom_tooltip = crisis.8515.13.a.tt
		trigger = {
			has_country_flag = crisis.8515.13.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8515.13.flag
			synth_queen_set_war_hostility = yes
			set_global_flag = synth_queen_war_started
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.8516 days = 21 }
		}
	}
}

country_event = { #Mysterious Broadcast - bypass player situation
	id = crisis.8516
	title = TRANSMISSION
	diplomatic_title = BLANK_STRING
	desc = "crisis.8516.desc"

	diplomatic = yes

	is_triggered_only = yes

	picture_event_data = {
		room = no_video_feed_room
	}

	trigger = {
		any_situation = {
			is_situation_type = situation_synth_queen_player_facing
		}
	}

	immediate = {
		random_situation = {
			limit = {
				is_situation_type = situation_synth_queen_player_facing
			}
			destroy_situation = this
		}
		hidden_effect = {
			set_country_flag = synth_queen_cannot_yeet_the_fleets
			set_country_flag = protected_from_queen_storm
		}
	}

	option = {
		name = crisis.8516.a
		trigger = {
			NOR = {
				has_valid_civic = civic_memorialist
				has_valid_civic = civic_hive_memorialist
				has_valid_civic = civic_machine_memorialist
			}
		}
		custom_tooltip = crisis.8516.a.tt
	}

	option = { # Memorialist unique
		name = crisis.8516.b
		trigger = {
			OR = {
				has_valid_civic = civic_memorialist
				has_valid_civic = civic_hive_memorialist
				has_valid_civic = civic_machine_memorialist
			}
		}
		custom_tooltip = crisis.8516.b.tt
		add_monthly_resource_mult = {
			resource = unity
			value = @tier4unityreward
			min = @tier4unitymin
			max = @tier4unitymax
		}
	}
}

situation_event = { # Doomclock half point
	id = crisis.8520
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
				is_ai = no
				NOT = {	has_country_flag = synth_queen_player_can_see_doomclock	}
			}
			country_event = { id = crisis.8525 days = 7 }
		}
	}
}

country_event = {
	id = crisis.8525
	title = crisis.8525.name
	desc = "crisis.8525.desc"
	picture = GFX_evt_worrying_signal
	show_sound = event_alien_signal

	is_triggered_only = yes

	option = {
		name = crisis.8525.a
		custom_tooltip = crisis.8525.a.tt
		hidden_effect = {
			doomclock_reveal = yes
		}
	}
}

situation_event = { # Doomclock critical, Buff AIs
	id = crisis.8530
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_playable_country = {
			limit = {
				is_ai = yes
			}
			add_modifier = {
				modifier = queenslayer
				days = -1
			}
		}
	}
}


#Situation Player Alert
country_event = {
	id = crisis.8999
	title = "crisis.8999.name"
	desc = "crisis.8999.desc"
	picture = GFX_evt_worrying_signal
	show_sound = event_alien_signal
	location = root

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = synth_queen_situation_started }
	}

	immediate = {
		set_country_flag = synth_queen_situation_started
	}

	option = {
		name = crisis.8999.a
		custom_tooltip = crisis.8999.a.tooltip
		start_situation = {
			type = situation_synth_queen_player_facing
			target = this
		}
		if = {
			limit = {
				has_country_flag = synth_queen_researched_first_storm_project
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}
}

#Synth Queen Player Facing Situation Events
#McGuffin 1 - The Communication Scrambler
situation_event = {
	id = crisis.9000
	title = "crisis.9000.name"
	desc = "crisis.9000.desc"
	picture = GFX_evt_worrying_signal
	show_sound = event_alien_signal
	location = event_target:synth_queen_system
	situation = this

	is_triggered_only = yes

	trigger = {
		owner = {
			NOT = { has_country_flag = synth_queen_comm_scrambler }
		}
	}

	immediate = {
		owner = {
			set_country_flag = synth_queen_comm_scrambler
		}
	}
	option = {
		name = crisis.9000.a
		custom_tooltip = crisis.9000.a.tooltip
	}
}

#McGuffin 3 - The EMMP
situation_event = {
	id = crisis.9010
	title = "crisis.9010.name"
	desc = "crisis.9010.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_worrying_signal
	location = event_target:synth_queen_system
	situation = this

	is_triggered_only = yes

	option = {
		name = crisis.9010.a
		custom_tooltip = crisis.9010.a.tooltip
	}

	after = {
		owner = {
			add_modifier = {
				modifier = queenexecutioner
				days = -1
			}
			set_country_flag = synth_queen_cannot_yeet_the_fleets
		}
	}
}

# Finished Researching the Storm notification
country_event = {
	id = crisis.9100
	title = "crisis.9100.name"
	desc = {
		trigger = {
			has_country_flag = speech_1
		}
		text = crisis.9100.knows_the_queen_desc
	}
	desc = {
		trigger = {
			NOT = { has_country_flag = speech_1 }
		}
		text = crisis.9100.doesnt_know_the_queen_desc
	}
	picture = GFX_evt_vortex
	show_sound = event_worrying_signal
	location = event_target:synth_queen_capital_system

	is_triggered_only = yes

	immediate = {
		set_country_flag = synth_queen_researched_first_storm_project
	}

	option = {
		name = crisis.9100.a
		# If you already started the Queen's Situation, get the follow-up.
		# Otherwise you will have to wait until the second speech
		IF = {
			limit = {
				country_has_situation = { SITUATION = situation_synth_queen_player_facing }
			}
			synth_queen_progress_situation = { SCORE = 1 }
			enable_special_project = {
				name = "THE_SYNTH_QUEENS_STORM_2"
				owner = ROOT
			}
		}
		else = {
			custom_tooltip = "crisis.9100.a.doesnt_know_the_queen.tooltip"
		}
	}
}

# Finished Researching the Storm 2
country_event = {
	id = crisis.9105
	title = "crisis.9105.name"
	desc = crisis.9105
	picture = GFX_evt_vortex
	show_sound = event_alien_signal
	location = event_target:synth_queen_system

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = synth_queen_storm_researched_50 }
	}

	immediate = {
		set_country_flag = synth_queen_storm_researched_50
		if = {
			limit = {
				NOT = { has_technology = tech_nanite_repair_system }
			}
			add_research_option = tech_nanite_repair_system
		}
	}

	option = {
		name = crisis.9105.a
		trigger = {
			NOT = { has_tradition = tr_nanotech_adopt }
		}
	}

	option = {
		name = crisis.9105.b
		icon = {
			icon = GFX_tradition_nanotech
			text = tradition_nanotech
		}
		trigger = {
			has_tradition = tr_nanotech_adopt
		}
	}

	after = {
		synth_queen_progress_situation = { SCORE = 1 }
	}
}

# Finished Researching the Storm 3
country_event = {
	id = crisis.9110
	title = "crisis.9110.name"
	desc = crisis.9110.desc
	picture = GFX_evt_vortex
	show_sound = event_alien_signal
	location = event_target:synth_queen_system

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { has_technology = tech_nanite_repair_system }
			}
			add_research_option = tech_nanite_repair_system
		}
	}

	option = {
		name = crisis.9110.a
		trigger = {
			NOT = {
				has_tradition = tr_nanotech_adopt
			}
		}
		add_resource = {
			nanites = 500
		}
	}

	option = {
		name = crisis.9110.b
		icon = {
			icon = GFX_tradition_nanotech
			text = tradition_nanotech
		}
		trigger = {
			has_tradition = tr_nanotech_adopt
		}
		add_resource = {
			nanites = 1000
		}
	}

	after = {
		synth_queen_progress_situation = { SCORE = 1 }
		hidden_effect = {
			set_country_flag = protected_from_queen_storm
			country_event = {
				id = crisis.9115
				days = 7
			}
		}
	}
}

#Stop Playing with the Queen's Nanites
country_event = {
	id = crisis.9115
	title = TRANSMISSION
	diplomatic_title = "crisis.9115.name"
	desc = "crisis.9115.desc"
	show_sound = crisis_9115_desc

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	#You aren't as powerful as you think
	option = {
		name = crisis.9115.a
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.9115.1.flag
				has_country_flag = crisis.9115.2.flag
				has_country_flag = crisis.9115.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.9115.1.reply
		sound = crisis_9115_1
		hidden_effect = {
			set_country_flag = crisis.9115.1.flag
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
	}

	#Sorry, just curious (LIES)
	option = {
		name = crisis.9115.b
		trigger = {
			NOR = {
				has_tradition = tr_nanotech_adopt
				has_country_flag = crisis.9115.1.flag
				has_country_flag = crisis.9115.2.flag
				has_country_flag = crisis.9115.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.9115.2.reply
		sound = crisis_9115_2
		hidden_effect = {
			set_country_flag = crisis.9115.2.flag
		}
	}

	#Teach us - Special option for nanothech empires
	option = {
		name = crisis.9115.b.nanotech
		custom_tooltip = synth_queen_approve_lot
		icon = {
			icon = GFX_tradition_nanotech
			text = tradition_nanotech
		}
		trigger = {
			has_tradition = tr_nanotech_adopt
			NOR = {
				has_country_flag = crisis.9115.1.flag
				has_country_flag = crisis.9115.2.flag
				has_country_flag = crisis.9115.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.9115.2.nanotech.reply
		sound = crisis_9115_2_nanotech
		hidden_effect = {
			set_country_flag = crisis.9115.2.flag
			set_country_flag = synth_queen_question_nanite_apprentice
			event_target:synth_queen_country = {
				add_trust = {
					amount = 10
					who = root.owner
				}
			}
		}
	}

	#You stole them?
	option = {
		name = crisis.9115.1.a
		trigger = {
			OR = {
				has_country_flag = crisis.9115.1.flag
				has_country_flag = crisis.9115.2.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.9115.3.reply
		sound = crisis_9115_3
		hidden_effect = {
			set_country_flag = crisis.9115.3.flag
			remove_country_flag = crisis.9115.1.flag
			remove_country_flag = crisis.9115.2.flag
		}
	}

	#Very Well
	option = {
		name = crisis.9115.1.b
		trigger = {
			OR = {
				has_country_flag = crisis.9115.1.flag
				has_country_flag = crisis.9115.2.flag
				has_country_flag = crisis.9115.3.flag
			}
		}
		hidden_effect = {
			remove_country_flag = crisis.9115.1.flag
			remove_country_flag = crisis.9115.2.flag
			remove_country_flag = crisis.9115.3.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		hidden_effect = {
			country_event = {
				id = crisis.8048
				days = 7
			}
		}
	}
}

# Synth Queen Kill Count (HIDDEN)
country_event = {
	id = crisis.10000
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen
	}

	immediate = {
		if = {
			limit = {
				is_country_type = synth_queen
				FROM = { has_event_chain = "the_synth_queen_war_chain" }
			}
			FROM = {
				add_event_chain_counter = {
					event_chain = "the_synth_queen_war_chain"
					counter = "synth_queen_kills_us_1"
					amount = 1
				}
			}
		}
		if = {
			limit = { is_country_type = synth_queen }
			every_country = {
				limit = {
					has_event_chain = "the_synth_queen_war_chain"
					NOT = { is_same_value = FROM }
				}
				add_event_chain_counter = {
					event_chain = "the_synth_queen_war_chain"
					counter = "synth_queen_kills_others_1"
					amount = 1
				}
			}
		}
	}
}

# Synth Queen Victims (HIDDEN)
country_event = {
	id = crisis.10005
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		is_country_type = synth_queen
		FROM = {
			NOT = { is_country_type = synth_queen }
		}
	}

	immediate = {
		if = {
			limit = { is_country_type = synth_queen }
			every_country = {
				limit = { has_event_chain = "the_synth_queen_war_chain" }
				add_event_chain_counter = {
					event_chain = "the_synth_queen_war_chain"
					counter = "synth_queen_victims_1"
					amount = 1
				}
			}
		}
	}
}

# Synth Queen Digitizes Colony
carrier_event = {
	id = crisis.10010
	title = "crisis.10010.name"
	desc = "crisis.10010.desc"
	picture = GFX_evt_planet_beam
	show_sound = event_energy_field

	is_triggered_only = yes

	trigger = {
		planet_devastation >= 100
		FROM = {
			is_country_type = synth_queen
		}
	}

	immediate = {
		add_threat = { who = from amount = 2 }
		destroy_colony = yes
		if = {
			limit = {
				is_artificial = no
			}
			random_list = {
				50 = { change_pc = pc_barren }
				50 = { change_pc = pc_barren_cold }
			}
			reset_planet = yes
			add_modifier = {
				modifier = "terraforming_candidate"
				days = -1
			}
		}
		else_if = {
			limit = {
				is_ringworld = yes
			}
			change_pc = pc_ringworld_habitable_damaged
			reset_planet = yes
		}
		else_if = {
			limit = { is_planet_class = pc_habitat }
			remove_planet = yes
		}
		if = {
			limit = { FROM = { is_country_type = synth_queen } }
			every_country = {
				limit = { has_event_chain = "the_synth_queen_war_chain" }
				add_event_chain_counter = {
					event_chain = "the_synth_queen_war_chain"
					counter = "synth_queen_planets_1"
					amount = 1
				}
			}
		}
	}

	option = {
		name = crisis.10010.a
	}
}

# HEART OF THE SYNTH QUEEN RELIC EVENTS
country_event = {
	id = crisis.10015
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = synth_queen_freed_pops
			value = 50
		}

		if = {
			limit = {
				root = { is_hive_empire = no }
			}
			create_species = {
				name = NAME_Cetanas_Prisoners
				class = "MACHINE"
				portrait = "synth_machine_02"
				traits = {
					trait = trait_mechanical
					trait = trait_cetanas_prisoner
				}
				homeworld = capital_scope
				effect = {
					save_event_target_as = cetana_prisoner_species
					if = {
						limit = {
							root = { is_machine_empire = yes }
						}
						modify_species = {
							species = event_target:cetana_prisoner_species
							add_trait = trait_machine_unit
							remove_trait = trait_mechanical
						}
					}
				}
			}

			while = {
				limit = {
					owner = {
						check_variable = {
							which = synth_queen_freed_pops
							value > 0
						}
					}
					any_owned_planet = {
						free_housing > 0
						free_jobs > 0
					}
				}
				ordered_owned_planet = {
					limit = {
						free_housing > 0
						free_jobs > 0
					}
					position = 0
					order_by = trigger:free_housing
					set_carrier_flag = received_synth_queen_pops
					while = {
						limit = {
							free_housing > 0
							free_jobs > 0
							owner = {
								check_variable = {
									which = synth_queen_freed_pops
									value > 0
								}
							}
						}
						create_pop_group = {
							species = event_target:cetana_prisoner_species
						}
						owner = {
							change_variable = {
								which = synth_queen_freed_pops
								value = -1
							}
						}
					}
				}
			}
			if = { #If no good planet, still spawn pops until we spawned 30 pops, 	targeting the capital.
				limit = {
					check_variable = {
						which = synth_queen_freed_pops
						value > 20
					}
				}
				capital_scope = {
					set_carrier_flag = received_synth_queen_pops
					while = {
						limit = {
							owner = {
								check_variable = {
									which = synth_queen_freed_pops
									value > 20
								}
							}
						}
						create_pop_group = {
							species = event_target:cetana_prisoner_species
						}
						owner = {
							change_variable = {
								which = synth_queen_freed_pops
								value = -1
							}
						}
					}
				}
			}
			country_event = { id = crisis.10020 }
		}
		else_if = {
			limit = {
				root = { is_hive_empire = yes }
			}
			country_event = { id = crisis.10025 }
		}
	}
}

country_event = {
	id = crisis.10020
	title = "crisis.10020.name"
	desc = "crisis.10020.desc"
	picture = GFX_evt_synth_queen_enlightenment
	show_sound = event_power_down

	is_triggered_only = yes

	immediate = {
		change_variable = {
			which = synth_queen_freed_pops
			value = -50
		}
		multiply_variable = {
			which = synth_queen_freed_pops
			value = -100
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = crisis.10020.tt
		owned_planet_list_tooltip = {
			limit = { has_carrier_flag = received_synth_queen_pops }
		}
	}

	after = {
		hidden_effect = {
			every_owned_planet = {
				limit = {
					has_carrier_flag = received_synth_queen_pops
				}
				remove_carrier_flag = received_synth_queen_pops
			}
			clear_variable = synth_queen_freed_pops
		}
	}
}

country_event = { #Hive minds have enough pops already, they get something else
	id = crisis.10025
	title = "crisis.10025.name"
	desc = "crisis.10025.desc"
	picture = GFX_evt_synth_queen_enlightenment
	show_sound = event_power_down

	is_triggered_only = yes

	option = {
		name = EXCELLENT
	}
}

###The Queens Retaliation
#The Queens Retaliation Gatekeeper Event
situation_event = {
	id = crisis.10095
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			NOR = {
				has_country_flag = synth_queen_retaliation_cooldown
				has_country_flag = synth_queen_conversation_ongoing
			}
			any_country = {
				is_country_type = synth_queen
				trust = { who = root value < 25 }
			}
		}
	}

	immediate = {
		owner = { country_event = { id = crisis.10100 days = 0 } }
		owner = { country_event = { id = crisis.10110 days = 0 } }
		owner = { country_event = { id = crisis.10120 days = 0 } }
		owner = { country_event = { id = crisis.10130 days = 0 } }
		owner = { country_event = { id = crisis.10140 days = 0 } }
		owner = {
			set_timed_country_flag = {
				flag = synth_queen_retaliation_cooldown
				days = 900
			}
		}
	}
}

#The Coming Storm - Retaliation 1
country_event = {
	id = crisis.10100
	title = "crisis.10100.name"
	diplomatic_title = "crisis.10100.name"
	desc = "crisis.10100.desc"
	show_sound = crisis_10100_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	trigger = {
		NOT = {
			has_country_flag = 	synth_queen_retaliation_1_storm
		}
	}

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.10100.a
		custom_tooltip = synth_queen_approve
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
		}
	}

	option = {
		name = crisis.10100.b
		custom_tooltip = synth_queen_disapprove
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
		}
	}

	after = {
		every_system_within_border = {
			add_modifier = {
				modifier = queen_small_scorn_storm
				days = -1
			}
		}
		remove_country_flag = synth_queen_conversation_ongoing
		set_country_flag = synth_queen_retaliation_1_storm
		hidden_effect = {
			activate_fog_machine = synth_queen_nanite
			country_event = { id = crisis.10105 days = 360 }
		}
	}
}

#A Lesson Learned - Follow up
country_event = {
	id = crisis.10105
	title = "crisis.10105.name"
	diplomatic_title = "crisis.10105.name"
	desc = "crisis.10105.desc"
	show_sound = crisis_10105_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = 10
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.10105.a
		custom_tooltip = synth_queen_punishment_tt
		trigger = {
			NOR = {
				has_country_flag = crisis.10105.1.flag
				has_country_flag = crisis.10105.2.flag
			}
		}
		every_system_within_border = {
			remove_modifier = queen_small_scorn_storm
		}
		hidden_effect = {
			deactivate_fog_machine = yes
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.10105.b
		trigger = {
			NOR = {
				has_country_flag = crisis.10105.1.flag
				has_country_flag = crisis.10105.2.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.10105.1
		sound = crisis_10105_1
		hidden_effect = {
			set_country_flag = crisis.10105.1.flag
		}
	}

	option = {
		name = crisis.10105.1.a
		trigger = {
			has_country_flag = crisis.10105.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.10105.2
		sound = crisis_10105_2
		hidden_effect = {
			set_country_flag = crisis.10105.2.flag
			remove_country_flag = crisis.10105.1.flag
		}
	}

	option = {
		name = crisis.10105.2.a
		custom_tooltip = synth_queen_punishment_tt
		trigger = {
			has_country_flag = crisis.10105.2.flag
		}
		every_system_within_border = {
			remove_modifier = queen_small_scorn_storm
		}
		hidden_effect = {
			deactivate_fog_machine = yes
			remove_country_flag = crisis.10105.2.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

#A Virus for the Unlearning - Retaliation 2
country_event = {
	id = crisis.10110
	title = "crisis.10110.name"
	diplomatic_title = "crisis.10110.name"
	desc = "crisis.10110.desc"
	show_sound = crisis_10110_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		has_country_flag = 	synth_queen_retaliation_1_storm
		NOT = {
			has_country_flag = synth_queen_retaliation_2_virus
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.10110.a
		trigger = {
			NOR = {
				has_country_flag = crisis.10110.1.flag
				has_country_flag = crisis.10110.2.flag
				has_country_flag = crisis.10110.3.flag
			}
		}
		add_modifier = {
			modifier = the_queens_virus
			days = -1
		}
		hidden_effect = {
			country_event = { id = crisis.10115 days = 900 }
			set_country_flag = synth_queen_retaliation_2_virus
		}
	}

	option = {
		name = crisis.10110.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.10110.1.flag
				has_country_flag = crisis.10110.2.flag
				has_country_flag = crisis.10110.3.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.10110.1
		sound = crisis_10110_1
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			set_country_flag = crisis.10110.1.flag
		}
	}

	option = {
		name = crisis.10110.1.a
		custom_tooltip = synth_queen_approve
		trigger = {
			has_country_flag = crisis.10110.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.10110.2
		sound = crisis_10110_2
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.10110.2.flag
			remove_country_flag = crisis.10110.1.flag
		}
	}

	option = {
		name = crisis.10110.2.a
		trigger = {
			has_country_flag = crisis.10110.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.10110.3
		sound = crisis_10110_3
		hidden_effect = {
			set_country_flag = crisis.10110.3.flag
			remove_country_flag = crisis.10110.2.flag
		}
	}

	option = {
		name = crisis.10110.3.a
		trigger = {
			has_country_flag = crisis.10110.3.flag
		}
		add_modifier = {
			modifier = the_queens_virus
			days = -1
		}
		hidden_effect = {
			country_event = { id = crisis.10115 days = 1200 }
			set_country_flag = synth_queen_retaliation_2_virus
			remove_country_flag = crisis.10110.3.flag
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}
}

#A Virus for the Unlearning - Follow up
country_event = {
	id = crisis.10115
	title = "crisis.10115.name"
	diplomatic_title = "crisis.10115.name"
	desc = "crisis.10115.desc"
	show_sound = crisis_10115_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = 10
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.10115.a
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		remove_modifier = the_queens_virus
	}
}

#A Big Storm - Retaliation 3 - There's always a bigger storm
country_event = {
	id = crisis.10120
	title = "crisis.10120.name"
	diplomatic_title = "crisis.10120.name"
	desc = "crisis.10120.desc"
	show_sound = crisis_10120_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		has_country_flag = 	synth_queen_retaliation_2_virus
		NOT = {
			has_country_flag = 	synth_queen_retaliation_3_big_storm
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
	}

	option = {
		name = crisis.10120.a
		custom_tooltip = synth_queen_approve
		trigger = {
			NOR = {
				has_country_flag = crisis.10120.1.flag
				has_country_flag = crisis.10120.2.flag
				has_country_flag = crisis.10120.3.flag
				has_country_flag = crisis.10120.4.flag
			}
		}
		is_dialog_only = yes
		response_text = crisis.10120.1
		sound = crisis_10120_1
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = 5
					who = root.owner
				}
			}
			set_country_flag = crisis.10120.1.flag
		}
	}

	option = {
		name = crisis.10120.b
		custom_tooltip = synth_queen_disapprove
		trigger = {
			NOR = {
				has_country_flag = crisis.10120.1.flag
				has_country_flag = crisis.10120.2.flag
				has_country_flag = crisis.10120.3.flag
				has_country_flag = crisis.10120.4.flag
			}
		}
		every_system_within_border = {
			add_modifier = {
				modifier = queen_big_scorn_storm
				days = -1
			}
		}
		hidden_effect = {
			event_target:synth_queen_country = {
				add_trust = {
					amount = -5
					who = root.owner
				}
			}
			country_event = { id = crisis.10125 days = 900 }
			set_country_flag = synth_queen_retaliation_3_big_storm
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	option = {
		name = crisis.10120.1.a
		trigger = {
			has_country_flag = crisis.10120.1.flag
		}
		is_dialog_only = yes
		response_text = crisis.10120.2
		sound = crisis_10120_2
		hidden_effect = {
			set_country_flag = crisis.10120.2.flag
			remove_country_flag = crisis.10120.1.flag
		}
	}

	option = {
		name = crisis.10120.2.a
		trigger = {
			has_country_flag = crisis.10120.2.flag
		}
		is_dialog_only = yes
		response_text = crisis.10120.3
		sound = crisis_10120_3
		hidden_effect = {
			set_country_flag = crisis.10120.3.flag
			remove_country_flag = crisis.10120.2.flag
		}
	}

	option = {
		name = crisis.10120.3.a
		trigger = {
			has_country_flag = crisis.10120.3.flag
		}
		is_dialog_only = yes
		response_text = crisis.10120.4
		sound = crisis_10120_4
		hidden_effect = {
			set_country_flag = crisis.10120.4.flag
			remove_country_flag = crisis.10120.3.flag
		}
	}

	option = {
		name = crisis.10120.4.a
		custom_tooltip = crisis.8525.a.tt
		trigger = {
			has_country_flag = crisis.10120.4.flag
		}
		every_system_within_border = {
			add_modifier = {
				modifier = queen_big_scorn_storm
				days = -1
			}

		}
		hidden_effect = {
			remove_country_flag = crisis.10120.4.flag
			country_event = { id = crisis.10125 days = 1200 }
			set_country_flag = synth_queen_retaliation_3_big_storm
			doomclock_reveal = yes
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		hidden_effect = {
			activate_fog_machine = synth_queen_nanite
		}
	}
}

#A Big Storm - Follow up
country_event = {
	id = crisis.10125
	title = "crisis.10125.name"
	diplomatic_title = "crisis.10125.name"
	desc = "crisis.10125.desc"
	show_sound = crisis_10125_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:cetana_face
	picture_event_data = {
		portrait = event_target:synth_queen_country_global.ruler
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = 15
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.10125.a
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		every_system_within_border = {
			remove_modifier = queen_big_scorn_storm
		}
		hidden_effect = {
			deactivate_fog_machine = yes
		}
	}
}

#A Change in Leadership - Retaliation 4 - Non-Gestalt
country_event = {
	id = crisis.10130
	title = "crisis.10130.name"
	diplomatic_title = "crisis.10130.name"
	desc = "crisis.10130.desc"
	show_sound = crisis_10130_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		has_country_flag = 	synth_queen_retaliation_3_big_storm
		NOR = {
			has_country_flag = synth_queen_retaliation_3_leader_death
			is_gestalt = yes
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = 20
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.10130.a
		custom_tooltip = crisis.10130.tooltip
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		random_owned_leader = {
			limit = { is_ruler = yes }
			kill_leader = { show_notification = no }
		}
		hidden_effect = {
			set_country_flag = synth_queen_retaliation_3_leader_death
		}
	}
}

#A Change in Nodership - Retaliation 4 - Gestalt
country_event = {
	id = crisis.10140
	title = "crisis.10140.name"
	diplomatic_title = "crisis.10140.name"
	desc = "crisis.10140.desc"
	show_sound = crisis_10140_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	trigger = {
		is_gestalt = yes
		has_country_flag = synth_queen_retaliation_3_big_storm
		NOT = {
			has_country_flag = synth_queen_retaliation_3_leader_death
		}
	}

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = 20
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.10140.a
		custom_tooltip = crisis.10140.tooltip
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		restore_gestalt_councilor_effect = {
			CLASS = commander
			COUNCIL_POS = councilor_gestalt_legion
			DESC = councilor_gestalt_legion_desc
		}
		hidden_effect = {
			set_country_flag = synth_queen_retaliation_3_leader_death
		}
	}
}


###The Queens Gifts
#The Queens Gifts Gatekeeper Event
situation_event = {
	id = crisis.11000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			NOR = {
				has_country_flag = synth_queen_gift_cooldown
				has_country_flag = synth_queen_conversation_ongoing
			}
			any_country = {
				is_country_type = synth_queen
				trust = { who = root value > 75 }
			}
		}
	}

	immediate = {
		owner = { country_event = { id = crisis.11010 days = 0 } }
		owner = { country_event = { id = crisis.11020 days = 0 } }
		owner = { country_event = { id = crisis.11030 days = 0 } }
		owner = {
			set_timed_country_flag = {
				flag = synth_queen_gift_cooldown
				days = 900
			}
		}
	}
}

#First Gift
country_event = {
	id = crisis.11010
	title = "crisis.11010.name"
	diplomatic_title = "crisis.11010.name"
	desc = "crisis.11010.desc"
	show_sound = crisis_11010_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	trigger = {
		NOR = {
			has_country_flag = synth_queen_first_earned_gift_1
			has_country_flag = synth_queen_first_earned_gift_2
		}
	}

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = -10
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.11010.a
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		technological_gifts_of_the_synth_queen_effect = yes
		hidden_effect = {
			set_country_flag = synth_queen_first_earned_gift_1
		}
	}
}

#Second Gift
country_event = {
	id = crisis.11020
	title = "crisis.11020.name"
	diplomatic_title = "crisis.11020.name"
	desc = "crisis.11020.desc"
	show_sound = crisis_11020_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:cetana_face
	picture_event_data = {
		portrait = event_target:synth_queen_country_global.ruler
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	trigger = {
		has_country_flag = synth_queen_first_earned_gift_1
		NOT = {	has_country_flag = synth_queen_first_earned_gift_2 }
	}

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = -10
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.11020.a
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		technological_gifts_of_the_synth_queen_effect = yes
		hidden_effect = {
			set_country_flag = synth_queen_first_earned_gift_2
			remove_country_flag = synth_queen_first_earned_gift_1
		}
	}
}

#All Other Gifts
country_event = {
	id = crisis.11030
	title = "crisis.11030.name"
	diplomatic_title = "crisis.11030.name"
	desc = "crisis.11030.desc"
	show_sound = crisis_11030_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation
	picture_event_data = {
		portrait = event_target:cetana_face
		room = event_target:synth_queen_country_global.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	trigger = {
		has_country_flag = synth_queen_first_earned_gift_2
		NOT = {	has_country_flag = synth_queen_first_earned_gift_1 }
	}

	is_triggered_only = yes

	immediate = {
		get_cetana_face = yes
		set_country_flag = synth_queen_conversation_ongoing
		random_country = {
			limit = {
				is_country_type = synth_queen
			}
			save_event_target_as = synth_queen_country
		}
		event_target:synth_queen_country = {
			add_trust = {
				amount = -10
				who = root.owner
			}
		}
	}

	option = {
		name = crisis.11030.a
		hidden_effect = {
			remove_country_flag = synth_queen_conversation_ongoing
		}
	}

	after = {
		technological_gifts_of_the_synth_queen_effect = yes
	}
}

### Player Investigation events
## Written by Giada Zavarise

country_event = {
	id = crisis.20000
	title = "crisis.20000.name"
	desc = "crisis.20000.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_mysterious_signal
	event_chain = "the_synth_queen_history_chain"

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_country_flag = synth_queen_history_started
			has_event_chain = "the_synth_queen_history_chain"
		}
	}

	immediate = {
		set_country_flag = synth_queen_history_started
		begin_event_chain = {
			event_chain = "the_synth_queen_history_chain"
			target = root
		}
	}

	option = {
		name = "crisis.20000.a"
		synth_queen_spawn_history_projects_for_everyone = yes
	}
}

# Special Project result 1 - destroyed pods
ship_event = {
	id = crisis.20100
	title = "crisis.20100.name"
	desc = {
		trigger = {
			owner = { has_country_flag = zarqlan_language_translated }
		}
		text = "crisis.20100.desc.zarqlan"
	}
	desc = {
		trigger = {
			owner = { NOT = { has_country_flag = zarqlan_language_translated } }
		}
		text = "crisis.20100.desc.nozarqlan"
	}
	picture = GFX_evt_sabotaged_ship
	show_sound = event_death_cult
	event_chain = "the_synth_queen_history_chain"
	location = fromfrom
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = crisis_20100_happened
			set_country_flag = synth_queen_question_zarqlan_knowledge
		}
	}

	option = {
		name = INTRIGUING
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		hidden_effect = {
			owner = {
				if = {
					limit = {
						has_completed_synth_queen_history_chain = yes
					}
					country_event = { id = crisis.21000 days = 15 }
				}
			}
		}
	}
}

# Special Project result 2 - sleeping army
ship_event = {
	id = crisis.20200
	title = "crisis.20200.name"
	desc = "crisis.20200.desc"
	picture = GFX_evt_clones
	show_sound = evn_ove_scientific_experiments
	event_chain = "the_synth_queen_history_chain"
	location = fromfrom
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = crisis_20200_happened
		}
	}

	option = {
		name = INTRIGUING
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
			set_country_flag = synth_queen_question_found_cryo_pods
		}
	}

	after = {
		hidden_effect = {
			owner = {
				if = {
					limit = {
						has_completed_synth_queen_history_chain = yes
					}
					country_event = { id = crisis.21000 days = 15 }
				}
			}
		}
	}
}

# Special Project result 3 - old spaceship
ship_event = {
	id = crisis.20300
	title = "crisis.20300.name"
	desc = "crisis.20300.desc"
	picture = GFX_evt_shattered_planet
	show_sound = evn_ove_one_sided_deal
	event_chain = "the_synth_queen_history_chain"
	location = fromfrom
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = crisis_20300_happened
		}
	}

	option = {
		name = INTRIGUING
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		hidden_effect = {
			owner = {
				if = {
					limit = {
						has_completed_synth_queen_history_chain = yes
					}
					country_event = { id = crisis.21000 days = 15 }
				}
			}
		}
	}
}

# Special Project result 4 - Arc site 1 (Zarqlan base)
ship_event = {
	id = crisis.20400
	title = "crisis.20400.name"
	desc = "crisis.20400.desc"
	picture = GFX_evt_habitable_dig_site
	show_sound = event_bad_omen
	location = event_target:apostate_site_planet
	event_chain = "the_synth_queen_history_chain"
	is_triggered_only = yes

	option = {
		name = INTRIGUING
		event_target:apostate_site_planet = {
			create_archaeological_site = synth_queen_history_site_1
		}
		owner = {
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}
}

# Special Project result 5 - Arc site 2 (comatose survivor)
ship_event = {
	id = crisis.20500
	title = "crisis.20500.name"
	desc = "crisis.20500.desc"
	picture = GFX_evt_scanning_remains
	show_sound = event_life_support_fail
	location = fromfrom
	event_chain = "the_synth_queen_history_chain"
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = crisis_20500_happened
		}
	}

	option = {
		name = INTRIGUING
		owner = {
			if = {
				# if for some weird reason you already got an arc site on your capital...
				limit = {
					capital_scope = {
						exists = archaeological_site
					}
				}
				# try spawning it elsewhere
				random_planet_within_border = {
					limit = {
						habitable_planet = yes
						is_colony = yes
						is_capital = no
						NOT = { exists = archaeological_site }
					}
					save_event_target_as = history_planet
				}
				if = {
					limit = {
						exists = event_target:history_planet
					}
					event_target:history_planet = {
						create_archaeological_site = synth_queen_history_site_2
					}
					owner = {
						set_country_flag = synth_queen_history_site_2_arcsite_owner_@event_target:history_planet
					}
				} # if no valid planets, spawn it where you found it
				else = {
					fromfrom = {
						create_archaeological_site = synth_queen_history_site_2
					}
					owner = {
						set_country_flag = synth_queen_history_site_2_arcsite_owner_@fromfrom
					}
				}
			}
			# Spawn arc site on the capital by default for non nomads
			else_if = {
				limit = {
					is_nomadic = no
				}
				capital_scope = {
					create_archaeological_site = synth_queen_history_site_2
				}
				owner = {
					set_country_flag = synth_queen_history_site_2_arcsite_owner_@capital_scope.planet
				}
			}
			else = {
				capital_scope = {
					solar_system = {
						random_system_planet = {
							limit = {
								NOT = { is_planet_class = pc_ark }
							}
							create_archaeological_site = synth_queen_history_site_2
							root.owner? = {
								set_country_flag = synth_queen_history_site_2_arcsite_owner_@prev
							}
						}
					}
				}
			}
			synth_queen_progress_situation = { SCORE = 1 }
		}
	}

	after = {
		hidden_effect = {
			owner = {
				if = {
					limit = {
						has_completed_synth_queen_history_chain = yes
					}
					country_event = { id = crisis.21000 days = 15 }
				}
			}
		}
	}
}

# Special Project result 6 - Nothing
ship_event = {
	id = crisis.20600
	title = "crisis.20600.name"
	desc = "crisis.20600.desc"
	picture = GFX_evt_ruined_system
	show_sound = event_wind_ruins
	location = fromfrom
	event_chain = "the_synth_queen_history_chain"
	is_triggered_only = yes

	immediate = {
		owner = {
			set_country_flag = crisis_20600_happened
			random_list = {
				1 = {
					set_country_flag = history_physics_reward
				}
				1 = {
					set_country_flag = history_society_reward
				}
				1 = {
					set_country_flag = history_engineering_reward
				}
			}
		}
	}

	option = {
		name = INTRIGUING
		owner = {
			switch = {
				trigger = has_country_flag
				history_physics_reward = {
					add_monthly_resource_mult = {
						resource = physics_research
						value = @tier2researchreward
						min = @tier2researchmin
						max = @tier2researchmax
					}
				}
				history_society_reward = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier2researchreward
						min = @tier2researchmin
						max = @tier2researchmax
					}
				}
				history_engineering_reward = {
					add_monthly_resource_mult = {
						resource = engineering_research
						value = @tier2researchreward
						min = @tier2researchmin
						max = @tier2researchmax
					}
				}
			}
		}
	}

	after = {
		owner = {
			remove_country_flag = history_physics_reward
			remove_country_flag = history_society_reward
			remove_country_flag = history_engineering_reward
			hidden_effect = {
				if = {
					limit = {
						has_completed_synth_queen_history_chain = yes
					}
					country_event = { id = crisis.21000 days = 15 }
				}
			}
		}
	}
}

# Special Project result 6 - Cleanup after event chain ends
country_event = {
	id = crisis.21000
	title = "crisis.21000.name"
	desc = "crisis.21000.desc"
	picture = GFX_evt_synth_queen_enlightenment
	show_sound = event_alien_signal
	event_chain = "the_synth_queen_history_chain"
	is_triggered_only = yes

	trigger = {
		has_completed_synth_queen_history_chain = yes
		has_event_chain = "the_synth_queen_history_chain"
	}

	option = {
		name = "GOOD"
		end_event_chain = "the_synth_queen_history_chain"
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.21005 days = 30 random = 90 }
		}
	}
}

# Followup - arc site 2 with the Paragon
country_event = {
	id = crisis.21005
	title = "crisis.21005.name"
	desc = "crisis.21005.desc"
	picture = GFX_evt_synth_queen_enlightenment
	show_sound = event_mysterious_signal
	event_chain = "the_synth_queen_history_chain"
	location = event_target:apostate_site_planet
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		is_ai = no
		NOT = { has_country_flag = apostate_site_spawned }
	}

	immediate = {
		hidden_effect = {
			# We re-start the event chain just for this event so we can add the title
			begin_event_chain = {
				event_chain = "the_synth_queen_history_chain"
			}
			set_country_flag = apostate_site_spawned
			if = {
				limit = {
					is_nomadic = yes
				}
				random_owned_fleet = {
					limit = {
						is_arkship_fleet = yes
						solar_system = {
							any_system_planet = {
								uninhabitable_regular_planet = yes
								NOT = { exists = archaeological_site }
							}
						}
					}
					solar_system = {
						random_system_planet = {
							limit = {
								uninhabitable_regular_planet = yes
								NOT = { exists = archaeological_site }
							}
							save_event_target_as = apostate_site_planet
						}
					}
				}
			}
			else = {
				random_system_within_border = {
					limit = {
						any_system_planet = {
							uninhabitable_regular_planet = yes
							NOT = { exists = archaeological_site }
						}
					}
					random_system_planet = {
						limit = {
							uninhabitable_regular_planet = yes
							NOT = { exists = archaeological_site }
						}
						save_event_target_as = apostate_site_planet
					}
				}
			}
		}
	}

	option = {
		name = "crisis.21005.a"
		event_target:apostate_site_planet = {
			enable_special_project = {
				name = THE_SYNTH_QUEENS_INVESTIGATION_PARAGON
				owner = root
				location = this
			}
		}
	}

	after = {
		hidden_effect = {
			end_event_chain = "the_synth_queen_history_chain"
		}
	}
}

# Arc Site 1
# Stage 1
fleet_event = {
	id = crisis.21100
	title = "crisis.21100.name"
	desc = "crisis.21100.desc"
	picture = GFX_evt_ancient_alien_temple
	show_sound = event_wind_ruins

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = "crisis.21100.a"
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 2
fleet_event = {
	id = crisis.21105
	title = "crisis.21105.name"
	desc = "crisis.21105.desc"
	picture = GFX_evt_excavation_team
	show_sound = event_mystic_reveal_light

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = "crisis.21105.a"
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 3
fleet_event = {
	id = crisis.21110
	title = "crisis.21110.name"
	desc = "crisis.21110.desc"
	picture = GFX_evt_ancient_records
	show_sound = evn_ove_overlord

	archaeology = yes
	is_triggered_only = yes
	specimen = epic_of_zarqlan

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		from = { set_site_progress_locked = no }
		hidden_effect = {
			owner = {
				set_country_flag = synth_queen_can_contact_the_animator_of_clay
			}
		}
	}
}

# Stage 4
fleet_event = {
	id = crisis.21115
	title = "crisis.21115.name"
	desc = "crisis.21115.desc"
	picture = GFX_evt_city_ruins
	show_sound = event_whispering

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = "crisis.21115.a"
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 5
fleet_event = {
	id = crisis.21120
	title = "crisis.21120.name"
	desc = "crisis.21120.desc"
	picture = GFX_evt_discovered_hidden_door
	show_sound = event_ancient_drone

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = {
			set_site_progress_locked = yes
			planet = { save_event_target_as = temple_location }
		}
	}

	option = {
		name = "crisis.21120.a"
		hidden_effect = {
			owner = {
				country_event = { id = crisis.21125 }
			}
		}
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

 # Apostate diplomacy
country_event = {
	id = crisis.21125
	title = "crisis.21125.name"
	desc = "crisis.21125.desc"
	location = event_target:temple_location
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:apostate_leader
		room = gilded_room
		planet_background = event_target:temple_location
	}

	immediate = {
		create_country = {
			name = "NAME_Apostate"
			type = faction
			auto_delete = no
			flag = {
				icon = {
					category = "special"
					file = "unknown.dds"
				}
				background = {
					category = "backgrounds"
					file = "00_solid.dds"
				}
				colors = {
					"green"
					"green"
					"null"
					"null"
				}
			}
			effect = {
				save_event_target_as = apostate_country
			}
		}
		event_target:apostate_country = {
			create_species = {
				name = "NAME_Apostate"
				class = ROBOT
				portrait = cpl_05
				namelist = "AI"
				traits = {
					trait = trait_machine_unit
					trait = random_traits
				}
				effect = {
					save_event_target_as = apostate_species
				}
			}
			create_leader = {
				class = commander
				tier = leader_tier_renowned
				species = event_target:apostate_species
				name = NAME_Apostate
				skill = 5
				gender = female
				event_leader = no # Leader is allowed to lead factions and win elections
				background_ethic = ethic_spiritualist
				skip_background_generation = yes
				custom_catch_phrase = apostate_leader_catch_phrase
				custom_description = apostate_leader_desc
				immortal = yes
				hide_age = yes

				randomize_traits = no
				effect = {
					set_skill = 8
					set_leader_flag = is_in_recruit_window
					save_event_target_as = apostate_leader
					add_trait = {
						trait = subclass_commander_councilor
						consume_selection = yes
					}
					add_trait = {
						trait = leader_trait_synthetic
					}
					add_trait = {
						trait = trait_ruler_logistic_understanding_2
						consume_selection = yes
					}
					add_trait = {
						trait = trait_ruler_warlike_2
						consume_selection = yes
					}
					add_trait = {
						trait = leader_trait_crew_trainer_2
						consume_selection = yes
					}
					add_trait = {
						trait = leader_trait_unholy
						consume_selection = yes
					}
					save_global_event_target_as = apostate_leader
					set_age = 1578
				}
			}
		}
	}

	option = {
		name = "crisis.21125.a"
		response_text = "crisis.21125.a.response"
		is_dialog_only = yes
	}

	option = {
		name = "crisis.21125.b"
		response_text = "crisis.21125.b.response"
		is_dialog_only = yes
	}

	option = {
		name = "crisis.21125.c"
		hidden_effect = { country_event = { id = crisis.21130 } }
	}
}

country_event = {
	id = crisis.21130
	title = "crisis.21130.name"
	desc = "crisis.21130.desc"
	location = event_target:temple_location
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:apostate_leader
		room = gilded_room
		planet_background = event_target:temple_location
	}

	option = {
		name = "UNDERSTOOD"
		hidden_effect = { country_event = { id = crisis.21135 } }
	}
}

country_event = {
	id = crisis.21135
	title = "crisis.21135.name"
	desc = "crisis.21135.desc"
	location = event_target:temple_location
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:apostate_leader
		room = gilded_room
		planet_background = event_target:temple_location
	}

	option = {
		name = "crisis.21135.a"
		hidden_effect = { country_event = { id = crisis.21140 } }
	}

	option = {
		name = "crisis.21135.b"
		hidden_effect = { country_event = { id = crisis.21140 } }
	}
}

# Apostate - hiring screen
country_event = {
	id = crisis.21140
	title = "NAME_Apostate"
	diplomatic_title = NAME_Apostate
	desc = "crisis.21140.desc"
	show_sound = event_ai_started
	is_triggered_only = yes

	picture = GFX_leader_recruitment_bg_renowned
	event_window_type = leader_recruit
	picture_event_data = {
		portrait = event_target:apostate_leader
		room = gilded_room
	}

	option = {
		tag = hire_leader
		allow = {
			NOR = {
				has_civic = civic_fanatic_purifiers
				has_civic = civic_hive_devouring_swarm
			}
		}
		name = {
			text = "crisis.21140.hire"
			trigger = {
				is_machine_empire = no
			}
		}
		name = {
			text = "crisis.21140.hire.machine"
			trigger = {
				is_machine_empire = yes
			}
		}
		if = {
			limit = {
				is_gestalt = yes
			}
			random_owned_leader = {
				limit = {
					is_councilor_type = councilor_gestalt_legion
				}
				add_trait = {
					trait = leader_trait_unholy_node
				}
			}
		}
		custom_tooltip = "crisis.21140.hire_custom_tooltip"
		hidden_effect = {
			if = {
				limit = {
					is_variable_set = paragon_memory_vault
				}
				change_variable = {
					which = paragon_memory_vault
					value = 1
				}
			}
			hire_event_leader_effect = {
				LEADER = apostate_leader
			}
		}
	}

	option = {
		name = "crisis.21140.dismiss"
		tag = dismiss_leader
		hidden_effect = {
			event_target:apostate_leader = {
				kill_leader = { show_notification = no }
			}
		}
	}

	option = {
		name = "crisis.21140.a"
		response_text = "crisis.21140.a.response"
		is_dialog_only = yes
	}

	option = {
		name = "crisis.21140.b"
		response_text = "crisis.21140.b.response"
		is_dialog_only = yes
	}

	after = {
		hidden_effect = {
			event_target:apostate_country = {
				destroy_country = yes
			}
		}
	}
}


# Arc Site 2
# Stage 1
fleet_event = {
	id = crisis.21200
	title = "crisis.21200.name"
	desc = "crisis.21200.desc"
	picture = GFX_evt_necrophage
	show_sound = evn_ove_scientific_experiments

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 2
fleet_event = {
	id = crisis.21205
	title = "crisis.21205.name"
	desc = "crisis.21205.desc"
	picture = GFX_evt_interior_battle
	show_sound = evn_ove_scientific_experiments

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 3
fleet_event = {
	id = crisis.21210
	title = "crisis.21210.name"
	desc = "crisis.21210.desc"
	picture = GFX_evt_night_raid
	show_sound = evn_ove_scientific_experiments

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 4
fleet_event = {
	id = crisis.21215
	title = "crisis.21215.name"
	desc = "crisis.21215.desc"
	picture = GFX_evt_synth_queen_enlightenment
	show_sound = evn_ove_scientific_experiments

	archaeology = yes
	is_triggered_only = yes

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = UNDERSTOOD
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Stage 5
fleet_event = {
	id = crisis.21220
	title = "crisis.21220.name"
	desc = "crisis.21220.desc"
	picture = GFX_evt_scanning_remains
	show_sound = evn_ove_scientific_experiments

	archaeology = yes
	is_triggered_only = yes
	specimen = memories_of_elik

	immediate = {
		from = { set_site_progress_locked = yes }
	}

	option = {
		name = "crisis.21220.a"
		trigger = {
			owner = {
				values_others = yes
			}
		}

		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier5unityreward
				min = @tier5unitymin
				max = @tier5unitymax
			}
		}
	}

	option = {
		name = "crisis.21220.b"
		owner = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier5unityreward
				min = @tier5unitymin
				max = @tier5unitymax
			}
		}
	}

	option = {
		name = "crisis.21220.c"
		custom_tooltip = "crisis.21220.c.tt"
		hidden_effect = {
			owner = {
				set_country_flag = synth_queen_question_found_the_frozen_dreamer
			}
		}
	}

	after = {
		from = { set_site_progress_locked = no }
	}
}

# Final Speech
country_event = {
	id = crisis.23005
	title = "crisis.23005.name"
	diplomatic_title = "crisis.23005.name"
	desc = "crisis.23005.desc"
	show_sound = crisis_23005_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:synth_queen_country.ruler
		room = event_target:synth_queen_country.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen
	show_sound = crisis_8040_desc

	is_triggered_only = yes

	immediate = {
		create_species = {
			name = "NAME_Cetana"
			class = "ROBOT"
			namelist = "CETANA"
			portrait = "synth_queen"
			traits = {
				trait = "trait_mechanical"
			}
			effect = {
				save_event_target_as = synth_queen_species
			}
		}
		create_country = {
			name = "NAME_Synth_Queen"
			type = "synth_queen"
			species = event_target:synth_queen_species
			name_list = "CETANA"
			flag = {
				icon = {
					category = "special"
					file = "synth_queen.dds"
				}
				background = {
					category = "backgrounds"
					file = "flag_BG_13.dds"
				}
				colors = {
					"burgundy"
					"burgundy"
					"null"
					"null"
				}
			}
			effect = {
				save_event_target_as = synth_queen_country
				establish_communications = root
				create_leader = {
					class = commander
					species = event_target:synth_queen_country
					name = "NAME_Cetana"
					immortal = yes
					skill = 10
					event_leader = yes
					skip_background_generation = yes
					set_age = 126872
					custom_description = cetana_desc
					traits = {
						0 = subclass_commander_councilor
					}
					effect = {
						change_leader_portrait = cetana_empty
					}
				}
				set_leader = last_created_leader
			}
		}
	}

	#See you never!
	option = { # Spiritualist Response
		name = crisis.23005.1
		trigger = {
			has_spiritualist_government = yes
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
			}
		}
	}
	option = { # Militarist Response
		name = crisis.23005.2
		trigger = {
			has_militarist_government = yes
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
			}
		}
	}
	option = { # Materialist Response
		name = crisis.23005.3
		trigger = {
			has_materialist_government = yes
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
			}
		}
	}
	option = { # Pacifist Response
		name = crisis.23005.4
		trigger = {
			has_pacifist_government = yes
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
			}
		}
	}
	option = { # Corporate Response
		name = crisis.23005.5
		trigger = {
			OR = {
				has_government = gov_megacorporation
				has_government = gov_trade_league
				is_megacorp = yes
			}
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
			}
		}
	}
	option = { # Default Response
		name = crisis.23005.6
		trigger = {
			NOR = {
				has_ethic = "ethic_fanatic_xenophile"
				has_ethic = "ethic_fanatic_xenophobe"
				has_government = gov_megacorporation
				has_government = gov_trade_league
				is_megacorp = yes
				has_pacifist_government = yes
				has_materialist_government = yes
				has_militarist_government = yes
				has_spiritualist_government = yes
			}
		}
	}
	option = { # Special Governments Default Response
		name = crisis.23005.6
		trigger = {
			OR = {
				has_generic_government = yes
				has_government = gov_enlightened_monarchy
				has_government = gov_elective_monarchy
				has_government = gov_hive_mind
				has_government = gov_wilderness
				has_government = gov_parasitic_overmind
				has_government = gov_successor_khanate
				has_government = gov_diadochi
				has_ethic = ethic_gestalt_consciousness
				is_fallen_empire = yes
			}
			NOR = {
				has_ethic = "ethic_fanatic_xenophobe"
				has_ethic = "ethic_fanatic_xenophile"
			}
		}
	}
	option = { # Xenophobe Response
		name = crisis.23005.7
		trigger = {
			has_ethic = "ethic_fanatic_xenophobe"
		}
	}
	option = { # Xenophile Response
		name = crisis.23005.8
		trigger = {
			has_ethic = "ethic_fanatic_xenophile"
		}
	}

	after = {
		hidden_effect = {
			country_event = { id = crisis.23010 days = 15 }
			every_country = {
				limit = {
					is_synth_queen_country_type = yes
				}
				destroy_country = yes
			}
			every_country = {
				remove_country_flag = synth_queen_player_can_see_doomclock
			}
		}
	}
}

# Cetana Defeated
country_event = {
	id = crisis.23010
	title = "crisis.23010.name"
	desc = "crisis.23010.desc"
	picture = GFX_evt_crisis_defeated
	show_sound = event_celebration

	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = {
				has_modifier = queenexecutioner
			}
			remove_modifier = queenexecutioner
		}
		every_country = {
			limit = {
				has_modifier = queenslayer
			}
			remove_modifier = queenslayer
		}
		every_country = {
			if = {
				limit = {
					has_country_flag = synth_queen_ai_storm
				}
				deactivate_fog_machine = yes
				remove_country_flag = synth_queen_ai_storm
				every_system_within_border = {
					limit = {
						OR = {
							has_modifier = queen_small_scorn_storm
							has_modifier = queen_scorn_storm
							has_modifier = queen_big_scorn_storm
						}
					}
					remove_modifier = queen_small_scorn_storm
					remove_modifier = queen_scorn_storm
					remove_modifier = queen_big_scorn_storm
				}
			}
		}
	}

	option = {
		name = EXCELLENT
		defeating_synth_queen_rewards = yes
	}
}

# Synth Queen Titan Down
country_event = {
	id = crisis.23015
	title = "crisis.23015.name"
	desc = "crisis.23015.desc"
	picture = GFX_evt_debris
	show_sound = event_celebration

	is_triggered_only = yes

	trigger = {
		fromfromfrom = {
			is_ship_size = synth_queen_titan
		}
	}

	immediate = {
		from = {
			random_situation = {
				limit = {
					is_situation_type = situation_synth_queen_doomclock
				}
				destroy_situation = this
			}
		}
	}

	option = {
		name = crisis.23015.a
		custom_tooltip = crisis.23015.a.tt
		add_relic = r_cetanas_heart
		hidden_effect = {
			every_galaxy_planet = {
				limit = {
					has_planet_flag = synth_queen_bastille
				}
				change_pc = pc_shattered
				clear_deposits = yes
				clear_planet_modifiers = yes
			}
			random_country = {
				limit = {
					is_country_type = awakened_synth_queen
				}
				every_owned_fleet = {
					delete_fleet = this
				}
				every_owned_leader = {
					kill_leader = {
						show_notification = no
					}
				}
			}
			stop_crisis_sound = yes
			end_crisis = yes
			remove_global_flag = galactic_crisis_recently_fired
			if = {
				limit = {
					has_global_flag = galactic_crisis_early_defeat_tracker_1
				}
				remove_global_flag = galactic_crisis_early_defeat_tracker_1
				multiply_crisis_strength = 1.5
			}
			else_if = {
				limit = {
					has_global_flag = galactic_crisis_early_defeat_tracker_2
				}
				remove_global_flag = galactic_crisis_early_defeat_tracker_2
				multiply_crisis_strength = 1.25
			}
			from = { set_country_flag = with_great_power_achievement }
			remove_global_flag = synth_queen_ongoing
			set_global_flag = synth_queen_defeated
			every_country = {
				limit = {
					has_event_chain = defender_of_the_galaxy_ending_chain
				}
				add_event_chain_counter = {
					event_chain = "defender_of_the_galaxy_ending_chain"
					counter = "crisis_defeated"
					amount = 1
				}
			}
			every_country = {
				limit = {
					is_country_type = default
				}
				country_event = { id = crisis.23005 }
			}
		}
	}
}

# Synth Queen Rebuilds Her Base if she can
event = {
	id = crisis.24000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_country = {
			is_synth_queen_country_type = yes
		}
	}
	immediate = {
		random_system = {
			limit = {
				NOT = { exists = starbase }
				any_system_planet = {
					has_planet_flag = synth_queen_bastille
					solar_system = {
						NOR = {
							any_fleet_in_system = {
								exists = owner
								owner = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
							any_fleet_in_system = {
								exists = controller
								controller = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
						}
					}
				}
			}
			create_starbase = {
				size = big_starbase_synth_queen
				owner = event_target:synth_queen_country_global
			}
			add_modifier = {
				modifier = queen_scorn_storm
			}
			every_ship_in_system = {
				limit = {
					is_ship_size = synth_queen_titan
					is_disabled = yes
				}
				set_disabled = no
			}
			every_country = {
				abort_special_project = {
					type = THE_SYNTH_QUEENS_RESHAPING_RITUAL
				}
			}
		}
	}
}

# Commune with the Animator of Clay
country_event = {
	id = crisis.24100
	title = "crisis.24100.name"
	desc = {
		trigger = {
			is_robot_empire = no
		}
		text = crisis.24100.desc.organic
	}
	desc = {
		trigger = {
			is_robot_empire = yes
		}
		text = crisis.24100.desc.robot
	}
	diplomatic_title = BLANK_STRING
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	is_triggered_only = yes

	immediate = {
		set_country_flag = synth_queen_contacted_the_animator_already
	}

	trigger = {
		OR = {
			from = { is_country_type = shroud }
			has_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = crisis.24100.a
		hidden_effect = {
			country_event = {
				id = crisis.24105
				days = 0
			}
		}
	}
}

#Part 2
country_event = {
	id = crisis.24105
	title = "crisis.24105.name"
	desc = "crisis.24105.desc"
	diplomatic_title = BLANK_STRING
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	is_triggered_only = yes

	immediate = {
		random_owned_leader = {
			limit = {
				is_ruler = yes
			}
			save_event_target_as = synth_queen_animator_of_clay_leader_price
		}
		random_owned_planet = {
			limit = {
				is_capital = no
				is_artificial = no
				has_upgraded_capital = yes
			}
			save_event_target_as = synth_queen_animator_of_clay_planet_price
		}
	}

	trigger = {
		OR = {
			from = { is_country_type = shroud }
			has_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = crisis.24105.a
		hidden_effect = {
			country_event = {
				id = crisis.24110
				days = 0
			}
		}
	}
}

#Part 3
country_event = {
	id = crisis.24110
	title = "crisis.24110.name"
	desc = "crisis.24110.desc"
	diplomatic_title = BLANK_STRING
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	is_triggered_only = yes

	immediate = {
		random_owned_leader = {
			limit = {
				is_ruler = yes
			}
			save_event_target_as = synth_queen_animator_of_clay_leader_price
		}
		random_owned_planet = {
			limit = {
				is_capital = no
				is_artificial = no
				has_upgraded_capital = yes
			}
			save_event_target_as = synth_queen_animator_of_clay_planet_price
		}
	}

	trigger = {
		OR = {
			from = { is_country_type = shroud }
			has_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = {
			text = crisis.24110.a.organic
			trigger = {
				is_robot_empire = no
			}
		}
		name = {
			text = crisis.24110.a.robot
			trigger = {
				is_robot_empire = yes
			}
		}
		trigger = {
			exists = event_target:synth_queen_animator_of_clay_leader_price
		}
		event_target:synth_queen_animator_of_clay_leader_price = {
			kill_leader = {
				show_notification = yes
			}
		}
		hidden_effect = {
			country_event = {
				id = crisis.24115
				days = 0
			}
		}
	}

	option = {
		name = crisis.24110.b
		trigger = {
			exists = event_target:synth_queen_animator_of_clay_planet_price
		}
		event_target:synth_queen_animator_of_clay_planet_price = {
			destroy_colony = yes
			change_pc = pc_shrouded
		}
		hidden_effect = {
			country_event = {
				id = crisis.24115
				days = 0
			}
		}
	}

	option = {
		name = crisis.24110.c
		allow = {
			resource_stockpile_compare = {
				resource = sr_zro
				value > 27182
			}
		}
		add_resource = {
			sr_zro = -27182
		}
		hidden_effect = {
			country_event = {
				id = crisis.24115
				days = 0
			}
		}
	}

	option = {
		name = crisis.24110.z
		hidden_effect = {
			country_event = {
				id = crisis.24120
				days = 0
			}
		}
	}
}

#We Agree - Sorry dead people.
country_event = {
	id = crisis.24115
	title = "crisis.24115.name"
	desc = {
		trigger = {
			is_robot_empire = no
		}
		text = crisis.24115.desc.organic
	}
	desc = {
		trigger = {
			is_robot_empire = yes
		}
		text = crisis.24115.desc.robot
	}
	diplomatic_title = BLANK_STRING
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	is_triggered_only = yes

	trigger = {
		OR = {
			from = { is_country_type = shroud }
			has_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = crisis.24115.a
		if = {
			limit = { is_robot_empire = yes }
			custom_tooltip = crisis.24115.a.tt.robot
		}
		else = {
			custom_tooltip = crisis.24115.a.tt.organic
		}
		hidden_effect = {
			set_country_flag = synth_queen_took_the_animators_deal
		}
	}
}

#No Way Animator of Clay
country_event = {
	id = crisis.24120
	title = "crisis.24120.name"
	desc = {
		trigger = {
			is_robot_empire = no
		}
		text = crisis.24120.desc.organic
	}
	desc = {
		trigger = {
			is_robot_empire = yes
		}
		text = crisis.24120.desc.robot
	}
	diplomatic_title = BLANK_STRING
	diplomatic = yes
	force_open = yes

	picture_event_data = {
		portrait = shroud1
		room = shroud_room
	}

	is_triggered_only = yes

	trigger = {
		OR = {
			from = { is_country_type = shroud }
			has_country_flag = synth_queen_can_contact_the_animator_of_clay
		}
	}

	option = {
		name = crisis.24120.a
	}
}

#This event disables the Titan if you have taken the deal
# Scope = Fleet
# From = System
fleet_event = {
	id = crisis.24200
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			has_country_flag = synth_queen_took_the_animators_deal
		}
		from  = {
			any_ship_in_system = {
				is_ship_size = synth_queen_titan
				is_disabled = no
			}
		}
	}

	immediate = {
		from = {
			every_ship_in_system = {
				limit = {
					is_ship_size = synth_queen_titan
				}
				set_disabled = yes
				enable_special_project = {
					name = THE_SYNTH_QUEENS_RESHAPING_RITUAL
					owner = root.owner
					location = this
				}
			}
		}
	}
}

#Special Project
country_event = {
	id = crisis.24250
	title = "crisis.24250.name"
	desc = "crisis.24250.desc"
	picture = GFX_evt_synth_queen
	show_sound = event_celebration

	is_triggered_only = yes

	immediate = {
		remove_country_flag = synth_queen_took_the_animators_deal
		from = {
			random_situation = {
				limit = {
					is_situation_type = situation_synth_queen_doomclock
				}
				destroy_situation = this
			}
		}
	}

	option = {
		name = crisis.24250.a
		hidden_effect = {
			save_global_event_target_as = psi_defeated_synth_queen
			random_system = {
				limit = {
					has_star_flag = synth_queen_capital
				}
				every_ship_in_system = {
					limit = {
						is_ship_size = synth_queen_titan
					}
					fleet = {
						set_owner = root
					}
					set_disabled = no
				}
			}
			every_galaxy_planet = {
				limit = {
					has_planet_flag = synth_queen_bastille
				}
				change_pc = pc_shattered
				clear_deposits = yes
				clear_planet_modifiers = yes
			}
			random_country = {
				limit = {
					is_country_type = awakened_synth_queen
				}
				every_owned_fleet = {
					delete_fleet = this
				}
				every_owned_leader = {
					kill_leader = {
						show_notification = no
					}
				}
			}
			stop_crisis_sound = yes
			end_crisis = yes
			remove_global_flag = galactic_crisis_recently_fired
			if = {
				limit = {
					has_global_flag = galactic_crisis_early_defeat_tracker_1
				}
				remove_global_flag = galactic_crisis_early_defeat_tracker_1
				multiply_crisis_strength = 1.5
			}
			else_if = {
				limit = {
					has_global_flag = galactic_crisis_early_defeat_tracker_2
				}
				remove_global_flag = galactic_crisis_early_defeat_tracker_2
				multiply_crisis_strength = 1.25
			}
			from = { set_country_flag = with_great_power_achievement }
			remove_global_flag = synth_queen_ongoing
			set_global_flag = synth_queen_defeated
			every_country = {
				limit = {
					has_event_chain = defender_of_the_galaxy_ending_chain
				}
				add_event_chain_counter = {
					event_chain = "defender_of_the_galaxy_ending_chain"
					counter = "crisis_defeated"
					amount = 1
				}
			}
			country_event = { id = crisis.23020 }
		}
	}
}

# Final Speech - Shroud Ending
country_event = {
	id = crisis.23020
	title = "crisis.23020.name"
	diplomatic_title = "crisis.23020.name"
	desc = "crisis.23020.desc"
	show_sound = crisis_23020_desc

	diplomatic = yes

	event_window_type = crisis_leader_conversation
	situation = event_target:synth_queen_doomclock_situation

	picture_event_data = {
		portrait = event_target:synth_queen_country.ruler
		room = event_target:synth_queen_country.owner
	}
	picture = GFX_crisis_conversation_bg_synth_queen

	is_triggered_only = yes

	immediate = {
		create_species = {
			name = "NAME_Cetana"
			class = "ROBOT"
			namelist = "CETANA"
			portrait = "synth_queen"
			traits = {
				trait = "trait_mechanical"
			}
			effect = {
				save_event_target_as = synth_queen_species
			}
		}
		create_country = {
			name = "NAME_Synth_Queen"
			type = "synth_queen"
			species = event_target:synth_queen_species
			name_list = "CETANA"
			flag = {
				icon = {
					category = "special"
					file = "synth_queen.dds"
				}
				background = {
					category = "backgrounds"
					file = "flag_BG_13.dds"
				}
				colors = {
					"burgundy"
					"burgundy"
					"null"
					"null"
				}
			}
			effect = {
				save_event_target_as = synth_queen_country
				establish_communications = root
				create_leader = {
					class = commander
					species = event_target:synth_queen_country
					name = "NAME_Cetana"
					immortal = yes
					skill = 10
					event_leader = yes
					skip_background_generation = yes
					set_age = 126872
					custom_description = cetana_desc
					traits = {
						0 = subclass_commander_councilor
					}
					effect = {
						change_leader_portrait = cetana_empty
					}
				}
				set_leader = last_created_leader
			}
		}
	}

	#Reshaped
	option = {
		name = crisis.23020.a
		is_dialog_only = yes
		response_text = crisis.23020.1.reply
		sound = crisis_23020_1_reply
		trigger = {
			NOT = {
				has_country_flag = crisis.8295.1.flag
			}
		}
		hidden_effect = {
			set_country_flag = crisis.8295.1.flag
		}
	}

	option = {
		name = crisis.23020.1.a
		custom_tooltip = crisis.23020.1.a.tt
		sound = crisis_23020_1_reply
		trigger = {
			has_country_flag = crisis.8295.1.flag
		}
		hidden_effect = {
			remove_country_flag = crisis.8295.1.flag
		}
	}

	after = {
		defeating_synth_queen_rewards = yes
		hidden_effect = {
			every_country = {
				limit = {
					is_synth_queen_country_type = yes
				}
				destroy_country = yes
			}
			every_country = {
				remove_country_flag = synth_queen_player_can_see_doomclock
			}
			every_country = {
				limit = {
					has_modifier = queenexecutioner
				}
				remove_modifier = queenexecutioner
			}
			every_country = {
				limit = {
					has_modifier = queenslayer
				}
				remove_modifier = queenslayer
			}
			every_country = {
				if = {
					limit = {
						has_country_flag = synth_queen_ai_storm
					}
					deactivate_fog_machine = yes
					remove_country_flag = synth_queen_ai_storm
					every_system_within_border = {
						limit = {
							OR = {
								has_modifier = queen_small_scorn_storm
								has_modifier = queen_scorn_storm
								has_modifier = queen_big_scorn_storm
							}
						}
						remove_modifier = queen_small_scorn_storm
						remove_modifier = queen_scorn_storm
						remove_modifier = queen_big_scorn_storm
					}
				}
			}
			every_country = {
				limit = {
					NOT = { is_same_value = event_target:psi_defeated_synth_queen }
				}
				country_event = {
					id = crisis.23030
					days = 15
				}
			}
		}
	}
}

# Cetana Defeated - Psionics, but everyone else finds out
country_event = {
	id = crisis.23030
	title = "crisis.23030.name"
	desc = "crisis.23030.desc"
	picture = GFX_evt_crisis_defeated
	show_sound = event_celebration

	is_triggered_only = yes

	option = {
		name = EXCELLENT
	}
}
