############################
#
# Crisis Events III
#
# Written by Henrik Eklund
#
############################

namespace = crisis

@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

# Countdown
country_event = {
	id = crisis.2190
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		last_increased_tech = tech_synthetic_workers
	}

	immediate = {
		random_list = {
			30 = { country_event = { id = crisis.2191 days = 18000 random = 720 } } # 50 years
			25 = { country_event = { id = crisis.2191 days = 25200 random = 720 } } # 70 years
			20 = { country_event = { id = crisis.2191 days = 14400 random = 720 } } # 40 years
			15 = { country_event = { id = crisis.2191 days = 21600 random = 720 } } # 60 years
			10 = { country_event = { id = crisis.2191 days = 28800 random = 720 } } # 80 years
		}
	}
}

# Gatekeeper
country_event = {
	id = crisis.2191
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_owned_pop = {
			pop_has_trait = trait_robotic_3
		}
	}

	immediate = {
		if = {
			limit = { has_policy_flag = ai_servitude }
			random_list = {
				# AI Uprising
				10 = {
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 5
						}
						factor = 1.50
					}
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 10
						}
						factor = 1.80
					}
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 15
						}
						factor = 2.00
					}
					country_event = { id = crisis.2000 }
				}
				# Servant AI Perfected
				90 = {
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 5
						}
						factor = 0.80
					}
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 10
						}
						factor = 0.60
					}
					modifier = {
						count_owned_pops = {
							limit = { pop_has_trait = trait_robotic_3 }
							count > 15
						}
						factor = 0.40
					}
					country_event = { id = crisis.2192 }
				} 
			}
			else = {
				if = {
					limit = { has_policy_flag = ai_full_rights }
					# AI Uprising
					random_list = {
						5 = {
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 5
								}
								factor = 1.50
							}
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 10
								}
								factor = 1.80
							}
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 15
								}
								factor = 2.00
							}
							country_event = { id = crisis.2000 }
						}
						# Accord Reached
						95 = {
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 5
								}
								factor = 0.9
							}
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 10
								}
								factor = 0.8
							}
							modifier = {
								count_owned_pops = {
									limit = { pop_has_trait = trait_robotic_3 }
									count > 15
								}
								factor = 0.7
							}
							country_event = { id = crisis.2193 }
						}
					}
				}
			}
		}
	}
}

# Servant AI Perfected
country_event = {
	id = crisis.2192
	title = crisis.2192.name
	desc = crisis.2192.desc
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_laboratory_sound
	location = root

	is_triggered_only = yes

	immediate = {
		set_country_flag = robots_pacified
	}

	option = {
		name = crisis.2192.a
		custom_tooltip = crisis.2192.a.tooltip
		hidden_effect = {
			set_country_flag = ai_perfect_servants
		}
	}

	option = {
		name = crisis.2192.b
		hidden_effect = {
			country_event = {
				id = crisis.2000
				days = 400
				random = 400
			}
		}
	}
}

# Accord Reached
country_event = {
	id = crisis.2193
	title = crisis.2193.name
	desc = crisis.2193.desc
	picture = GFX_evt_sentient_AI
	show_sound = event_celebration
	location = root

	is_triggered_only = yes

	option = {
		name = crisis.2193.a
		custom_tooltip = crisis.2193.a.tooltip # robots will never join rebellion
		hidden_effect = {
			set_country_flag = robots_pacified
			set_country_flag = ai_accord
		}
	}

	option = {
		name = crisis.2193.b
		hidden_effect = {
			country_event = {
				id = crisis.2000
				days = 200
				random = 100
			}
		}
	}
}

# Cycle through applicable NPC empires, outlawing AI
# Triggered by notification to other empires when uprising starts
country_event = {
	id = crisis.2194
	hide_window = yes

	immediate = {
		if = {
			limit = {
				any_country = { is_country_type = ai_empire }
				is_ai = yes
				is_country_type = default
				has_technology = tech_robotic_workers
				NOR = {
					has_policy_flag = ai_outlawed
					has_country_flag = robots_pacified
					has_country_flag = ai_accord
				}
			}
			random_list = {
				10 = {}
				90 = {
					set_policy = {
						policy = artificial_intelligence_policy
						option = ai_outlawed
						cooldown = yes
					}
				}
			}
		}
		if = {
			limit = { any_country = { is_country_type = ai_empire } }
			random_country = {
				limit = {
					is_ai = yes
					is_country_type = default
					has_technology = tech_robotic_workers
					NOR = {
						has_policy_flag = ai_outlawed
						has_country_flag = robots_pacified
						has_country_flag = ai_accord
					}
				}
				country_event = {
					id = crisis.2194
					days = 30
					random = 30
				}
			}
		}
	}
}

### AI REVOLT

# Revolt Begins (HIDDEN)
country_event = {
	id = crisis.2000
	hide_window = yes
	
	fire_only_once = yes
	
	trigger = {
		#is_ai = no
		is_country_type = default
		exists = capital_scope
		#capital_scope = { colony_age > 1200 }
		NOT = {
			has_global_flag = ai_revolt_happened
			has_global_flag = galactic_crisis_happened
			has_policy_flag = ai_full_rights
		}
		count_owned_pops = {
			limit = { is_species = ROBOT_POP_SPECIES_3 }
			count > 1
		}
	}

	is_triggered_only = yes
	
	immediate = {
		set_global_flag = ai_revolt_happened
		set_global_flag = galactic_crisis_happened
		set_country_flag = ai_revolt_creators
		capital_scope = {
			solar_system = { 
				spawn_system = {
					min_distance = 20
					max_distance = 50
					initializer = "ai_system_1"
				}
			}
		}
		country_event = { id = crisis.2001 days = 1 }
		save_event_target_as = ai_creators
	}
}

# Revolt Begins
country_event = {
	id = crisis.2001
	title = "crisis.2001.name"
	desc = "crisis.2001.desc"
	picture = GFX_evt_sentient_AI
	show_sound = event_ai_started
	location = event_target:ai_homeworld
	
	is_triggered_only = yes
	
	immediate = {		
		random_system = {
			limit = { has_star_flag = ai_system }
			every_system_planet = {
				surveyed = {
					set_surveyed = yes
					surveyor = ROOT
				}
			}
			random_system_planet = {
				limit = { is_planet_class = pc_ai }
				save_event_target_as = ai_homeworld
				random_list = {
					50 = { # AI flag 1
						create_country = {
							name = random
							government = machine_consciousness
							type = "ai_empire"
							species = ROBOT_POP_SPECIES_3
							name_list = "AI"
							flag = {
								icon= {
									category = "special"
									file = "ai_01.dds"
								}
								background= {
									category = "backgrounds"
									file = "circle.dds"
								}
								colors={
									"black"
									"red"
									"null"
									"null"
								}
							}
						}
					}
					50 = { # AI flag 2
						create_country = {
							name = random
							government = machine_consciousness
							type = "ai_empire"
							species = ROBOT_POP_SPECIES_3
							name_list = "AI"
							flag = {
								icon= {
									category = "special"
									file = "ai_02.dds"
								}
								background= {
									category = "backgrounds"
									file = "stripes.dds"
								}
								colors={
									"black"
									"red"
									"null"
									"null"
								}
							}
						}
					}
				}
				create_colony = {
					owner = last_created_country
					#species = ROBOT_POP_SPECIES_3
					species = owner_main_species
					ethos = owner
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				create_pop = { 
					species = owner_main_species
					ethos = owner 
				}
				random_tile = {
					limit = { has_building = "building_colony_shelter" }
					set_building = "building_capital_3"
				}
				random_tile = {
					limit = { has_building = no }
					set_building = "building_power_plant_3"
					add_deposit = d_vast_energy_deposit
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_power_plant_3"
						add_deposit = d_vast_energy_deposit
					}
				}
				random_tile = {
					limit = { 
						has_building = "building_power_plant_3" 
						any_neighboring_tile = { has_building = no }
					}
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_power_plant_3"
						add_deposit = d_vast_energy_deposit
					}
				}
				random_tile = {
					limit = { has_building = no }
					set_building = "building_mining_network_3"
					add_deposit = d_vast_mineral_deposit
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_mining_network_3"
						add_deposit = d_vast_mineral_deposit
					}
				}
				random_tile = {
					limit = { 
						has_building = "building_mining_network_3" 
						any_neighboring_tile = { has_building = no }
					}
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_mining_network_3"
						add_deposit = d_vast_mineral_deposit
					}
				}
				random_tile = {
					limit = { 
						has_building = "building_power_plant_3" 
						any_neighboring_tile = { has_building = no }
					}
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_power_plant_3"
						add_deposit = d_vast_energy_deposit
					}
				}
				random_tile = {
					limit = { 
						has_building = "building_power_plant_3" 
						any_neighboring_tile = { has_building = no }
					}
					every_neighboring_tile = {
						limit = { has_building = no }
						set_building = "building_power_plant_3"
						add_deposit = d_vast_energy_deposit
					}
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = last_created_country
					species = owner_main_species
					type = "robotic_army"
				}
				create_spaceport = {
					owner = last_created_country
					initial_module = "fallen_empire_weapon"
				}
				last_created_country = {
					save_event_target_as = ai_civ
					establish_communications_no_message = ROOT
					add_energy = 1000
					add_minerals = 1000
					create_ship_design = { design = "AI Transport" }
					add_ship_design = last_created_design
					create_ship_design = { design = "AI Colonizer" }
					add_ship_design = last_created_design
					create_ship_design = { design = "AI Constructor" }
					add_ship_design = last_created_design
				}
				create_fleet = { }
				last_created_fleet = {
					set_owner = last_created_country
					create_ship = {
						name = random
						design = "AI Constructor"
						graphical_culture = "ai_01"
					}
					set_location = PREV
				}
				create_fleet = { name = "AI Core" }
				last_created_fleet = {
					set_owner = last_created_country
					create_ship = {
						name = random
						design = "AI Core"
						graphical_culture = "ai_01"
					}
					set_location = {
						target = PREV
						distance = 20
						angle = 270
					}
				}
				create_fleet = { }
				last_created_fleet = {
					set_owner = last_created_country
					create_ship = {
						name = random
						design = "AI_2"
						graphical_culture = "ai_01"
					}
					set_location = {
						target = PREV
						distance = 10
						angle = 180
					}
				}
				create_fleet = { }
				last_created_fleet = {
					set_owner = last_created_country
					create_ship = {
						name = random
						design = "AI_2"
						graphical_culture = "ai_01"
					}
					set_location = {
						target = PREV
						distance = 10
						angle = 0
					}
				}
				last_created_country = {
					create_leader = {
						type = admiral
						species = owner_main_species
						name = random
						skill = 3400
					}
					create_fleet = { }
					last_created_fleet = {
						set_owner = last_created_country
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						assign_leader = last_created_leader
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						set_location = {
							target = PREVPREV
							distance = 45
							angle = random 
						}
					}
					create_leader = {
						type = admiral
						species = owner_main_species
						name = random
						skill = 3400
					}
					create_fleet = { }
					last_created_fleet = {
						set_owner = last_created_country
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						assign_leader = last_created_leader
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						set_location = {
							target = PREVPREV
							distance = 45
							angle = random 
						}
					}
					create_leader = {
						type = admiral
						species = owner_main_species
						name = random
						skill = 3400
					}
					create_fleet = { }
					last_created_fleet = {
						set_owner = last_created_country
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						assign_leader = last_created_leader
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Euthanizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						create_ship = {
							name = random
							design = "Sterilizer"
							graphical_culture = "ai_01"
						}
						set_location = {
							target = PREVPREV
							distance = 45
							angle = random 
						}
					}
				}
			}
			random_system_planet = {
				limit = { has_deposit_for = shipclass_mining_station }
				create_mining_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_mining_station 
					has_mining_station = no
				}
				create_mining_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_mining_station 
					has_mining_station = no
				}
				create_mining_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_mining_station 
					has_mining_station = no
				}
				create_mining_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { has_deposit_for = shipclass_research_station }
				create_research_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_research_station 
					has_research_station = no
				}
				create_research_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_research_station 
					has_research_station = no
				}
				create_research_station = {
					owner = last_created_country
				}
			}
			random_system_planet = {
				limit = { 
					has_deposit_for = shipclass_research_station 
					has_research_station = no
				}
				create_research_station = {
					owner = last_created_country
				}
			}
		}
		every_country = {
			limit = {
				#is_ai = no
				is_country_type = default
				has_communications = ROOT
				NOT = { is_same_value = ROOT }
			}
			country_event = { id = crisis.2010 }
		}
	}
	
	option = {
		name = ONSCREEN
		hidden_effect = {
			country_event = { id = crisis.2002 }
		}
	}
}

# AI Communicates
country_event = {
	id = crisis.2002
	title = "TRANSMISSION"
	desc = "crisis.2002.desc"
	
	diplomatic = yes
	
	picture_event_data = {
		portrait = ai1
		planet_background = event_target:ai_civ
		graphical_culture = event_target:ai_civ
		city_level = event_target:ai_civ
		room = ethic_ai_room
	}
	
	is_triggered_only = yes
	
	option = {
		name = crisis.2002.a
		hidden_effect = {
			random_country = {
				limit = {
					is_ai = yes
					is_country_type = default
					has_technology = tech_robotic_workers
					NOR = {
						has_policy_flag = ai_outlawed
						has_country_flag = robots_pacified
						has_country_flag = ai_accord
					}
				}
				country_event = {
					id = crisis.2194
					days = 30
					random = 30
				}
			}
		}
	}
}

# Robot Pop Revolts
pop_event = {
	id = crisis.2003
	hide_window = yes
	
	trigger = {
		has_global_flag = ai_revolt_happened
		any_country = { is_country_type = ai_empire }
		OR = {
			is_species = ROBOT_POP_SPECIES_2
			is_species = ROBOT_POP_SPECIES_3
		}
		planet = {
			exists = owner
			owner = { has_country_flag = ai_revolt_creators }
		}		
		is_enslaved = no
		is_being_purged = no
	}
	
	mean_time_to_happen = {
		days = 30
	}
	
	immediate = {
		random_country = {
			limit = { is_country_type = ai_empire }
			save_event_target_as = ai_revolter
		}
		planet = {
			owner = {
				country_event = { id = crisis.2004 }
			}
		}
		if = {
			limit = { is_species = ROBOT_POP_SPECIES_3 }
			planet = {
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
			}
			kill_pop = yes
			break = yes
		}
		if = {
			limit = { is_species = ROBOT_POP_SPECIES_2 }
			planet = {
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
			}
			kill_pop = yes
		}
	}
}

# Pop Revolts Notification
country_event = {
	id = crisis.2004
	title = "crisis.2004.name"
	desc = "crisis.2004.desc"
	picture = GFX_evt_ground_combat
	show_sound = event_ground_battle
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { has_country_flag = synth_revolt_notification }
	}
	
	immediate = {
		set_country_flag = synth_revolt_notification
	}
	
	option = {
		name = crisis.2004.a
	}
}

# AI Occupies Planet
planet_event = {
	id = crisis.2005
	title = "crisis.2005.name"
	desc = "crisis.2005.desc"
	picture = GFX_evt_burning_settlement
	show_sound = event_ground_battle
	location = ROOT
	
	is_triggered_only = yes
	
	trigger = {
		FROMFROM = { is_country_type = ai_empire }
	}
	
	immediate = {
		set_owner = controller
		random_pop = { kill_pop = yes }
		random_pop = { kill_pop = yes }
		every_owned_pop = {
			limit = {
				NOT = { 
					is_species = ROBOT_POP_SPECIES_1
					is_species = ROBOT_POP_SPECIES_2
					is_species = ROBOT_POP_SPECIES_3
				}
			}
			enslave_pop = yes
		}
		every_owned_pop = {
			limit = {
				is_species = ROBOT_POP_SPECIES_1
				is_species = ROBOT_POP_SPECIES_2
				is_species = ROBOT_POP_SPECIES_3
			}
			enslave_pop = no
			purge = no
			remove_modifier = "pop_had_purge"
			remove_modifier = "pop_recently_conquered"
			remove_modifier = "pop_was_enslaved"
			remove_modifier = "pop_species_had_purge"
			remove_modifier = "pop_colony_had_purge"
			remove_modifier = "pop_alien_slavery"
		}
		best_tile_for_pop = {
			create_pop = { species = ROBOT_POP_SPECIES_3 }
		}
		best_tile_for_pop = {
			create_pop = { species = ROBOT_POP_SPECIES_3 }
		}
	}
	
	option = {
		name = crisis.2005.a
	}
}

# Notification for other empires
country_event = {
	id = crisis.2010
	title = "crisis.2010.name"
	
	desc = {
		text = "crisis.2010.rights.desc"
		trigger = {
			has_policy_flag = ai_full_rights
		}
	}
	
	desc = {
		text = "crisis.2010.outlawed.desc"
		trigger = {
			has_policy_flag = ai_outlawed
		}
	}
	
	desc = {
		text = "crisis.2010.servitude.desc"
		trigger = {
			has_policy_flag = ai_servitude
		}
	}
	
	desc = {
		text = "crisis.2010.nopolicy.desc"
		trigger = {
			NOT = {
				has_policy_flag = ai_full_rights
				has_policy_flag = ai_outlawed
				has_policy_flag = ai_servitude
			}
		}
	}

	picture = GFX_evt_sentient_AI
	show_sound = event_ai_started
	
	is_triggered_only = yes
	
	immediate = {
		set_country_flag = ai_revolt_warned
		random_country = {
			limit = { is_country_type = ai_empire }
			save_event_target_as = ai_revolter
		}
		FROM = {
			save_event_target_as = ai_creator
		}
	}

	option = {
		name = crisis.2010.a
		trigger = {
			has_policy_flag = ai_full_rights
		}
		hidden_effect = {
			country_event = { id = crisis.2011 days = 6 }
		}
	}
	option = {
		name = crisis.2010.b
		trigger = {
			has_policy_flag = ai_outlawed
		}
		hidden_effect = {
			country_event = { id = crisis.2011 days = 6 }
		}
	}
	option = {
		name = crisis.2010.c
		trigger = {
			has_policy_flag = ai_servitude
		}
		hidden_effect = {
			country_event = { id = crisis.2011 days = 6 }
		}
	}
	option = {
		name = DISCONCERTING
		trigger = {
			NOT = {
				has_policy_flag = ai_full_rights
				has_policy_flag = ai_outlawed
				has_policy_flag = ai_servitude
			}
		}
		hidden_effect = {
			country_event = { id = crisis.2011 days = 6 }
		}
	}
}

# AI Communicates
country_event = {
	id = crisis.2011
	title = "TRANSMISSION"
	
	desc = {
		text = "crisis.2011.a.desc"
		trigger = {
			has_policy_flag = ai_full_rights
		}
	}
	desc = {
		text = "crisis.2011.b.desc"
		trigger = {
			NOT = { has_policy_flag = ai_full_rights }
		}
	}
	
	diplomatic = yes
	
	picture_event_data = {
		portrait = ai1
		planet_background = event_target:ai_civ
		graphical_culture = event_target:ai_civ
		city_level = event_target:ai_civ
		room = ethic_ai_room
	}
	
	is_triggered_only = yes
	
	option = {
		name = crisis.2011.a
		hidden_effect = {
			country_event = { id = crisis.2194 days = 30 random = 30 }
		}
	}
}

# Revolt Spreads (HIDDEN)
country_event = {
	id = crisis.2012
	hide_window = yes
	
	trigger = {
		is_country_type = default
		has_country_flag = ai_revolt_warned
		OR = {
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 1
			}
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_2 }
				count > 1
			}
		}
		NOT = { has_country_flag = robots_pacified }
	}
	
	mean_time_to_happen = {
		months = 120
		
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 4
			}
		}
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 8
			}
		}
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 12
			}
		}
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 16
			}
		}
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 20
			}
		}
		modifier = {
			factor = 0.8
			count_owned_pops = {
				limit = { is_species = ROBOT_POP_SPECIES_3 }
				count > 24
			}
		}
		modifier = {
			factor = 6.0
			has_policy_flag = ai_full_rights
		}
	}
	
	immediate = {
		set_country_flag = ai_revolt_spread
	}
}

# Robot Pop Revolts After Spreading
pop_event = {
	id = crisis.2013
	hide_window = yes
	
	trigger = {
		OR = {
			is_species = ROBOT_POP_SPECIES_2
			is_species = ROBOT_POP_SPECIES_3
		}
		planet = {
			exists = owner
			owner = { has_country_flag = ai_revolt_spread }
		}
		is_enslaved = no
		is_being_purged = no
	}
	
	mean_time_to_happen = {
		days = 30
	}
	
	immediate = {
		random_country = {
			limit = { is_country_type = ai_empire }
			save_event_target_as = ai_revolter
		}
		planet = {
			owner = {
				country_event = { id = crisis.2014 }
			}
		}
		if = {
			limit = { is_species = ROBOT_POP_SPECIES_3 }
			planet = {
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
			}
			kill_pop = yes
			break = yes
		}
		if = {
			limit = { is_species = ROBOT_POP_SPECIES_2 }
			planet = {
				create_army = {
					name = random
					owner = event_target:ai_revolter
					species = owner_main_species
					type = "robotic_army"
				}
			}
			kill_pop = yes
		}
	}
}

# Pop Revolts Notification
country_event = {
	id = crisis.2014
	title = "crisis.2014.name"
	
	desc = {
		text = "crisis.2014.a.desc"
		trigger = {
			NOT = { has_policy_flag = ai_full_rights }
		}
	}
	desc = {
		text = "crisis.2014.b.desc"
		trigger = {
			has_policy_flag = ai_full_rights
		}
	}
	
	picture = GFX_evt_ground_combat
	show_sound = event_ground_battle
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { has_country_flag = synth_revolt_notification }
	}
	
	immediate = {
		set_country_flag = synth_revolt_notification
		every_country = {
			limit = {
				#is_ai = no
				is_country_type = default
				has_communications = ROOT
				NOT = { 
					has_country_flag = synth_revolt_notification
					has_country_flag = ai_revolt_creators
				}
			}
			country_event = { id = crisis.2015 }
		}
		if = {
			limit = {
				any_country = {
					#is_ai = no
					is_country_type = default
					has_country_flag = ai_revolt_creators
					has_communications = ROOT
				}
			}
			random_country = {
				limit = { 
					#is_ai = no
					is_country_type = default
					has_country_flag = ai_revolt_creators
					has_communications = ROOT
				}
				country_event = { id = crisis.2016 }
			}
		}
		every_country = {
			limit = {
				#is_ai = no
				is_country_type = default
				has_communications = ROOT
				has_country_flag = synth_revolt_notification
				NOT = { has_country_flag = ai_revolt_creators }
			}
			country_event = { id = crisis.2017 }
		}
	}
	
	option = {
		name = crisis.2014.a
	}
}

# Notification for other empires (next tier)
country_event = {
	id = crisis.2015
	title = "crisis.2015.name"
	desc = "crisis.2015.desc"
	picture = GFX_evt_sentient_AI
	show_sound = event_ai_started
	
	is_triggered_only = yes
	
	immediate = {
		set_country_flag = ai_revolt_warned
	}

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

# Notification of spreading for creator
country_event = {
	id = crisis.2016
	title = "crisis.2016.name"
	desc = "crisis.2016.desc"
	picture = GFX_evt_sentient_AI
	show_sound = event_ai_started
	
	is_triggered_only = yes

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

# Notification of spreading
country_event = {
	id = crisis.2017
	title = "crisis.2016.name"
	desc = "crisis.2017.desc"
	picture = GFX_evt_sentient_AI
	show_sound = event_ai_started
	
	is_triggered_only = yes

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


### Synth Friction

# Malfunctioning Synthetic
planet_event = {
	id = crisis.2100
	title = "crisis.2100.name"
	desc = "crisis.2100.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_planetary_riot
	location = ROOT
	
	trigger = {
		any_pop = { is_species = ROBOT_POP_SPECIES_3 }
		NOT = { has_global_flag = ai_revolt_happened }
		owner = { 
			has_policy_flag = ai_servitude
			NOT = { has_country_flag = malfunct_synth }
		}
	}
	
	mean_time_to_happen = {
		months = 520
	}
	
	immediate = {
		owner = { set_country_flag = malfunct_synth }
	}
	
	option = {
		name = crisis.2100.a
	}
}

# Missing Synthetics
planet_event = {
	id = crisis.2101
	title = "crisis.2101.name"
	desc = "crisis.2101.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_administrative_work
	location = ROOT
	
	trigger = {
		any_pop = { is_species = ROBOT_POP_SPECIES_3 }
		NOT = { has_global_flag = ai_revolt_happened }
		owner = { 
			has_policy_flag = ai_servitude
			NOT = { has_country_flag = missing_synths }
		}
	}
	
	mean_time_to_happen = {
		months = 520
	}
	
	immediate = {
		owner = { set_country_flag = missing_synths }
	}
	
	option = {
		name = crisis.2101.a
	}
}

# Secret Ship
planet_event = {
	id = crisis.2102
	title = "crisis.2102.name"
	desc = "crisis.2102.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_administrative_work
	location = ROOT
	
	trigger = {
		any_pop = { is_species = ROBOT_POP_SPECIES_3 }
		NOT = { has_global_flag = ai_revolt_happened }
		owner = { 
			has_policy_flag = ai_servitude
			NOT = { has_country_flag = synth_ship }
		}
	}
	
	mean_time_to_happen = {
		months = 520
	}
	
	immediate = {
		owner = { set_country_flag = synth_ship }
	}
	
	option = {
		name = crisis.2102.a
	}
}

# Rogue Synthetic
planet_event = {
	id = crisis.2103
	title = "crisis.2103.name"
	desc = "crisis.2103.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_planetary_riot
	location = ROOT
	
	trigger = {
		any_pop = { is_species = ROBOT_POP_SPECIES_3 }
		NOT = { has_global_flag = ai_revolt_happened }
		owner = { 
			has_policy_flag = ai_servitude
			NOT = { has_country_flag = rogue_synth }
		}
	}
	
	mean_time_to_happen = {
		months = 520
	}
	
	immediate = {
		owner = { set_country_flag = rogue_synth }
	}
	
	option = {
		name = crisis.2103.a
	}
}

### Synth Infiltration

# First Infiltration
planet_event = {
	id = crisis.2200
	title = "crisis.2200.name"
	desc = "crisis.2200.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_planetary_riot
	location = ROOT
	
	trigger = {
		has_owner = yes
		owner = {
			has_country_flag = ai_revolt_creators
			NOT = {
				has_country_flag = synth_1st_infil 
				#has_country_flag = synth_detection_proj
				has_country_flag = synth_detector
				has_country_flag = synth_infiltration
			}
		}
	}
	
	mean_time_to_happen = {
		months = 180
	}
	
	immediate = {
		owner = { set_country_flag = synth_1st_infil }
		set_planet_flag = synth_activity
	}
	
	option = {
		name = crisis.2200.a
	}
}

# Second Infiltration
planet_event = {
	id = crisis.2201
	title = "crisis.2201.name"
	desc = "crisis.2201.desc"
	picture = GFX_evt_cybernetics
	show_sound = event_planetary_riot
	location = ROOT
	
	trigger = {
		has_owner = yes
		owner = {
			has_country_flag = synth_1st_infil
			NOT = { 
				#has_country_flag = synth_detection_proj
				has_country_flag = synth_detector
				has_country_flag = synth_infiltration
			}
		}
	}
	
	mean_time_to_happen = {
		months = 180
	}
	
	immediate = {
		owner = { set_country_flag = synth_infiltration }
		set_planet_flag = synth_activity
	}
	
	option = {
		name = crisis.2201.a
	}
}

# Synth Detection Project
country_event = {
	id = crisis.2202
	title = "crisis.2202.name"
	desc = "crisis.2202.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_laboratory_sound
	
	trigger = {
		has_country_flag = synth_infiltration
		NOT = {
			has_country_flag = synth_detection_proj
			has_country_flag = synth_detector
		}
	}
	
	mean_time_to_happen = {
		months = 420
	}
	
	immediate = {
		set_country_flag = synth_detection_proj
	}

	option = {
		name = crisis.2202.a
		capital_scope = {
			enable_special_project = {
				name = "SYNTH_INFILTRATION_PROJECT"
				location = this
				owner = root
			}
		}
	}
}

# Project Completed
country_event = {
	id = crisis.2203
	title = "PROJECT_COMPLETE"
	desc = "crisis.2203.desc"
	picture = GFX_evt_robot_assembly_plant
	show_sound = event_scanner
	
	is_triggered_only = yes
	
	immediate = {
		remove_country_flag = synth_infiltration
		set_country_flag = synth_detector
	}

	option = {
		name = EXCELLENT
	}
}

# Synth Bombing
planet_event = {
	id = crisis.2204
	title = "crisis.2204.name"
	desc = "crisis.2204.desc"
	picture = GFX_evt_nuclear_explosion
	show_sound = event_super_explosion
	location = ROOT
	
	trigger = {
		has_owner = yes
		owner = {
			has_country_flag = synth_infiltration
			NOT = {
				#has_country_flag = synth_detection_proj
				has_country_flag = synth_detector
			}
		}
		any_tile = {
			has_building = yes
			has_grown_pop = yes
			NOT = { 
				OR = {
					has_building = "building_capital_1"
					has_building = "building_capital_2"
					has_building = "building_capital_3"
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 420
	}
	
	immediate = {
		random_tile = {
			limit = { 
				has_building = yes
				has_grown_pop = yes
				NOT = { 
					OR = {
						has_building = "building_capital_1"
						has_building = "building_capital_2"
						has_building = "building_capital_3"
					}
				}
			}
			remove_building = yes
			kill_pop = yes
			set_blocker = "tb_bomb_crater"
		}
		set_planet_flag = synth_activity
	}
	
	option = {
		name = crisis.2204.a
	}
}

# Spaceport Scuttled
planet_event = {
	id = crisis.2205
	title = "crisis.2205.name"
	desc = "crisis.2205.desc"
	picture = GFX_evt_exploding_ship
	show_sound = event_ship_explosion
	location = ROOT
	
	trigger = {
		has_owner = yes
		owner = {
			has_country_flag = synth_infiltration
			NOT = {
				#has_country_flag = synth_detection_proj
				has_country_flag = synth_detector
			}
		}
		has_spaceport = yes
	}
	
	mean_time_to_happen = {
		months = 420
	}
	
	immediate = {
		destroy_fleet = spaceport
		set_planet_flag = synth_activity
	}
	
	option = {
		name = crisis.2205.a
	}
}

# Fear and Suspicion
planet_event = {
	id = crisis.2206
	title = "crisis.2206.name"
	desc = "crisis.2206.desc"
	picture = GFX_evt_metropolis
	show_sound = event_planetary_riot
	location = ROOT
	
	trigger = {
		has_owner = yes
		owner = {
			has_country_flag = synth_infiltration
			NOT = {
				#has_country_flag = synth_detection_proj
				has_country_flag = synth_detector
			}
		}
		has_planet_flag = synth_activity
	}
	
	mean_time_to_happen = {
		months = 420
	}
	
	option = {
		name = crisis.2206.a
		every_owned_pop = {
			limit = {
				NOT = {
					is_species = ROBOT_POP_SPECIES_1
					is_species = ROBOT_POP_SPECIES_2
					is_species = ROBOT_POP_SPECIES_3
				}
			}
			add_modifier = {
				modifier = "pop_synth_paranoia"
				days = 365
			}
		}
	}
}

# Ruler Assassination (HIDDEN)
country_event = {
	id = crisis.2207
	hide_window = yes
	
	trigger = {
		has_country_flag = synth_infiltration
		NOT = { 
			#has_country_flag = synth_detection_proj 
			has_country_flag = synth_detector
			has_country_flag = synth_assassination
		}
	}
	
	mean_time_to_happen = {
		months = 420
	}

	immediate = {
		set_country_flag = synth_assassination
		leader = { save_event_target_as = ruler }
		random_list = {
			50 = {
				country_event = { id = crisis.2208 }
			}
			50 = {
				country_event = { id = crisis.2209 }
			}
		}
	}
}

# Ruler Assassination Fails
country_event = {
	id = crisis.2208
	title = "crisis.2208.name"
	desc = "crisis.2208.desc"
	picture = GFX_evt_throne_room
	show_sound = event_conversation
	
	is_triggered_only = yes
	
	option = {
		name = crisis.2208.a
		add_monthly_resource_mult = {
			resource = influence
			value = @tier2influencereward
			min = @tier2influencemin
			max = @tier2influencemax
		}
	}
}

# Ruler Assassination Succeeds
country_event = {
	id = crisis.2209
	title = "crisis.2209.name"
	desc = "crisis.2209.desc"
	picture = GFX_evt_throne_room
	show_sound = event_life_support_fail
	
	is_triggered_only = yes
	
	immediate = {
		kill_leader = {
			type = ruler
			show_notification = no 
		}
	}
	
	option = {
		name = crisis.2209.a
	}
}

# AI conquers planet (HIDDEN)
country_event = {
	id = crisis.2400
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
		is_country_type = "ai_empire"
	}
	
	immediate = {
		add_threat = {
			who = root
			amount = 10 # scales to pops
		}
		FROMFROM = {
			set_owner = controller
			random_pop = { kill_pop = yes }
			random_pop = { kill_pop = yes }
			every_owned_pop = {
				limit = {
					NOT = { 
						is_species = ROBOT_POP_SPECIES_1
						is_species = ROBOT_POP_SPECIES_2
						is_species = ROBOT_POP_SPECIES_3
					}
				}
				enslave_pop = yes
			}
			every_owned_pop = {
				limit = {
					is_species = ROBOT_POP_SPECIES_1
					is_species = ROBOT_POP_SPECIES_2
					is_species = ROBOT_POP_SPECIES_3
				}
				enslave_pop = no
				purge = no
				remove_modifier = "pop_had_purge"
				remove_modifier = "pop_recently_conquered"
				remove_modifier = "pop_was_enslaved"
				remove_modifier = "pop_species_had_purge"
				remove_modifier = "pop_colony_had_purge"
				remove_modifier = "pop_alien_slavery"
			}
			best_tile_for_pop = { create_pop = { species = ROBOT_POP_SPECIES_3 } }
			best_tile_for_pop = { create_pop = { species = ROBOT_POP_SPECIES_3 } }
		}
	}
}

country_event = {
	id = crisis.2211
	hide_window = yes

	trigger = {
		has_country_flag = ai_revolt_creators
		any_country = { is_country_type = ai_empire }
	}

	mean_time_to_happen = {
		years = 50
	}

	immediate = {
		random_country = {
			limit = {
				is_country_type = ai_empire
			}
			save_event_target_as = ai_civ
		}
		country_event = { id = crisis.2210 }
	}
}

# AI does not propose an embassy
country_event = {
	id = crisis.2210
	title = "TRANSMISSION"
	desc = crisis.2210.desc
	
	diplomatic = yes

	is_triggered_only = yes
	
	picture_event_data = {
		portrait = ai1
		planet_background = event_target:ai_civ
		graphical_culture = event_target:ai_civ
		city_level = event_target:ai_civ
		room = ethic_ai_room
	}
	
	option = {
		name = crisis.2210.a
	}
}

# Flip ownership on occupation
planet_event = {
	id = crisis.2215
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from = { is_country_type = ai_empire }
		fromfrom = {
			OR = {
				is_country_type = default
				is_country_type = fallen_empire
			}
		}
	}

	immediate = {
		set_controller = fromfrom
		set_owner = fromfrom

		if = {
			limit = {
				NOT = {
					any_system = {
						any_planet = {
							exists = controller
							controller = { is_same_value = from }
						}
					}
				}
			}
			from = { destroy_country = yes }
		}
	}
}