namespace = lazy_con_meg_events

fleet_event = {
	id = lazy_con_meg_events.1
	title = "lazy_con_meg_events.1.name"
	desc = "lazy_con_meg_events.1.desc"
	picture = GFX_evt_machine_sapience
	hide_window = no

	is_triggered_only = yes
	
	option = { 
		name = "lazy_con_meg_events.1.b"
		allow = {
			root.owner = {
				has_technology = tech_hyper_relays
			}
			hidden_trigger = {
				NOT = {
					has_fleet_flag = auto_construct_hyper_relays_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_hyper_relays_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.2
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.c"
		allow = {
			root.owner = {
				has_technology = tech_gateway_construction
			}
			hidden_trigger = {
				NOT = {
					has_fleet_flag = auto_construct_gateway_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_gateway_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.3
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.d"
		allow = {
			hidden_trigger = {
				root.owner = {
					OR = {
						has_technology = tech_habitat_1
						has_civic = civic_diadochi
						has_civic = civic_great_khans_legacy
						has_country_flag = democratic_khanate_flag
					}
				}
				NOT = {
					has_fleet_flag = auto_construct_habitat_central_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_habitat_central_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.4
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	# option = { 
	# 	name = "lazy_con_meg_events.1.e"
	# 	allow = {
	# 		hidden_trigger = {
	# 			always = no
	# 			root.owner = {
	# 				OR = {
	# 					has_technology = tech_habitat_1
	# 					has_civic = civic_diadochi
	# 					has_civic = civic_great_khans_legacy
	# 					has_country_flag = democratic_khanate_flag
	# 				}
	# 			}
	# 			NOT = {
	# 				has_fleet_flag = auto_construct_major_orbital_flag
	# 			}
	# 		}
	# 	}
	# 	hidden_effect = {
	# 		reset_and_set_mega_fleet_flag = {
	# 			FLAG = auto_construct_major_orbital_flag
	# 		}

	# 		fleet_event = {
	# 			id = lazy_con_meg_events.5
	# 		}
	# 		fleet_event = {
	# 			id = lazy_con_meg_events.1
	# 		}
	# 	}
	# }

	# option = { 
	# 	name = "lazy_con_meg_events.1.f"
	# 	allow = {
	# 		hidden_trigger = {
	# 			always = no
	# 			root.owner = {
	# 				OR = {
	# 					has_technology = tech_habitat_1
	# 					has_civic = civic_diadochi
	# 					has_civic = civic_great_khans_legacy
	# 					has_country_flag = democratic_khanate_flag
	# 				}
	# 			}
	# 			NOT = {
	# 				has_fleet_flag = auto_construct_minor_orbital_flag
	# 			}
	# 		}
	# 	}
	# 	hidden_effect = {
	# 		reset_and_set_mega_fleet_flag = {
	# 			FLAG = auto_construct_minor_orbital_flag
	# 		}

	# 		fleet_event = {
	# 			id = lazy_con_meg_events.6
	# 		}
	# 		fleet_event = {
	# 			id = lazy_con_meg_events.1
	# 		}
	# 	}
	# }

	option = { 
		name = "lazy_con_meg_events.1.g"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					giga_has_frameworld_origin = yes
				}
				NOT = {
					has_fleet_flag = auto_construct_frameworld_outpost_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_frameworld_outpost_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.5
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.h"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					giga_has_frameworld_origin = yes
				}
				NOT = {
					has_fleet_flag = auto_construct_frameworld_harvest_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_frameworld_harvest_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.6
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.i"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = tech_habitat_1
					giga_has_frameworld_origin = yes
				}
				NOT = {
					has_fleet_flag = auto_construct_frameworld_salvage_habitat_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_frameworld_salvage_habitat_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.7
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.j"
		allow = {
			root.owner = {
				has_technology = tech_orbital_ring_tier_1
			}
			hidden_trigger = {
				NOT = {
					has_fleet_flag = auto_construct_orbital_ring_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_orbital_ring_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.8
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.k"
		allow = {
			root.owner = {
				has_technology = tech_dyson_swarm
			}
			hidden_trigger = {
				root.owner = {
					has_machine_age_dlc = yes
				}
				NOT = {
					has_fleet_flag = auto_construct_dyson_swarm_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_dyson_swarm_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.9
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.l"
		allow = {
			root.owner = {
				has_technology = tech_orbital_arc_furnace
			}
			hidden_trigger = {
				NOT = {
					has_fleet_flag = auto_construct_arc_furnace_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_arc_furnace_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.10
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.m"
		allow = {
			root.owner = {
				has_technology = tech_deep_space_citadel
			}
			hidden_trigger = {
				NOT = {
					has_fleet_flag = auto_construct_deep_space_citadel_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_deep_space_citadel_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.11
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.n"
		trigger = {
			root.owner = {
				OR = {
					has_civic = civic_SRARociviaEmpire
					has_civic = civic_SRAtechnology
				}
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = tech_SRA_starbase_turret
				}
				NOT = {
					has_fleet_flag = auto_construct_sra_orbital_ring_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_sra_orbital_ring_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.12
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = {
		name = "lazy_con_meg_events.1.o"
		trigger = {
			root.owner = {
				OR = {
					has_civic = civic_SRARociviaEmpire
					has_civic = civic_SRAtechnology
				}
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = tech_SRA_Barrier_megastructure_0
				}
				NOT = {
					has_fleet_flag = auto_construct_sra_barrier_guard_station_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_sra_barrier_guard_station_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.13
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.p"
		trigger = {
			root.owner = {
				OR = {
					has_civic = civic_SRARociviaEmpire
					has_civic = civic_SRAtechnology
				}
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = tech_SRA_T4_ship_Part
				}
				NOT = {
					has_fleet_flag = auto_construct_sra_gz_platform_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_sra_gz_platform_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.14
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.q"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = giga_tech_planetary_computer
					NOT = { has_global_flag = planetary_computer_disabled }
					OR = {
						has_global_flag = planetary_computer_capped_u
						check_variable = {
							which = giga_current_planetary_computer
							value < value:giga_planetary_computer_limit
						}
					}
				}
				NOT = {
					has_fleet_flag = auto_construct_planetary_computer_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_planetary_computer_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.15
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.r"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					OR = {
						has_technology = giga_tech_terraform_molten
						has_technology = giga_tech_terraform_barren
						has_technology = giga_tech_terraform_toxic
					}
					NAND = {
						has_global_flag = geothermal_disabled
						has_global_flag = terraform_barren_disabled
						has_global_flag = terraform_toxic_disabled
					}
					OR = {
						OR = {
							has_global_flag = geothermal_capped_u
							check_variable = {
								which = giga_current_geothermal
								value < value:giga_geothermal_limit
							}
						}
						OR = {
							has_global_flag = terraform_toxic_capped_u
							check_variable = {
								which = giga_current_terraform_toxic
								value < value:giga_terraform_toxic_limit
							}
						}
						OR = {
							has_global_flag = terraform_barren_capped_u
							check_variable = {
								which = giga_current_terraform_barren
								value < value:giga_terraform_barren_limit
							}
						}
					}
				}
				NOT = {
					has_fleet_flag = auto_construct_terraform_site_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_terraform_site_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.16
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "lazy_con_meg_events.1.s"
		trigger = {
			hidden_trigger = {
				has_global_flag = giga_game_started
			}
		}
		allow = {
			hidden_trigger = {
				root.owner = {
					has_technology = giga_tech_asteroid_manufactory
					NOT = { has_global_flag = asteroid_manufactory_disabled }
					OR = {
						has_global_flag = asteroid_manufactory_capped_u
						check_variable = {
							which = giga_current_asteroid_manufactory
							value < value:giga_asteroid_manufactory_limit
						}
					}
				}
				NOT = {
					has_fleet_flag = auto_construct_asteroid_manufactory_flag
				}
			}
		}
		hidden_effect = {
			reset_and_set_mega_fleet_flag = {
				FLAG = auto_construct_asteroid_manufactory_flag
			}

			fleet_event = {
				id = lazy_con_meg_events.17
			}
			fleet_event = {
				id = lazy_con_meg_events.1
			}
		}
	}

	option = { 
		name = "EXIT"
	}
}

fleet_event = {
	id = lazy_con_meg_events.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_hyper_relays_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_hyper_relay_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.2.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_hyper_relay_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.2.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.2.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
									}
									auto_construct_hyper_relay_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								effect = {
									id = lazy_con_meg_events.2.effect.2
									prev = {
										spawn_megastructure = {
											type = constructing_og_megastructure
											owner = root.owner
											random_pos = yes
											# orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												prev = {
													spawn_planet = {
														class = pc_asteroid
														
														size = 1
														location = prev
														init_effect = {
															set_name = "The Magic Rock (made of stardust and my tears)"
															set_carrier_flag = auto_construct_planet_pos_flag
															set_carrier_flag = auto_construct_hyper_relay_planet_flag
															clear_deposits = yes
														}
													}
												}
												delete_megastructure = this
											}
										}
									}
								}
								find_closest_planet = {
									trigger = {
										id = lazy_con_meg_events.2.trigger.3
										has_carrier_flag = auto_construct_hyper_relay_planet_flag
										NOT = {
											has_carrier_flag = auto_construct_planet_flag
										}
									}
									found_planet = {
										orbit_planet = this
										effect = {
											id = lazy_con_meg_events.2.effect.3
											if = {
												limit = {
													auto_construct_checks = {
														FLEET = root
														BLOCK_PLANET = this
													}
												}
												auto_construct_mega_setup = {
													FLEET = root
													BUILD_TIME = @auto_construct_mega_hyper_relay_time
													EVENT = lazy_con_meg_events.201
												}
												prevprev = {
													spawn_megastructure = {
														type = constructing_og_megastructure
														owner = root.owner
														coords_from = prev
														# orbit_angle = 360
														graphical_culture = root.owner
			
														init_effect = {
															set_megastructure_flag = constructing_mega_with_@root
														}
													}
												}
											}
										}
									}
									failed = {
										effect = {
											id = lazy_con_meg_events.2.effect.4
											root = {
												fleet_event = {
													id = lazy_con_meg_events.2
													days = 1
												}
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.2.effect.5
									root = {
										fleet_event = {
											id = lazy_con_meg_events.2
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.2.effect.6
							root = {
								fleet_event = {
									id = lazy_con_meg_events.2
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.201
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_hyper_relay_check = {
						CHECK_SYSTEM = solar_system
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 25
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = rare_crystals
							value >= 100
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = hyper_relay
						owner = prev.owner
						coords_from = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						influence = 25
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						rare_crystals = 100
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.201
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.3
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_gateway_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_gateway_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.3.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_gateway_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.3.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.3.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
									}
									auto_construct_gateway_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								effect = {
									id = lazy_con_meg_events.3.effect.2
									prev = {
										spawn_megastructure = {
											type = constructing_og_megastructure
											owner = root.owner
											random_pos = yes
											orbit_angle = 180
											graphical_culture = root.owner

											init_effect = {
												prev = {
													spawn_planet = {
														class = pc_asteroid
														
														size = 1
														location = prev
														init_effect = {
															set_name = "The Magic Rock (made of stardust and my tears)"
															set_carrier_flag = auto_construct_planet_pos_flag
															set_carrier_flag = auto_construct_gateway_planet_flag
															clear_deposits = yes
														}
													}
												}
												delete_megastructure = this
											}
										}
									}
								}
								find_closest_planet = {
									trigger = {
										id = lazy_con_meg_events.3.trigger.3
										has_carrier_flag = auto_construct_gateway_planet_flag
										NOT = {
											has_carrier_flag = auto_construct_planet_flag
										}
									}
									found_planet = {
										orbit_planet = this
										effect = {
											id = lazy_con_meg_events.3.effect.3
											if = {
												limit = {
													auto_construct_checks = {
														FLEET = root
														BLOCK_PLANET = this
													}
												}
												if = {
													limit = {
														has_global_flag = giga_game_started
													}
													auto_construct_mega_setup = {
														FLEET = root
														BUILD_TIME = @auto_construct_mega_giga_gateway_time
														EVENT = lazy_con_meg_events.301
													}
												}
												else = {
													auto_construct_mega_setup = {
														FLEET = root
														BUILD_TIME = @auto_construct_mega_gateway_time
														EVENT = lazy_con_meg_events.301
													}
												}
												prevprev = {
													spawn_megastructure = {
														type = constructing_og_megastructure
														owner = root.owner
														coords_from = prev
														orbit_angle = 180
														graphical_culture = root.owner
			
														init_effect = {
															set_megastructure_flag = constructing_mega_with_@root
														}
													}
												}
											}
										}
									}
									failed = {
										effect = {
											id = lazy_con_meg_events.3.effect.4
											root = {
												fleet_event = {
													id = lazy_con_meg_events.3
													days = 1
												}
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.3.effect.5
									root = {
										fleet_event = {
											id = lazy_con_meg_events.3
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.3.effect.6
							root = {
								fleet_event = {
									id = lazy_con_meg_events.3
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.301
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_gateway_check = {
						CHECK_SYSTEM = solar_system
					}
					owner = {
						if = {
							limit = {
								has_global_flag = giga_game_started
							}
							resource_stockpile_compare = {
								resource = influence
								value >= 75
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 5000
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = energy
								value >= 6000
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
						else = {
							resource_stockpile_compare = {
								resource = influence
								value >= 75
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 2500
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
					}
				}
				solar_system = {
					if = {
						limit = {
							prev.owner = {
								has_global_flag = giga_game_started
							}
						}
						spawn_megastructure = {
							type = gateway_final
							owner = prev.owner
							coords_from = prevprev
							graphical_culture = prev.owner
						}
					}
					else = {
						spawn_megastructure = {
							type = gateway_0
							owner = prev.owner
							coords_from = prevprev
							graphical_culture = prev.owner
						}
					}
				}
				owner = {
					if = {
						limit = {
							has_global_flag = giga_game_started
						}
						add_resource = {
							influence = 75
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							alloys = 5000
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							alloys = 6000
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
					else = {
						add_resource = {
							influence = 75
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							alloys = 2500
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.301
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.4
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_habitat_central_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_central_habitat_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.4.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_habitat_central_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.4.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.4.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_habitat_central_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.4.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_habitat_central_time
										EVENT = lazy_con_meg_events.401
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.4.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.4
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.4.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.4
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.401
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_habitat_central_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 200
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 1500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = habitat_central_complex
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						influence = 200
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 1500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.401
						days = 10
					}
				}
			}
		}
	}
}

# fleet_event = {
# 	id = lazy_con_meg_events.5
# 	hide_window = yes
# 	is_triggered_only = yes

# 	trigger = {
# 		has_fleet_flag = auto_mega_ship_flag
# 		has_fleet_flag = auto_construct_major_orbital_flag
# 	}

# 	immediate = {
# 		clear_fleet_actions = this
# 		clear_orders = yes
# 		set_name = "Auto Major Orbital Ship"
#
# 		queue_actions = {
# 			repeat = {
# 				find_closest_system = {
# 					trigger = {
# 						id = lazy_con_meg_events.5.trigger.1
# 						# root = {
# 						# 	NOR = {
# 						# 		has_fleet_order = build_orbital_station_order
# 						# 		has_fleet_order = evade_hostiles_order
# 						# 		has_fleet_order = build_megastructure_fleet_order
# 						# 		has_fleet_order = collect_data_fleet_order
# 						# 		has_fleet_order = orbit_planet_order
# 						# 		has_fleet_order = return_fleet_order
# 						# 		has_fleet_order = auto_patrol_order
# 						# 		has_fleet_order = repair_fleet_order
# 						# 		has_fleet_order = use_bypass_order
# 						# 		has_fleet_order = jumpdrive_order
# 						# 		has_fleet_order = jumpdrive_windup
# 						# 		has_fleet_order = follow_order
# 						# 		has_fleet_order = move_to_system_point_order	
# 						# 	}
# 						# }
# 						exists = starbase
# 						is_inside_border = root.owner
# 						any_system_planet = {
# 							has_planet_flag = habitat
# 						}
# 						NOT = {
# 							any_ship_in_system = {
# 								exists = owner
# 								owner = {
# 									is_hostile = root.owner
# 								}
# 							}
# 						}
# 						any_system_planet = {
# 							NOT = {
# 								has_planet_flag = auto_construct_planet_flag
# 							}
# 							is_surveyed = {
# 								who = root.owner
# 								status = yes
# 							}
# 							NOT = { has_anomaly = yes }
# 							NOR = {
# 								has_planet_flag = megastructure
# 								has_planet_flag = has_megastructure
# 								solar_system = {
# 									OR = {
# 										has_star_flag = ring_world_built
# 										has_star_flag = ithomes_gate
# 									}
# 								}
# 								is_planet_class = pc_ringworld_habitable
# 								is_planet_class = pc_ringworld_habitable_damaged
# 								is_planet_class = pc_ringworld_tech
# 								is_planet_class = pc_ringworld_tech_damaged
# 								is_planet_class = pc_ringworld_seam
# 								is_planet_class = pc_ringworld_seam_damaged
# 								is_planet_class = pc_habitat
# 							}
# 							NOR = {
# 								has_planet_flag = has_orbital_debris
# 							}
# 							NOR = {
# 								is_asteroid = yes
# 								is_moon = yes
# 							}
# 							NOT = {
# 								solar_system = {
# 									has_star_flag = solarpunk_system_02
# 								}
# 							}
# 							NOT = {
# 								any_fleet_in_orbit = {
# 									is_constructing = habitat_major_orbital
# 								}
# 							}
# 						}
# 					}
# 					found_system = {
# 						move_to = this
# 						find_closest_planet = {
# 							trigger = {
# 								id = lazy_con_meg_events.5.trigger.2
# 								NOR = {
# 									any_fleet_in_orbit = {
# 										is_constructing = habitat_major_orbital
# 									}
# 									solar_system = {
# 										any_ship_in_system = {
# 											exists = owner
# 											owner = {
# 												is_hostile = root.owner
# 											}
# 										}
# 									}
# 									has_planet_flag = auto_construct_planet_flag
# 								}
# 								is_surveyed = {
# 									who = prev.from
# 									status = yes
# 								}
# 								NOT = { has_anomaly = yes }
# 								NOR = {
# 									has_planet_flag = megastructure
# 									has_planet_flag = has_megastructure
# 									solar_system = {
# 										OR = {
# 											has_star_flag = ring_world_built
# 											has_star_flag = ithomes_gate
# 										}
# 									}
# 									is_planet_class = pc_ringworld_habitable
# 									is_planet_class = pc_ringworld_habitable_damaged
# 									is_planet_class = pc_ringworld_tech
# 									is_planet_class = pc_ringworld_tech_damaged
# 									is_planet_class = pc_ringworld_seam
# 									is_planet_class = pc_ringworld_seam_damaged
# 									is_planet_class = pc_habitat
# 								}
# 								NOR = {
# 									has_planet_flag = has_orbital_debris
# 								}
# 								NOR = {
# 									is_asteroid = yes
# 									is_moon = yes
# 								}
# 								NOT = {
# 									solar_system = {
# 										has_star_flag = solarpunk_system_02
# 									}
# 								}
# 							}
# 							found_planet = {
# 								move_to = this
# 								effect = {
# 									id = lazy_con_meg_events.5.effect.1
# 									set_timed_planet_flag = {
# 										flag = auto_construct_planet_flag
# 										days = 720
# 									}
# 									root = {
# 										set_event_locked = yes
# 									}
# 									prev = {
# 										spawn_megastructure = {
# 											type = constructing_megastructure
# 											owner = root.owner
# 											planet = prev
# 											orbit_angle = 360
# 											graphical_culture = root.owner

# 											init_effect = {
# 												set_megastructure_flag = constructing_mega_with_@root
# 												prev = {
# 													system_event = {
# 														id = lazy_con_meg_events.11
# 														days = 720
# 													}
# 												}
# 											}
# 										}
# 									}
# 								}
# 								wait = 720
# 								effect = {
# 									id = lazy_con_meg_events.5.effect.2
# 									root = {
# 										set_event_locked = no
# 									}
# 									if = {
# 										limit = {
# 											is_surveyed = {
# 												who = prev.from
# 												status = yes
# 											}
# 											NOT = { has_anomaly = yes }
# 											NOR = {
# 												has_planet_flag = megastructure
# 												has_planet_flag = has_megastructure
# 												solar_system = {
# 													OR = {
# 														has_star_flag = ring_world_built
# 														has_star_flag = ithomes_gate
# 													}
# 												}
# 												is_planet_class = pc_ringworld_habitable
# 												is_planet_class = pc_ringworld_habitable_damaged
# 												is_planet_class = pc_ringworld_tech
# 												is_planet_class = pc_ringworld_tech_damaged
# 												is_planet_class = pc_ringworld_seam
# 												is_planet_class = pc_ringworld_seam_damaged
# 												is_planet_class = pc_habitat
# 											}
# 											NOR = {
# 												has_planet_flag = has_orbital_debris
# 											}
# 											NOR = {
# 												is_asteroid = yes
# 												is_moon = yes
# 											}
# 											NOT = {
# 												solar_system = {
# 													has_star_flag = solarpunk_system_02
# 												}
# 											}
# 											root.owner = {
# 												resource_stockpile_compare = {
# 													resource = alloys
# 													value >= 200
# 													mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
# 												}
# 											}
# 										}
# 										prev = {
# 											spawn_megastructure = {
# 												type = habitat_major_orbital
# 												owner = root.owner
# 												planet = prev
# 												graphical_culture = root.owner
# 											}
# 										}
# 										root.owner = {
# 											add_resource = {
# 												alloys = 200
# 												mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
# 											}
# 										}
# 										prev = {
# 											random_system_megastructure = {
# 												limit = {
# 													has_megastructure_flag = constructing_mega_with_@root
# 												}
# 												remove_megastructure = this
# 											}
# 										}
# 									}
# 									else = {
# 										prev = {
# 											random_system_megastructure = {
# 												limit = {
# 													has_megastructure_flag = constructing_mega_with_@root
# 												}
# 												remove_megastructure = this
# 											}
# 										}
# 									}

# 								}
# 							}
# 							failed = {
# 								effect = {
# 									id = lazy_con_meg_events.5.effect.3
# 									random_system_megastructure = {
# 										limit = {
# 											has_megastructure_flag = constructing_mega_with_@root
# 										}
# 										remove_megastructure = this
# 									}
# 									root = {
# 										fleet_event = {
# 											id = lazy_con_meg_events.5
# 											days = 1
# 										}
# 									}
# 								}
# 							}
# 						}
# 					}
# 					failed = {
# 						effect = {
# 							id = lazy_con_meg_events.5.effect.4
# 							root = {
# 								fleet_event = {
# 									id = lazy_con_meg_events.5
# 									days = 1
# 								}
# 							}
# 						}
# 					}
# 				}
# 			}
# 		}
# 	}
# }

# fleet_event = {
# 	id = lazy_con_meg_events.6
# 	hide_window = yes
# 	is_triggered_only = yes

# 	trigger = {
# 		has_fleet_flag = auto_mega_ship_flag
# 		has_fleet_flag = auto_construct_minor_orbital_flag
# 	}

# 	immediate = {
# 		clear_fleet_actions = this
# 		clear_orders = yes
# 		set_name = "Auto Minor Orbital Ship"
#
# 		queue_actions = {
# 			repeat = {
# 				find_closest_system = {
# 					trigger = {
# 						id = lazy_con_meg_events.6.trigger.1
# 						# root = {
# 						# 	NOR = {
# 						# 		has_fleet_order = build_orbital_station_order
# 						# 		has_fleet_order = evade_hostiles_order
# 						# 		has_fleet_order = build_megastructure_fleet_order
# 						# 		has_fleet_order = collect_data_fleet_order
# 						# 		has_fleet_order = orbit_planet_order
# 						# 		has_fleet_order = return_fleet_order
# 						# 		has_fleet_order = auto_patrol_order
# 						# 		has_fleet_order = repair_fleet_order
# 						# 		has_fleet_order = use_bypass_order
# 						# 		has_fleet_order = jumpdrive_order
# 						# 		has_fleet_order = jumpdrive_windup
# 						# 		has_fleet_order = follow_order
# 						# 		has_fleet_order = move_to_system_point_order	
# 						# 	}
# 						# }
# 						exists = starbase
# 						is_inside_border = root.owner
# 						any_system_planet = {
# 							has_planet_flag = habitat
# 						}
# 						NOT = {
# 							any_ship_in_system = {
# 								exists = owner
# 								owner = {
# 									is_hostile = root.owner
# 								}
# 							}
# 						}
# 						any_system_planet = {
# 							NOT = {
# 								has_planet_flag = auto_construct_planet_flag
# 							}
# 							is_surveyed = {
# 								who = root.owner
# 								status = yes
# 							}
# 							NOT = { has_anomaly = yes }
# 							NOR = {
# 								has_planet_flag = megastructure
# 								has_planet_flag = has_megastructure
# 								solar_system = {
# 									OR = {
# 										has_star_flag = ring_world_built
# 										has_star_flag = ithomes_gate
# 									}
# 								}
# 								is_planet_class = pc_ringworld_habitable
# 								is_planet_class = pc_ringworld_habitable_damaged
# 								is_planet_class = pc_ringworld_tech
# 								is_planet_class = pc_ringworld_tech_damaged
# 								is_planet_class = pc_ringworld_seam
# 								is_planet_class = pc_ringworld_seam_damaged
# 								is_planet_class = pc_habitat
# 							}
# 							NOR = {
# 								has_planet_flag = has_orbital_debris
# 							}
# 							OR = {
# 								is_asteroid = yes
# 								is_moon = yes
# 							}
# 							is_star = no
# 							NOT = {
# 								solar_system = {
# 									has_star_flag = solarpunk_system_02
# 								}
# 							}
# 							NOT = {
# 								any_fleet_in_orbit = {
# 									is_constructing = habitat_minor_orbital
# 								}
# 							}
# 						}
# 					}
# 					found_system = {
# 						move_to = this
# 						find_closest_planet = {
# 							trigger = {
# 								id = lazy_con_meg_events.6.trigger.2
# 								NOR = {
# 									any_fleet_in_orbit = {
# 										is_constructing = habitat_minor_orbital
# 									}
# 									solar_system = {
# 										any_ship_in_system = {
# 											exists = owner
# 											owner = {
# 												is_hostile = root.owner
# 											}
# 										}
# 									}
# 									has_planet_flag = auto_construct_planet_flag
# 								}
# 								is_surveyed = {
# 									who = root.owner
# 									status = yes
# 								}
# 								NOT = { has_anomaly = yes }
# 								NOR = {
# 									has_planet_flag = megastructure
# 									has_planet_flag = has_megastructure
# 									solar_system = {
# 										OR = {
# 											has_star_flag = ring_world_built
# 											has_star_flag = ithomes_gate
# 										}
# 									}
# 									is_planet_class = pc_ringworld_habitable
# 									is_planet_class = pc_ringworld_habitable_damaged
# 									is_planet_class = pc_ringworld_tech
# 									is_planet_class = pc_ringworld_tech_damaged
# 									is_planet_class = pc_ringworld_seam
# 									is_planet_class = pc_ringworld_seam_damaged
# 									is_planet_class = pc_habitat
# 								}
# 								NOR = {
# 									has_planet_flag = has_orbital_debris
# 								}
# 								OR = {
# 									is_asteroid = yes
# 									is_moon = yes
# 								}
# 								NOT = {
# 									solar_system = {
# 										has_star_flag = solarpunk_system_02
# 									}
# 								}
# 							}
# 							found_planet = {
# 								move_to = this
# 								effect = {
# 									id = lazy_con_meg_events.6.effect.1
# 									set_timed_planet_flag = {
# 										flag = auto_construct_planet_flag
# 										days = 180
# 									}
# 									root = {
# 										set_event_locked = yes
# 									}
# 									prev = {
# 										spawn_megastructure = {
# 											type = constructing_megastructure
# 											owner = root.owner
# 											planet = prev
# 											orbit_angle = 360
# 											graphical_culture = root.owner

# 											init_effect = {
# 												set_megastructure_flag = constructing_mega_with_@root
# 												prev = {
# 													system_event = {
# 														id = lazy_con_meg_events.11
# 														days = 180
# 													}
# 												}
# 											}
# 										}
# 									}
# 								}
# 								wait = 180
# 								effect = {
# 									id = lazy_con_meg_events.6.effect.2
# 									root = {
# 										set_event_locked = no
# 									}
# 									if = {
# 										limit = {
# 											is_surveyed = {
# 												who = prev.from
# 												status = yes
# 											}
# 											NOT = { has_anomaly = yes }
# 											NOR = {
# 												has_planet_flag = megastructure
# 												has_planet_flag = has_megastructure
# 												solar_system = {
# 													OR = {
# 														has_star_flag = ring_world_built
# 														has_star_flag = ithomes_gate
# 													}
# 												}
# 												is_planet_class = pc_ringworld_habitable
# 												is_planet_class = pc_ringworld_habitable_damaged
# 												is_planet_class = pc_ringworld_tech
# 												is_planet_class = pc_ringworld_tech_damaged
# 												is_planet_class = pc_ringworld_seam
# 												is_planet_class = pc_ringworld_seam_damaged
# 												is_planet_class = pc_habitat
# 											}
# 											NOR = {
# 												has_planet_flag = has_orbital_debris
# 											}
# 											OR = {
# 												is_asteroid = yes
# 												is_moon = yes
# 											}
# 											NOT = {
# 												solar_system = {
# 													has_star_flag = solarpunk_system_02
# 												}
# 											}
# 											root.owner = {
# 												resource_stockpile_compare = {
# 													resource = alloys
# 													value >= 50
# 													mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
# 												}
# 											}
# 										}
# 										prev = {
# 											spawn_megastructure = {
# 												type = habitat_minor_orbital
# 												owner = root.owner
# 												planet = prev
# 												graphical_culture = root.owner
# 											}
# 										}
# 										root.owner = {
# 											add_resource = {
# 												alloys = 50
# 												mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
# 											}
# 										}
# 										prev = {
# 											random_system_megastructure = {
# 												limit = {
# 													has_megastructure_flag = constructing_mega_with_@root
# 												}
# 												remove_megastructure = this
# 											}
# 										}
# 									}
# 									else = {
# 										prev = {
# 											random_system_megastructure = {
# 												limit = {
# 													has_megastructure_flag = constructing_mega_with_@root
# 												}
# 												remove_megastructure = this
# 											}
# 										}
# 									}

# 								}
# 							}
# 							failed = {
# 								effect = {
# 									id = lazy_con_meg_events.6.effect.3
# 									random_system_megastructure = {
# 										limit = {
# 											has_megastructure_flag = constructing_mega_with_@root
# 										}
# 										remove_megastructure = this
# 									}
# 									root = {
# 										fleet_event = {
# 											id = lazy_con_meg_events.6
# 											days = 1
# 										}
# 									}
# 								}
# 							}
# 						}
# 					}
# 					failed = {
# 						effect = {
# 							id = lazy_con_meg_events.6.effect.4
# 							root = {
# 								fleet_event = {
# 									id = lazy_con_meg_events.6
# 									days = 1
# 								}
# 							}
# 						}
# 					}
# 				}
# 			}
# 		}
# 	}
# }

fleet_event = {
	id = lazy_con_meg_events.5
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_frameworld_outpost_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_frameworld_outpost_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.5.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_frameworld_outpost_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.5.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.5.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_frameworld_outpost_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.5.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_frameworld_outpost_time
										EVENT = lazy_con_meg_events.501
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.5.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.5
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.5.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.5
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.501
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_frameworld_outpost_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						if = {
							limit = {
								is_gestalt = no
								is_lithoid_empire = no
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = food
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = consumer_goods
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = influence
								value >= 50
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
						else_if = {
							limit = {
								is_gestalt = no
								is_lithoid_empire = yes
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = minerals
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = consumer_goods
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = influence
								value >= 50
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
						else_if = {
							limit = {
								is_hive_empire = yes
								is_lithoid_empire = no
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = food
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = influence
								value >= 50
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
						else_if = {
							limit = {
								is_hive_empire = yes
								is_lithoid_empire = yes
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 200
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = minerals
								value >= 500
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
							resource_stockpile_compare = {
								resource = influence
								value >= 50
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
						else_if = {
							limit = {
								is_machine_empire = yes
							}
							resource_stockpile_compare = {
								resource = alloys
								value >= 400
								mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
							}
						}
					}
				}
				solar_system = {
					if = {
						limit = {
							prev.owner = {
								is_gestalt = no
								is_lithoid_empire = no
							}
						}
						spawn_megastructure = {
							type = frameworld_outpost_construction
							owner = prev.owner
							planet = prevprev
							graphical_culture = prev.owner
						}
					}
					else_if = {
						limit = {
							prev.owner = {
								is_gestalt = no
								is_lithoid_empire = yes
							}
						}
						spawn_megastructure = {
							type = frameworld_outpost_construction_lithoid
							owner = prev.owner
							planet = prevprev
							graphical_culture = prev.owner
						}
					}
					else_if = {
						limit = {
							prev.owner = {
								is_hive_empire = yes
								is_lithoid_empire = no
							}
						}
						spawn_megastructure = {
							type = frameworld_outpost_construction_hive
							owner = prev.owner
							planet = prevprev
							graphical_culture = prev.owner
						}
					}
					else_if = {
						limit = {
							prev.owner = {
								is_hive_empire = yes
								is_lithoid_empire = yes
							}
						}
						spawn_megastructure = {
							type = frameworld_outpost_construction_hive_lithoid
							owner = prev.owner
							planet = prevprev
							graphical_culture = prev.owner
						}
					}
					else_if = {
						limit = {
							prev.owner = {
								is_machine_empire = yes
							}
						}
						spawn_megastructure = {
							type = frameworld_outpost_construction_machine
							owner = prev.owner
							planet = prevprev
							graphical_culture = prev.owner
						}
					}
				}
				owner = {
					if = {
						limit = {
							is_gestalt = no
							is_lithoid_empire = no
						}
						add_resource = {
							alloys = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							food = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							consumer_goods = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							influence = 50
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
					else_if = {
						limit = {
							is_gestalt = no
							is_lithoid_empire = yes
						}
						add_resource = {
							alloys = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							minerals = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							consumer_goods = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							influence = 50
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
					else_if = {
						limit = {
							is_hive_empire = yes
							is_lithoid_empire = no
						}
						add_resource = {
							alloys = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							food = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							influence = 50
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
					else_if = {
						limit = {
							is_hive_empire = yes
							is_lithoid_empire = yes
						}
						add_resource = {
							alloys = 200
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							minerals = 500
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						add_resource = {
							influence = 50
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
					else_if = {
						limit = {
							is_machine_empire = yes
						}
						add_resource = {
							alloys = 400
							mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.501
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.6
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_frameworld_harvest_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_frameworld_asteroid_harvest_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.6.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_frameworld_harvest_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.6.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.6.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_frameworld_harvest_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.6.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_frameworld_harvest_time
										EVENT = lazy_con_meg_events.601
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.6.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.6
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.6.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.6
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.601
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_frameworld_harvest_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = energy
							value >= 1000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = influence
							value >= 25
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = frameworld_harvest_0
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						energy = 1000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						influence = 25
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.601
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.7
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_frameworld_salvage_habitat_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_frameworld_habitat_salvage_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.7.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_frameworld_salvage_habitat_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.7.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.7.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_frameworld_salvage_habitat_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.7.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_frameworld_habitat_salvage_time
										EVENT = lazy_con_meg_events.701
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.7.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.7
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.7.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.7
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.701
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_frameworld_salvage_habitat_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = energy
							value >= 2500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = influence
							value >= 50
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = frameworld_salvage_habitat_0
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						energy = 2500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						influence = 50
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.701
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.8
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_orbital_ring_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_orbital_ring_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.8.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_orbital_ring_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.8.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.8.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_orbital_ring_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.8.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_orbital_ring_time
										EVENT = lazy_con_meg_events.801
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.8.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.8
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.8.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.8
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.801
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_orbital_ring_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 50
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 1000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = orbital_ring
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						influence = 50
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 1000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.801
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.9
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_dyson_swarm_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_dyson_swarm_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.9.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_dyson_swarm_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.9.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.9.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_dyson_swarm_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.9.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_dyson_swarm_time
										EVENT = lazy_con_meg_events.901
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.9.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.9
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.9.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.9
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.901
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_dyson_swarm_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = alloys
							value >= 500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = unity
							value >= 1000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = dyson_swarm_1
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					if = {
						limit = {
							NOT = {
								has_global_flag = giga_game_started
							}
						}
						change_variable = {
							which = dyson_swarm_counter
							value = 1
						}
					}

					add_resource = {
						alloys = 500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						unity = 1000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.901
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.10
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_arc_furnace_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_arc_furnace_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.10.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_arc_furnace_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.10.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.10.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_arc_furnace_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.10.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_arc_furnace_time
										EVENT = lazy_con_meg_events.1001
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.10.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.10
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.10.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.10
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1001
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_arc_furnace_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = alloys
							value >= 500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = unity
							value >= 500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = orbital_arc_furnace_1
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					if = {
						limit = {
							NOT = {
								has_global_flag = giga_game_started
							}
						}
						change_variable = {
							which = arc_furnace_counter
							value = 1
						}
					}

					add_resource = {
						alloys = 500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						unity = 500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1001
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.11
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_deep_space_citadel_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_deep_space_citadel_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.11.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_deep_space_citadel_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.11.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.11.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
									}
									auto_construct_deep_space_citadel_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.11.effect.2
									prev = {
										spawn_planet = {
											class = pc_asteroid
											
											size = 1
											location = prev
											orbit_distance_offset = 70
											orbit_angle_offset = 270
											init_effect = {
												set_name = "The Magic Rock (made of stardust and my tears)"
												set_carrier_flag = auto_construct_deep_space_citadel_planet_flag
												clear_deposits = yes
											}
										}
									}
								}
								find_closest_planet = {
									trigger = {
										id = lazy_con_meg_events.11.trigger.3
										has_carrier_flag = auto_construct_deep_space_citadel_planet_flag
										NOT = {
											has_carrier_flag = auto_construct_planet_flag
										}
									}
									found_planet = {
										orbit_planet = this
										effect = {
											id = lazy_con_meg_events.11.effect.3
											if = {
												limit = {
													auto_construct_checks = {
														FLEET = root
														BLOCK_PLANET = this
													}
												}
												auto_construct_mega_setup = {
													FLEET = root
													BUILD_TIME = @auto_construct_mega_deep_space_citadel_time
													EVENT = lazy_con_meg_events.1101
												}
												prevprev = {
													spawn_megastructure = {
														type = constructing_megastructure
														owner = root.owner
														coords_from = prev
														graphical_culture = root.owner
			
														init_effect = {
															set_megastructure_flag = constructing_mega_with_@root
														}
													}
												}
											}
										}
									}
									failed = {
										effect = {
											id = lazy_con_meg_events.11.effect.4
											root = {
												fleet_event = {
													id = lazy_con_meg_events.11
													days = 1
												}
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.11.effect.5
									root = {
										fleet_event = {
											id = lazy_con_meg_events.11
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.11.effect.6
							root = {
								fleet_event = {
									id = lazy_con_meg_events.11
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1101
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_deep_space_citadel_check = {
						CHECK_SYSTEM = solar_system
					}
					owner = {
						resource_stockpile_compare = {
							resource = unity
							value >= 2500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 1000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = deep_space_citadel_0
						owner = prev.owner
						coords_from = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						unity = 2500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 1000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1101
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.12
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_sra_orbital_ring_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_sra_orbital_ring_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.12.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_sra_orbital_ring_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.12.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.12.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_sra_orbital_ring_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.12.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_sra_orbital_ring_check
										EVENT = lazy_con_meg_events.1201
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.12.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.12
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.12.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.12
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1201
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_sra_orbital_ring_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 200
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 40000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					prevprev = {
						orbital_defence = {
							fleet = {
								delete_fleet = this
							}
						}
						add_modifier = {
							modifier = planet_SRA_orbital_ring_Buff_1
						}
						if = {
							limit = { has_orbital_station = yes }
							orbital_station = {
								dismantle = yes
							}
						}
						create_starbase = {
							size = SRA_orbital_ring
							owner = prevprev.owner
							effect = {
								set_ship_construction_type = starbase_shipyard
							}
						}
					}
				}
				owner = {
					add_resource = {
						influence = 200
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 40000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1201
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.13
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_sra_barrier_guard_station_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_sra_barrier_guard_station_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.13.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_sra_barrier_guard_station_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.13.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.13.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
									}
									auto_construct_sra_barrier_guard_station_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.13.effect.2
									prev = {
										spawn_planet = {
											class = pc_asteroid
											
											size = 1
											location = prev
											orbit_distance_offset = 70
											orbit_angle_offset = 270
											init_effect = {
												set_name = "The Magic Rock (made of stardust and my tears)"
												set_carrier_flag = auto_construct_planet_pos_flag
												set_carrier_flag = auto_construct_sra_bgs_planet_flag
												clear_deposits = yes
											}
										}
									}
								}
								find_closest_planet = {
									trigger = {
										id = lazy_con_meg_events.13.trigger.3
										has_carrier_flag = auto_construct_sra_bgs_planet_flag
										NOT = {
											has_carrier_flag = auto_construct_planet_flag
										}
									}
									found_planet = {
										orbit_planet = this
										effect = {
											id = lazy_con_meg_events.13.effect.3
											if = {
												limit = {
													auto_construct_checks = {
														FLEET = root
														BLOCK_PLANET = this
													}
												}
												auto_construct_mega_setup = {
													FLEET = root
													BUILD_TIME = @auto_construct_mega_sra_barrier_guard_station_check
													EVENT = lazy_con_meg_events.1301
												}
												prevprev = {
													spawn_megastructure = {
														type = constructing_megastructure
														owner = root.owner
														coords_from = prev
														graphical_culture = root.owner
			
														init_effect = {
															set_megastructure_flag = constructing_mega_with_@root
														}
													}
												}
											}
										}
									}
									failed = {
										effect = {
											id = lazy_con_meg_events.13.effect.4
											root = {
												fleet_event = {
													id = lazy_con_meg_events.13
													days = 1
												}
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.13.effect.5
									root = {
										fleet_event = {
											id = lazy_con_meg_events.13
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.13.effect.6
							root = {
								fleet_event = {
									id = lazy_con_meg_events.13
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1301
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_sra_barrier_guard_station_check = {
						CHECK_SYSTEM = solar_system
					}
					owner = {
						resource_stockpile_compare = {
							resource = alloys
							value >= 1000000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					create_fleet = {
						name = "NAME_SRA_Barrier_Guard_Station_fleet_1"
						effect = {
							set_owner = prevprev.owner
							set_location = {
								target = prevprevprev
							}
							while = {
								count = 32
								create_ship = {
									design = NAME_SRA_Barrier_Guard_Cruiser
								}
							}
							while = {
								count = 4
								create_ship = {
									design = NAME_SRA_Barrier_Guard_Titan
								}
							}
							create_ship = {
								name = "NAME_SRA_Barrier_Guard_Station_Name_1"
								design = "NAME_SRA_Barrier_Guard_Station"
								prefix = no
							}
							set_fleet_flag = auto_construct_sra_barrier_guard_station_fleet_flag
						}
						settings = { 
							can_upgrade = no 
							uses_naval_capacity = no
							can_change_composition = no
							spawn_debris = no
						}
					}
				}
				owner = {
					add_resource = {
						alloys = 1000000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
					PLANET = prev
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1301
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.14
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_sra_gz_platform_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_sra_gz_platform_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.14.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
								BLOCK_SYSTEM = prev
							}
							auto_construct_sra_gz_platform_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.14.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.14.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
									}
									auto_construct_sra_gz_platform_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.14.effect.2
									prev = {
										spawn_planet = {
											class = pc_asteroid
											
											size = 1
											location = prev
											orbit_distance_offset = 70
											orbit_angle_offset = 270
											init_effect = {
												set_name = "The Magic Rock (made of stardust and my tears)"
												set_carrier_flag = auto_construct_planet_pos_flag
												set_carrier_flag = auto_construct_sra_gz_platform_planet_flag
												clear_deposits = yes
											}
										}
									}
								}
								find_closest_planet = {
									trigger = {
										id = lazy_con_meg_events.14.trigger.3
										has_carrier_flag = auto_construct_sra_gz_platform_planet_flag
										NOT = {
											has_carrier_flag = auto_construct_planet_flag
										}
									}
									found_planet = {
										orbit_planet = this
										effect = {
											id = lazy_con_meg_events.14.effect.3
											if = {
												limit = {
													auto_construct_checks = {
														FLEET = root
														BLOCK_PLANET = this
													}
												}
												auto_construct_mega_setup = {
													FLEET = root
													BUILD_TIME = @auto_construct_mega_sra_gz_platform_check
													EVENT = lazy_con_meg_events.1401
												}
												prevprev = {
													spawn_megastructure = {
														type = constructing_megastructure
														owner = root.owner
														coords_from = prev
														graphical_culture = root.owner
			
														init_effect = {
															set_megastructure_flag = constructing_mega_with_@root
														}
													}
												}
											}
										}
									}
									failed = {
										effect = {
											id = lazy_con_meg_events.14.effect.4
											root = {
												fleet_event = {
													id = lazy_con_meg_events.14
													days = 1
												}
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.14.effect.5
									root = {
										fleet_event = {
											id = lazy_con_meg_events.14
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.14.effect.6
							root = {
								fleet_event = {
									id = lazy_con_meg_events.14
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1401
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_sra_gz_platform_check = {
						CHECK_SYSTEM = solar_system
					}
					owner = {
						resource_stockpile_compare = {
							resource = alloys
							value >= 48000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					create_fleet = {
						name = "NAME_SRA_GZ_Platform"
						settings = { spawn_debris = no }
						effect = {
							set_owner = prevprev.owner
							set_fleet_flag = auto_construct_sra_gz_platform_fleet_flag
							create_ship = {
								name = "NAME_SRA_GZ_Platform"
								design = "NAME_SRA_GZ_Platform"
								prefix = no
							}
							set_location = {
								target = prevprevprev
							}
						}
					}
				}
				owner = {
					add_resource = {
						alloys = 48000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1401
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.15
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_planetary_computer_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_planetary_computer_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.15.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_planetary_computer_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.15.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.15.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_planetary_computer_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.15.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_planetary_computer_time
										EVENT = lazy_con_meg_events.1501
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.15.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.15
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.15.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.15
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1501
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_planetary_computer_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 150
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 2500
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = planetary_computer_0
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						influence = 150
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 2500
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1501
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.16
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_terraform_site_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_terraform_site_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.16.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_terraform_site_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.16.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_system_block_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.16.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_terraform_site_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.16.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_terraform_site_time
										EVENT = lazy_con_meg_events.1601
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.16.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.16
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.16.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.16
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1601
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					auto_construct_terraform_site_check = {
						CHECK_SYSTEM = solar_system
						CHECK_PLANET = prev
					}
					owner = {
						resource_stockpile_compare = {
							resource = influence
							value >= 50
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 2000
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = terraform_site_0
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						influence = 50
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 2000
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1601
						days = 10
					}
				}
			}
		}
	}
}

fleet_event = {
	id = lazy_con_meg_events.17
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_fleet_flag = auto_mega_ship_flag
		has_fleet_flag = auto_construct_asteroid_manufactory_flag
	}

	immediate = {
		clear_fleet_actions = this
		clear_orders = yes
		set_name = "auto_asteroid_manufactory_ship"

		queue_actions = {
			repeat = {
				find_closest_system = {
					trigger = {
						id = lazy_con_meg_events.17.trigger.1
						root = {
							auto_construct_checks = {
								FLEET = root
							}
							auto_construct_asteroid_manufactory_check = {
								CHECK_SYSTEM = prev
							}
						}
					}
					found_system = {
						effect = {
							id = lazy_con_meg_events.17.effect.1
							set_timed_star_flag = {
								flag = auto_construct_blocked_system_flag
								days = @auto_construct_mega_asteroid_manufactory_time
							}
						}
						move_to = this
						find_closest_planet = {
							trigger = {
								id = lazy_con_meg_events.17.trigger.2
								root = {
									auto_construct_checks = {
										FLEET = root
										BLOCK_PLANET = prev
									}
									auto_construct_asteroid_manufactory_check = {
										CHECK_SYSTEM = prevprev
										CHECK_PLANET = prev
									}
								}
							}
							found_planet = {
								orbit_planet = this
								effect = {
									id = lazy_con_meg_events.17.effect.2
									auto_construct_mega_setup = {
										FLEET = root
										BUILD_TIME = @auto_construct_mega_asteroid_manufactory_time
										EVENT = lazy_con_meg_events.1701
									}
									prev = {
										spawn_megastructure = {
											type = constructing_megastructure
											owner = root.owner
											coords_from = prev
											orbit_angle = 360
											graphical_culture = root.owner

											init_effect = {
												set_megastructure_flag = constructing_mega_with_@root
											}
										}
									}
								}
							}
							failed = {
								effect = {
									id = lazy_con_meg_events.17.effect.3
									root = {
										fleet_event = {
											id = lazy_con_meg_events.17
											days = 1
										}
									}
								}
							}
						}
					}
					failed = {
						effect = {
							id = lazy_con_meg_events.17.effect.4
							root = {
								fleet_event = {
									id = lazy_con_meg_events.17
									days = 1
								}
							}
						}
					}
				}
			}
		}
	}
}

carrier_event = {
	id = lazy_con_meg_events.1701
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_fleet_in_orbit = {
			has_fleet_flag = auto_mega_ship_flag
		}	
	}

	immediate = {
		random_fleet_in_orbit = {
			limit = {
				has_fleet_flag = auto_mega_ship_flag
				has_fleet_flag = auto_construct_blocked_fleet_flag
			}
			if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
					# auto_construct_asteroid_manufactory_check = {
					# 	CHECK_SYSTEM = solar_system
					# 	CHECK_PLANET = prev
					# }
					owner = {
						resource_stockpile_compare = {
							resource = unity
							value >= @giga_kilo_unity_cost
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
						resource_stockpile_compare = {
							resource = alloys
							value >= 750
							mult = value:positive_modifier_mult|MODIFIER|megastructures_cost_mult|
						}
					}
				}
				solar_system = {
					spawn_megastructure = {
						type = asteroid_manufactory_0
						owner = prev.owner
						planet = prevprev
						graphical_culture = prev.owner
					}
				}
				owner = {
					add_resource = {
						unity = @giga_kilo_unity_cost
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
					add_resource = {
						alloys = 750
						mult = value:negative_modifier_mult|MODIFIER|megastructures_cost_mult|
					}
				}

				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else_if = {
				limit = {
					prev = {
						NOT = {
							has_carrier_flag = auto_construct_planet_flag
						}
					}
				}
				auto_construct_mega_cleanup = {
					FLEET = this
					SYSTEM = solar_system
				}
			}
			else = {
				prev = {
					carrier_event = {
						id = lazy_con_meg_events.1701
						days = 10
					}
				}
			}
		}
	}
}