###############################
# Narrative Progression Events
# by Maximilian Olbers
###############################

namespace = story

@tier1materialreward = 6
@tier1materialmin = 100
@tier1materialmax = 500
@tier2materialreward = 12
@tier2materialmin = 150
@tier2materialmax = 1000
@tier3materialreward = 18
@tier3materialmin = 250
@tier3materialmax = 1500
@tier4materialreward = 24
@tier4materialmin = 350
@tier4materialmax = 2000

@tier1influencereward = 6
@tier1influencemin = 40
@tier1influencemax = 100
@tier2influencereward = 12
@tier2influencemin = 80
@tier2influencemax = 175
@tier3influencereward = 18
@tier3influencemin = 125
@tier3influencemax = 250
@tier4influencereward = 24
@tier4influencemin = 150
@tier4influencemax = 300

@tier1researchreward = 6
@tier1researchmin = 60
@tier1researchmax = 150
@tier2researchreward = 12
@tier2researchmin = 90
@tier2researchmax = 250
@tier3researchreward = 18
@tier3researchmin = 120
@tier3researchmax = 350
@tier4researchreward = 24
@tier4researchmin = 150
@tier4researchmax = 500

### 1 - Microbial, simple plant life
country_event = {
	id = story.1
	title = story.1.name
	desc = {
		trigger = {
			switch = {
				trigger = has_ethic
				ethic_fanatic_spiritualist = { text = story.1.desc.spiri }
				ethic_fanatic_xenophobe = { text = story.1.desc.phobe }
				ethic_fanatic_xenophile = { text = story.1.desc.phile }
				ethic_spiritualist = { text = story.1.desc.spiri }
				ethic_xenophobe = { text = story.1.desc.phobe }
				ethic_xenophile = { text = story.1.desc.phile }
				default = { text = story.1.desc }
			}
		}
	}

	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = Story1
			has_country_flag = Story2
			has_country_flag = Story3
			has_country_flag = Story4
			has_country_flag = Story5
			has_country_flag = Story6
			has_country_flag = Story7
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = StoryFirst
		set_country_flag = Story1
	}

	option = {
		name = OK
	}
}

### 2 - Spacers
country_event = {
	id = story.2
	title = story.2.name
	# First
	desc = {
		trigger = { NOT = {has_country_flag = StoryFirst } }
		text = story.2.desc
	}
	# Xenophile regardless of status
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile } }
		text = story.2.desc.phile
	}
	# Followup
	desc = {
		trigger = { has_country_flag = Story1 }
		text = story.2.desc.followup
	}
	# Fallback
	desc = {
		trigger = { has_country_flag = StoryFirst NOT = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile } }
		text = story.2.desc
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner
#	location = from

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = Story2
			has_country_flag = Story3
			has_country_flag = Story4
			has_country_flag = Story5
			has_country_flag = Story6
			has_country_flag = Story7
			#has_country_flag = Story8
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = Story2
	}

	option = {
		name = OK
	}
}

### 3 - Animalia
country_event = {
	id = story.3
	title = story.3.name
	# First
	desc = {
		text = story.3.desc
		trigger = {
			NOT = {
				has_country_flag = StoryFirst
			}
		}
	}
	# Spiritualist regardless of status
	desc = {
		text = story.3.desc.spiri
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
			}
		}
	}
	# Followup
	desc = {
		trigger = { OR = { has_country_flag = Story1 has_country_flag = Story2 } }
		text = story.3.desc.followup
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = Story3
			has_country_flag = Story4
			has_country_flag = Story5
			has_country_flag = Story6
			has_country_flag = Story7
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = Story3
	}

	option = {
		name = OK
	}
}

### 4 - Pre-Sentients
country_event = {
	id = story.4
	title = story.4.name
	# First
	desc = {
		trigger = { NOT = {has_country_flag = StoryFirst } }
		text = story.4.desc
	}
	# Fanatic Spiritualist regardless of status
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_spiritualist has_ethic = ethic_spiritualist } }
		text = story.4.desc.spiri
	}
	# Xenophobe
	desc = {
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_xenophobe
				has_ethic = ethic_xenophobe
			}
		}
		text = story.4.desc.phobe
	}
	# Xenophile
	desc = {
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_xenophile
			}
		}
		text = story.4.desc.phile
	}
	# Followup
	desc = {
		trigger = {
			OR = {
				has_country_flag = Story1
				has_country_flag = Story2
				has_country_flag = Story3
			}
		}
		text = story.4.desc.followup
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = has_uplifted_species
			has_country_flag = Story4
			has_country_flag = Story41
			has_country_flag = Story5
			has_country_flag = Story6
			has_country_flag = Story7
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = Story4
	}

	option = {
		name = OK
	}
}

### 5 - Remnants
country_event = {
	id = story.5
	title = story.5.name
	# First
	desc = {
		trigger = { NOT = { has_country_flag = StoryFirst } }
		text = story.5.desc
	}
	# Xenophobe
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophobe has_ethic = ethic_xenophobe } }
		text = story.5.desc.phobe
	}
	# Xenophile
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile } }
		text = story.5.desc.phile
	}
	# Followup
	desc = {
		trigger = {
			OR = {
				has_country_flag = Story1
				has_country_flag = Story2
				has_country_flag = Story3
				has_country_flag = Story4
			}
		}
		text = story.5.desc.followup
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = Story5
			has_country_flag = Story6
			has_country_flag = Story7
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = Story5
	}

	option = {
		name = OK
	}
}

### 6 - Primitives
country_event = {
	id = story.6
	title = story.6.name
	# First
	desc = {
		trigger = { NOT = { has_country_flag = StoryFirst } }
		text = story.6.desc
	}
	# Xenophobe
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophobe has_ethic = ethic_xenophobe } }
		text = story.6.desc.phobe
	}
	# Xenophile
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile } }
		text = story.6.desc.phile
	}
	# Followup 5
	desc = {
		trigger = { has_country_flag = Story5 }
		text = story.6.desc.followup5
	}
	# Followup 4
	desc = {
		trigger = { has_country_flag = Story4 }
		text = story.6.desc.followup4
	}
	# Followup 1-2-3
	desc = {
		text = story.6.desc.followup123
		trigger = {
			OR = {
				has_country_flag = Story1
				has_country_flag = Story2
				has_country_flag = Story3
			}
		}
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = Story6
			has_country_flag = Story7
		}
	}

	immediate = {
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
		set_country_flag = Story6
	}

	option = {
		name = OK
	}
}

### 7 - Unknown Empire
country_event = {
	id = story.7
	title = story.7.name
	# First
	desc = {
		trigger = { NOT = { has_country_flag = StoryFirst } }
		text = story.7.desc
	}
	# Xenophobe
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophobe has_ethic = ethic_xenophobe } }
		text = story.7.desc.phobe
	}
	# Xenophile
	desc = {
		trigger = { OR = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile } }
		text = story.7.desc.phile
	}
	# Followup 6
	desc = {
		trigger = { has_country_flag = Story6 }
		text = story.7.desc.followup6
	}
	# Followup 1-2-3-4-5
	desc = {
		trigger = {
			OR = {
				has_country_flag = Story1
				has_country_flag = Story2
				has_country_flag = Story3
				has_country_flag = Story4
				has_country_flag = Story5
			}
		}
		text = story.7.desc.followup12345
	}
	picture = GFX_evt_metropolis
	show_sound = event_scanner

	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = Story7 }
		FROM = {
			NOT = {
				has_country_flag = radical_cult
				is_country_type = fallen_empire
				has_relation_flag = { flag = no_coms who = root }
				has_relation_flag = { flag = AbandonedRefugees who = root }
				has_relation_flag = { flag = pirate_relation who = root }
				has_country_flag = day_0
			}
		}
	}

	immediate = {
		set_country_flag = Story7
		set_country_flag = has_encountered_other_empire
		if = {
			limit = { NOT = { has_country_flag = StoryFirst } }
			set_country_flag = StoryFirst
		}
		if = {
			limit = { NOT = { has_country_flag = first_alien_life } }
			set_country_flag = first_alien_life
		}
	}

	option = {
		name = OK
	}
}

##############################
# Uchuukaijuu
##############################

### Tiyanki

#### Space Amoebas
# Triggered by action.15
country_event = {
	id = story.100
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = { is_country_type = amoeba }
			establish_communications = ROOT
		}
		country_event = { id = story.101 }
	}
}

country_event = {
	id = story.101
	title = story.101.name
	desc = {
		trigger = {
			switch = {
				trigger = has_ethic
				ethic_fanatic_xenophile = { text = story.101.desc.phile }
				ethic_fanatic_xenophobe = { text = story.101.desc.phobe }
				ethic_fanatic_militarist = { text = story.101.desc.milit }
				ethic_fanatic_pacifist = { text = story.101.desc.pacif }
				ethic_fanatic_materialist = { text = story.101.desc.mater }
				ethic_xenophile = { text = story.101.desc.phile }
				ethic_xenophobe = { text = story.101.desc.phobe}
				ethic_militarist = { text = story.101.desc.milit }
				ethic_pacifist = { text = story.101.desc.pacif }
				ethic_materialist = { text = story.101.desc.mater }
				default = { text = story.101.desc.pacif }
			}
		}
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_amoeba
	location = fromfromfrom

	is_triggered_only = yes
	
	option = {
		name = story.101.a
		capital_scope = {
			enable_special_project = {
				name = "AMOEBAS_1_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = story.101.b
		trigger = {	not = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_fanatic_spiritualist has_ethic = ethic_fanatic_pacifist } }
		begin_event_chain = {
			event_chain = "amoebas_1_chain"
			target = root
		}
	}
}

# Project complete
country_event = {
	id = story.105
	title = story.105.name
	desc = {
		trigger = {
			switch = {
				trigger = has_ethic
				ethic_fanatic_xenophile = { text = story.105.desc.phile }
				ethic_xenophile = { text = story.105.desc.phile }
				ethic_fanatic_pacifist = { text = story.105.desc.pacif }
				ethic_pacifist = { text = story.105.desc.pacif }
				default = { text = story.105.desc }
			}
		}
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_amoeba
	location = from

	is_triggered_only = yes

	option = {
		name = story.105.a
		add_modifier = { modifier = flagellating_movement days = -1 }
	}
}

# Amoeba kill-check for chain 1
# This = owner of fleet 1 (combatant)
# From = owner of fleet 2 (destroyed)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
country_event = {
	id = story.109
	trigger = {
		exists = from
		is_ai = no
		has_event_chain = "amoebas_1_chain"
		from = { is_country_type = amoeba}
	}
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		add_event_chain_counter = { 
			event_chain = "amoebas_1_chain" 
			counter = "specimen_procured" 
			amount = 1 
		}
		country_event = { id = story.110 days = 5 }
	}
}

# One killed, chain 1 and chain 2 begins
country_event = {
	id = story.110
	title = story.110.name
	# Phobe
	desc = {
		trigger = { OR = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		text = story.110.desc.phobe
	}
	# Militarist
	desc = {
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } NOT = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		text = story.110.desc.milit
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		text = story.110.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_amoeba
	location = from

	is_triggered_only = yes

	option = {
		name = story.110.a.phobe
		trigger = { OR = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		end_event_chain = "amoebas_1_chain"
		begin_event_chain = {
			event_chain = "amoebas_2_chain"
			target = this
		}
	}
	option = {
		name = story.110.b.milit
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		end_event_chain = "amoebas_1_chain"
		begin_event_chain = {
			event_chain = "amoebas_2_chain"
			target = this
		}
	}
	option = {
		name = story.110.b.milit
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		end_event_chain = "amoebas_1_chain"
		begin_event_chain = {
			event_chain = "amoebas_2_chain"
			target = this
		}
	}
}

# Amoeba kill-check for chain 2
country_event = {
	id = story.114
	trigger = {
		exists = from
		is_ai = no
		has_event_chain = "amoebas_2_chain"
		from = { is_country_type = amoeba}
	}
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		add_event_chain_counter = { 
			event_chain = "amoebas_2_chain"
			counter = "amoebas_slaughtered"  
			amount = 1
		}
		if = {
			limit = {
				has_completed_event_chain_counter = {
					event_chain = "amoebas_2_chain" 
					counter = "amoebas_slaughtered" 
				}
			}
			end_event_chain = amoebas_2_chain
			country_event = { id = story.115 }
		}
	}
}

# Chain complete
country_event = {
	id = story.115
	title = story.115.name
	# Phobe
	desc = {
		trigger = { OR = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		text = story.115.desc.phobe
	}
	# Militarist
	desc = {
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } NOT = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		text = story.115.desc.milit
	}
	# Generic
	desc = {
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		text = story.115.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_amoeba
	location = from

	is_triggered_only = yes

	option = {
		name = story.115.a.phobe
		trigger = {
			OR = {
				has_ethic = ethic_xenophobe
				has_ethic = ethic_fanatic_xenophobe
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_militarist
			}
		}
		add_modifier = {
			modifier = amoeba_extirpator
			days = -1
		}
	}

	option = {
		name = story.115.c
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		add_modifier = { modifier = "cosmic_ray_catalysis" days = -1 }
	}
}

#### Crystals
# Triggered by action.16
country_event = {
	id = story.200
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		country_event = { id = story.201 days = 5 }
		every_country = {
			limit = { is_country_type = crystal }
			establish_communications = ROOT
		}
	}
}

country_event = {
	id = story.201
	title = story.201.name
	# Phile
	desc = {
		trigger = {
			OR = { has_ethic = ethic_xenophile has_ethic = ethic_fanatic_xenophile }
		}
		text = story.201.desc.phile
	}
	# Phobe
	desc = {
		trigger = { OR = { has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe } }
		text = story.201.desc.phobe
	}
	# Pacif
	desc = {
		trigger = { OR = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist } }
		text = story.201.desc.pacif
	}
	# Spiri
	desc = {
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.201.desc.spiri
	}
	# Milit
	desc = {
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		text = story.201.desc.milit
	}
	# Generic
	desc = {
		trigger = {
			NOT = {
				has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist has_ethic = ethic_xenophobe has_ethic = ethic_fanatic_xenophobe has_ethic = ethic_xenophile has_ethic = ethic_fanatic_xenophile
			}
		}
		text = story.201.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_crystal_ship
	location = fromfromfrom

	is_triggered_only = yes

	option = {
		name = story.201.a
		capital_scope = {
			enable_special_project = {
				name = "CRYSTALS_1_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = story.201.b
		trigger = {	NOT = { has_ethic = ethic_fanatic_xenophile has_ethic = ethic_xenophile has_ethic = ethic_fanatic_pacifist } }
		begin_event_chain = {
			event_chain = "crystals_1_chain"
			target = root
		}
	}
}

# Project complete
country_event = {
	id = story.205
	title = story.205.name
	# Phile
	desc = {
		trigger = { OR = { has_ethic = ethic_xenophile has_ethic = ethic_fanatic_xenophile } }

		text = story.205.desc.phile
	}
	# Pacifist
	desc = {
		trigger = { OR = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist } }
		text = story.205.desc.pacif
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist has_ethic = ethic_xenophile has_ethic = ethic_fanatic_xenophile has_ethic = ethic_fanatic_spiritualist has_ethic = ethic_spiritualist } }
		text = story.205.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_crystal_ship
	location = from

	is_triggered_only = yes

	option = {
		name = story.205.a
		custom_tooltip = story.205.a.tooltip
		trigger = {
			OR = {
				has_ethic = ethic_xenophile
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_pacifist
				has_ethic = ethic_fanatic_pacifist
			}
		}
		hidden_effect = {
			add_modifier = { modifier = prismatic_lenses days = -1 }
		}
	}

	option = {
		name = story.205.b
		custom_tooltip = story.205.b.tooltip
		hidden_effect = {
			set_country_flag = crystal_sonar_edict_available
		}
	}
}

# Crystal kill-check for chain 1
country_event = {
	id = story.209
	trigger = {
		is_ai = no
		exists = from
		from = { is_country_type = crystal }
		has_event_chain = "crystals_1_chain"
	}
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		add_event_chain_counter = { 
			event_chain = "crystals_1_chain" 
			counter = "shard_collected" 
			amount = 1 
		}
		country_event = { id = story.210 days = 5 }
	}
}

# One killed, chain 1 and chain 2 begins
country_event = {
	id = story.210
	title = story.210.name
	# Militarist
	desc = {
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		text = story.210.desc.milit
	}
	# Mater
	desc = {
		trigger = { OR = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.210.desc.mater
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.210.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_crystal_ship
	location = from

	is_triggered_only = yes

	option = {
		name = story.210.a
		end_event_chain = "crystals_1_chain"
		begin_event_chain = {
			event_chain = "crystals_2_chain"
			target = this
		}
	}
}

# Crystal kill-check for chain 2
country_event = {
	id = story.214
	trigger = {
		exists = from
		from = { is_country_type = crystal }
		has_event_chain = "crystals_2_chain"
		is_ai = no
	}
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		add_event_chain_counter = { 
			event_chain = "crystals_2_chain"
			counter = "crystals_shattered" 
			amount = 1
		}
		if = {
			limit = {
				has_completed_event_chain_counter = {
					event_chain = "crystals_2_chain" 
					counter = "crystals_shattered" 
				}
			}
			end_event_chain = crystals_2_chain
			country_event = { id = story.215 }
		}
	}
}

# second chain concluded
country_event = {
	id = story.215
	title = story.215.name
	# Milit
	desc = {
		trigger = { OR = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		text = story.215.desc.milit
	}
	# Materialist
	desc = {
		trigger = { OR = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.215.desc.mater
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.215.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_crystal_ship
	location = from

	is_triggered_only = yes

	option = {
		name = story.215.a.milit
		trigger = {
			OR = {
				has_ethic = ethic_militarist
				has_ethic = ethic_fanatic_militarist
			}
		}
		add_modifier = {
			modifier = crystal_breaker
			days = -1
		}
	}

	option = {
		name = story.215.b.mater
		custom_tooltip = story.215.b.mater.tooltip
		trigger = {
			OR = {
				has_ethic = ethic_materialist
				has_ethic = ethic_fanatic_materialist
			}
		}
		hidden_effect = {
			set_country_flag = greater_crystal_bounty_edict_available
		}
	}

	option = {
		name = story.215.c
		custom_tooltip = story.215.b.mater.tooltip
		trigger = { NOT = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist has_ethic = ethic_militarist has_ethic = ethic_fanatic_militarist } }
		hidden_effect = {
			set_country_flag = crystal_bounty_edict_available
		}
	}
}

# On-action check for destroyed crystal fleet
country_event = {
	id = story.216
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		exists = from
		from = { is_country_type = crystal }
		is_ai = no
	}

	immediate = {
		if = {
			limit = { has_edict = greater_crystal_bounty }
			add_minerals = 100
		}
		if = {
			limit = { has_edict = crystal_bounty }
			add_minerals = 50
		}
	}
}

fleet_event = {
	id = story.218
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			has_edict = crystal_sonar
		}
		from = {
			any_ship_in_system = {
				exists = owner
				owner = {
					is_country_type = crystal
				}
			}
		}
	}

	immediate = {
		owner = {
			country_event = { id = story.219 }
		}
	}
}

country_event = {
	id = story.219
	title = story.219.name
	desc = story.219.desc
	picture = GFX_evt_fleet_evil
	show_sound = event_crystal_ship
	location = from

	is_triggered_only = yes

	trigger = {
		fromfrom = {
			any_planet = {
				is_surveyed = {
					who = root
					status = no
				}
			}
		}
	}

	option = {
		name = story.219.a
		custom_tooltip = story.219.a.tooltip
		trigger = { energy > 29 }
		hidden_effect = {
			add_energy = -30
			fromfrom = {
				every_system_planet = {
					surveyed = {
						set_surveyed = yes
						surveyor = root
					}
				}
			}
		}
	}

	option = {
		name = story.219.b
		trigger = { energy > 29 }
	}

	option = {
		name = story.219.c
		trigger = { energy < 30 }
	}
}

### Drones
# Triggered by action.17
country_event = {
	id = story.300
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = { is_country_type = drone }
			establish_communications = ROOT
		}
		country_event = { id = story.301 days = 5 }
	}
}

country_event = {
	id = story.301
	title = story.301.name
	# Phile
	desc = {
		trigger = {
			OR = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist }
		}
		text = story.301.desc.mater
	}
	# Phobe
	desc = {
		trigger = {
			OR = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist }
		}
		text = story.301.desc.pacif
	}
	# Generic
	desc = {
		trigger = {
			NOT = {
				has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist
			}
		}
		text = story.301.desc
	}
	picture = GFX_evt_mining_station

	show_sound = event_ancient_drone
	location = from

	is_triggered_only = yes

	option = {
		name = story.301.a
		capital_scope = {
			enable_special_project = {
				name = "DRONES_1_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = story.301.b
		trigger = { NOT = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist } }
		begin_event_chain = {
			event_chain = "drones_1_chain"
			target = root
		}
	}
}

# Project complete
country_event = {
	id = story.305
	title = story.305.name
	# Phile
	desc = {
		trigger = { OR = { has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist } }

		text = story.305.desc.pacif
	}
	# Pacifist
	desc = {
		trigger = { OR = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.305.desc.mater
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist has_ethic = ethic_pacifist has_ethic = ethic_fanatic_pacifist } }
		text = story.305.desc
	}
	picture = GFX_evt_mining_station
	show_sound = event_ancient_drone
	location = from

	is_triggered_only = yes

	option = {
		name = story.305.a
		custom_tooltip = story.305.a.tooltip
		trigger = {
			OR = {
				has_ethic = ethic_xenophile
				has_ethic = ethic_fanatic_xenophile
				has_ethic = ethic_pacifist
				has_ethic = ethic_fanatic_pacifist
			}
		}
		hidden_effect = {
			set_country_flag = droning_optimizations_edict_available
		}
	}

	option = {
		name = story.305.b
		custom_tooltip = story.305.b.tooltip
		hidden_effect = {
		# High-value targets
			begin_event_chain = {
				event_chain = "mineral_planet_chain"
				target = root
			}
			country_event = { id = story.306 }
		}
	}
}

country_event = {
	id = story.306
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		capital_scope = { save_event_target_as = capital }
		closest_system = {
			min_steps = 5
			limit = {
				has_owner = no
				NOT = {
					has_star_flag = hostile_system
					any_planet = { has_planet_flag = mineral_planet_1 }
					any_planet = { has_planet_flag = mineral_planet_2 }
					any_planet = { has_planet_flag = mineral_planet_3 }
					any_planet = { has_planet_flag = mineral_planet_4 }
					any_planet = { has_planet_flag = mineral_planet_5 }
				}
				any_planet = {
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					NOT = {
						has_planet_flag = mineral_planet_1
						has_planet_flag = mineral_planet_2
						has_planet_flag = mineral_planet_3
						has_planet_flag = mineral_planet_4
						has_planet_flag = mineral_planet_5
					}
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
				save_event_target_as = mineral_planet_1
				set_planet_flag = mineral_planet_1
				root = { set_country_flag = mineral_planet_1_exists }
			}
		}
		closest_system = {
			min_steps = 5
			limit = {
				has_owner = no
				NOT = {
					has_star_flag = hostile_system
					any_planet = { has_planet_flag = mineral_planet_1 }
					any_planet = { has_planet_flag = mineral_planet_2 }
					any_planet = { has_planet_flag = mineral_planet_3 }
					any_planet = { has_planet_flag = mineral_planet_4 }
					any_planet = { has_planet_flag = mineral_planet_5 }
				}
				any_planet = {
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					NOT = {
						has_planet_flag = mineral_planet_1
						has_planet_flag = mineral_planet_2
						has_planet_flag = mineral_planet_3
						has_planet_flag = mineral_planet_4
						has_planet_flag = mineral_planet_5
					}
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
				save_event_target_as = mineral_planet_2
				set_planet_flag = mineral_planet_2
				root = { set_country_flag = mineral_planet_2_exists }
			}
		}
		closest_system = {
			min_steps = 5
			limit = {
				has_owner = no
				NOT = {
					has_star_flag = hostile_system
					any_planet = { has_planet_flag = mineral_planet_1 }
					any_planet = { has_planet_flag = mineral_planet_2 }
					any_planet = { has_planet_flag = mineral_planet_3 }
					any_planet = { has_planet_flag = mineral_planet_4 }
					any_planet = { has_planet_flag = mineral_planet_5 }
				}
				any_planet = {
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					NOT = {
						has_planet_flag = mineral_planet_1
						has_planet_flag = mineral_planet_2
						has_planet_flag = mineral_planet_3
						has_planet_flag = mineral_planet_4
						has_planet_flag = mineral_planet_5
					}
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
				save_event_target_as = mineral_planet_3
				set_planet_flag = mineral_planet_3
				root = { set_country_flag = mineral_planet_3_exists }
			}
		}
		closest_system = {
			min_steps = 5
			limit = {
				has_owner = no
				NOT = {
					has_star_flag = hostile_system
					any_planet = { has_planet_flag = mineral_planet_1 }
					any_planet = { has_planet_flag = mineral_planet_2 }
					any_planet = { has_planet_flag = mineral_planet_3 }
					any_planet = { has_planet_flag = mineral_planet_4 }
					any_planet = { has_planet_flag = mineral_planet_5 }
				}
				any_planet = {
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					NOT = {
						has_planet_flag = mineral_planet_1
						has_planet_flag = mineral_planet_2
						has_planet_flag = mineral_planet_3
						has_planet_flag = mineral_planet_4
						has_planet_flag = mineral_planet_5
					}
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
				save_event_target_as = mineral_planet_4
				set_planet_flag = mineral_planet_4
				root = { set_country_flag = mineral_planet_4_exists }
			}
		}
		closest_system = {
			min_steps = 5
			limit = {
				has_owner = no
				NOT = {
					has_star_flag = hostile_system
					any_planet = { has_planet_flag = mineral_planet_1 }
					any_planet = { has_planet_flag = mineral_planet_2 }
					any_planet = { has_planet_flag = mineral_planet_3 }
					any_planet = { has_planet_flag = mineral_planet_4 }
					any_planet = { has_planet_flag = mineral_planet_5 }
				}
				any_planet = {
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					NOT = {
						has_planet_flag = mineral_planet_1
						has_planet_flag = mineral_planet_2
						has_planet_flag = mineral_planet_3
						has_planet_flag = mineral_planet_4
						has_planet_flag = mineral_planet_5
					}
					exists = orbital_deposit_tile
					orbital_deposit_tile = {
						has_resource = {
							type = minerals
							amount > 3
						}
					}
				}
				save_event_target_as = mineral_planet_5
				set_planet_flag = mineral_planet_5
				root = { set_country_flag = mineral_planet_5_exists }
			}
		}
		country_event = { id = story.308 }
	}
}

# eh
country_event = {
	id = story.308
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { has_country_flag = mineral_planet_1_exists }
			create_point_of_interest = {
				id = mineral_planet_1_poi
				name = mineral_planet_poi_title
				desc = mineral_planet_poi_desc
				event_chain = mineral_planet_chain
				category = mineral_planet_chain_cat
				location = event_target:mineral_planet_1
			}
		}
		if = {
			limit = { has_country_flag = mineral_planet_2_exists }
			create_point_of_interest = {
				id = mineral_planet_2_poi
				name = mineral_planet_poi_title
				desc = mineral_planet_poi_desc
				event_chain = mineral_planet_chain
				category = mineral_planet_chain_cat
				location = event_target:mineral_planet_2
			}
		}
		if = {
			limit = { has_country_flag = mineral_planet_3_exists }
			create_point_of_interest = {
				id = mineral_planet_3_poi
				name = mineral_planet_poi_title
				desc = mineral_planet_poi_desc
				event_chain = mineral_planet_chain
				category = mineral_planet_chain_cat
				location = event_target:mineral_planet_3
			}
		}
		if = {
			limit = { has_country_flag = mineral_planet_4_exists }
			create_point_of_interest = {
				id = mineral_planet_4_poi
				name = mineral_planet_poi_title
				desc = mineral_planet_poi_desc
				event_chain = mineral_planet_chain
				category = mineral_planet_chain_cat
				location = event_target:mineral_planet_4
			}
		}
		if = {
			limit = { has_country_flag = mineral_planet_5_exists }
			create_point_of_interest = {
				id = mineral_planet_5_poi
				name = mineral_planet_poi_title
				desc = mineral_planet_poi_desc
				event_chain = mineral_planet_chain
				category = mineral_planet_chain_cat
				location = event_target:mineral_planet_5
			}
		}

		if = {
			limit = {
				any_system = {
					any_planet = {
						has_point_of_interest = {
							id = mineral_planet_1_poi
							owner = root
							event_chain = mineral_planet_chain
						}
						is_surveyed = {
							status = yes
							who = root
						}
					}
				}
			}
			remove_point_of_interest = mineral_planet_1_poi
		}

		if = {
			limit = {
				any_system = {
					any_planet = {
						has_point_of_interest = {
							id = mineral_planet_2_poi
							owner = root
							event_chain = mineral_planet_chain
						}
						is_surveyed = {
							status = yes
							who = root
						}
					}
				}
			}
			remove_point_of_interest = mineral_planet_2_poi
		}

		if = {
			limit = {
				any_system = {
					any_planet = {
						has_point_of_interest = {
							id = mineral_planet_3_poi
							owner = root
							event_chain = mineral_planet_chain
						}
						is_surveyed = {
							status = yes
							who = root
						}
					}
				}
			}
			remove_point_of_interest = mineral_planet_3_poi
		}

		if = {
			limit = {
				any_system = {
					any_planet = {
						has_point_of_interest = {
							id = mineral_planet_4_poi
							owner = root
							event_chain = mineral_planet_chain
						}
						is_surveyed = {
							status = yes
							who = root
						}
					}
				}
			}
			remove_point_of_interest = mineral_planet_4_poi
		}

		if = {
			limit = {
				any_system = {
					any_planet = {
						has_point_of_interest = {
							id = mineral_planet_5_poi
							owner = root
							event_chain = mineral_planet_chain
						}
						is_surveyed = {
							status = yes
							who = root
						}
						is_same_value = event_target:mineral_planet_5
					}
				}
			}
			remove_point_of_interest = mineral_planet_5_poi
		}

		if = {
			limit = {
				has_completed_event_chain_counter = {
					event_chain = "mineral_planet_chain"
					counter = "systems_visited"
				}
			}
			end_event_chain = "mineral_planet_chain"
			country_event = { id = story.320 }
		}
	}
}

# A ship has surveyed a planet.
# Scope = Ship
# From = Planet
ship_event = {
	id = story.307
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			has_event_chain = "mineral_planet_chain"
		}
		from = {
			OR = {
				has_planet_flag = mineral_planet_1
				has_planet_flag = mineral_planet_2
				has_planet_flag = mineral_planet_3
				has_planet_flag = mineral_planet_4
				has_planet_flag = mineral_planet_5
			}
		}
	}

	immediate = {
		owner = { save_event_target_as = chainowner }
		from = {
			if = {
				limit = { has_planet_flag = mineral_planet_1 }
				root = {
					owner = {
						remove_point_of_interest = mineral_planet_1_poi
						add_event_chain_counter = { 
							event_chain = "mineral_planet_chain" 
							counter = "systems_visited" 
							amount = 1 
						}
					}
				}
				remove_planet_flag = mineral_planet_1
			}
			if = {
				limit = { has_planet_flag = mineral_planet_2 }
				root = {
					owner = {
						remove_point_of_interest = mineral_planet_2_poi
						add_event_chain_counter = { 
							event_chain = "mineral_planet_chain" 
							counter = "systems_visited" 
							amount = 1 
						}
					}
				}
				remove_planet_flag = mineral_planet_2
			}
			if = {
				limit = { has_planet_flag = mineral_planet_3 }
				root = {
					owner = {
						remove_point_of_interest = mineral_planet_3_poi
						add_event_chain_counter = { 
							event_chain = "mineral_planet_chain" 
							counter = "systems_visited"
							amount = 1 
						}
					}
				}
				remove_planet_flag = mineral_planet_3
			}
			if = {
				limit = { has_planet_flag = mineral_planet_4 }
				root = {
					owner = {
						remove_point_of_interest = mineral_planet_4_poi
						add_event_chain_counter = { 
							event_chain = "mineral_planet_chain" 
							counter = "systems_visited" 
							amount = 1 
						}
					}
				}
				remove_planet_flag = mineral_planet_4
			}
			if = {
				limit = { has_planet_flag = mineral_planet_5 }
				root = {
					owner = {
						remove_point_of_interest = mineral_planet_5_poi
						add_event_chain_counter = { 
							event_chain = "mineral_planet_chain" 
							counter = "systems_visited" 
							amount = 1 
						}
					}
				}
				remove_planet_flag = mineral_planet_5
			}
		}
		if = {
			limit = {
				owner = {
					has_completed_event_chain_counter = {
						event_chain = "mineral_planet_chain"
						counter = "systems_visited"
					}
				}
			}
			owner = {
				end_event_chain = "mineral_planet_chain"
				country_event = { id = story.320 }
			}
			break = yes
		}
		if = {
			limit = {
				NOT = {
					any_system = {
						any_planet = {
							has_point_of_interest = {
								id = mineral_planet_1_poi
								owner = event_target:chainowner
								event_chain = mineral_planet_chain
							}
						}
					}
				}
				NOT = {
					any_system = {
						any_planet = {
							has_point_of_interest = {
								id = mineral_planet_2_poi
								owner = event_target:chainowner
								event_chain = mineral_planet_chain
							}
						}
					}
				}
				NOT = {
					any_system = {
						any_planet = {
							has_point_of_interest = {
								id = mineral_planet_3_poi
								owner = event_target:chainowner
								event_chain = mineral_planet_chain
							}
						}
					}
				}
				NOT = {
					any_system = {
						any_planet = {
							has_point_of_interest = {
								id = mineral_planet_4_poi
								owner = event_target:chainowner
								event_chain = mineral_planet_chain
							}
						}
					}
				}
				NOT = {
					any_system = {
						any_planet = {
							has_point_of_interest = {
								id = mineral_planet_5_poi
								owner = event_target:chainowner
								event_chain = mineral_planet_chain
							}
						}
					}
				}
			}
			owner = {
				end_event_chain = "mineral_planet_chain"
				country_event = { id = story.320 }
			}
		}
	}
}

# Drone kill-check for chain 1
country_event = {
	id = story.309
	trigger = {
		exists = from
		is_ai = no
		has_event_chain = "drones_1_chain"
		from = { is_country_type = drone }
	}
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		add_event_chain_counter = { 
			event_chain = "drones_1_chain" 
			counter = "drone_disassembled" 
			amount = 1 
		}
		country_event = { id = story.310 days = 5 }
	}
}

# One killed, chain 1 ends
country_event = {
	id = story.310
	title = story.310.name
	# Materialist
	desc = {
		trigger = { OR = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.310.desc.mater
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_materialist has_ethic = ethic_fanatic_materialist } }
		text = story.310.desc
	}
	picture = GFX_evt_mining_station
	show_sound = event_ancient_drone
	location = from

	is_triggered_only = yes

	option = {
		name = story.310.a
		custom_tooltip = story.310.a.tooltip
		end_event_chain = "drones_1_chain"
		hidden_effect = {
			set_country_flag = drone_bounty_edict_available
		}
	}
}

country_event = {
	id = story.311
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		exists = from
		is_ai = no
		has_edict = drone_bounty
		from = { is_country_type = drone }
	}

	immediate = {
		add_energy = 50
	}
}

# All deposits surveyed
country_event = {
	id = story.320
	title = story.320.name
	desc = story.320.desc
	picture = GFX_evt_mining_station
	show_sound = event_ancient_drone

	is_triggered_only = yes

	option = {
		name = OK
	}
}


### Space Clouds
# Triggered by action.18
country_event = {
	id = story.400
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = { is_country_type = cloud }
			establish_communications = ROOT
		}
		country_event = { id = story.401 days = 5 }
	}
}

country_event = {
	id = story.401
	title = story.401.name
	# Spiri
	desc = {
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.401.desc.spiri
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.401.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_cloud
	location = fromfromfrom

	is_triggered_only = yes

	option = {
		name = story.401.a.spiri
		trigger = {
			OR = {
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_spiritualist
			}
		}
		capital_scope = {
			enable_special_project = {
				name = "CLOUDS_1_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = story.401.c
		trigger = {	NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		capital_scope = {
			enable_special_project = {
				name = "CLOUDS_1_PROJECT"
				location = this
				owner = root
			}
		}
	}

	option = {
		name = story.401.b.spiri
		trigger = {
			OR = { has_ethic = ethic_spiritualist
			has_ethic = ethic_fanatic_spiritualist
			}
		}
		begin_event_chain = {
			event_chain = "clouds_1_chain"
			target = root
		}
	}
}

# project complete
country_event = {
	id = story.405
	title = story.405.name
	# Spiri
	desc = {
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.405.desc.spiri
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.405.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_cloud
	location = from

	is_triggered_only = yes

	option = {
		name = story.405.a.spiri
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		add_modifier = { modifier = "grand_design" days = -1 }
	}

	option = {
		name = story.405.b
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier1researchreward
			min = @tier1researchmin
			max = @tier1researchmax
		}
		add_modifier = { modifier = "cloudbuster" days = -1 }
	}

	option = {
		name = story.405.c
		custom_tooltip = story.405.c.tooltip
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		hidden_effect = {
			begin_event_chain = {
				event_chain = "cloud_chain"
				target = root
			}
			country_event = { id = story.406 }
		}
	}
}

country_event = {
	id = story.406
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		capital_scope = {
			save_event_target_as = capital
			solar_system = {
				closest_system = {
					limit = {
						root = {
							intel_level = {
								level = none
								system = prev
							}
						}
						has_star_flag = hostile_system
						any_ship_in_system = { owner = { is_country_type = cloud } }
						NOT = {
							has_star_flag = cloud_1
							has_star_flag = cloud_2
							has_star_flag = cloud_3
							has_star_flag = cloud_4
							has_star_flag = cloud_5
						}
					}
					save_event_target_as = cloud_1
					set_star_flag = cloud_1
					root = { set_country_flag = has_cloud_1 }
				}
				closest_system = {
					limit = {
						root = {
							intel_level = {
								level = none
								system = prev
							}
						}
						has_star_flag = hostile_system
						any_ship_in_system = { owner = { is_country_type = cloud } }
						NOT = {
							has_star_flag = cloud_1
							has_star_flag = cloud_2
							has_star_flag = cloud_3
							has_star_flag = cloud_4
							has_star_flag = cloud_5
						}
					}
					save_event_target_as = cloud_2
					set_star_flag = cloud_2
					root = { set_country_flag = has_cloud_2 }
				}
				closest_system = {
					limit = {
						root = {
							intel_level = {
								level = none
								system = prev
							}
						}
						has_star_flag = hostile_system
						any_ship_in_system = { owner = { is_country_type = cloud } }
						NOT = {
							has_star_flag = cloud_1
							has_star_flag = cloud_2
							has_star_flag = cloud_3
							has_star_flag = cloud_4
							has_star_flag = cloud_5
						}
					}
					save_event_target_as = cloud_3
					set_star_flag = cloud_3
					root = { set_country_flag = has_cloud_3 }
				}
				closest_system = {
					limit = {
						root = {
							intel_level = {
								level = none
								system = prev
							}
						}
						has_star_flag = hostile_system
						any_ship_in_system = { owner = { is_country_type = cloud } }
						NOT = {
							has_star_flag = cloud_1
							has_star_flag = cloud_2
							has_star_flag = cloud_3
							has_star_flag = cloud_4
							has_star_flag = cloud_5
						}
					}
					save_event_target_as = cloud_4
					set_star_flag = cloud_4
					root = { set_country_flag = has_cloud_4 }
				}
				closest_system = {
					limit = {
						root = {
							intel_level = {
								level = none
								system = prev
							}
						}
						has_star_flag = hostile_system
						any_ship_in_system = { owner = { is_country_type = cloud } }
						NOT = {
							has_star_flag = cloud_1
							has_star_flag = cloud_2
							has_star_flag = cloud_3
							has_star_flag = cloud_4
							has_star_flag = cloud_5
						}
					}
					save_event_target_as = cloud_5
					set_star_flag = cloud_5
					root = { set_country_flag = has_cloud_5 }
				}
			}
		}
		country_event = { id = story.407 }
	}
}

# eh
country_event = {
	id = story.407
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { has_country_flag = has_cloud_1 }
			create_point_of_interest = {
				id = cloud_1_poi
				name = cloud_poi_title
				desc = cloud_poi_desc
				event_chain = cloud_chain
				category = cloud_chain_cat
				location = event_target:cloud_1
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_2 }
			create_point_of_interest = {
				id = cloud_2_poi
				name = cloud_poi_title
				desc = cloud_poi_desc
				event_chain = cloud_chain
				category = cloud_chain_cat
				location = event_target:cloud_2
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_3 }
			create_point_of_interest = {
				id = cloud_3_poi
				name = cloud_poi_title
				desc = cloud_poi_desc
				event_chain = cloud_chain
				category = cloud_chain_cat
				location = event_target:cloud_3
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_4 }
			create_point_of_interest = {
				id = cloud_4_poi
				name = cloud_poi_title
				desc = cloud_poi_desc
				event_chain = cloud_chain
				category = cloud_chain_cat
				location = event_target:cloud_4
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_5 }
			create_point_of_interest = {
				id = cloud_5_poi
				name = cloud_poi_title
				desc = cloud_poi_desc
				event_chain = cloud_chain
				category = cloud_chain_cat
				location = event_target:cloud_5
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_1 }
			event_target:cloud_1 = {
				root = {
					clear_uncharted_space = {
						from = prev
						radius = 10
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_2 }
			event_target:cloud_2 = {
				root = {
					clear_uncharted_space = {
						from = prev
						radius = 10
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_3 }
			event_target:cloud_3 = {
				root = {
					clear_uncharted_space = {
						from = prev
						radius = 10
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_4 }
			event_target:cloud_4 = {
				root = {
					clear_uncharted_space = {
						from = prev
						radius = 10
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = has_cloud_5 }
			event_target:cloud_5 = {
				root = {
					clear_uncharted_space = {
						from = prev
						radius = 10
					}
				}
			}
		}
	}
}

# Fleet enters Void Cloud system
# Scope = Ship
# From = System
fleet_event = {
	id = story.408
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = {
			is_ai = no
			has_event_chain = "cloud_chain"
		}
		from = {
			OR = {
				has_star_flag = cloud_1
				has_star_flag = cloud_2
				has_star_flag = cloud_3
				has_star_flag = cloud_4
				has_star_flag = cloud_5
			}
		}
	}

	immediate = {
		from = {
			if = {
				limit = { has_star_flag = cloud_1 }
				root = {
					owner = {
						remove_point_of_interest = cloud_1_poi
						add_event_chain_counter = { 
							event_chain = "cloud_chain" 
							counter = "clouds_watched" 
							amount = 1 
						}
					}
				}
				remove_star_flag = cloud_1
			}
			if = {
				limit = { has_star_flag = cloud_2 }
				root = {
					owner = {
						remove_point_of_interest = cloud_2_poi
						add_event_chain_counter = { 
							event_chain = "cloud_chain" 
							counter = "clouds_watched" 
							amount = 1 
						}
					}
				}
				remove_star_flag = cloud_2
			}
			if = {
				limit = { has_star_flag = cloud_3 }
				root = {
					owner = {
						remove_point_of_interest = cloud_3_poi
						add_event_chain_counter = { 
							event_chain = "cloud_chain" 
							counter = "clouds_watched" 
							amount = 1 
						}
					}
				}
				remove_star_flag = cloud_3
			}
			if = {
				limit = { has_star_flag = cloud_4 }
				root = {
					owner = {
						remove_point_of_interest = cloud_4_poi
						add_event_chain_counter = { 
							event_chain = "cloud_chain" 
							counter = "clouds_watched" 
							amount = 1 
						}
					}
				}
				remove_star_flag = cloud_4
			}
			if = {
				limit = { has_star_flag = cloud_5 }
				root = {
					owner = {
						remove_point_of_interest = cloud_5_poi
						add_event_chain_counter = { 
							event_chain = "cloud_chain" 
							counter = "clouds_watched" 
							amount = 1 
						}
					}
				}
				remove_star_flag = cloud_5
			}
		}
		if = {
			limit = {
				owner = {
					has_completed_event_chain_counter = {
						event_chain = "cloud_chain"
						counter = "clouds_watched"
					}
				}
			}
			owner = { end_event_chain = "cloud_chain" }
		}
	}
}

# Cloud kill-check for chain 1
country_event = {
	id = story.409
	trigger = {
		exists = from
		from = { is_country_type = cloud }
		is_ai = no
		has_event_chain = "clouds_1_chain"
	}
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		add_event_chain_counter = { 
			event_chain = "clouds_1_chain" 
			counter = "stardust_sifted" 
			amount = 1 
		}
		country_event = { id = story.410 days = 5 }
	}
}

country_event = {
	id = story.410
	title = story.410.name
	# Phobe
	desc = {
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.410.desc.spiri
	}
	desc = {
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		text = story.410.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_space_cloud
	location = from

	is_triggered_only = yes

	option = {
		name = story.410.a.spiri
		trigger = { OR = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		end_event_chain = "clouds_1_chain"
		add_modifier = {
			modifier = "malefaction"
			days = 1460
		}
	}
	option = {
		name = story.410.b
		trigger = { NOT = { has_ethic = ethic_spiritualist has_ethic = ethic_fanatic_spiritualist } }
		end_event_chain = "clouds_1_chain"
		add_modifier = {
			modifier = "cloudbuster"
			days = -1
		}
	}
}

### Tiyanki
# Triggered by action.25
country_event = {
	id = story.500
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_country = {
			limit = { is_country_type = tiyanki }
			establish_communications_no_message = ROOT
		}
		country_event = { id = story.501 days = 5 }
	}
}

country_event = {
	id = story.501
	title = story.501.name
	# Spiri
	desc = {
		trigger = {
			OR = {
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_spiritualist
			}
		}
		text = story.501.desc.spiri
	}
	desc = {
		trigger = {
			NOT = {
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_spiritualist
			}
		}
		text = story.501.desc
	}
	picture = GFX_evt_fleet_evil
	show_sound = event_alien_nature
	location = from

	is_triggered_only = yes

	option = {
		name = story.501.a.spiri
		trigger = {
			OR = {
				has_ethic = ethic_fanatic_spiritualist
				has_ethic = ethic_spiritualist
			}
		}
		if = {
			limit = {
				has_tech_option = tech_space_whale_weapon_1
			}
			add_tech_progress = {
				tech = tech_space_whale_weapon_1
				progress = 0.6
			}
			else = {
				add_research_option = tech_space_whale_weapon_1
				add_tech_progress = {
					tech = tech_space_whale_weapon_1
					progress = 0.2
				}
			}
		}
	}

	option = {
		name = story.501.a.mater
		trigger = {
			OR = {
				has_ethic = ethic_materialist
				has_ethic = ethic_fanatic_materialist
			}
		}
		if = {
			limit = {
				has_tech_option = tech_space_whale_weapon_1
			}
			add_tech_progress = {
				tech = tech_space_whale_weapon_1
				progress = 0.3
			}
			else = {
				add_research_option = tech_space_whale_weapon_1
				add_tech_progress = {
					tech = tech_space_whale_weapon_1
					progress = 0.1
				}
			}
		}
	}

	option = {
		name = OK
		trigger = {
			NOT = {
				has_ethic = ethic_materialist
				has_ethic = ethic_fanatic_materialist
				has_ethic = ethic_spiritualist
				has_ethic = ethic_fanatic_spiritualist
			}
		}
	}
}