namespace = giga_mega

country_event = { #It splits lol
	id = giga_mega.711
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		fromfrom = {
			OR = {
				is_ship_size = giga_systemcraft
				is_ship_size = giga_o_systemcraft
			}

		}
	}

	immediate = {
		subtract_variable = {
			which = giga_current_systemcraft
			value = 1
		}
		subtract_variable = {
			which = giga_current_systemcraft_finished
			value = 1
		}
		if = {
			limit = {
				check_variable = {
					which = giga_current_systemcraft_finished
					value = 0
				}
				NOT = {
					any_owned_megastructure = {
						OR = {
							is_megastructure_type = nicoll_beam_cooldown
							is_megastructure_type = nicoll_beam_menu
							is_megastructure_type = nicoll_beam_ready
							is_megastructure_type = nicoll_beam_firing
							is_megastructure_type = quasi_stellar_obliterator_5
							is_megastructure_type = quasi_stellar_obliterator_6
							is_megastructure_type = quasi_stellar_obliterator_firing_1
						}
					}
				}
			}
			remove_country_flag = giga_has_active_hyperweapon
		}
		create_message = {
			type = WAR_SYSTEM_DESTROYED
			localization = MESSAGE_WAR_SYSTEM_DESTROYED_DESC
			days = 30
			target = fromfrom
			variable = {
				type = name
				localization = ENEMY_NAME
				scope = from
			}
			variable = {
				type = name
				localization = CELESTIAL_WARSHIP_NAME
				scope = fromfrom
			}
			variable = {
				type = name
				localization = SYSTEM_NAME
				scope = fromfrom.solar_system
			}
		}
		fromfrom = {
			solar_system = {
				save_event_target_as = giga_debris_system
				create_ambient_object = {
					type = systemcraft_death_explosion_effect
					location = ROOT.fromfrom
					duration = 30
					use_3d_location = yes
					entity_offset = 0
					scale = 1
				}
				create_fleet = {
					name = "Systemcraft Remains"
					settings = {
						spawn_debris = no
						can_change_composition = yes
                        is_boss = no
					}
					effect = {
						set_owner = ROOT
						while = {
							count = 4
							create_ship = {
								name = "Behemoth Planetcraft"
								graphical_culture = ROOT
								random_existing_design = giga_planet_behemoth
								effect = {
									set_ship_flag = giga_planet
									reduce_hp = 3000000
								}
							}
						}
						while = {
							count = 5
							create_ship = {
								name = "Attack Moon"
								random_existing_design = giga_war_moon
								effect = {
									reduce_hp = 150000
								}
							}
						}
						set_formation_scale = 12
						set_location = {
							target = ROOT.fromfrom
							distance = 0
							angle = 0
						}
					}
				}
			}
			event_target:giga_temp_planet = { remove_planet = yes }
		}
	}
}
