######################################
# Astral Rifts Events - 1000 to 1900 #
######################################

################################
# Astral Rift - Crystal Events #
################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1000
	title = astral_rift.1000.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1000.desc.gestalt }
				default = { text = astral_rift.1000.desc.default }
			}
		}
	}
	picture = GFX_evt_astral_rift_crystal_1
	show_sound = event_administrative_work
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1000.a
		set_next_astral_rift_event = { id = astral_rift.1005 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1000.b
		allow = {
			explorer = {
				resource_stockpile_compare = {
					resource = energy
					value >= 1000
				}
			}
		}
		explorer = {
			add_resource = {
				energy = -1000
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1010 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1005
	title = astral_rift.1005.name
	desc = astral_rift.1005.desc
	picture = GFX_evt_astral_rift_crystal_1
	show_sound = ap_rift_event_10_hologram_generation
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1005.a
		explorer = {
			add_random_research_option = {
				add_progress = 0.25
				category = particles
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = physics_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1015 }
	}
	option = {
		name = astral_rift.1005.b
		explorer = {
			add_random_research_option = {
				add_progress = 0.25
				category = field_manipulation
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = physics_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
		}
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1015 }
	}

	after = {
		explorer = {
			astral_thread_medium_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1006
	title = astral_rift.1006.name
	desc = astral_rift.1006.desc
	picture = GFX_evt_astral_rift_crystal_1
	show_sound = ap_rift_event_10_hologram_generation
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1006.a
		explorer = {
			add_random_research_option = {
				add_progress = 0.25
				category = particles
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = physics_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1015 }
	}
	option = {
		name = astral_rift.1006.b
		explorer = {
			add_random_research_option = {
				add_progress = 0.25
				category = field_manipulation
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = physics_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
		}
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1015 }
	}

	after = {
		explorer = {
			astral_thread_medium_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1010
	title = astral_rift.1010.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1010.desc.gestalt }
				default = { text = astral_rift.1010.desc.default }
			}
		}
	}
	picture = GFX_evt_astral_rift_crystal_1
	show_sound = ap_rift_event_10_emp_sound
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1010.a
		set_next_astral_rift_event = { id = astral_rift.1006 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1010.b
		set_next_astral_rift_event = { id = astral_rift.1025 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
			astral_thread_large_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1015
	title = astral_rift.1015.name
	desc = astral_rift.1015.desc
	picture = GFX_evt_astral_rift_crystal_2
	show_sound = ap_rift_event_10_gaseous_clouds
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1015.a
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1020 }
	}
	option = {
		name = astral_rift.1015.b
		explorer = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1020 }
	}
}

astral_rift_event = {
	id = astral_rift.1020
	title = astral_rift.1020.name
	desc = astral_rift.1020.desc
	picture = GFX_evt_astral_rift_crystal_3
	show_sound = ap_rift_event_10_multidimensional_cataclysm
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1020.a
		hidden_effect = {
			solar_system = {
				system_event = {
					id = astral_rift.1095
					days = 2	# Trigger the event once the science ship has returned from exploration (MIA)
					scopes = { from = root fromfrom = root.fleet }
				}
			}
		}
		finish_astral_rift = yes

		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				explorer = {
					is_xenophobe = yes
					is_spiritualist = no
					has_technology = tech_wormhole_stabilization
					has_resource = {
						type = astral_threads
						amount >= 500
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1020.b
		allow = {
			explorer = {
				has_technology = tech_wormhole_stabilization
				has_resource = {
					type = astral_threads
					amount >= 500
				}
			}
		}
		explorer = {
			add_resource = { astral_threads = -500 }
		}
		set_next_astral_rift_event = { id = astral_rift.1030 }

		ai_chance = {
			modifier = {
				factor = 0
				explorer = {
					is_spiritualist = yes
				}
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1025
	title = astral_rift.1025.name
	desc = astral_rift.1025.desc
	picture = GFX_evt_astral_rift_crystal_3
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		explorer = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier5unityreward
				min = @tier5unitymin
				max = @tier5unitymax
			}
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1030
	title = astral_rift.1030.name
	desc = astral_rift.1030.desc
	picture = GFX_evt_astral_rift_crystal_3
	show_sound = ap_rift_event_10_wormhole_sealed
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = MARVELOUS
		add_deposit = d_crystal_rift
		finish_astral_rift = yes
	}
}

system_event = {
	id = astral_rift.1095
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				exists = from
			}
			no_scope = {
				# place system position at galactic core
				spawn_system = {
					min_distance >= 0
					max_distance <= 0
					min_orientation_angle = 0
					max_orientation_angle = 360
					initializer = formless_system_initializer
					hyperlane = no
					authorize_spawn_on_galactic_core = yes
				}
			}
			spawn_natural_wormhole = {
				bypass_type = strange_wormhole
				in_place_of = from
				graphics_entity_name = strange_wormhole_entity
				init_effect = {
					link_wormholes = event_target:strange_wormhole_bypass
					clear_global_event_target = strange_wormhole_bypass
				}
			}
			set_global_flag = strange_wormholes_locked
			from = {
				explorer = {
					set_country_flag = opened_wormhole_to_formless_system
				}
			}
			destroy_astral_rift = from
			# Strange Wormhole encounter
			fromfrom = {
				fleet_event = {
					id = astral_planes.45
					days = 1
					scopes = { from = prev }
				}
			}
		}
	}
}
######################################
# Astral Rift - Lonely Planet Events #
######################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1100
	title = astral_rift.1100.name
	desc = astral_rift.1100.desc
	picture = GFX_evt_astral_rift_lonely_planet
	show_sound = ap_rift_event_11_wriggling_eggs
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = FASCINATING
		explorer = {
			astral_thread_small_reward = yes
		}
		set_next_astral_rift_event = { id = astral_rift.1105 }
	}
}

astral_rift_event = {
	id = astral_rift.1105
	title = astral_rift.1105.name
	desc = astral_rift.1105.desc
	picture = GFX_evt_astral_rift_lonely_planet_hatched
	show_sound = ap_rift_event_11_gliding_alien
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1105.a
		set_next_astral_rift_event = { id = astral_rift.1110 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1105.b
		set_next_astral_rift_event = { id = astral_rift.1115 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1110
	title = astral_rift.1110.name
	desc = astral_rift.1110.desc
	picture = GFX_evt_astral_rift_lonely_planet_hatched
	show_sound = ap_rift_event_11_alien_hatchling_cute
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		trigger = { explorer = { owner = { country_uses_bio_ships = no } } }
		name = astral_rift.1110.a
		explorer = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1125 }
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1110.b.evopred
		explorer = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium }
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1125 }
	}

	option = {
		trigger = { explorer = { owner = { country_uses_bio_ships = yes } } }
		name = astral_rift.1110.c.bio
		explorer = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1125 }
	}
}

astral_rift_event = {
	id = astral_rift.1115
	title = astral_rift.1115.name
	desc = astral_rift.1115.desc
	picture = GFX_evt_astral_rift_lonely_planet_hatched
	show_sound = ap_rift_event_11_gliding_alien
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1115.a
		explorer = {
			add_modifier =  {
				modifier = lonely_planet_propulsion_modifier
				years = 15
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1120 }
	}
}

astral_rift_event = {
	id = astral_rift.1120
	title = astral_rift.1120.name
	desc = astral_rift.1120.desc
	picture = GFX_evt_astral_rift_hatchingground
	show_sound = ap_rift_event_11_alien_mother
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1120.a
		explorer = {
			astral_thread_large_reward = yes
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1125
	title = astral_rift.1125.name
	desc = astral_rift.1125.desc
	picture = GFX_evt_astral_rift_hatchingground
	show_sound = ap_rift_event_11_alien_mother
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1125.a
		explorer = {
			astral_thread_large_reward = yes
			add_monthly_resource_mult = {
				resource = unity
				value = @tier3unityreward
				min = @tier3unitymin
				max = @tier3unitymax
			}
		}
		finish_astral_rift = yes
	}
}
###################################
# Astral Rift - Microverse Events #
###################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1200
	title = astral_rift.1200.name
	desc = astral_rift.1200.desc
	picture = GFX_evt_wormhole
	show_sound = ap_rift_event_12_burst_acceleration
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = WORRYING
		explorer = {
			add_resource = { sr_dark_matter = 100 }
		}
		set_next_astral_rift_event = { id = astral_rift.1205 }
	}
}

astral_rift_event = {
	id = astral_rift.1205
	title = astral_rift.1205.name
	desc = astral_rift.1205.desc
	picture = GFX_evt_wormhole
	show_sound = event_administrative_work
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = ALARMING
		explorer = {
			astral_thread_small_reward = yes
		}
		set_next_astral_rift_event = { id = astral_rift.1210 }
	}
}

astral_rift_event = {
	id = astral_rift.1210
	title = astral_rift.1210.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1210.desc.gestalt }
				default = { text = astral_rift.1210.desc.default }
			}
		}
	}
	picture = GFX_evt_wormhole
	show_sound = ap_rift_event_3_clock_slowing_down
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1210.a
		set_next_astral_rift_event = { id = astral_rift.1215 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1210.b
		allow = {
			explorer = {
				has_resource = {
					type = astral_threads
					amount >= 10
				}
			}
		}
		explorer = { add_resource = { astral_threads = -10 } }
		set_next_astral_rift_event = { id = astral_rift.1220 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1215
	title = astral_rift.1215.name
	desc = astral_rift.1215.desc
	picture = GFX_evt_wormhole
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier5researchreward
				min = @tier5researchmin
				max = @tier5researchmax
			}
		}
		leader = { add_age = -5 }
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1220
	title = astral_rift.1220.name
	desc = astral_rift.1220.desc
	picture = GFX_evt_wormhole
	show_sound = ap_rift_event_12_polarized_by_astral_charge
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1220.a
		set_next_astral_rift_event = { id = astral_rift.1225 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1220.b
		set_next_astral_rift_event = { id = astral_rift.1230 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier3researchreward
				min = @tier3researchmin
				max = @tier3researchmax
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1225
	title = astral_rift.1225.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1225.desc.gestalt }
				default = { text = astral_rift.1225.desc.default }
			}
		}
	}
	picture = GFX_evt_astral_rift_microverse
	show_sound = ap_rift_event_12_star_to_gas
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1225.a
		explorer = {
			astral_thread_medium_reward = yes
		}
		set_next_astral_rift_event = { id = astral_rift.1235 }
	}
}

astral_rift_event = {
	id = astral_rift.1230
	title = astral_rift.1230.name
	desc = astral_rift.1230.desc
	picture = GFX_evt_wormhole
	show_sound = ap_rift_event_12_universe_collapsing
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1230.a
		explorer = {
			add_monthly_resource_mult = {
				resource = physics_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
			astral_thread_small_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1235
	title = astral_rift.1235.name
	desc = astral_rift.1235.desc
	picture = GFX_evt_astral_rift_microverse
	show_sound = ap_rift_event_12_star_to_gas
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1235.a
		explorer = {
			add_modifier =  {
				modifier = microverse_knownledge_modifier
				years = 10
			}
			astral_thread_small_reward = yes
		}
		finish_astral_rift = yes
	}
}
##############################
# Astral Rift - Fluid Events #
##############################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1300
	title = astral_rift.1300.name
	desc = astral_rift.1300.desc
	picture = GFX_evt_astral_rift_fluid
	show_sound = ap_rift_event_13_blood_pulse
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_astral_rift_flag = sample_rig_available
	}

	option = {
		name = astral_rift.1300.a
		set_next_astral_rift_event = { id = astral_rift.1305 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1300.b
		set_next_astral_rift_event = { id = astral_rift.1310 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1305
	title = astral_rift.1305.name
	desc = {
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		text = astral_rift.1305.desc.gases
	}
	desc = {
		trigger = {
			explorer = {
				NOR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		text = astral_rift.1305.desc.no_gases
	}
	picture = GFX_evt_astral_rift_fluid
	show_sound = event_bad_omen
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1305.a
		hidden_effect = {
			remove_astral_rift_flag = sample_rig_available
		}
		explorer = {
			astral_thread_small_reward = yes
		}
		set_next_astral_rift_event = { id = astral_rift.1310 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1305.b
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = { has_resource = { type = exotic_gases amount >= 50 } }
		}
		explorer = {
			add_resource = { exotic_gases = -50 }
			add_random_research_option = {
				add_progress = 0.15
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			astral_thread_small_reward = yes
		}

		set_next_astral_rift_event = { id = astral_rift.1311 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
}

astral_rift_event = {
	id = astral_rift.1310
	title = astral_rift.1310.name
	desc = {
		trigger = {
			if = {
				limit = {
					has_astral_rift_flag = sample_rig_available
				}
				text = astral_rift.1310.desc.common
			}
			else = {
				text = astral_rift.1310.desc
			}
		}
	}
	desc = astral_rift.1310.desc
	picture = GFX_evt_astral_rift_fluid
	show_sound = ap_rift_event_13_blood_pulse
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1310.a
		set_next_astral_rift_event = { id = astral_rift.1315 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1310.b
		set_next_astral_rift_event = { id = astral_rift.1316 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1311
	title = astral_rift.1311.name
	desc = astral_rift.1311.desc
	picture = GFX_evt_astral_rift_fluid
	show_sound = ap_rift_event_13_blood_pulse
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	specimen = dimensional_endothelial_lining

	option = {
		name = astral_rift.1310.a
		explorer = { add_resource = { exotic_gases = 200 } }
		set_next_astral_rift_event = { id = astral_rift.1315 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1310.b
		explorer = { add_resource = { rare_crystals = 200 } }
		set_next_astral_rift_event = { id = astral_rift.1316 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
}

astral_rift_event = {
	id = astral_rift.1315
	title = astral_rift.1315.name
	desc = {
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
				is_gestalt = yes
			}
		}
		text = astral_rift.1315.desc.gases.gestalt
	}
	desc = {
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
				is_gestalt = no
			}
		}
		text = astral_rift.1315.desc.gases.default
	}
	desc = {
		trigger = {
			explorer = {
				NOR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		text = astral_rift.1315.desc.default
	}
	picture = GFX_evt_astral_rift_fluid_devour
	show_sound = ap_rift_event_13_absorbed_by_blob
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1315.a
		set_next_astral_rift_event = { id = astral_rift.1320 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
					has_resource = { type = exotic_gases amount >= 100 }
				}
			}
		}
	}
	option = {
		name = astral_rift.1315.b
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = { has_resource = { type = exotic_gases amount >= 100 } }
		}
		explorer = { add_resource = { exotic_gases = -100 } }
		set_next_astral_rift_event = {
			id = astral_rift.1325
			on_roll_failed = astral_rift.1330
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1316
	title = astral_rift.1316.name
	desc = {
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
				is_gestalt = yes
			}
		}
		text = astral_rift.1316.desc.gases.gestalt
	}
	desc = {
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
				is_gestalt = no
			}
		}
		text = astral_rift.1316.desc.gases.default
	}
	desc = {
		trigger = {
			explorer = {
				NOR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		text = astral_rift.1316.desc.default
	}
	picture = GFX_evt_astral_rift_fluid_devour
	show_sound = ap_rift_event_13_absorbed_by_blob
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1316.a
		set_next_astral_rift_event = { id = astral_rift.1320 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
					has_resource = { type = exotic_gases amount >= 100 }
				}
			}
		}
	}
	option = {
		name = astral_rift.1316.b
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = { has_resource = { type = exotic_gases amount >= 100 } }
		}
		explorer = { add_resource = { exotic_gases = -100 } }
		set_next_astral_rift_event = {
			id = astral_rift.1325
			on_roll_failed = astral_rift.1330
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1320
	title = astral_rift.1320.name
	desc = {
		trigger = {
			has_astral_rift_flag = sample_rig_available
		}
		text = astral_rift.1320.desc.rig
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = sample_rig_available }
		}
		text = astral_rift.1320.desc.no_rig
	}
	picture = GFX_evt_astral_rift_fluid_devour
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = OK
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1320.b.evopred
		explorer = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = toxoid }
		}
	}

	after = {
		explorer = {
			astral_thread_large_reward = yes
		}
		if = {
			limit = { has_astral_rift_flag = sample_rig_available }
			explorer = {
				add_modifier = {
					modifier = rift_samples_biology_modifier
					years = 10
				}
			}
		}
		else = {
			explorer = {
				add_modifier = {
					modifier = rift_samples_biology_modifier
					years = 5
				}
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1325
	title = astral_rift.1325.name
	desc = {
		trigger = {
			has_astral_rift_flag = sample_rig_available
		}
		text = astral_rift.1325.desc.rig
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = sample_rig_available }
		}
		text = astral_rift.1325.desc.no_rig
	}
	picture = GFX_evt_astral_rift_fluid_devour
	show_sound = ap_rift_event_13_blob_dissolve
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = GOOD
		explorer = {
			add_relic = r_plasmic_core
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1330
	title = astral_rift.1330.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1330.desc.gestalt }
				default = { text = astral_rift.1330.desc.default }
			}
		}
	}
	picture = GFX_evt_astral_rift_fluid_devour
	show_sound = ap_rift_event_13_absorbed_by_blob
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		explorer = {
			add_modifier = {
				modifier = rift_samples_biology_modifier
				years = 10
			}
			astral_thread_large_reward = yes
		}
		fleet = {
			kill_leader = { show_notification = yes }
			destroy_fleet = this
		}
		finish_astral_rift = yes
	}
}
###############################
# Astral Rift - Garden Events #
###############################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1400
	title = astral_rift.1400.name
	desc = astral_rift.1400.desc
	picture = GFX_evt_astral_rift_garden_1
	show_sound = ap_rift_event_14_writhing_plants_vine
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1400.a
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_3 }
		}
		set_astral_rift_flag = has_burnt_anything
		set_next_astral_rift_event = { id = astral_rift.1410 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1400.b
		set_next_astral_rift_event = {
			id = astral_rift.1410
			on_roll_failed = astral_rift.1405
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1405
	title = astral_rift.1405.name
	desc = astral_rift.1405.desc
	picture = GFX_evt_astral_rift_garden_1
	show_sound = ap_rift_event_14_writhing_plants_vine
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1405.a
		set_astral_rift_flag = has_burnt_anything
		set_next_astral_rift_event = {
			id = astral_rift.1410
			on_roll_failed = astral_rift.1415
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1405.b
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1420 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1410
	title = astral_rift.1410.name
	desc = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		text = astral_rift.1410.desc.burn
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		text = astral_rift.1410.desc.extract
	}
	picture = GFX_evt_astral_rift_garden_1
	show_sound = ap_rift_event_14_dripping_thick_fluid
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1410.a
		set_next_astral_rift_event = { id = astral_rift.1425 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1410.b
		explorer = {
			give_specimen = { key = symbiotic_fruit }
		}
		set_next_astral_rift_event = {
			id = astral_rift.1440
			on_roll_failed = astral_rift.1430
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				has_astral_rift_flag = has_burnt_anything
			}
			explorer = {
				astral_thread_small_reward = yes
			}
		}
		else = {
			explorer = {
				add_random_research_option = {
					add_progress = 0.25
					category = biology
					ignore_prereqs = yes
					fail_effects = {
						add_monthly_resource_mult = {
							resource = society_research
							value = @tier3researchreward
							min = @tier3researchmin
							max = @tier3researchmax
						}
					}
				}
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1415
	title = astral_rift.1415.name
	desc = astral_rift.1415.desc
	picture = GFX_evt_astral_rift_garden_1
	show_sound = event_ship_explosion
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		explorer = {
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1420
	title = astral_rift.1420.name
	desc = astral_rift.1420.desc
	picture = GFX_evt_astral_rift_garden_1
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1420.b.evopred
		explorer = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = small TYPE = plantoid }
		}
	}

	after = {
		explorer = {
			add_random_research_option = {
				add_progress = 0.25
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1425
	title = astral_rift.1425.name
	desc = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		text = astral_rift.1425.desc.previousburn
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		text = astral_rift.1425.desc.nopreviousburn
	}
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_angry
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1425.a
		set_next_astral_rift_event = { id = astral_rift.1420 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1425.b
		set_next_astral_rift_event = { id = astral_rift.1445 }

		ai_chance = {
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1425.c
		set_next_astral_rift_event = {
			id = astral_rift.1450
			on_roll_failed = astral_rift.1445
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1430
	title = astral_rift.1430.name
	desc = astral_rift.1430.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_angry
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1430.a
		set_next_astral_rift_event = { id = astral_rift.1420 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1430.b
		set_next_astral_rift_event = {
			id = astral_rift.1450
			on_roll_failed = astral_rift.1445
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1435
	title = astral_rift.1435.name
	desc = astral_rift.1435.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_angry
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1435.a
		set_next_astral_rift_event = { id = astral_rift.1420 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1435.b
		set_next_astral_rift_event = {
			id = astral_rift.1450
			on_roll_failed = astral_rift.1445
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1440
	title = astral_rift.1440.name
	desc = astral_rift.1440.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_passive
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1440.a
		set_next_astral_rift_event = { id = astral_rift.1451 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1440.b
		set_next_astral_rift_event = {
			id = astral_rift.1455
			on_roll_failed = astral_rift.1435
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_pacifist = yes
						is_spiritualist = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1445
	title = astral_rift.1445.name
	desc = astral_rift.1445.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_writhing_plants_vine
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1445.b.evopred
		explorer = { give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = plantoid } }
	}

	after = {
		hidden_effect = {
			explorer = {
				country_event = {
					id = astral_planes.205
					scopes = { from = prev fromfrom = prev.fleet }
				}
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
				clone_leader = {
					target = prev.leader
					species = event_target:infinity_root_leader_species
					set_age = 1
					effect = {
						save_event_target_as = garden_astral_rift_dead_scientist@owner
						exile_leader_as = garden_astral_rift_dead_scientist@owner
					}
				}
			}
		}
		leader = {
			kill_leader = { class = scientist show_notification = yes }
		}
		explorer = {
			astral_thread_medium_reward = yes
			add_random_research_option = {
				add_progress = 0.25
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			hidden_effect = {
				country_event = {
					id = astral_rift.1465
					days = 1800
					scopes = {
						from = event_target:garden_astral_rift_dead_scientist@this
						fromfrom = prev.fleet
					}
				}
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1450
	title = astral_rift.1450.name
	desc = astral_rift.1450.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_flamethrower
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = AMAZING
		explorer = {
			add_relic = r_infinity_root
			hidden_effect = {
				set_country_flag = infinity_root_v1
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1450.b.evopred
		explorer = {
			add_relic = r_infinity_root
			hidden_effect = {
				set_country_flag = infinity_root_v1
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}
}

# astral_rift.1450 from easy path
astral_rift_event = {
	id = astral_rift.1451
	title = astral_rift.1450.name
	desc = astral_rift.1450.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_flamethrower
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = AMAZING
		explorer = {
			add_relic = r_infinity_root
			hidden_effect = {
				set_country_flag = infinity_root_v1
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1450.b.evopred
		explorer = {
			add_relic = r_infinity_root
			hidden_effect = {
				set_country_flag = infinity_root_v1
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1455
	title = astral_rift.1455.name
	desc = astral_rift.1455.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_passive
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1455.a
		set_next_astral_rift_event = {
			id = astral_rift.1456
			on_roll_failed = astral_rift.1435
			fail_probability = @default_failure_probability
		}
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1456
	title = astral_rift.1456.name
	desc = astral_rift.1456.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_passive
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1455.a
		set_next_astral_rift_event = {
			id = astral_rift.1457
			on_roll_failed = astral_rift.1435
			fail_probability = @default_failure_probability
		}
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1457
	title = astral_rift.1457.name
	desc = astral_rift.1457.desc
	picture = {
		trigger = {
			has_astral_rift_flag = has_burnt_anything
		}
		picture = GFX_evt_astral_rift_garden_2_fire
	}
	picture = {
		trigger = {
			NOT = { has_astral_rift_flag = has_burnt_anything }
		}
		picture = GFX_evt_astral_rift_garden_2
	}
	show_sound = ap_rift_event_14_centipede_monster_passive
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = AMAZING
		explorer = {
			add_relic = r_infinity_root
			hidden_effect = {
				set_country_flag = infinity_root_v2
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1450.b.evopred
		explorer = {
			add_relic = r_infinity_root
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = large TYPE = plantoid }
			hidden_effect = {
				set_country_flag = infinity_root_v1
				country_event = { id = astral_rift.1460 } # Plantoid leader species creation
			}
		}
		finish_astral_rift = yes
	}
}

country_event = {
	id = astral_rift.1460
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { exists = event_target:infinity_root_leader_species }
	}

	immediate = {
		create_species = {
			name = random
			class = PLANT
			portrait = pla2
			traits = random
			allow_negative_traits = no
			namelist = PLANT
			effect = {
				save_global_event_target_as = infinity_root_leader_species
			}
		}
	}
}

# Scientist comes back as a plantoid
# FROM : scientist
# FROMFROM : fleet
country_event = {
	id = astral_rift.1465
	title = astral_rift.1465.name
	desc = astral_rift.1465.desc
	picture = GFX_evt_astral_rift_garden_1

	is_triggered_only = yes

	option = {
		name = INCREDIBLE
		clone_leader = {
			target = from
			species = event_target:infinity_root_leader_species
			set_age = 1
			custom_description = garden_astral_rift_resurrected_leader_desc
			effect = {
				change_leader_portrait = event_target:infinity_root_leader_species
				if = {
					limit = {
						exists = fromfrom
						fromfrom = {
							NOT = { exists = leader }
						}
					}
					fromfrom = {
						assign_leader = prev
					}
				}
			}
		}
		custom_tooltip = astral_rift.1465.tt
		create_message = {
			type = MESSAGE_RECRUITED_LEADER
			localization = MESSAGE_RECRUITED_LEADER_DESC
			days = @toast_message_days
			target = last_created_leader
			variable = {
				type = name
				localization = LEADER
				scope = last_created_leader
			}
			variable = {
				key = "border"
				value = "GFX_border_veteran"
			}
		}
		hidden_effect ={
			from = {
				kill_leader = { show_notification = no }
			}
		}
	}
}
#####################################
# Astral Rift - Desert Ruins Events #
#####################################

namespace = astral_rift

@timeToSolve = 3

astral_rift_event = {
	id = astral_rift.1500
	title = astral_rift.1500.name
	desc = astral_rift.1500.desc
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_wind_ruins
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = FASCINATING
		set_next_astral_rift_event = { id = astral_rift.1515 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1505
	title = astral_rift.1505.name
	desc = astral_rift.1505.desc
	picture = GFX_evt_archaeology_trap
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1505.a
		explorer = {
			astral_thread_large_reward = yes
		}
		leader = {
			kill_leader = { show_notification = yes }
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1510
	title = astral_rift.1510.name
	desc = {
		trigger = {
			if = {
				limit = {
					OR = {
						has_astral_rift_flag = description_psionic
						has_astral_rift_flag = description_latent_psionic
					}
				}
				if = {
					limit = { has_astral_rift_flag = description_robotic }
					text = astral_rift.1510.desc.psionic_or_latent_robot
				}
				else = {
					text = astral_rift.1510.desc.psionic_or_latent
				}
			}
			else = {
				text = astral_rift.1510.desc.default
			}
		}
	}
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_wind_ruins
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = {
			text = astral_rift.1510.b.default
			trigger = {
				explorer = {
					is_robot_empire = no
					is_gestalt = no
				}
			}
		}
		name = {
			text = astral_rift.1510.b.hive
			trigger = {
				explorer = {
					is_robot_empire = no
					is_gestalt = yes
				}
			}
		}
		name = {
			text = astral_rift.1510.b.robot
			trigger = {
				explorer = { is_robot_empire = yes }
			}
		}
		hidden_effect = {
			set_variable = {
				which = time_passed
				value = 0
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1520 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1515
	title = astral_rift.1515.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1515.desc.gestalt }
				default = { text = astral_rift.1515.desc.default }
			}
		}
	}
	picture = GFX_evt_archaeology_trap
	show_sound = event_bad_omen
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1515.a
		set_next_astral_rift_event = { id = astral_rift.1510 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1520
	title = astral_rift.1520.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1520.desc.gestalt }
				default = { text = astral_rift.1520.desc.default }
			}
		}
	}
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_wind_ruins
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1520.a
		set_next_astral_rift_event = { id = astral_rift.1530 }
	}
	option = {
		name = astral_rift.1520.b
		set_next_astral_rift_event = { id = astral_rift.1535 }

		ai_chance = {
			modifier = {
				factor = 0
				OR = {
					leader = { has_trait = leader_trait_psionic }
					leader.species = { is_latent_psionic_species = yes }
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1525
	title = astral_rift.1525.name
	desc = {
		trigger = {
			if = {
				limit = {
					OR = {
						has_astral_rift_flag = description_psionic
						has_astral_rift_flag = description_latent_psionic
					}
				}
				if = {
					limit = { has_astral_rift_flag = description_robotic }
					text = astral_rift.1525.desc.psionic_or_latent_robot
				}
				else = {
					text = astral_rift.1525.desc.psionic_or_latent
				}
			}
			else = {
				text = astral_rift.1525.desc.default
			}
		}
	}
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_wind_ruins
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1525.a
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1530 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1530
	title = astral_rift.1530.name
	desc = astral_rift.1530.desc
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_big_door_opening
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1530.a
		set_next_astral_rift_event = { id = astral_rift.1545 }

		ai_chance = {
			modifier = {
				factor = 0
				OR = {
					leader = { has_trait = leader_trait_psionic }
					leader.species = { is_latent_psionic_species = yes }
				}
			}
		}
	}
	option = {
		name = astral_rift.1530.b
		set_next_astral_rift_event = { id = astral_rift.1550 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1535
	title = astral_rift.1535.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1535.desc.gestalt }
				default = { text = astral_rift.1535.desc.default }
			}
		}
	}
	picture = GFX_evt_archaeology_trap
	show_sound = ap_rift_event_15_conflagration
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1535.a
		hidden_effect = {
			change_variable = {
				which = time_passed
				value = 1
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1525 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1540
	title = astral_rift.1540.name
	desc = {
		trigger = {
			if = {
				limit = {
					OR = {
						has_astral_rift_flag = description_psionic
						has_astral_rift_flag = description_latent_psionic
					}
				}
				if = {
					limit = { has_astral_rift_flag = description_robotic }
					text = astral_rift.1540.desc.psionic_or_latent_robot
				}
				else = {
					text = astral_rift.1540.desc.psionic_or_latent
				}
			}
			else = {
				text = astral_rift.1540.desc.default
			}
		}
	}
	picture = GFX_evt_astral_rift_desert_ruins_first_chamber
	show_sound = event_big_door_opening
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = freeze_time_left_1540
			value = time_passed
		}
		multiply_variable = {
			which = freeze_time_left_1540
			value = -1
		}
		change_variable = {
			which = freeze_time_left_1540
			value = @timeToSolve
		}
	}

	option = {
		name = astral_rift.1540.b
		set_next_astral_rift_event = { id = astral_rift.1550 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1545
	title = astral_rift.1545.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = {
					switch = {
						trigger = has_astral_rift_flag
						description_toxoid = { text = astral_rift.1545.desc.toxoid_gestalt }
						default = { text = astral_rift.1545.desc.gestalt }
					}
				}
				default = {
					switch = {
						trigger = has_astral_rift_flag
						description_toxoid = { text = astral_rift.1545.desc.toxoid }
						default = { text = astral_rift.1545.desc.default }
					}
				}
			}
		}
	}
	picture = GFX_evt_archaeology_trap
	show_sound = ap_rift_event_15_corrosive_gas
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		trigger = {
			NOT = {
				leader.species = {
					is_species_class = TOX
				}
			}
		}
		hidden_effect = {
			change_variable = {
				which = time_passed
				value = 1
			}
		}
		set_next_astral_rift_event = { id = astral_rift.1540 }
	}
	option = {
		name = astral_rift.1545.b
		trigger = {
			leader.species = {
				is_species_class = TOX
			}
		}
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1550 }
	}
}

astral_rift_event = {
	id = astral_rift.1550
	title = astral_rift.1550.name
	desc = astral_rift.1550.desc
	picture = GFX_evt_astral_rift_desert_ruins_third_chamber
	show_sound = event_big_door_opening
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1550.a
		set_next_astral_rift_event = { id = astral_rift.1560 }

		ai_chance = {
			modifier = {
				factor = 0
				OR = {
					leader = { has_trait = leader_trait_psionic }
					leader.species = { is_latent_psionic_species = yes }
				}
			}
		}
	}
	option = {
		name = astral_rift.1550.b
		set_next_astral_rift_event = { id = astral_rift.1565 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1555
	title = astral_rift.1555.name
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value = 1
			}
			NOR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
				has_astral_rift_flag = description_robotic
			}
		}
		text = astral_rift.1555.desc.default_singular
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value = 1
			}
			NOR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			has_astral_rift_flag = description_robotic
		}
		text = astral_rift.1555.desc.robot_singular
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value > 1
			}
			NOR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
				has_astral_rift_flag = description_robotic
			}
		}
		text = astral_rift.1555.desc.default_plural
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value > 1
			}
			NOR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			has_astral_rift_flag = description_robotic
		}
		text = astral_rift.1555.desc.robot_plural
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value = 1
			}
			OR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			NOT = { has_astral_rift_flag = description_robotic }
		}
		text = astral_rift.1555.desc.psionic_or_latent_singular
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value = 1
			}
			OR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			has_astral_rift_flag = description_robotic
		}
		text = astral_rift.1555.desc.psionic_or_latent_robot_singular
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value > 1
			}
			OR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			NOT = { has_astral_rift_flag = description_robotic }
		}
		text = astral_rift.1555.desc.psionic_or_latent_plural
	}
	desc = {
		trigger = {
			check_variable = {
				which = freeze_time_left_1555
				value > 1
			}
			OR = {
				has_astral_rift_flag = description_psionic
				has_astral_rift_flag = description_latent_psionic
			}
			has_astral_rift_flag = description_robotic
		}
		text = astral_rift.1555.desc.psionic_or_latent_robot_plural
	}
	picture = GFX_evt_astral_rift_desert_ruins_third_chamber
	show_sound = event_big_door_opening
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = freeze_time_left_1555
			value = time_passed
		}
		multiply_variable = {
			which = freeze_time_left_1555
			value = -1
		}
		change_variable = {
			which = freeze_time_left_1555
			value = @timeToSolve
		}
	}

	option = {
		name = astral_rift.1555.b
		set_next_astral_rift_event = { id = astral_rift.1565 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1560
	title = astral_rift.1560.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = {
					switch = {
						trigger = has_astral_rift_flag
						description_aquatic = { text = astral_rift.1560.desc.aquatic_gestalt }
						default = { text = astral_rift.1560.desc.gestalt }
					}
				}
				default = {
					switch = {
						trigger = has_astral_rift_flag
						description_aquatic = { text = astral_rift.1560.desc.aquatic }
						default = { text = astral_rift.1560.desc.default }
					}
				}
			}
		}
	}
	picture = GFX_evt_archaeology_trap
	show_sound = ap_rift_event_15_flooding_chamber
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		trigger = {
			NOT = {
				leader.species = {
					has_aquatic_trait = yes
				}
			}
		}
		hidden_effect = {
			change_variable = {
				which = time_passed
				value = 1
			}
		}
		if = {
			limit = {
				check_variable = {
					which = time_passed
					value < 3
				}
			}
			set_next_astral_rift_event = { id = astral_rift.1555 }
		}
		else = {
			set_next_astral_rift_event = { id = astral_rift.1505 }
		}
	}
	option = {
		name = astral_rift.1560.b
		trigger = {
			leader.species = {
				has_aquatic_trait = yes
			}
		}
		hidden_effect = {
			add_stage_modifier = { modifier = astral_rift_difficulty_decrease_2 }
		}
		set_next_astral_rift_event = { id = astral_rift.1565 }
	}
}

astral_rift_event = {
	id = astral_rift.1565
	title = astral_rift.1565.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_robotic = {
					switch = {
						trigger = has_astral_rift_flag
						description_psionic = { text = astral_rift.1565.desc.psionic_robot }
						description_latent_psionic = { text = astral_rift.1565.desc.latent_psionic_robot }
						default = { text = astral_rift.1565.desc.default }
					}
				}
				default = {
					switch = {
						trigger = has_astral_rift_flag
						description_psionic = { text = astral_rift.1565.desc.psionic }
						description_latent_psionic = { text = astral_rift.1565.desc.latent_psionic }
						default = { text = astral_rift.1565.desc.default }
					}
				}
			}
		}
	}
	picture = GFX_evt_astral_rift_desert_ruins_third_chamber
	show_sound = ap_rift_event_15_time_crystal
	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_variable = {
			which = time_left
			value = time_passed
		}
		multiply_variable = {
			which = time_left
			value = -1
		}
		change_variable = {
			which = time_left
			value = @timeToSolve
		}
	}

	option = {
		name = astral_rift.1565.a
		explorer = {
			if = { #This should never happen
				limit = {
					NOT = { has_relic = r_time_crystal }
				}
				add_relic = r_time_crystal
			}
			if = {
				limit = { check_variable = { which = time_left value = 1 } }
				astral_thread_small_reward = yes
			}
			else_if = {
				limit = { check_variable = { which = time_left value = 2 } }
				astral_thread_medium_reward = yes
			}
			else_if = {
				limit = { check_variable = { which = time_left value = 3 } }
				astral_thread_large_reward = yes
			}
		}
		leader = {
			if = {
				limit = {
					species = {
						is_latent_psionic_species = yes
					}
					NOT = { has_trait = leader_trait_psionic }
				}
				add_trait = {
					trait = leader_trait_psionic
				}
			}
		}
		finish_astral_rift = yes
	}
}
########################################
# Astral Rift - Strange Station Events #
########################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1600
	title = astral_rift.1600.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag

				explorer_is_materialist = { text = astral_rift.1600.desc.materialist }
				explorer_is_spiritualist = { text = astral_rift.1600.desc.spiritualist }
				explorer_is_militarist = { text = astral_rift.1600.desc.militarist }
				explorer_is_pacifist = { text = astral_rift.1600.desc.pacifist }
				explorer_is_xenophile = { text = astral_rift.1600.desc.xenophile }
				explorer_is_xenophobe = { text = astral_rift.1600.desc.xenophobe }
				explorer_is_authoritarian = { text = astral_rift.1600.desc.authoritarian }
				explorer_is_egalitarian = { text = astral_rift.1600.desc.egalitarian }
				default = { text = astral_rift.1600.desc.gestalt }
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		trigger = { explorer = { is_gestalt = no } }
		name = astral_rift.1600.a
		set_next_astral_rift_event = { id = astral_rift.1605 }

		ai_chance = {
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_militarist = yes
						is_xenophobe = yes
						is_unfriendly = yes
					}
				}
			}
		}
	}
	option = {
		trigger = { explorer = { is_gestalt = no } }
		name = astral_rift.1600.b
		set_next_astral_rift_event = { id = astral_rift.1610 }

		ai_chance = {
			modifier = {
				factor = 0
				explorer = {
					OR = {
						is_pacifist = yes
						is_xenophile = yes
					}
				}
			}
			modifier = {
				add = 10
				explorer = {
					OR = {
						is_militarist = yes
						is_homicidal = yes
					}
				}
			}
		}
	}
	option = {
		trigger = { explorer = { is_gestalt = yes } }
		name = FASCINATING
		set_next_astral_rift_event = { id = astral_rift.1611 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1605
	title = astral_rift.1605.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag

				explorer_is_materialist = { text = astral_rift.1605.desc.materialist }
				explorer_is_spiritualist = { text = astral_rift.1605.desc.spiritualist }
				explorer_is_militarist = { text = astral_rift.1605.desc.militarist }
				explorer_is_pacifist = { text = astral_rift.1605.desc.pacifist }
				explorer_is_xenophile = { text = astral_rift.1605.desc.xenophile }
				explorer_is_xenophobe = { text = astral_rift.1605.desc.xenophobe }
				explorer_is_authoritarian = { text = astral_rift.1605.desc.authoritarian }
				explorer_is_egalitarian = { text = astral_rift.1605.desc.egalitarian }
				default = { text = astral_rift.1605.desc.gestalt }
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1605.a
		explorer = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			astral_thread_small_reward = yes
		}
		if = {
			limit = {
				explorer = { is_homicidal = yes }
			}
			set_next_astral_rift_event = { id = astral_rift.1616 }
		}
		else = {
			set_next_astral_rift_event = { id = astral_rift.1615 }
		}
	}
}

astral_rift_event = {
	id = astral_rift.1610
	title = astral_rift.1610.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag

				explorer_is_materialist = { text = astral_rift.1610.desc.materialist }
				explorer_is_spiritualist = { text = astral_rift.1610.desc.spiritualist }
				explorer_is_militarist = { text = astral_rift.1610.desc.militarist }
				explorer_is_pacifist = { text = astral_rift.1610.desc.pacifist }
				explorer_is_xenophile = { text = astral_rift.1610.desc.xenophile }
				explorer_is_xenophobe = { text = astral_rift.1610.desc.xenophobe }
				explorer_is_authoritarian = { text = astral_rift.1610.desc.authoritarian }
				explorer_is_egalitarian = { text = astral_rift.1610.desc.egalitarian }
				default = { text = astral_rift.1610.desc.gestalt }
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1610.a
		explorer = {
			add_monthly_resource_mult = {
				resource = engineering_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
			astral_thread_small_reward = yes
		}
		if = {
			limit = {
				explorer = { is_homicidal = yes }
			}
			set_next_astral_rift_event = { id = astral_rift.1616 }
		}
		else = {
			set_next_astral_rift_event = { id = astral_rift.1615 }
		}
	}
}

# Gestalt only
astral_rift_event = {
	id = astral_rift.1611
	title = astral_rift.1611.name
	desc = astral_rift.1611.desc
	picture = GFX_evt_space_station
	show_sound = event_radio_chatter
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = ALARMING
		explorer = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier2unityreward
				min = @tier2unitymin
				max = @tier2unitymax
			}
			astral_thread_small_reward = yes
		}
		if = {
			limit = {
				explorer = { is_homicidal = yes }
			}
			set_next_astral_rift_event = { id = astral_rift.1616 }
		}
		else = {
			set_next_astral_rift_event = { id = astral_rift.1615 }
		}
	}
}

astral_rift_event = {
	id = astral_rift.1615
	title = astral_rift.1615.name
	desc = {
		trigger = {
			if = {
				limit = {
					explorer = { is_gestalt = yes }
				}
				text = astral_rift.1615.desc.gestalt
			}
			else = {
				switch = {
					trigger = has_astral_rift_flag
					explorer_is_xenophobe = { text = astral_rift.1615.desc.xenophobe }
					default = { text = astral_rift.1615.desc.default }
				}
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_salute
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		trigger = {
			explorer = {
				is_gestalt = no
			}
		}
		name = astral_rift.1615.a
		set_next_astral_rift_event = { id = astral_rift.1620 }

		ai_chance = {
			modifier = {
				factor = 0
				explorer = { is_xenophobe = yes	}
			}
		}
	}
	option = {
		trigger = {
			explorer = {
				is_gestalt = no
			}
		}
		name = astral_rift.1615.b
		set_next_astral_rift_event = { id = astral_rift.1625 }
	}

	option = {
		trigger = {
			explorer = {
				is_gestalt = yes
			}
		}
		name = astral_rift.1615.c
		set_next_astral_rift_event = { id = astral_rift.1620 }
	}
	option = {
		trigger = {
			explorer = {
				is_gestalt = yes
			}
		}
		name = astral_rift.1615.d
		set_next_astral_rift_event = { id = astral_rift.1625 }
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

# Homicidal version of astral_rift.1615
astral_rift_event = {
	id = astral_rift.1616
	title = astral_rift.1616.name
	desc = {
		trigger = {
			if = {
				limit = {
					explorer = { is_gestalt = yes }
				}
				text = astral_rift.1616.desc.gestalt
			}
			else = {
				text = astral_rift.1616.desc.default
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_salute
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1616.a
		explorer = {
			astral_thread_small_reward = yes
		}
		set_next_astral_rift_event = { id = astral_rift.1625 }
	}
}

astral_rift_event = {
	id = astral_rift.1620
	title = astral_rift.1620.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				description_gestalt = { text = astral_rift.1620.desc.gestalt }
				explorer_is_xenophobe = { text = astral_rift.1620.desc.xeno }
				default = { text = astral_rift.1620.desc.default }
			}
		}
	}
	picture = GFX_evt_space_station
	show_sound = event_hand_shake

	difficulty = @astral_rift_easy_plus_difficulty
	astral_rift = yes
	is_triggered_only = yes
	specimen = interdimensional_treaty

	immediate = {
		event_target:mirrored_empire = {
			save_event_target_as = final_mirrored_empire

			set_faction_hostility = {
				target = root.explorer
				set_hostile = no
				set_neutral = no
				set_friendly = yes
			}
			establish_communications_no_message = root.explorer
			add_opinion_modifier = {
				who = root.explorer
				modifier = opinion_mirrored_empire
			}
		}
		explorer = {
			set_country_flag = negociating_with_mirrored_empire
			country_event = { id = astral_planes.1690 }
		}
	}

	option = {
		name = GOOD
		custom_tooltip = "mirrored_empire_diplomacy"
		explorer = {
			if = {
				limit = { is_gestalt = yes }
				add_modifier = {
					modifier = "fractured_ambassadors_modifier"
				}
			}
			add_modifier = {
				modifier = "station_friendship_modifier"
				years = 10
			}
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier4researchreward
				min = @tier4researchmin
				max = @tier4researchmax
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1625
	title = astral_rift.1625.name
	desc = {
		trigger = {
			explorer = {
				is_gestalt = no
				is_homicidal = no
			}
		}
		text = astral_rift.1625.desc.default
	}
	desc = {
		trigger = {
			explorer = {
				is_gestalt = no
				is_homicidal = yes
			}
		}
		text = astral_rift.1625.desc.default.homicidal
	}
	desc = {
		trigger = {
			explorer = {
				is_gestalt = yes
				is_homicidal = no
			}
		}
		text = astral_rift.1625.desc.gestalt
	}
	desc = {
		trigger = {
			explorer = {
				is_gestalt = yes
				is_homicidal = yes
			}
		}
		text = astral_rift.1625.desc.gestalt.homicidal
	}
	picture = GFX_evt_space_station
	show_sound = event_comms_cutoff
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		event_target:mirrored_empire = {
			save_event_target_as = final_mirrored_empire
		}
	}

	option = {
		name = GOOD
		explorer = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier5unityreward
				min = @tier5unitymin
				max = @tier5unitymax
			}
			astral_thread_medium_reward = yes
		}
		finish_astral_rift = yes
	}
}

country_event = { # Mirrored Empire setup
	id = astral_planes.1690
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_astral_planes_dlc = yes
		has_country_flag = negociating_with_mirrored_empire
	}

	immediate = {
		every_relation = {
			limit = {
				is_country_type = mirrored_country
				has_communications = root
			}
			copy_basic_resources_effect = { FROM = root }
			copy_manufactured_resources_effect = { FROM = root }
			copy_advanced_resources_effect = { FROM = root }
			copy_rare_resources_effect = { FROM = root }
			copy_basic_resources_incomes_effect = { FROM = root }
			copy_manufactured_resources_incomes_effect = { FROM = root }
			copy_advanced_resources_incomes_effect = { FROM = root }
			copy_rare_resources_incomes_effect = { FROM = root }
		}
	}
}

# Event to clear mirrored country global event target
country_event = {
	id = astral_rift.1698
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_astral_planes_dlc = yes
		from = {
			has_astral_rift_flag = mirrored_rift
		}
		exists = event_target:mirrored_empire
	}

	immediate = {
		clear_global_event_target = mirrored_empire
	}
}

# Event to create the mirrored country
country_event = {
	id = astral_rift.1699
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_astral_planes_dlc = yes
		from = {
			has_astral_rift_flag = mirrored_rift
		}
		NOT = { exists = event_target:mirrored_empire }
	}

	immediate = {
		create_species = {
			is_mod = yes
			name = this
			plural = this
			class = this
			portrait = this
			traits = this
			can_be_modified = this
			homeworld = this
			namelist = this
			gender = this
			effect =  {
				save_event_target_as = mirrored_species
			}
		}
		create_country = {
			type = "mirrored_country"
			species = event_target:mirrored_species
			set_capital_from_species = yes
			origin = this
			authority = this
			civics = this
			nomadic = this
			ignore_initial_colony_error = yes
			day_zero_contact = no
			flag = random
			ethos = this
			effect = {
				save_global_event_target_as = mirrored_empire
			}
		}
		event_target:mirrored_empire = {
			if = {
				limit = { prev = { is_gestalt = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_gestalt }
				country_remove_ethic = ethic_gestalt_consciousness
				country_add_ethic = ethic_fanatic_egalitarian
			}
			else_if = {
				limit = { prev = { is_fanatic_materialist = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_materialist }
				country_remove_ethic = ethic_fanatic_materialist
				country_add_ethic = ethic_fanatic_spiritualist
			}
			else_if = {
				limit = { prev = { is_fanatic_spiritualist = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_spiritualist }
				country_remove_ethic = ethic_fanatic_spiritualist
				country_add_ethic = ethic_fanatic_materialist
			}
			else_if = {
				limit = { prev = { is_fanatic_militarist = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_militarist }
				country_remove_ethic = ethic_fanatic_militarist
				country_add_ethic = ethic_fanatic_pacifist
			}
			else_if = {
				limit = { prev = { is_fanatic_pacifist = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_pacifist }
				country_remove_ethic = ethic_fanatic_pacifist
				country_add_ethic = ethic_fanatic_militarist
			}
			else_if = {
				limit = { prev = { is_fanatic_xenophile = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_xenophile }
				country_remove_ethic = ethic_fanatic_xenophile
				country_add_ethic = ethic_fanatic_xenophobe
			}
			else_if = {
				limit = { prev = { is_fanatic_xenophobe = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_xenophobe }
				country_remove_ethic = ethic_fanatic_xenophobe
				country_add_ethic = ethic_fanatic_xenophile
			}
			else_if = {
				limit = { prev = { is_fanatic_authoritarian = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_authoritarian }
				country_remove_ethic = ethic_fanatic_authoritarian
				country_add_ethic = ethic_fanatic_egalitarian
			}
			else_if = {
				limit = { prev = { is_fanatic_egalitarian = yes } }
				prev.from = { set_astral_rift_flag = explorer_is_egalitarian }
				country_remove_ethic = ethic_fanatic_egalitarian
				country_add_ethic = ethic_fanatic_authoritarian
			}
			else = {
				random_list = {
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_materialist } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_materialist }
						country_remove_ethic = ethic_materialist
						country_add_ethic = ethic_spiritualist
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_spiritualist } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_spiritualist }
						country_remove_ethic = ethic_spiritualist
						country_add_ethic = ethic_materialist
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_militarist } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_militarist }
						country_remove_ethic = ethic_militarist
						country_add_ethic = ethic_pacifist
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_pacifist } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_pacifist }
						country_remove_ethic = ethic_pacifist
						country_add_ethic = ethic_militarist
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_xenophile } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_xenophile }
						country_remove_ethic = ethic_xenophile
						country_add_ethic = ethic_xenophobe
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_xenophobe } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_xenophobe }
						country_remove_ethic = ethic_xenophobe
						country_add_ethic = ethic_xenophile
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_authoritarian } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_authoritarian }
						country_remove_ethic = ethic_authoritarian
						country_add_ethic = ethic_egalitarian
					}
					1 = {
						modifier = {
							factor = 0
							prev = { NOT = { has_ethic = ethic_egalitarian } }
						}
						prev.from = { set_astral_rift_flag = explorer_is_egalitarian }
						country_remove_ethic = ethic_egalitarian
						country_add_ethic = ethic_authoritarian
					}
				}
			}
			change_government = {
				authority = random
				civics = random
			}
			set_name = random
		}
	}
}

###############################################
# Astral Rift - The Tomb / Lone Object Events #
###############################################

astral_rift_event = {
	id = astral_rift.1700
	title = astral_rift.1700.name
	desc = astral_rift.1700.desc
	picture = GFX_evt_astral_rift_tomb
	show_sound = event_mystic_reveal
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1700.a
		set_next_astral_rift_event = { id = astral_rift.1705 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1700.b
		set_next_astral_rift_event = { id = astral_rift.1710 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1705
	title = astral_rift.1705.name
	desc = astral_rift.1705.desc
	picture = GFX_evt_astral_rift_tomb
	show_sound = event_administrative_work
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_astral_rift_flag = has_seen_glyphs
	}

	option = {
		name = astral_rift.1705.a
		set_next_astral_rift_event = { id = astral_rift.1710 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1705.b
		set_next_astral_rift_event = {
			id = astral_rift.1720
			on_roll_failed = astral_rift.1725
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			add_monthly_resource_mult = {
				resource = society_research
				value = @tier2researchreward
				min = @tier2researchmin
				max = @tier2researchmax
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1710
	title = astral_rift.1710.name
	desc = astral_rift.1710.desc
	picture = GFX_evt_astral_rift_tomb
	show_sound = event_scanner
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1710.a
		set_next_astral_rift_event = { id = astral_rift.1715 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1710.b
		set_next_astral_rift_event = {
			id = astral_rift.1720
			on_roll_failed = astral_rift.1725
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1715
	title = astral_rift.1715.name
	desc = astral_rift.1715.desc
	picture = GFX_evt_astral_rift_tomb
	show_sound = ap_rift_event_17_dust_passage
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	immediate = {
		set_astral_rift_flag = drone_sent
	}

	option = {
		name = astral_rift.1715.a
		explorer = {
			astral_thread_medium_reward = yes
		}
		finish_astral_rift = yes

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1715.b
		explorer = {
			astral_thread_large_reward = yes
		}
		set_next_astral_rift_event = {
			id = astral_rift.1720
			on_roll_failed = astral_rift.1725
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
}

astral_rift_event = {
	id = astral_rift.1720
	title = astral_rift.1720.name
	desc = {
		trigger = {
			switch = {
				trigger = has_astral_rift_flag
				drone_sent = {
					switch = {
						trigger = has_astral_rift_flag
						has_seen_glyphs = {
							switch = {
								trigger = has_astral_rift_flag
								description_psionic = { text = astral_rift.1720.desc.drones.glyphs.psionic }
								default = { text = astral_rift.1720.desc.drones.glyphs }
							}
						}
						default = { text = astral_rift.1720.desc.drones.no_glyphs }
					}
				}
				default = {
					switch = {
						trigger = has_astral_rift_flag
						has_seen_glyphs = {
							switch = {
								trigger = has_astral_rift_flag
								description_psionic = { text = astral_rift.1720.desc.outside.glyphs.psionic }
								default = { text = astral_rift.1720.desc.outside.glyphs }
							}
						}
						default = { text = astral_rift.1720.desc.outside.no_glyphs }
					}
				}
			}
		}
	}
	picture = GFX_evt_astral_rift_tomb_chamber
	show_sound = {
		trigger = { explorer = { is_robot_empire = yes } }
		sound = event_psionic_robot
	}
	show_sound = {
		trigger = { explorer = { is_robot_empire = no } }
		sound = event_psionic
	}
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = REMARKABLE
		explorer = {
			if = {
				limit = {
					leader = { has_trait = leader_trait_psionic }
				}
				add_random_research_option = {
					add_progress = 1.0
					category = psionics
					ignore_rare = no
					fail_effects = {
						add_monthly_resource_mult = {
							resource = society_research
							value = @tier3researchreward
							min = @tier3researchmin
							max = @tier3researchmax
						}
					}
				}
			}
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier2materialreward
				min = @tier2materialmin
				max = @tier2materialmax
			}
			medium_artifact_reward = yes
			add_monthly_resource_mult = {
				resource = alloys
				value = @tier1materialreward
				min = @tier1materialmin
				max = @tier1materialmax
			}
			add_resource = {
				rare_crystals = 500
			}
			add_monthly_resource_mult = {
				resource = unity
				value = @tier2unityreward
				min = @tier2unitymin
				max = @tier2unitymax
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1725
	title = astral_rift.1725.name
	desc = astral_rift.1725.desc
	picture = GFX_evt_astral_rift_tomb
	show_sound = ap_rift_event_17_booby_trap
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1725.a
		custom_tooltip = lone_object_swarm_unleashed
		hidden_effect = {
			create_country = {
				name = "NAME_Grave_Guardians"
				type = grave_guardian
				auto_delete = no
				effect = {
					set_faction_hostility = {
						target = prev.explorer
						set_hostile = yes
					}
					save_event_target_as = grave_guardians_country
				}
			}
			event_target:grave_guardians_country = {
				every_country = {
					establish_communications_no_message = prev
				}
			}
			create_fleet = {
				name = "NAME_Grave_Guardians"
				settings = {
					can_upgrade = no
					can_change_composition = no
					can_change_leader = no
				}
				effect = {
					set_owner = event_target:grave_guardians_country
					while = {
						count = value:grave_guardians_fleet_size|MIN_SIZE|10|MAX_SIZE|30|
						create_ship = {
							name = "NAME_Grave_Guardian"
							design = "NAME_Grave_Guardian"
							prefix = no
							upgradable = no
						}
					}
					set_location = prev
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 1000
				}
			}
		}
		finish_astral_rift = yes
	}
}
##################################
# Astral Rift - Rockworms Events #
##################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1800
	title = astral_rift.1800.name
	desc = astral_rift.1800.desc
	picture = GFX_evt_astral_rift_rockworms_1
	show_sound = ap_rift_event_18_falling_rock
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1800.a
		set_next_astral_rift_event = { id = astral_rift.1805 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1800.b
		set_next_astral_rift_event = { id = astral_rift.1810 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1805
	title = astral_rift.1805.name
	desc = astral_rift.1805.desc
	picture = GFX_evt_astral_rift_rockworms_1
	show_sound = ap_rift_event_18_giant_worms_grazing
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1805.a
		set_astral_rift_flag = sample_route
		set_next_astral_rift_event = { id = astral_rift.1815 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1805.b
		set_next_astral_rift_event = { id = astral_rift.1810 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			add_random_research_option = {
				add_progress = 0.15
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
		}
	}
}

astral_rift_event = {
	id = astral_rift.1810
	title = astral_rift.1810.name
	desc = astral_rift.1810.desc
	picture = GFX_evt_astral_rift_rockworms_1
	show_sound = ap_rift_event_18_quiet_tunnels
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1810.a
		set_astral_rift_flag = harvest_route
		set_next_astral_rift_event = { id = astral_rift.1816 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1810.b
		set_next_astral_rift_event = { id = astral_rift.1820 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1815
	title = astral_rift.1815.name
	desc = {
		trigger = {
			has_astral_rift_flag = description_has_exotic_gases
		}
		text = astral_rift.1815.desc.gas
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = description_has_exotic_gases }
		}
		text = astral_rift.1815.desc
	}
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_18_giant_worm_swallow
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1815.a
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = {
				has_resource = {
					type = exotic_gases
					amount >= 100
				}
			}
		}
		explorer = {
			add_resource = { exotic_gases = -100 }
		}
		set_next_astral_rift_event = {
			id = astral_rift.1835
			on_roll_failed = astral_rift.1830
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_homicidal = yes
						is_militarist = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1815.b
		set_next_astral_rift_event = { id = astral_rift.1825 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1816
	title = astral_rift.1816.name
	desc = {
		trigger = {
			has_astral_rift_flag = description_has_exotic_gases
			has_astral_rift_flag = harvest_route
		}
		text = astral_rift.1816.desc.harvest.gas
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = description_has_exotic_gases }
			has_astral_rift_flag = harvest_route
		}
		text = astral_rift.1816.desc.harvest
	}
	desc = {
		trigger = {
			has_astral_rift_flag = description_has_exotic_gases
			has_astral_rift_flag = capture_route
		}
		text = astral_rift.1816.desc.capture.gas
	}
	desc = {
		trigger = {
			NOT = { has_astral_rift_flag = description_has_exotic_gases }
			has_astral_rift_flag = capture_route
		}
		text = astral_rift.1816.desc.capture
	}
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_18_giant_worm_swallow
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1816.a
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = {
				has_resource = {
					type = exotic_gases
					amount >= 100
				}
			}
		}
		explorer = {
			add_resource = { exotic_gases = -100 }
		}
		set_next_astral_rift_event = {
			id = astral_rift.1835
			on_roll_failed = astral_rift.1830
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_homicidal = yes
						is_militarist = yes
					}
				}
			}
		}
	}
	option = {
		name = astral_rift.1816.b
		set_next_astral_rift_event = { id = astral_rift.1825 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1820
	title = astral_rift.1820.name
	desc = astral_rift.1820.desc
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_18_nymphs_crawling_walls
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1820.a
		explorer = {
			astral_thread_small_reward = yes
		}
		set_astral_rift_flag = capture_route
		set_next_astral_rift_event = { id = astral_rift.1816 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		trigger = { explorer = { NOT = { has_origin = origin_evolutionary_predators } } }
		name = astral_rift.1820.b
		explorer = {
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
			add_random_research_option = {
				add_progress = 0.15
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			astral_thread_small_reward = yes
		}
		finish_astral_rift = yes

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	option = {
		trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1820.b.evopred
		explorer = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = lithoid }
			add_monthly_resource_mult = {
				resource = unity
				value = @tier1unityreward
				min = @tier1unitymin
				max = @tier1unitymax
			}
			add_random_research_option = {
				add_progress = 0.15
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			astral_thread_small_reward = yes
		}
		finish_astral_rift = yes

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
}

astral_rift_event = {
	id = astral_rift.1825
	title = astral_rift.1825.name
	desc = astral_rift.1825.desc
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = site_success
		explorer = {
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1830
	title = astral_rift.1830.name
	desc = astral_rift.1830.desc
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		hidden_effect = {
			explorer = {
				country_event = {
					id = astral_planes.205
					scopes = { from = prev fromfrom = prev.fleet }
				}
				clone_leader = {
					target = prev.leader
					effect = {
						save_event_target_as = rockworms_astral_rift_dead_scientist@owner
						exile_leader_as = rockworms_astral_rift_dead_scientist@owner
					}
				}
			}
		}
		leader = {
			kill_leader = { class = scientist show_notification = yes }
		}
		explorer = {
			add_random_research_option = {
				add_progress = 0.1
				category = biology
				ignore_prereqs = yes
				fail_effects = {
					add_monthly_resource_mult = {
						resource = society_research
						value = @tier3researchreward
						min = @tier3researchmin
						max = @tier3researchmax
					}
				}
			}
			hidden_effect = {
				country_event = {
					id = astral_rift.1890
					days = 360
					scopes = {
						from = event_target:rockworms_astral_rift_dead_scientist@this
						fromfrom = prev.fleet
					}
				}
			}
			astral_thread_small_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1835
	title = astral_rift.1835.name
	desc = {
		trigger = {
			has_astral_rift_flag = sample_route
		}
		text = astral_rift.1835.desc.recover
	}
	desc = {
		trigger = {
			has_astral_rift_flag = capture_route
		}
		text = astral_rift.1835.desc.capture
	}
	desc = {
		trigger = {
			has_astral_rift_flag = harvest_route
		}
		text = astral_rift.1835.desc.harvest
	}
	picture = GFX_evt_astral_rift_rockworms_2
	show_sound = ap_rift_event_18_worm_explode
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1835.a
		explorer = {
			set_country_flag = can_breed_rockworm_hives
			custom_tooltip = can_breed_rockworm_hives_tt
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}

	option = {
		exclusive_trigger = { explorer = { has_origin = origin_evolutionary_predators } }
		name = astral_rift.1835.b.evopred
		explorer = {
			give_evolutionary_predator_situation_progress_and_dna = { AMOUNT = medium TYPE = lithoid }
			set_country_flag = can_breed_rockworm_hives
			custom_tooltip = can_breed_rockworm_hives_tt
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

# Scientist comes back partially digested
# FROM : scientist
# FROMFROM : fleet
country_event = {
	id = astral_rift.1890
	title = astral_rift.1890.name
	desc = astral_rift.1890.desc
	picture = GFX_evt_astral_rift_rockworms_2

	is_triggered_only = yes

	option = {
		name = astral_rift.1890.a
		create_species = {
			name = random
			class = TOX
			portrait = tox13
			effect = {
				save_event_target_as = toxoid_digested_leader_species
			}
		}
		clone_leader = {
			target = from
			species = event_target:toxoid_digested_leader_species
			effect = {
				add_trait = {
					trait = leader_trait_partially_digested
				}
				freeze_leader_age = no
				change_leader_portrait = event_target:toxoid_digested_leader_species
				if = {
					limit = {
						exists = fromfrom
						fromfrom = {
							NOT = { exists = leader }
						}
					}
					fromfrom = {
						assign_leader = prev
					}
				}
			}
		}
		hidden_effect = {
			from = { kill_leader = { show_notification = no } }
		}
	}
}
################################
# Astral Rift - Volcano Events #
################################

namespace = astral_rift

astral_rift_event = {
	id = astral_rift.1900
	title = astral_rift.1900.name
	desc = astral_rift.1900.desc
	picture = GFX_evt_astral_rift_volcano
	show_sound = ap_rift_event_19_magma_cavern
	difficulty = @astral_rift_initial_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1900.a
		set_next_astral_rift_event = { id = astral_rift.1905 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1900.b
		set_astral_rift_flag = fly_towards_obelisk
		set_next_astral_rift_event = { id = astral_rift.1910 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1905
	title = astral_rift.1905.name
	desc = astral_rift.1905.desc
	picture = GFX_evt_astral_rift_volcano
	show_sound = ap_rift_event_19_tortured_aliens
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1905.a
		set_next_astral_rift_event = { id = astral_rift.1920 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1905.b
		set_astral_rift_flag = submerge_hide
		set_next_astral_rift_event = { id = astral_rift.1915 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1910
	title = astral_rift.1910.name
	desc = astral_rift.1910.desc
	picture = GFX_evt_astral_rift_volcano
	show_sound = ap_rift_event_19_tendrils_chains
	difficulty = @astral_rift_medium_plus_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1910.a
		allow = {
			explorer = {
				has_resource = { type = astral_threads amount >= 100 }
			}
		}
		explorer = {
			add_resource = { astral_threads = -100 }
		}
		set_astral_rift_flag = submerge_escape
		set_next_astral_rift_event = { id = astral_rift.1915 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
	option = {
		name = astral_rift.1910.b
		set_next_astral_rift_event = { id = astral_rift.1920 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
		}
	}
}

astral_rift_event = {
	id = astral_rift.1915
	title = astral_rift.1915.name
	desc = {
		trigger = {
			has_astral_rift_flag = submerge_hide
		}
		text = astral_rift.1915.desc.lava_hide
	}
	desc = {
		trigger = {
			has_astral_rift_flag = submerge_escape
		}
		text = astral_rift.1915.desc.lava_escape
	}
	desc = {
		trigger = {
			NOR = {
				has_astral_rift_flag = submerge_hide
				has_astral_rift_flag = submerge_escape
			}
		}
		text = astral_rift.1915.desc.common
	}
	picture = GFX_evt_astral_rift_volcano_obelisk
	show_sound = ap_rift_event_19_black_obelisk
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1915.a
		set_next_astral_rift_event = { id = astral_rift.1925 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
		}
	}
	option = {
		name = astral_rift.1915.b
		trigger = {
			explorer = {
				OR = {
					has_technology = tech_exotic_gases
					has_resource = { type = exotic_gases amount > 0 }
				}
			}
		}
		allow = {
			explorer = { has_resource = { type = exotic_gases amount >= 100 } }
		}
		explorer = {
			add_resource = { exotic_gases = -100 }
		}
		set_next_astral_rift_event = {
			id = astral_rift.1930
			on_roll_failed = astral_rift.1935
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_homicidal = yes
						is_militarist = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_medium_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1920
	title = astral_rift.1920.name
	desc = astral_rift.1920.desc
	picture = GFX_evt_astral_rift_volcano
	show_sound = ap_rift_event_6_anchor_retrieval
	difficulty = @astral_rift_transition_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = OK
		explorer = {
			astral_thread_medium_reward = yes
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1925
	title = astral_rift.1925.name
	desc = astral_rift.1925.desc
	picture = GFX_evt_astral_rift_volcano_obelisk
	show_sound = ap_rift_event_19_wailing_alien
	difficulty = @astral_rift_easy_difficulty
	astral_rift = yes

	is_triggered_only = yes

	option = {
		name = astral_rift.1925.a
		set_next_astral_rift_event = { id = astral_rift.1920 }

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			min = 1
		}
	}
	option = {
		name = astral_rift.1925.b
		set_next_astral_rift_event = {
			id = astral_rift.1930
			on_roll_failed = astral_rift.1935
			fail_probability = @default_failure_probability
		}

		ai_chance = {
			inline_script = astral_rift/rift_difficulty_ai_weight
			modifier = {
				add = 100
				explorer = {
					OR = {
						is_homicidal = yes
						is_militarist = yes
					}
				}
			}
		}
	}

	after = {
		explorer = {
			astral_thread_small_reward = yes
		}
	}
}

astral_rift_event = {
	id = astral_rift.1930
	title = astral_rift.1930.name
	desc = astral_rift.1930.desc
	picture = GFX_evt_astral_rift_volcano_obelisk
	show_sound = event_ship_explosion
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	specimen = obsidian_obelisk_fragment

	option = {
		name = REMARKABLE
		explorer = {
			add_monthly_resource_mult = {
				resource = minerals
				value = @tier2materialreward
				min = @tier2materialmin
				max = @tier2materialmax
			}
			add_monthly_resource_mult = {
				resource = alloys
				value = @tier2materialreward
				min = @tier2materialmin
				max = @tier2materialmax
			}
			add_monthly_resource_mult = {
				resource = unity
				value = @tier2unityreward
				min = @tier2unitymin
				max = @tier2unitymax
			}
			astral_thread_large_reward = yes
			hidden_effect = {
				country_event = {
					id = astral_rift.1940
					days = 2160
				}
			}
		}
		finish_astral_rift = yes
	}
}

astral_rift_event = {
	id = astral_rift.1935
	title = astral_rift.1935.name
	desc = astral_rift.1935.desc
	picture = GFX_evt_astral_rift_volcano
	show_sound = ap_rift_event_19_smoke_ash
	difficulty = @astral_rift_hard_difficulty
	astral_rift = yes

	is_triggered_only = yes

	trigger = {
		explorer = { is_wilderness_empire = no } # cannot afford to sacrifice Pops/whole planets
	}

	option = {
		name = UNFORTUNATE
		hidden_effect = {
			explorer = {
				country_event = {
					id = astral_planes.205
					scopes = { from = prev fromfrom = prev.fleet }
				}
				clone_leader = {
					target = prev.leader
					set_age = 1
					effect = {
						save_event_target_as = volcano_dead_scientist@owner
						exile_leader_as = volcano_dead_scientist@owner
					}
				}
				country_event = {
					id = astral_rift.1950
					days = 360
					scopes = {
						from = event_target:volcano_dead_scientist@this
						fromfrom = prev.fleet
					}
				}
			}
		}
		leader = {
			kill_leader = { class = scientist show_notification = yes }
		}
		explorer = {
			astral_thread_large_reward = yes
		}
		finish_astral_rift = yes
	}
}

# Lava Lithoid visits empite years after the end - SUCCESS path
country_event = {
	id = astral_rift.1940
	title = astral_rift.1940.name
	desc = astral_rift.1940.desc
	picture = GFX_evt_astral_rift_volcano

	is_triggered_only = yes

	option = {
		name = ONSCREEN
		country_event = { id = astral_rift.1941 }
	}
}

# Lava Lithoid visits empire years after the end - SUCCESS path (transmission)
country_event = {
	id = astral_rift.1941
	title = "TRANSMISSION"
	desc = astral_rift.1941.desc

	diplomatic = yes

	picture_event_data = {
		portrait = lith2
	}

	is_triggered_only = yes

	option = {
		name = astral_rift.1941.a
		add_modifier = {
			modifier = restoring_the_balance_modifier
			years = 6
		}
		hidden_effect = {
			country_event = {
				id = astral_rift.1945
				days = 360
			}
		}
		custom_tooltip = restoring_the_balance_tt

		ai_chance = {
			base = 5
			modifier = {
				factor = 0
				OR = {
					is_spiritualist = yes
					is_pacifist = yes
				}
			}
		}
	}
	option = {
		name = astral_rift.1941.b
		capital_scope = {
			if = {
				limit = {
					prev = {
						OR = {
							is_machine_empire = yes
							is_hive_empire = yes
						}
					}
				}
				add_modifier = {
					modifier = obelisks_curse_machine_modifier
					years = 6
				}
			}
			else = {
				add_modifier = {
					modifier = obelisks_curse_modifier
					years = 6
				}
			}
		}
	}
}

# Kill one pop every year as long as we restore the balance
country_event = {
	id = astral_rift.1945
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_modifier = restoring_the_balance_modifier
	}

	immediate = {
		random_owned_planet = {
			random_owned_pop_group = {
				planet = {
					save_event_target_as = sacrificed_pop_planet
				}
				kill_single_pop = yes
			}
		}
		create_message = {
			type = MESSAGE_RESTORING_THE_BALANCE_SACRIFICE
			localization = MESSAGE_RESTORING_THE_BALANCE_SACRIFICE_DESC
			days = 30
			target = event_target:sacrificed_pop_planet
			variable = {
				type = name
				localization = PLANET
				scope = event_target:sacrificed_pop_planet
			}
		}
		country_event = {
			id = astral_rift.1945
			days = 360
		}
	}
}

# Dead Scientist returns from rift
# FROM : scientist
# FROMFROM : fleet
country_event = {
	id = astral_rift.1950
	title = astral_rift.1950.name
	desc = astral_rift.1950.desc
	picture = GFX_evt_astral_rift

	is_triggered_only = yes

	immediate = {
		clone_leader = {
			target = from
			leader_age_min = 600
			leader_age_max = 700
			immortal = yes
			effect = {
				save_event_target_as = volcano_returned_scientist
			}
		}
		hidden_effect = {
			from = {
				kill_leader = { show_notification = no }
			}
		}
		if = {
			limit = {
				exists = fromfrom
				fromfrom = {
					NOT = {
						exists = leader
					}
				}
			}
			fromfrom = {
				set_leader = event_target:volcano_returned_scientist
			}
		}
	}

	option = {
		name = astral_rift.1950.a
		event_target:volcano_returned_scientist = {
			locked_random_list = {
				1 = {
					modifier = {
						factor = 0
						owner = {
							has_civic = civic_hive_one_mind
						}
					}
					add_trait = {
						trait = leader_trait_paranoid
					}
				}
				1 = {
					add_trait = {
						trait = leader_trait_traumatized
					}
				}
			}
		}
		hidden_effect = {
			country_event = {
				id = astral_rift.1955
				days = 360
				scopes = {
					from = event_target:volcano_returned_scientist
				}
			}
		}
	}
}

# Returned scientist is sending people into the rift
country_event = {
	id = astral_rift.1955
	title = astral_rift.1955.name
	desc = astral_rift.1955.desc
	picture = GFX_evt_astral_rift_volcano

	is_triggered_only = yes

	trigger = {
		exists = from
	}

	option = {
		name = astral_rift.1955.a
		from = {
			kill_leader = {
				show_notification = yes
				fire = yes
			}
		}
	}
	option = {
		name = astral_rift.1955.b
		allow = {
			NOT = {
				is_spiritualist = yes
			}
		}
		from = {
			add_trait = {
				trait = leader_trait_obelisk_curse
			}
		}
	}
}

# Kill one pop every year as long as cursed leader is in the council
country_event = {
	id = astral_rift.1960
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = from
	}

	immediate = {
		if = {
			limit = {
				from = {
					is_councilor = yes
				}
			}
			random_owned_planet = {
				random_owned_pop_group = {
					planet = {
						save_event_target_as = sacrificed_pop_planet
					}
					kill_single_pop = yes
				}
			}
			create_message = {
				type = MESSAGE_RESTORING_THE_BALANCE_SACRIFICE
				localization = MESSAGE_RESTORING_THE_BALANCE_SACRIFICE_DESC_LEADER
				days = 30
				target = event_target:sacrificed_pop_planet
				variable = {
					type = name
					localization = PLANET
					scope = event_target:sacrificed_pop_planet
				}
				variable = {
					type = name
					localization = LEADER
					scope = from
				}
			}
		}
		country_event = {
			id = astral_rift.1960
			days = 360
			scopes = {
				from = from
			}
		}
	}
}
