############################
#
# Gray Goo Events
#
# Written by Henrik Thyrwall
#
############################
namespace = graygoo

# Invasion begins
country_event = {
	id = graygoo.1
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		set_update_modifiers_batch = begin
		awaken_guardians_of_the_galaxy = yes
		set_global_flag = gray_goo_crisis_active
		every_megastructure = {
			limit = {
				is_megastructure_type = lgate_base
			}
			activate_gateway = this
			set_megastructure_flag = lgate_activated
		}
		event_target:graygoo_factory_system = {
			random_system_planet = {
				limit = {
					has_planet_flag = main_star
				}
				save_global_event_target_as = rg_main_star
				save_event_target_as = main_star
			}
			create_country = {
				name = "NAME_Gray_Goo"
				type = "gray_goo"
				name_list = "graygoo"
				flag = {
					icon = {
						category = "special"
						file = "gray_goo.dds"
					}
					background = {
						category = "backgrounds"
						file = "sinus.dds"
					}
					colors = {
						"grey"
						"dark_grey"
						"null"
						"null"
					}
				}
				effect = {
					save_global_event_target_as = rg_graygoo_country
					save_event_target_as = graygoo_country
					create_ship_design = {
						design = "NAME_RG_armed_transport_ship"
					}
					add_ship_design = last_created_design
					create_ship_design = {
						design = "NAME_RG_GRAY_scienceship"
					}
					add_ship_design = last_created_design
					create_ship_design = {
						design = "NAME_RG_GRAY_constructor"
					}
					add_ship_design = last_created_design
					create_ship_design = {
						design = "NAME_Gatebuilder_Starbase"
					}
					add_ship_design = last_created_design
				}
			}
			create_fleet = {
				effect = {
					set_owner = event_target:graygoo_country
					create_ship = {
						name = random
						design = "NAME_Nanite_Factory"
						graphical_culture = "pirate_01"
					}
					set_location = {
						target = event_target:main_star
						distance = 55
						angle = 270
					}
					save_event_target_as = nanite_factory
				}
			}
			every_country = {
				establish_communications_no_message = event_target:graygoo_country
			}
			create_fleet = {
				name = "NAME_Tempest_Fleet"
				effect = {
					set_owner = event_target:graygoo_country
					rg_create_graygoo_ships_1 = yes
					set_formation_scale = 2
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 250
					set_location = {
						target = event_target:nanite_factory
						distance = 80
						angle = 0
					}
				}
				settings = {
					garrison = yes
				}
			}
			create_fleet = {
				name = "NAME_Tempest_Fleet"
				effect = {
					set_owner = event_target:graygoo_country
					rg_create_graygoo_ships_1 = yes
					set_formation_scale = 2
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 250
					set_location = {
						target = event_target:nanite_factory
						distance = 80
						angle = 90
					}
				}
				settings = {
					garrison = yes
				}
			}
			create_fleet = {
				name = "NAME_Tempest_Fleet"
				effect = {
					set_owner = event_target:graygoo_country
					rg_create_graygoo_ships_1 = yes
					set_formation_scale = 2
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 250
					set_location = {
						target = event_target:nanite_factory
						distance = 80
						angle = 180
					}
				}
				settings = {
					garrison = yes
				}
			}
			create_fleet = {
				name = "NAME_Tempest_Fleet"
				effect = {
					set_owner = event_target:graygoo_country
					rg_create_graygoo_ships_1 = yes
					set_formation_scale = 2
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 250
					set_location = {
						target = event_target:nanite_factory
						distance = 80
						angle = 270
					}
				}
				settings = {
					garrison = yes
				}
			}
			every_system = {
				limit = {
					has_star_flag = lgate
				}
				system_event = {
					id = rg_storms.1
				}
			}
			every_system = {
				limit = {
					has_star_flag = lcluster
				}
				every_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					create_fleet = {
						name = "NAME_Tempest_Fleet"
						effect = {
							set_owner = event_target:graygoo_country
							rg_create_graygoo_ships_1 = yes
							set_formation_scale = 2
							set_fleet_stance = aggressive
							set_aggro_range_measure_from = self
							set_aggro_range = 250
							set_location = {
								target = prev
								distance = 15
								angle = random
							}
						}
						settings = {
							garrison = yes
						}
					}
				}
			}
			event_target:lcluster1 = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_1
				}
			}
			event_target:lcluster2 = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_2
				}
			}
			event_target:lcluster3 = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_3
				}
			}
			event_target:lcluster4 = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_4
				}
			}
			event_target:lcluster5 = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_5
				}
			}
			event_target:lcluster1b = {
				random_system_planet = {
					limit = {
						is_planet_class = pc_gray_goo
					}
					save_event_target_as = start_6
				}
			}
			rg_create_graygoo_roamers_1 = yes
			rg_create_graygoo_roamers_2 = yes
			rg_create_graygoo_roamers_3 = yes
			rg_create_graygoo_roamers_4 = yes
			rg_create_graygoo_roamers_5 = yes
			rg_create_graygoo_roamers_6 = yes
			rg_create_graygoo_roamers_7 = yes
		}
		event_target:graygoo_country = {
			country_event = {
				id = graygoo.3
				days = 3600
			}
		}
		every_megastructure = {
			limit = {
				is_megastructure_type = lgate_base
				solar_system = {
					NOR = {
						has_star_flag = lcluster_lgate
						has_star_flag = lgate_originating_system
					}
				}
			}
			create_fleet = {
				name = "NAME_Tempest_Fleet"
				effect = {
					set_owner = event_target:graygoo_country
					rg_create_graygoo_ships_1 = yes
					set_formation_scale = 2
					set_fleet_stance = aggressive
					set_aggro_range_measure_from = self
					set_aggro_range = 250
					set_location = {
						target = prev
						distance = 0
						angle = 0
					}
				}
			}
		}
		set_update_modifiers_batch = end
		country_event = {
			id = graygoo.10
		}
		every_playable_country = {
			limit = {
				NOR = {
					has_event_chain = l_cluster_chain
					has_special_project = RG_LCLUSTER_PROJECT
					is_same_value = root
				}
			}
			country_event = {
				id = graygoo.13
			}
		}
		every_playable_country = {
			limit = {
				OR = {
					has_event_chain = l_cluster_chain
					has_special_project = RG_LCLUSTER_PROJECT
				}
				NOT = {
					is_same_value = root
				}
			}
			country_event = {
				id = graygoo.11
			}
		}
		observer_event = {
			id = observer.64
		}
	}
}

# Reinforcements 1
country_event = {
	id = graygoo.3
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		event_target:graygoo_factory_system = {
			any_fleet_in_system = {
				is_ship_size = graygoo_factory
			}
		}
	}
	immediate = {
		if = {
			limit = {
				any_system = {
					has_star_flag = lcluster
					any_fleet_in_system = {
						owner = {
							NOT = {
								is_same_value = root
							}
						}
					}
				}
			}
			# Reinforce at factory if someone else is in the cluster...
			country_event = {
				id = graygoo.4
			}
			# Else spawn reinforcements...
		}
		else = {
			every_megastructure = {
				limit = {
					is_megastructure_type = lgate_base
					solar_system = {
						NOR = {
							has_star_flag = lcluster_lgate
							has_star_flag = lgate_originating_system
						}
					}
				}
				create_ambient_object = {
					type = "horror_spawn_object"
					location = THIS
					use_3d_location = yes
					duration = 10
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_1 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_2 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_3 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_4 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_5 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_6 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
				create_fleet = {
					name = "NAME_Tempest_Fleet"
					effect = {
						set_owner = event_target:graygoo_country
						rg_create_graygoo_roamers_7 = yes
						set_formation_scale = 2
						set_fleet_stance = aggressive
						set_aggro_range_measure_from = self
						set_aggro_range = 250
						set_location = {
							target = prev
							distance = 0
							angle = 0
						}
					}
				}
			}
			country_event = {
				id = graygoo.3
				days = 3600
			}
		}
	}
}

# Reinforcements 2
country_event = {
	id = graygoo.4
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		random_owned_ship = {
			limit = {
				is_ship_size = graygoo_factory
			}
			save_event_target_as = graygoo_factory
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_1 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_2 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_3 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_4 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_5 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_6 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		create_fleet = {
			name = "NAME_Tempest_Fleet"
			effect = {
				set_owner = event_target:graygoo_country
				rg_create_graygoo_roamers_7 = yes
				set_formation_scale = 2
				set_fleet_stance = aggressive
				set_aggro_range_measure_from = self
				set_aggro_range = 250
				set_location = {
					target = event_target:graygoo_factory
					distance = 0
					angle = 0
				}
			}
		}
		country_event = {
			id = graygoo.3
			days = 3600
		}
	}
}

# Factory Destroyed
country_event = {
	id = graygoo.6
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		is_country_type = gray_goo
		fromfrom = {
			is_ship_size = graygoo_factory
		}
	}
	immediate = {
		remove_global_flag = active_gray_goo
		remove_global_flag = gray_goo_crisis_active
		fromfromfrom = {
			save_event_target_as = goo_slayer_ship
		}
		from = {
			save_event_target_as = goo_slayer
			country_event = {
				id = graygoo.15
			}
			country_event = {
				id = rg_event.200
				days = 80
				random = 120
			}
		}
		every_playable_country = {
			limit = {
				is_ai = no
				NOT = {
					is_same_value = event_target:goo_slayer
				}
			}
			country_event = {
				id = graygoo.16
			}
		}
		observer_event = {
			id = observer.65
		}
		every_galaxy_planet = {
			limit = {
				is_planet_class = pc_gray_goo
			}
			add_modifier = {
				modifier = "terraforming_candidate"
				days = -1
			}
		}
		every_owned_fleet = {
			destroy_fleet = this
		}
		destroy_country = yes
	}
}

# The Dessanu Consonance
country_event = {
	id = graygoo.110
	title = "distar.10951.name"
	desc = "graygoo.110.desc"
	picture = GFX_evt_l-gateway
	show_sound = event_radio_chatter
	is_triggered_only = yes
	after = {
		hidden_effect = {
			every_playable_country = {
				limit = {
					OR = {
						has_special_project = RG_LCLUSTER_PROJECT
						has_event_chain = l_cluster_chain
					}
					NOT = {
						is_same_value = root
					}
				}
				country_event = {
					id = graygoo.111
				}
			}
			every_playable_country = {
				limit = {
					NOR = {
						has_event_chain = l_cluster_chain
						has_special_project = RG_LCLUSTER_PROJECT
						is_same_value = root
					}
				}
				country_event = {
					id = graygoo.112
				}
			}
		}
	}
	option = {
		name = graygoo.10.a
		hidden_effect = {
			country_event = {
				id = graygoo.115
			}
		}
	}
}

# Factory Destroyed (Dessanu)
country_event = {
	id = graygoo.180
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		is_country_type = gate_builders
		fromfrom = {
			is_ship_size = graygoo_factory
		}
	}
	immediate = {
		fromfromfrom = {
			save_event_target_as = goo_slayer_ship
		}
		from = {
			save_event_target_as = goo_slayer
			country_event = {
				id = graygoo.181
			}
			country_event = {
				id = rg_event.200
				days = 80
				random = 120
			}
		}
		every_playable_country = {
			limit = {
				is_ai = no
				NOT = {
					is_same_value = event_target:goo_slayer
				}
			}
			country_event = {
				id = graygoo.182
			}
		}
		observer_event = {
			id = observer.67
		}
		every_owned_planet = {
			limit = {
				is_planet_class = pc_gaia
			}
			change_pc = pc_gray_goo
			reroll_planet = yes
			destroy_colony = yes
			add_modifier = {
				modifier = "terraforming_candidate"
				days = -1
			}
		}
		every_owned_fleet = {
			destroy_fleet = this
		}
		destroy_country = yes
	}
}

# Encountered Gray
ship_event = {
	id = graygoo.400
	title = "graygoo.400.name"
	trigger = {
		NOT = {
			any_playable_country = {
				has_country_flag = gray_owner
			}
		}
	}
	desc = {
		trigger = {
			owner = {
				is_synthetic_empire = no
			}
		}
		text = "graygoo.400.a.desc"
	}
	desc = {
		trigger = {
			owner = {
				is_synthetic_empire = yes
			}
		}
		text = "graygoo.400.b.desc"
	}
	picture = GFX_evt_ship_in_orbit_2
	show_sound = event_radio_chatter
	is_triggered_only = yes
	immediate = {
		from = {
			save_global_event_target_as = gray_homeworld
		}
		rg_timeline_attract_field_init = yes
	}
	option = {
		name = graygoo.400.a
		hidden_effect = {
			owner = {
				country_event = {
					id = graygoo.401
				}
			}
		}
	}
}

# Gray 1
country_event = {
	id = graygoo.401
	title = "TRANSMISSION"
	desc = {
		trigger = { is_machine_empire = no }
		text = "graygoo.401.a.desc"
	}
	desc = {
		trigger = { is_machine_empire = yes }
		text = "graygoo.401.b.desc"
	}
	is_triggered_only = yes
	diplomatic = yes

	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = "ethic_spaceship_room"
	}

	immediate = {
		rg_gray_country_init = yes		#创建国家
		rg_timeline_attract_field_init = yes
	}

	option = {
		name = graygoo.401.a
		trigger = {
			NOR = {
				is_machine_empire = yes
				is_hive_empire = yes
			}
		}
		hidden_effect = {
			country_event = { id = graygoo.402 }
		}
	}
	option = {
		name = graygoo.401.b
		trigger = {
			is_machine_empire = yes
		}
		hidden_effect = {
			country_event = { id = graygoo.402 }
		}
	}
	option = {
		name = graygoo.401.c
		trigger = {
			is_hive_empire = yes
		}
		hidden_effect = {
			country_event = { id = graygoo.402 }
		}
	}
}

# Gray 2
country_event = {
	id = graygoo.402
	title = "TRANSMISSION"
	desc = {
		trigger = { is_machine_empire = no }
		text = "graygoo.402.a.desc"
	}
	desc = {
		trigger = { is_machine_empire = yes }
		text = "graygoo.402.b.desc"
	}
	diplomatic = yes
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = "ethic_spaceship_room"
	}
	is_triggered_only = yes
	option = {
		name = graygoo.402.a
		hidden_effect = {
			country_event = { id = graygoo.403 }
		}
	}
}

# Gray 3
country_event = {
	id = graygoo.403
	title = "TRANSMISSION"
	desc = "graygoo.403.desc"
	diplomatic = yes
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = "ethic_spaceship_room"
	}
	is_triggered_only = yes
	option = {
		name = graygoo.403.a
		hidden_effect = {
			country_event = { id = graygoo.404 }
		}
	}
}

# Gray 4
country_event = {
	id = graygoo.404
	title = "TRANSMISSION"
	desc = "graygoo.404.desc"
	diplomatic = yes
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = "ethic_spaceship_room"
	}
	is_triggered_only = yes
	option = {
		name = graygoo.404.a
		hidden_effect = {
			country_event = { id = graygoo.405 }
		}
	}
}

# Gray 5
country_event = {
	id = graygoo.405
	title = "TRANSMISSION"
	desc = "graygoo.405.desc"
	diplomatic = yes
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = "ethic_spaceship_room"
	}
	is_triggered_only = yes
	option = {
		name = graygoo.405.a
		hidden_effect = {
			country_event = { id = graygoo.406 }
		}
	}
	option = {
		name = graygoo.405.b
		response_text = graygoo.405.b.response
	}
}


# Gray 6
country_event = {
	id = graygoo.406
	title = "TRANSMISSION"
	desc = "graygoo.406.desc"
	diplomatic = yes

	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		planet_background = event_target:gray_homeworld
		room = ship_room
	}
	event_window_type = leader_recruit

	is_triggered_only = yes

	option = {
		name = graygoo.406.a
		response_text = graygoo.406.a.response
		is_dialog_only = yes
	}
	option = {
		name = graygoo.406.b
		response_text = graygoo.406.b.response
		is_dialog_only = yes
	}
	option = {
		name = graygoo.405.b
		tag = dismiss_leader
		response_text = graygoo.405.b.response
		owner = {
			country_event = {
				id = rg_grayleader_dialog.4051
			}
		}
	}
	option = {
		name = graygoo.406.c
		response_text = graygoo.406.c.response
		default_hide_option = yes
		tag = hire_leader
		hidden_effect = {
			# create_message = {
			# 	type = MESSAGE_RECRUITED_LEADER
			# 	localization = MESSAGE_RECRUITED_LEADER_DESC
			# 	days = @toast_message_days
			# 	target = event_target:gray_governor
			# 	variable = {
			# 		type = name
			# 		localization = LEADER
			# 		scope = event_target:gray_governor
			# 	}
			# }
			owner = {
				country_event = {
					id = rg_grayleader_dialog.4063
				}
			}
			country_event = {
				id = graygoo.499
			}
		}
	}
}

# Create Gray
country_event = {
	id = graygoo.499
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		NOT = {
			exists = event_target:gray_owner
		}
		is_ai = no
	}
	immediate = {
		if = {
			# 非正常触发补事件
			limit = {
				NOT = {
					exists = event_target:rg_gray_country
				}
			}
			rg_gray_country_init = yes			#创建国家
		}
		rg_gray_country_after_init = yes
		set_country_flag = machine_age_nanites_studied
		create_message = {
			type = MESSAGE_TYPE_RG_GRAY_GOO_LEADER_CHAT
			localization = "rg_event.2.desc"
			days = @toast_message_days
			target = event_target:rg_gray_country_leader
			variable = {
				type = name
				localization = LEADER
				scope = event_target:rg_gray_country_leader
			}
		}
	}
}

# Main Menu (Initial)
country_event = {
	id = graygoo.500
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		is_same_value = event_target:gray_owner
		NOR = {
			RG_gray_scientist_active_trigger = yes
			RG_gray_official_active_trigger = yes
			RG_gray_warship_active_trigger = yes
			RG_gray_army_active_trigger = yes
			RG_gray_not_avaliable_trigger = yes
		}
	}
	immediate = {
		country_event = {
			id = rg_grayleader.500
		}
	}
}

# Main Menu (Governor)
country_event = {
	id = graygoo.501
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		is_same_value = event_target:gray_owner
		RG_gray_official_active_trigger = yes
		NOR = {
			RG_gray_not_avaliable_trigger = yes
		}
		exists = event_target:gray_governor
	}
	immediate = {
		country_event = {
			id = rg_grayleader.501
		}
	}
}

# Main Menu (Warship)
country_event = {
	id = graygoo.502
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		is_same_value = event_target:gray_owner
		RG_gray_warship_active_trigger = yes
		NOR = {
			RG_gray_not_avaliable_trigger = yes
		}
		exists = event_target:gray_warship
		any_owned_fleet = {
			is_same_value = event_target:gray_warship
		}
		event_target:gray_warship = {
			num_ships > 0
		}
	}
	immediate = {
		country_event = {
			id = rg_grayleader.502
		}
	}
}

# Main Menu (Army)
country_event = {
	id = graygoo.503
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		RG_gray_army_active_trigger = yes
		NOR = {
			RG_gray_not_avaliable_trigger = yes
		}
		is_same_value = event_target:gray_owner
		any_owned_army = {
			army_type = gray_army
			OR = {
				exists = planet
				AND = {
					exists = fleet
					fleet = {
						num_ships > 0
					}
				}
			}
		}
	}
	immediate = {
		country_event = {
			id = rg_grayleader.503
		}
	}
}

# Main Menu (Gray Reforming)
country_event = {
	id = graygoo.504
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		is_same_value = event_target:gray_owner
		RG_gray_is_reforming_trigger = yes
	}
	immediate = {
		country_event = {
			id = rg_grayleader.504
		}
	}
}

# Main Menu (const)
country_event = {
	id = graygoo.505
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		from = {
			OR = {
				is_country_type = gray
				is_same_value = ROOT
			}
		}
		is_same_value = event_target:gray_owner
		RG_gray_scientist_active_trigger = yes
		NOR = {
			RG_gray_not_avaliable_trigger = yes
		}
		exists = event_target:global_gray_constship
		any_owned_fleet = {
			is_same_value = event_target:global_gray_constship
		}
		event_target:global_gray_constship = {
			num_ships > 0
		}
	}
	immediate = {
		country_event = {
			id = rg_grayleader.505
		}
	}
}

# Gray destroyed or disbanded
event = {
	id = graygoo.510
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		any_country = {
			is_country_type = gray
		}
		exists = event_target:gray_owner
		event_target:gray_owner = {
			OR = {
				AND = {
					RG_gray_army_active_trigger = yes
					NOT = {
						any_owned_army = {
							army_type = gray_army
						}
					}
				}
				AND = {
					RG_gray_warship_active_trigger = yes
					NOT = {
						exists = event_target:gray_warship
					}
				}
				AND = {
					has_country_flag = gray_official_active
					NOT = {
						exists = event_target:gray_official
					}
				}
				AND = {
					RG_gray_scientist_active_trigger = yes
					NOT = {
						exists = event_target:global_gray_constship
					}
				}
			}
		}
	}
	immediate = {
		event_target:gray_owner = {
			remove_country_flag = gray_official_active			#新版flag
			remove_country_flag = gray_governor_active			#旧版flag	#总督
			remove_country_flag = gray_warship_active			#旗舰
			remove_country_flag = gray_army_active			#陆军
			remove_country_flag = gray_constship_active			#科舰
			set_country_flag = gray_reforming
			add_modifier = {
				modifier = "gray_scattered"
				days = 3600
			}
			country_event = {
				id = graygoo.511
			}
			country_event = {
				id = graygoo.512
				days = 3600
			}
		}
	}
}

# Gray regenerating
country_event = {
	id = graygoo.511
	title = "graygoo.511.name"
	desc = "graygoo.511.desc"
	picture = GFX_evt_circuitry_modification
	show_sound = event_radio_chatter

	is_triggered_only = yes

	option = {
		name = graygoo.511.a
	}
}

# Gray Returns
country_event = {
	id = graygoo.512
	title = "graygoo.500.title"
	desc = "graygoo.512.a.desc"
	desc = "graygoo.512.b.desc"
	desc = "graygoo.512.c.desc"
	event_window_type = leader_story
	picture = GFX_evt_gray_gooed_planet
	picture_event_data = {
		portrait = event_target:rg_gray_country_leader
		room = root
	}
	is_triggered_only = yes
	immediate = {
		remove_country_flag = gray_reforming
	}
	option = {
		name = graygoo.512.a
	}
}

# Entering Empty Cluster
ship_event = {
	id = graygoo.550
	title = "graygoo.550.name"
	desc = "graygoo.550.desc"
	picture = GFX_evt_ruined_system
	show_sound = event_radio_chatter
	is_triggered_only = yes
	trigger = {
		NOR = {
			has_global_flag = gray_goo_crisis_set
			has_global_flag = dragon_season
			has_global_flag = gray_goo_empire_set
			has_global_flag = rg_l_cluster
		}
		from = {
			has_star_flag = lcluster1
		}
		owner = {
			NOT = {
				has_country_flag = origin_gray_country
			}
		}
	}
	option = {
		name = graygoo.550.a
	}
}