# === GENERATED by _gen_giga_menu_gate.ps1 -- DO NOT EDIT BY HAND ===
# Giga buildable-root overrides that add the AoW-only-tab hide check to potential.
# Re-run the generator after Gigastructural Engineering updates.

frameworld_harvest_0 = {
	entity = ""
	construction_entity = ""
	portrait = "GFX_megastructure_construction_background"
	show_galactic_map_icon = no
	place_entity_on_planet_plane = yes
	construction_blocks_and_blocked_by = none
	show_in_outliner = no
	
	build_time = 360
	resources = {
		category = deposit_blockers_frameworld
		cost = {
			energy = 1000
			influence = 25 
		}
	}
	
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
    	giga_has_frameworld_origin = yes
		
	}
	
	possible = { 
		hidden_trigger = {
			exists = starbase
		}	
		custom_tooltip = { fail_text = "requires_inside_border" is_inside_border = from } 
	}
	
	placement_rules = {
		planet_possible = {
			frameworld_can_harvest_asteroid = yes

			
			hidden_trigger = {
				OR = {
					space_owner = {
						is_ai = no
					}
					AND = {
						space_owner = {
							is_ai = yes
						}
						OR = {
							has_deposit = no
							AND = {
								mid_game_years_passed > 0
								frameworld_asteroid_has_rare_resource = no
							}
						}
					}
				}	
			}
		}
	}
	
	ai_weight = {
    	weight = 10 

		
		modifier = {
			factor = 10
			FROM = {
				has_resource = {
					type = influence
					amount > 200
				}
				has_resource = {
					type = energy
					amount > 5000
				}
				has_monthly_income = {
					resource = energy
					value > 30
				}
				count_owned_fleet = {
					count > 1
					limit = {
						is_ship_class = shipclass_constructor
						is_fleet_idle = yes
					}
				}
			}
		}

		
		modifier = {
			factor = 0.1
			FROM = {
				exists = capital_scope
				capital_scope = {
					free_district_slots > 8
				}
			}
		}

		
		modifier = {
			factor = 0.25
			FROM = {
				exists = capital_scope
				capital_scope = {
					free_district_slots > 16
				}
			}
		}

		
		modifier = {
			factor = 100
			FROM = {
				exists = capital_scope
				capital_scope = {
					OR = {
						free_district_slots < 1
						free_housing < -5
					}
				}
			}
		}
	}
	
	on_build_complete = {
		from = {
			random_owned_planet = {
				limit = {
					has_planet_flag = giga_frameworld@prev
				}

				giga_frameworld_expand_deposit = { 
					DEPOSIT = d_frameworld_asteroid
					VAR = giga_frameworld_asteroids
				}
				giga_frameworld_expand_deposit = { 
					DEPOSIT = d_frameworld_expansion 
					VAR = giga_frameworld_expansions
				}
				change_planet_size = 1
				giga_frameworld_update_entity_with_fallback = yes
				frameworld_conduct_audit_check_ai = yes

				
				
				from.planet = { remove_planet = yes }
			}
		}
		remove_megastructure = fromfrom
		print_scope_effect = yes
	}
}

frameworld_salvage_habitat_0 = {
	entity = ""
	construction_entity = ""
	portrait = "GFX_megastructure_construction_background"
	show_galactic_map_icon = no
	place_entity_on_planet_plane = yes
	construction_blocks_and_blocked_by = none
	show_in_outliner = no
	
	build_time = 720
	resources = {
		category = deposit_blockers_frameworld
		cost = {
			energy = 2500
			influence = 50
		}
	}
	
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
    	giga_has_frameworld_origin = yes
		has_technology = tech_habitat_1
	}
	
	possible = { 
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border" is_inside_border = from } 
	}
	
	placement_rules = {
		planet_possible = {
			frameworld_can_salvage_habitat = yes
		}
	}
	
	ai_weight = {
    	weight = 10 

		
		modifier = {
			factor = 20
			FROM = {
				has_resource = {
					type = influence
					amount > 200
				}
				has_resource = {
					type = energy
					amount > 5000
				}
				has_monthly_income = {
					resource = energy
					value > 30
				}
				count_owned_fleet = {
					count > 1
					limit = {
						is_ship_class = shipclass_constructor
						is_fleet_idle = yes
					}
				}
			}
		}

		
		modifier = {
			factor = 0.1
			FROM = {
				exists = capital_scope
				capital_scope = {
					free_district_slots > 8
				}
			}
		}

		
		modifier = {
			factor = 0.25
			FROM = {
				exists = capital_scope
				capital_scope = {
					free_district_slots > 16
				}
			}
		}

		
		modifier = {
			factor = 100
			FROM = {
				exists = capital_scope
				capital_scope = {
					OR = {
						free_district_slots < 1
						free_housing < -5
					}
				}
			}
		}
	}
	
	on_build_complete = {
		from = {
			random_owned_planet = {
				limit = {
					has_planet_flag = giga_frameworld@prev
				}

				giga_frameworld_expand_deposit = { 
					DEPOSIT = d_frameworld_habitat
					VAR = giga_frameworld_habitats
					COUNT = from.planet.value:giga_frameworld_hab_harvest_count
				}
				giga_frameworld_expand_deposit = { 
					DEPOSIT = d_frameworld_expansion 
					VAR = giga_frameworld_expansions
					COUNT = from.planet.value:giga_frameworld_hab_harvest_count
				}
				change_planet_size = from.planet.value:giga_frameworld_hab_harvest_count
				giga_frameworld_update_entity_with_fallback = yes
				frameworld_conduct_audit_check_ai = yes

				
				from.planet = { giga_frameworld_remove_asteroid = yes }
				from.solar_system = { giga_remove_system_orbitals = yes }
			}
		}
		remove_megastructure = fromfrom
	}
}

habitat_central_complex = {
    entity = "habitat_phase_03_entity"
    construction_entity = "habitat_phase_03_entity"
    portrait = "GFX_megastructure_habitat_background"
    place_entity_on_planet_plane = no
    show_galactic_map_icon = no
    hide_name = yes
    show_in_outliner = no
    entity_offset = { x = 7 y = -7 }
    build_time = @central_orbital_build_time

    resources = {
        category = megastructures_habitat
        cost = {
            influence = @central_orbital_influence_cost
        }
        inline_script = {
            script = megastructures/generic_parts/giga_mega_alloy_cost
            alloys = @central_orbital_alloy_cost
        }
    }

    construction_blocks_and_blocked_by = self_type
    custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_HABITAT_CENTRAL_COMPLEX"
    build_system_tooltip = habitat_tooltip

    potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
        giga_are_habitats_available = yes
    }

    possible = {
        hidden_trigger = { exists = starbase }
        custom_tooltip = {
            fail_text = "requires_inside_border"
            is_inside_border = from
        }
        custom_tooltip = {
            fail_text = "requires_not_habitat_central_complex"
            NOT = {
                OR = {
                    any_system_planet = {
                        OR = {
                            has_planet_flag = habitat
                            has_planet_flag = hold_the_line_habitat
                        }
                    }
                    has_megastructure = habitat_central_complex_ruined
                }
            }
        }
        custom_tooltip = {
            fail_text = "requires_no_orbital_debris"
            NOT = {
                any_system_planet = {
                    has_planet_flag = has_orbital_debris
                }
            }
        }

        
        hidden_trigger = {
            from = {
                if = {
                    limit = {
                        is_ai = yes
                    }
                    count_planet_within_border = {
                        count <= value:ai_habitat_cap
                        limit = {
                            is_planet_class = pc_habitat
                        }
                    }
                }
            }
        }
    }

    placement_rules = {
        planet_possible = {
            custom_tooltip = {
                fail_text = "requires_surveyed_planet"
                is_surveyed = {			
                    who = prev.from
                    status = yes
                }
            }
            custom_tooltip = {
                fail_text = "requires_no_anomaly"
                NOT = { has_anomaly = yes }
            }
            custom_tooltip = {
                fail_text = "requires_no_existing_megastructure"
                
                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
                    is_planet_class = pc_cosmogenesis_world
                }
            }
            custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
            
            custom_tooltip = {
                fail_text = "requires_not_minor_planetary_body"
                NOR = {
                    is_asteroid = yes
                    is_moon = yes
                }
            }
            custom_tooltip = {
                fail_text = "requires_not_solarpunk"
                NOT = {
                    solar_system = {
                        has_star_flag = solarpunk_system_02
                    }
                }
            }
            if = {
                limit = {
                    from = { is_ai = yes }
                }
                or = {
                    has_deposit_for = shipclass_mining_station
                    has_deposit_for = shipclass_research_station
                }
            }
        } 
    }

    
    
    ai_weight = {
        factor = 5

        
        modifier = {
            factor = 0
            from = {
                nor = {
                    has_void_dweller_origin = yes
                    has_origin = origin_toxic_knights
                }
                has_country_flag = has_recently_built_habitat
            }
        }

        modifier = {
            
            factor = 0
            owner = {
                any_planet_within_border = {
                    is_planet_class = pc_habitat
                    is_colony = no
                }
            }
        }

        modifier = {
            
            
            factor = 0
            owner = {
                is_void_dweller_empire = no
            }
            starbase = { NOT = { has_starbase_size >= starbase_starport } }
        }

        modifier = {
            factor = 5
            exists = sector
            sector = { has_sector_type = core_sector }
        }

        modifier = {
            factor = 100
            OR = {
                has_star_flag = ideal_habitat_t1
                has_star_flag = ideal_habitat_t2
            }
        }

        modifier = {
            factor = value:num_orbital_sites
        }
    }

    on_build_queued = {
        from = {
            set_timed_country_flag = { flag = has_recently_built_habitat years = 30 }
        }
    }
    on_build_unqueued = {
        from = {
            remove_country_flag = has_recently_built_habitat
        }
    }
    on_build_cancel = {
        from = {
            remove_country_flag = has_recently_built_habitat
        }
    }

    on_build_complete = {
        fromfrom.planet = {
            save_event_target_as = target_planet
        }
        if = {
            limit = {
                fromfrom.planet = {
                    is_star = yes
                }
            }
            spawn_habitat_effect = {
                DISTANCE = 19.798
            }
        }
        else = {
            spawn_habitat_effect = {
                DISTANCE = 9.899
            }
        }
        fromfrom.solar_system = {
            set_star_flag = has_habitat
        }
        from = {
            save_event_target_as = habitat_owner
        }
        remove_megastructure = fromfrom
        from = {
            country_event = { id = megastructures.10 }
        }
    }
}

orbital_elysium_0 = {
	entity = giga_elysium_01_entity
	construction_entity = giga_elysium_01_entity
	construction_blocks_and_blocked_by = none
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_orbital_elysium }

	entity_offset = { x = -7 y = -7 }

	build_time = 1800
	resources = {
		category = giga_kilostructures
		cost = {
			influence = 150
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 1500
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		always = no 
		OR = {
			has_origin = giga_elysium_origin
			NOT = { has_global_flag = giga_elysium_disabled }
		}
		giga_can_use_habitables = yes
		has_technology = giga_tech_orbital_elysium
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_surveyed_planet"			is_surveyed = { who = prev.from status = yes } }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			custom_tooltip = { 
				fail_text = "must_build_around_developed_planet"
				or = {
					
					from = { has_origin = origin_elysium }
					and = {
						is_colony = yes
						exists = owner
						exists = controller
						has_upgraded_capital = yes
					}
				}
			}
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	NOT = { has_planet_flag = has_orbital_elysium } }
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
		}
	}

	ai_weight = {
		

		weight = 0
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			save_event_target_as = giga_elysium_host
			giga_set_has_mega_flag = yes
			set_planet_flag = has_orbital_elysium

			add_modifier = {
				modifier = giga_elysium_host_planet
			}
			remove_modifier = resort_colony
			remove_modifier = slave_colony
			remove_modifier = penal_colony

			giga_set_elysium_buildings = yes
			set_planet_flag = can_organic_assemble_flag

			
			planet_event = { id = giga_elysium_origin.100 }
		}
		from = {
			if = {
				limit = {
					not = { has_origin = origin_elysium }
					fromfrom = {
						not = { 
							has_megastructure_flag = origin_elysium 
						}
					}
				}
				set_timed_country_flag = { flag = has_recently_built_giga_orbital_elysiums years = 20 }
				country_event = { id = giga_dialog.1101 }	
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = giga_achievements_disabled
						has_country_flag = giga_achievement_63
					}
				}
				set_country_flag = giga_achievement_63
				set_timed_country_flag = { flag = giga_achievement_63_notification days = 30 }
				giga_achievement_sound = yes
			}
		}
		spawn_planet = {
			class = "pc_giga_elysium"
			location = fromfrom.planet
			orbit_location = yes
			orbit_angle_offset = 45
			orbit_distance_offset = 9.899
			size = 5
			has_ring = no

			init_effect = {
				set_surveyed = { surveyed = yes surveyor = from }
				set_all_comms_surveyed = yes
				clear_blockers = yes
				set_planet_flag = forbid_guillis_planet_modifiers
				set_planet_flag = megastructure
				set_planet_flag = colony_event			
				set_planet_flag = giga_elysium

				add_deposit = d_giga_elysium_buildings

				giga_get_species_for_colony = {
					TARGET = this
					WHO = from
				}
				start_colony = {
					owner = from
					species = event_target:giga_colony_species
				}

				set_name = {
					key = "GIGA_ELYSIUM_PLANET_NAME"
					variable_string = "[event_target:giga_elysium_host.GetName]"
				}
			}
		}
		remove_megastructure = fromfrom
	}
}

orbital_ring = {
	entity = ""
	construction_entity = "orbital_ring_construction_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	scales_with_planet = yes
	show_galactic_map_icon = no
	show_in_outliner = no
	build_time = 720

	starbase = starbase_level_orbital_ring_tier_1

	resources = {
		category = giga_kilostructures
		cost = {
			influence = 50
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 1000
		}
	}
	construction_blocks_and_blocked_by = none
	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_ORBITAL_RING"

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga has_technology = tech_orbital_ring_tier_1 }

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_surveyed_planet"
				is_surveyed = { 
					who = prev.from
					status = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {
				fail_text = "requires_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			custom_tooltip = {
				fail_text = "requires_not_hostile_or_primitive"
				NOR = {
					planet_is_hostile_or_crisis = yes
					AND = {
						exists = owner
						owner = {
							is_country_type = primitive
						}
					}
				}
			}
			
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOT = {
					exists = orbital_defence
					any_system_megastructure = {
						giga_is_orbital_ring = yes
						
						exists = planet
						planet = {
							is_same_value = root
						}
					}
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				
				if = { 
					limit = {
						NOT = { has_global_flag = orbital_ring_overwrite } 
					}
					NOR = {
						solar_system = {
							has_star_flag = ring_world_built
						}
					}
					OR = {
						
						has_planet_flag = giga_planet_mega
						is_planet_class = pc_giga_planetary_computer
						is_planet_class = pc_habitable_gas_giant
						
						has_planet_flag = has_payback_habitat
						
						AND = {
							giga_habitable_structure = no 
							habitable_structure = no 
							is_regular_giga_maginot_world = no
							NOT = { has_planet_flag = ruined_orbital_ring_planet }
						}
					}
				}
				else = { 
					NOR = {
						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
						
					}
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
			OR = {
				
				inline_script = {
					script = generic_parts/giga_toggled_code
					code = "
					AND = {
						oxr_mdlc_is_planet_world_machine = yes
						exists = owner
						owner = {
							OR = {
								has_xvcv_mdlc_ap_world_machines = yes
								has_oxr_mdlc_origin_world_machine_awakened = yes
							}
						}
					}
					"
					toggle = @oxr_mdlc_mod
				}
				
				if = {
					limit = {
						from = { is_ai = yes }
					}
					pop_amount >= 2500
				}
			}
		}
	}

	
	
	ai_weight = {
		factor = 5

		modifier = {
			factor = 0.1
			starbase = { NOT = { has_starbase_size >= starbase_starport } }
		}

		modifier = {
			factor = 3
			solar_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
			}
		}
		modifier = {
			factor = 2
			any_neighbor_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
			}
		}

		modifier = {
			factor = 0.1
			any_neighbor_system = {
				exists = owner
				owner = { NOT = { is_same_value = from } }
			}
		}
		modifier = {
			factor = 3
			any_system_colony = {
				pop_amount >= 5000
				NOT = { exists = orbital_defence }
			}
		}
	}

	on_build_start = {}
	on_build_cancel = {}

	on_build_complete = {
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
			save_event_target_as = orbital_ring_planet

			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
			create_starbase = {
				size = orbital_ring_tier_1
				owner = FROM
				
				
				effect = { }
			}
		}
		remove_megastructure = fromfrom
		from = {
			country_event = { id = tutorial.2121 }
			country_event = { id = giga_dialog.13500 }
		}
	}
}

shroud_seal = {
	entity = "shroud_seal_entity"
	construction_entity = "shroud_seal_entity"
	construction_scale = 1.2 
	portrait = "GFX_megastructure_shroud_seal_background"
	is_shroud_seal = yes
	place_entity_on_planet_plane = no
	build_type = inside_gravity_well
	show_galactic_map_icon = yes
	entity_offset = { x = @entity_x y = @entity_y }
	build_time = 1800

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	resources = {
		category = giga_kilostructures
		cost = {
			alloys = 500
			sr_zro = 100
		}
		upkeep = {
			energy = 5
		}
		produces = {
			trigger = {
				exists = owner
				owner = {
					has_relic = r_the_lost_patron
				}
			}
			unity = 25
		}
	}

	triggered_country_modifier = {
		potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
			exists = owner
			owner = {
				has_relic = r_the_lost_patron
			}
		}
		country_naval_cap_add = 10
	}

	triggered_country_modifier = {
		potential = {
			exists = owner
			owner = { has_technology = tech_storm_prediction_1 }
		}
		
		shroud_storm_repelling = 0.75
	}

	construction_blocks_and_blocked_by = none
	prerequisites = { "tech_psionic_suppression" }
	show_prereqs = yes

	dismantle_time = 180
	dismantle_potential = {
		always = yes
	}
	can_be_dismantled_by_non_owner = yes
	dismantle_possible = {
		solar_system = { is_owned_by = from }
		if = { 
			limit = {
				NOT = { is_owned_by = from }
			}
			custom_tooltip = shroud_seal_dismantle_conditions_tt
			hidden_trigger = {
				solar_system = {
					NOT = {
						any_fleet_in_system = {
							is_ship_class = shipclass_military
							exists = controller
							controller = { is_hostile = from }
						}
					}
				}
			}
		}
	}
	should_ai_dismantle = {
		from = { giga_is_standard_country_type = yes }
		OR = {
			from = { is_psionic = yes }
			solar_system = {
				NOR = {
					has_psionic_aura = yes
					any_neighbor_system = {
						OR = {
							system_has_hostile_aura = { COUNTRY = root.from }
							any_neighbor_system = {
								system_has_hostile_aura = { COUNTRY = root.from }
							}
						}
					}
				}
			}
		}
	}
	on_dismantle_complete = {
		on_shroud_seal_destroyed = yes
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_shroud_seal"
			NOT = { has_megastructure = shroud_seal }
		}
	}

	
	
	ai_weight = {
		base = 0
		modifier = {
			add = 5
			from = { is_psionic = no }
			any_neighbor_system = {
				system_has_hostile_aura = { COUNTRY = root.from }
			}
		}
		modifier = {
			add = 50
			from = { is_psionic = no }
			system_has_hostile_aura = { COUNTRY = root.from }
		}
		
		modifier = {
			set = 1000
			from = {
				count_owned_megastructure = {
					limit = { is_megastructure_type = shroud_seal }
					count < 3
				}
			}
			any_playable_country = {
				NOT = { is_same_value = root.from }
				has_covenant_with_end_of_the_cycle = yes
			}
		}
		modifier = {
			factor = 0
			any_neighbor_system = {
				has_megastructure = shroud_seal
			}
		}
	}

	

	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		fromfrom = {
			set_megastructure_flag = giga_outliner_hidden_by_@owner
		}
        add_modifier = {
            modifier = shroud_seal_modifier
            days = -1
        }
		every_playable_country = {
			limit = {
				has_event_chain = mindwarden_enclave_chain
			}
			add_event_chain_counter = {
				event_chain = mindwarden_enclave_chain
				counter = shroud_seals_built
				amount = 1
			}
		}
		every_playable_country = {
			limit = {
				has_event_chain = shroud_seal_construction_chain
				prev = {
					exists = event_target:exiled_system_border@prev
					is_same_value = event_target:exiled_system_border@prev
				}
			}
			add_event_chain_counter = {
				event_chain = shroud_seal_construction_chain
				counter = shroud_seal_built
				amount = 1
			}
		}
		every_playable_country = {
			limit = {
				has_event_chain = shroud_seal_reconstruction_chain
				prev = {
					exists = event_target:exiled_system_border@prev
					is_same_value = event_target:exiled_system_border@prev
				}
			}
			add_event_chain_counter = {
				event_chain = shroud_seal_reconstruction_chain
				counter = shroud_seal_built
				amount = 1
			}
		}
        add_eotc_aura_shroud_seal = yes
	}

	show_in_outliner = yes
}

asteroid_artillery_0 = {
	entity = "giga_asteroid_artillery_cover_entity"
	construction_entity = "giga_asteroid_artillery_cover_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { giga_tech_asteroid_artillery }
	construction_blocks_and_blocked_by = none

	build_time = 1800
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @giga_kilo_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_asteroid_artillery
		NOT = { has_global_flag = asteroid_artillery_disabled }
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_asteroid"			is_asteroid = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
		}
	}

	ai_weight = {
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega 
		mult = value:giga_ai_strategic_location
		mult = value:giga_ai_prevent_spam|MEGA|asteroid_artillery|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_cap_availability_boost
	}

	on_build_start = {
		from = {
			set_country_flag = is_currently_building_asteroid_artillery
		}
		apply_giga_bulwark_trad_build_speed = yes
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_asteroid_artillery
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			set_planet_flag = megastructure
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_asteroid_artillery years = 10 }
			remove_country_flag = is_currently_building_asteroid_artillery
			country_event = { id = giga_artillery.1004 }	
		}
	}
}

atmosphere_shredder_0 = {
	entity = "giga_storm_observatory_1"
	construction_entity = "giga_storm_observatory_1_con"
	portrait = "GFX_megastructure_gas_giant"
	place_entity_on_planet_plane = yes
	use_planet_resource = yes
	entity_offset = { x = 0 y = 0 } 
	scales_with_planet = yes
	construction_blocks_and_blocked_by = none

	prerequisites = { giga_tech_macro_scale_weather_manipulation }

	build_time = 360
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @science_kilo_cost_1
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @science_kilo_cost_1
		}
		upkeep = {
			energy = 10
		}
		upkeep = {
			trigger = { 
				exists = owner
				owner = { 
					is_gestalt = no
				}
			}
			consumer_goods = 5
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = no
				}
			}
			minerals = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = yes
				}
			}
			energy = 10
		}
	}

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_macro_scale_weather_manipulation
		NOT = { has_global_flag = storm_observatory_disabled }
		OR = {
			has_global_flag = storm_observatory_capped_u
			check_variable = {
				which = giga_current_storm_observatory
				value < value:giga_storm_observatory_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border" 			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_no_anomaly" 				NOT = { any_system_planet = { has_anomaly = yes } } }
		custom_tooltip = { fail_text = "requires_no_arc_furnace" 			system_has_arc_furnace = no }
		custom_tooltip = { fail_text = "requires_no_atmosphere_shredder"	giga_system_has_atmosphere_shredder = no } 
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = storm_observatory_capped_u
					check_variable = {
						which = giga_current_storm_observatory
						value < value:giga_storm_observatory_limit
					}
				}
			}
		}
	}

	country_modifier = {
		custom_tooltip = orbital_atmosphere_shredder_1_mod_tooltip
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = { fail_text = "must_build_around_gas" 				giga_is_gas_giant = yes }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			OR = {
				from = { is_ai = no }
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							giga_is_science_candidate = yes
						}
					}
				}
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|25|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_large_system
		mult = value:giga_ai_deposit_stack
		mult = value:giga_ai_prevent_spam|MEGA|atmosphere_shredder|
		mult = value:giga_ai_materialist_plus

		modifier = { factor = 2.00	from = { has_federation = yes federation = { has_federation_type = research_federation } } }
	}
	on_build_start = {
		from = {
			set_country_flag = is_currently_building_atmosphere_shredder
		}
		set_star_flag = atmosphere_shredder_construction
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_atmosphere_shredder
		}
		remove_star_flag = atmosphere_shredder_construction
	}
	on_build_complete = {
		save_event_target_as = giga_system
		remove_star_flag = atmosphere_shredder_construction
		fromfrom.planet = {
			set_planet_flag = has_atmosphere_shredder
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_entity = {
				entity = storm_gas_giant_01_entity
			}
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_atmosphere_shredder years = 20 }
			remove_country_flag = is_currently_building_atmosphere_shredder
			create_message = {
				type = MEGASTRUCTURE_BUILT
				localization = MESSAGE_MEGASTRUCTURE_BUILT
				days = 30
				target = from 
				variable = {
					type = name
					localization = MEGASTRUCTURE
					scope = from
				}
				variable = {
					type = name
					localization = SYSTEM
					scope = root
				}
			}
			change_variable = { which = giga_current_storm_observatory value = 1 }
		}
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			remove_trade_deposits = yes
			set_planet_flag = giga_atmosphere_shredder_stage_1
			save_event_target_as = target_planet
			add_deposit = d_physics_2
			science_kilo_update_orbital_effect = yes
			
			
			
			
		}
	}
					
	dismantle_cost = {
		category = giga_kilostructures
		cost = {
			energy = 500
		}
	}

	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}

	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = giga_tech_macro_scale_weather_manipulation
		}
		
		
		
		
	}
	on_dismantle_start = { 
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
				NOT = { has_planet_flag = giga_atmosphere_shredder_stage_1 }
			}
			set_planet_flag = giga_atmosphere_shredder_stage_1
		}
		fromfrom.planet = {
			set_planet_flag = has_atmosphere_shredder
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			giga_dismantle_science_kilo_effect = {
				FLAG = atmosphere_shredder
				TYPE = physics
			}
		}
		random_system_planet = {
			limit = {
				has_planet_flag = has_atmosphere_shredder
			}
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_atmosphere_shredder
			set_planet_entity = {
				entity = pc_gas_giant
			}
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
			if = {
				limit = {
					check_variable = {
						which = giga_current_storm_observatory
						value >= 1
					}
				}
				change_variable = {
					which = giga_current_storm_observatory
					value = -1
				}
			}
		}
	}
}

automated_stripmine_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_automated_stripmine_2 }
	construction_blocks_and_blocked_by = none

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 3500
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_automated_stripmine_2
		NOT = { has_global_flag = drill_disabled }
		OR = {
			has_global_flag = drill_capped_u
			check_variable = {
				which = giga_current_drill
				value < value:giga_drill_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
				has_global_flag = drill_capped_u
					check_variable = {
						which = giga_current_drill
						value < value:giga_drill_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_crisis_planet"			NOT = { has_planet_flag = crisis_vital_planet } }
			custom_tooltip = { fail_text = "already_stripmined"					NOR = { has_planet_flag = stripminedplanet is_planet_class = pc_core_mined } }
			custom_tooltip = { fail_text = "requires_not_asteroid"	is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
				NOT = {
					is_planet_class = pc_astral_scar
				}
			}
			custom_tooltip = {
				fail_text = "must_build_around_molten"
				giga_is_molten = yes
			}
			hidden_trigger = {
				or = {
					is_colonizable = no
					and = {
						from = { is_ai = no }
					}
				}
			}
		}
	}

	ai_weight = {

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|75|
		mult = value:giga_ai_output|RESOURCE|minerals|AMOUNT|250|
		mult = value:giga_ai_prevent_spam|MEGA|automated_stripmine|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_cap_availability_boost
	}

	on_build_start = {
		from = {
			set_country_flag = is_currently_building_automated_stripmine
		}
	}

	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_automated_stripmine
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_automated_stripmine years = 20 }
			remove_country_flag = is_currently_building_automated_stripmine
			country_event = { id = giga_dialog.3301 }	
			change_variable = { which = giga_current_drill value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

crystal_megabore_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_crystal_megabore }
	construction_blocks_and_blocked_by = none

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 2000
	resources = {
		category = giga_crystal_megabore
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|unity|AMOUNT|@giga_small_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		from = {
			set_country_flag = is_currently_building_crystal_megabore
		}
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = unity  AMOUNT = @giga_small_mega_unity_cost }
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_crystal_megabore
		}
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_crystal_megabore
		NOT = { has_global_flag = crystal_disabled }
		OR = {
			has_global_flag = crystal_capped_u
			check_variable = {
				which = giga_current_crystal
				value < value:giga_crystal_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = crystal_capped_u
					check_variable = {
						which = giga_current_crystal
						value < value:giga_crystal_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_larger_planet"				planet_size >= 6 }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = {
				fail_text = "must_build_around_frozen"
				giga_is_frozen = yes
			}
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|40|MIN|0.25|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|7.5|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|minerals|AMOUNT|100|MIN|0.75|
		mult = value:giga_ai_output|RESOURCE|rare_crystals|AMOUNT|100|MIN|0.2|
		mult = value:giga_ai_prevent_spam|MEGA|crystal_megabore|
		mult = value:giga_ai_weight_savings|CATEGORY|resource|RESOURCE|alloys|AMOUNT|10000|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_cap_availability_boost
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_crystal_megabore years = 20 }
			remove_country_flag = is_currently_building_crystal_megabore
			country_event = { id = giga_dialog.3501 }	
			change_variable = { which = giga_current_crystal value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

deep_space_citadel_0 = {
    entity = ""
    construction_entity = "deep_space_01_starbase_citadel_section_1_entity"
    portrait = "GFX_megastructure_construction_background"
    place_entity_on_planet_plane = no
    build_type = inside_gravity_well
    show_in_outliner = no
    use_planet_resource = no
    build_time = 1080 
    must_select_ship_design = yes

    starbase = starbase_level_deep_space_citadel_1

    resources = {
        category = megastructures
        cost = {
            unity = 2500
        }
        cost = {
            trigger = {
                country_uses_bio_ships = no
            }
            alloys = @starhold_cost
        }
        cost = {
            trigger = {
                country_uses_bio_ships = yes
            }
            alloys = @starhold_cost
            mult = 0.5
        }
        cost = {
            trigger = {
                country_uses_bio_ships = yes
            }
            food = @starhold_cost
            mult = @halved_alloy_to_food_cost_ratio
        }
    }

    construction_blocks_and_blocked_by = self_type
    prerequisites = { "tech_deep_space_citadel" }

    potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
        always = yes
    }

    possible = {
        hidden_trigger = {
            exists = starbase
        }
        custom_tooltip = {
            fail_text = "requires_inside_border"
            is_inside_border = from
        }
        custom_tooltip = {
            fail_text = "requires_surveyed_system"
            NOT = {
                any_system_planet = {
                    is_surveyed = {
                        who = prev.from
                        status = no
                    }
                }
            }
        }
        custom_tooltip = {
            fail_text = "requires_less_than_x_deep_space_citadel"
            count_ship_in_system = {
                limit = {
                    is_space_citadel_ship_size = yes
                }
                count < from.modifier:deep_space_citadel_limit_add
            }
        }
    }

    placement_rules = {
        planet_possible = {
            custom_tooltip = {
                fail_text = "BUILD_MEGASTRUCTURE_PLANET_TARGET_NEEDED"	
                always = no
            }
        }
    }

    
    
    ai_weight = {
        factor = 15

        modifier = {
            add = 10
            is_bottleneck_system = yes
        }

        complex_trigger_modifier = {
            trigger = count_neighbor_system
            mode = add
            mult = 1
        }

        complex_trigger_modifier = {
            trigger = count_starbase_in_system
            mode = add
            mult = -1
        }

        complex_trigger_modifier = {
            trigger = count_bypass_in_system
            mode = add
            mult = 1
        }

        modifier = {
            factor = 0.1
            starbase = { NOT = { has_starbase_size >= starbase_starfortress } }
        }

        modifier = {
            add = 5
            any_neighbor_system = {
                exists = owner
                NOT = {
                    owner = { is_same_value = from }
                }
            }
        }

        modifier = {
            factor = 1.15
            from = {
                has_origin = origin_starlit_citadel
            }
        }
    }

    on_build_start = {}
    on_build_cancel = {}
    on_build_complete = {
        fromfrom = {
            remove_megastructure = this
        }
    }
}

grand_archive_0 = {
	entity = "grand_archive_entity"
	construction_entity = "grand_archive_entity"
	portrait = "GFX_megastructure_grand_archive_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }
	is_grand_archive = yes
	build_time = 1800
	resources = {
		category = megastructures_grand_archive
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 1000
		}

		upkeep = {
			energy = 10
		}
	}

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	construction_blocks_and_blocked_by = self_type
	prerequisites = { "tech_galactic_archivism" }
	show_prereqs = yes

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		giga_is_standard_country_type = yes
		NOT = {
			any_owned_megastructure = {
				is_megastructure_type = grand_archive_0
			}
		}
	}

	possible = {
        hidden_trigger = {
            exists = starbase
        }
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
        custom_tooltip = {
            fail_text = must_have_2500_pops
            OR = {
                from = {
                    pop_amount >= 2500
                }
                from.owner = {
                    is_wilderness_empire = yes
                }
            }
        }
	}

	placement_rules = {
		planet_possible = {
			is_colony = yes
            owner = {
                NOT = { is_primitive = yes }
            }
			OR = {
				
				inline_script = {
					script = generic_parts/giga_toggled_code
					code = "oxr_mdlc_can_build_grand_archive = yes"
					toggle = @oxr_mdlc_mod
				}
				pop_amount >= 2500
				AND = {
					exists = owner
					owner = { is_wilderness_empire = yes }
				}
			}
		}
	}

	country_modifier = {
		country_vivarium_max_capacity_add = @grand_archive_vivarium_capacity
	}

	
	
	ai_weight = {
		factor = 5
		modifier = {
			factor = 3
			from = {
				acquired_specimen_count > 6
			}
		}
		modifier = {
			factor = 0
			from = {
				is_unfriendly = yes
			}
		}
	}

	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		from = {
			if = {
				limit = { has_country_flag = grand_archive_destroyed }
				remove_country_flag = grand_archive_destroyed
				country_event = {
					id = grand_archive.4580
					scopes = { from = fromfrom.solar_system }
				}
			}
		}
		fromfrom.planet = {
			set_planet_flag = has_megastructure
		}
	}
}

kugelblitz_0 = {
	entity = "kugelblitz_new_empty_entity"
	construction_entity = "kugelblitz_new_empty_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_kugelblitz }
	construction_blocks_and_blocked_by = none

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = {
			alloys = 5
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_kugelblitz
		NOT = { has_global_flag = kugel_disabled }
		OR = {
			has_global_flag = kugel_capped_u
			check_variable = {
				which = giga_current_kugel
				value < value:giga_kugel_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border" is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = kugel_capped_u
					check_variable = {
						which = giga_current_kugel
						value < value:giga_kugel_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|15|
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|50|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_cap_availability_boost
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|kugelblitz|
	}

	on_build_start = {
		from = {
			set_country_flag = is_currently_building_kugelblitz
		}
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_kugelblitz
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_kugelblitz years = 20 }
			remove_country_flag = is_currently_building_kugelblitz
			
			
			change_variable = { which = giga_current_kugel value = 1 }
		}
	}
}

macro_test_site_0 = {
	entity = "giga_test_site_1"
	construction_entity = "giga_test_site_stage_1_entity_con"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	scales_with_planet = yes
	prerequisites = { giga_tech_engineering_test_site }
	use_planet_resource = yes
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	construction_blocks_and_blocked_by = none

	build_time = 360
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @science_kilo_cost_1
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @science_kilo_cost_1
		}
		upkeep = {
			energy = 10
		}
		upkeep = {
			trigger = { 
				exists = owner
				owner = { 
					is_gestalt = no
				}
			}
			consumer_goods = 5
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = no
				}
			}
			minerals = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = yes
				}
			}
			energy = 10
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_engineering_test_site
		NOT = { has_global_flag = megabase_disabled }
		OR = {
			has_global_flag = megabase_capped_u
			check_variable = {
				which = giga_current_megabase
				value < value:giga_megabase_limit
			}
		}
	}
	country_modifier = {
		custom_tooltip = orbital_test_site_1_mod_tooltip
	}
	possible = {
		custom_tooltip = { fail_text = "requires_inside_border" 			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_no_anomaly" 				NOT = { any_system_planet = { has_anomaly = yes } } }
		custom_tooltip = { fail_text = "requires_no_arc_furnace" 			system_has_arc_furnace = no }
		custom_tooltip = { fail_text = "requires_no_macro_test_site"		NOT = { any_system_megastructure = { ehof_giga_new_is_macrotest = yes } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = megabase_capped_u
					check_variable = {
						which = giga_current_megabase
						value < value:giga_megabase_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = { fail_text = "must_build_around_frozen" 			giga_is_frozen = yes }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			OR = {
				from = { is_ai = no }
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							giga_is_science_candidate = yes
						}
					}
				}
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|25|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_large_system
		mult = value:giga_ai_deposit_stack
		mult = value:giga_ai_prevent_spam|MEGA|macro_test_site|
		mult = value:giga_ai_materialist_plus

		modifier = { factor = 2.00	from = { has_federation = yes federation = { has_federation_type = research_federation } } }
	}
	on_build_start = {
		from = {
			set_country_flag = is_currently_building_macro_test_site
		}
		set_star_flag = mega_base_construction
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_macro_test_site
		}
		remove_star_flag = mega_base_construction
	}
	on_build_complete = {
		save_event_target_as = giga_system
		remove_star_flag = mega_base_construction
		fromfrom.planet = {
			set_planet_flag = has_test_site
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_entity = {
				entity = invisible_turret_entity
			}
		}
		fromfrom = {
			set_megastructure_flag = giga_dismantle_ready
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_macro_test_site years = 10 }
			remove_country_flag = is_currently_building_macro_test_site
			create_message = {
				type = MEGASTRUCTURE_BUILT
				localization = MESSAGE_MEGASTRUCTURE_BUILT
				days = 30
				target = from 
				variable = {
					type = name
					localization = MEGASTRUCTURE
					scope = from
				}
				variable = {
					type = name
					localization = SYSTEM
					scope = root
				}
			}
			change_variable = { which = giga_current_megabase value = 1 }
		}
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			remove_trade_deposits = yes
			set_planet_flag = giga_test_site_stage_1
			save_event_target_as = target_planet
			add_deposit = d_engineering_2
			science_kilo_update_orbital_effect = yes
			
			
			
			
		}
	}

	dismantle_cost = {
		category = giga_kilostructures
		cost = {
			energy = 500
		}
	}

	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}

	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = giga_tech_engineering_test_site
		}
		
		
		
		
	}
	on_dismantle_start = { 
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
				NOT = { has_planet_flag = giga_test_site_stage_1 }
			}
			set_planet_flag = giga_test_site_stage_1
		}
		fromfrom.planet = {
			set_planet_flag = has_test_site
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			giga_dismantle_science_kilo_effect = {
				FLAG = test_site
				TYPE = engineering
			}
		}
		random_system_planet = {
			limit = {
				has_planet_flag = has_test_site
			}
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_test_site
			set_planet_entity = { entity = giga_test_site_devastated_planet_entity }
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
			if = {
				limit = {
					check_variable = {
						which = giga_current_megabase
						value >= 1
					}
				}
				change_variable = {
					which = giga_current_megabase
					value = -1
				}
			}
		}
	}
}

orbital_arc_furnace_1 = {
	entity = "arc_crucible_stage_1_entity"
	construction_entity = "arc_crucible_stage_1_entity"
	construction_scale = 1.02 
	portrait = "GFX_megastructure_arc_furnace_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = 0 y = 0 }
	rotate_to_center = no
	scale_offset = yes
	
	use_planet_resource = yes
	scales_with_planet = yes
	build_time = 360 
	resources = {
		category = giga_kilostructures
		cost = {
			unity = 500
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 500
		}

		upkeep = {
			energy = 20
		}
	}

	construction_blocks_and_blocked_by = self_type

	prerequisites = { "tech_orbital_arc_furnace" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_machine_age_dlc = yes
		OR = {
			check_variable = {
				which = arc_furnace_counter
				value < value:arc_furnace_limit
			}
			has_global_flag = vanilla_furnace_capped_u
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_dyson_sphere"
			system_has_dyson_sphere = no
		}
		custom_tooltip = {
			fail_text = "requires_no_dyson_sphere_construction"
			if = {
				limit = {
					system_has_dyson_sphere = no
				}
				NOT = {
					solar_system = {
						has_star_flag = dyson_sphere_construction
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_arc_furnace"
			system_has_arc_furnace = no
		}
		custom_tooltip = { 
			fail_text = "requires_no_planetary_seeder_nexus"		
			giga_system_has_planetary_seeder_nexus = no
		} 
		custom_tooltip = { 
			fail_text = "requires_no_macro_test_site"		
			giga_system_has_macro_test = no
		} 
		custom_tooltip = { 
			fail_text = "requires_no_atmosphere_shredder"	
			giga_system_has_atmosphere_shredder = no 
		} 
		custom_tooltip = { 
			fail_text = "requires_no_orb_eco_arc"			
			giga_system_has_artificial_eco = no
		}

		custom_tooltip = {
			fail_text = "requires_less_than_x_arc_furnaces"
			from = {
				OR = {
					check_variable = {
						which = arc_furnace_counter
						value < value:arc_furnace_limit
					}
					has_global_flag = vanilla_furnace_capped_u
				}

			}
		}
	}

	dismantle_cost = {
		category = giga_kilostructures
		cost = {
			energy = 500
		}
	}

	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}

	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = tech_orbital_arc_furnace
		}
	}

	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				has_modifier = orbital_arc_furnace_1_mod
			}
			dismantle_arc_furnace_effect = yes
		}
		random_system_planet = {
			limit = {
				has_planet_flag = has_arc_furnace
			}
			set_planet_entity = { entity = pc_molten }
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_arc_furnace
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
			if = {
				limit = {
					check_variable = {
						which = arc_furnace_counter
						value >= 1
					}
				}
				change_variable = {
					which = arc_furnace_counter
					value = -1
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			is_planet_class = pc_molten
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOR = {
					has_planet_flag = megastructure
					has_planet_flag = has_megastructure
				}
			}
			if = {
				limit = {
					from = { is_ai = yes }
				}
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							NOT = { has_deposit_for = shipclass_research_station }
							is_star = no
							is_astral_scar = no
							colonizable_planet = no
						}
					}
				}
			}
		}
	}

	country_modifier = {
		custom_tooltip = orbital_arc_furnace_1_mod_tooltip
	}

	
	
	ai_weight = {
		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_deposit_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|20|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_large_system
		mult = value:giga_ai_prevent_spam|MEGA|orbital_arc_furnace|
		mult = value:giga_ai_militarist_plus
		mult = value:giga_ai_xenophobe_plus
	}

	on_build_start = {
		set_star_flag = arc_furnace_construction
		from = {
			set_country_flag = is_currently_building_orbital_arc_furnace
		}
	}
	on_build_cancel = {
		remove_star_flag = arc_furnace_construction
		from = {
			remove_country_flag = is_currently_building_orbital_arc_furnace
		}
	}
	on_build_complete = {
		remove_star_flag = arc_furnace_construction
		fromfrom.planet = {
			set_planet_flag = has_megastructure
			set_planet_flag = has_arc_furnace
			if = {
				limit = { has_orbital_station = yes }
				orbital_station = {
					dismantle = yes
				}
			}
			set_planet_entity = { entity = invisible_turret_entity }
		}
		from = {
			remove_country_flag = is_currently_building_orbital_arc_furnace
			set_timed_country_flag = { flag = has_recently_built_orbital_arc_furnace years = 3 }
			country_event = {
				id = cybernetics.1000
			}
			country_event = {
				id = machine_age.3405 
			}
			change_variable = {
				which = arc_furnace_counter
				value = 1
			}
		}

	}
}

orbital_artificial_eco_0 = {
	entity = "giga_zoo_new_1"
	construction_entity = "giga_zoo_new_1_part"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	scales_with_planet = yes
	use_planet_resource = yes
	prerequisites = { giga_tech_orbital_artificial_eco }
	country_modifier = {
		custom_tooltip = orbital_eco_arcology_1_mod_tooltip
	}
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	construction_blocks_and_blocked_by = none

	build_time = 360
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @science_kilo_cost_1
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @science_kilo_cost_1
		}
		upkeep = {
			energy = 10
		}
		upkeep = {
			trigger = { 
				exists = owner
				owner = { 
					is_gestalt = no
				}
			}
			consumer_goods = 5
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = no
				}
			}
			minerals = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = yes
				}
			}
			energy = 10
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_orbital_artificial_eco
		NOT = { has_global_flag = orbital_artificial_eco_disabled }
		OR = {
			has_global_flag = orbital_artificial_eco_capped_u
			check_variable = {
				which = giga_current_orbital_artificial_eco
				value < value:giga_orbital_artificial_eco_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_no_anomaly" 				NOT = { any_system_planet = { has_anomaly = yes } } }
		custom_tooltip = { fail_text = "requires_no_arc_furnace" 			system_has_arc_furnace = no }
		custom_tooltip = { fail_text = "requires_no_orb_eco_arc"			NOT = { any_system_megastructure = { ehof_giga_new_is_artificial_eco = yes } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = orbital_artificial_eco_capped_u
					check_variable = {
						which = giga_current_orbital_artificial_eco
						value < value:giga_orbital_artificial_eco_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = { fail_text = "must_build_around_toxic" 			giga_is_toxic = yes}
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			OR = {
				from = { is_ai = no }
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							giga_is_science_candidate = yes
						}
					}
				}
			}
		}
	}
	
	ai_weight = {
		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|25|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_large_system
		mult = value:giga_ai_deposit_stack
		mult = value:giga_ai_prevent_spam|MEGA|orbital_artificial_eco|
		mult = value:giga_ai_materialist_plus

		modifier = { factor = 2.00	from = { has_federation = yes federation = { has_federation_type = research_federation } } }
	}


	on_build_start = {
		from = {
			set_country_flag = is_currently_building_orbital_artificial_eco
		}
		set_star_flag = eco_arc_construction
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_orbital_artificial_eco
		}
		remove_star_flag = eco_arc_construction
	}
	on_build_complete = {
		save_event_target_as = giga_system
		remove_star_flag = eco_arc_construction
		fromfrom.planet = {
			set_planet_flag = has_eco_arc
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_orbital_artificial_eco years = 10 }
			remove_country_flag = is_currently_building_orbital_artificial_eco
			create_message = {
				type = MEGASTRUCTURE_BUILT
				localization = MESSAGE_MEGASTRUCTURE_BUILT
				days = 30
				target = from 
				variable = {
					type = name
					localization = MEGASTRUCTURE
					scope = from
				}
				variable = {
					type = name
					localization = SYSTEM
					scope = root
				}
			}
			change_variable = { which = giga_current_orbital_artificial_eco value = 1 }
		}
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			remove_trade_deposits = yes
			set_planet_flag = giga_eco_arcology_stage_1
			save_event_target_as = target_planet
			add_deposit = d_society_2
			science_kilo_update_orbital_effect = yes
		}
		fromfrom = {
			set_megastructure_flag = giga_dismantle_ready
		}
	}
	
	dismantle_cost = {
		category = giga_kilostructures
		cost = {
			energy = 500
		}
	}

	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}

	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = giga_tech_orbital_artificial_eco
		}
		
		
		
		
	}
	on_dismantle_start = { 
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
				NOT = { has_planet_flag = giga_eco_arcology_stage_1 }
			}
			set_planet_flag = giga_eco_arcology_stage_1
		}
		fromfrom.planet = {
			set_planet_flag = has_eco_arc
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				giga_is_science_candidate = yes
			}
			giga_dismantle_science_kilo_effect = {
				FLAG = eco_arcology
				TYPE = society
			}
		}
		random_system_planet = {
			limit = {
				has_planet_flag = has_eco_arc
			}
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_eco_arc
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
			if = {
				limit = {
					check_variable = {
						which = giga_current_orbital_artificial_eco
						value >= 1
					}
				}
				change_variable = {
					which = giga_current_orbital_artificial_eco
					value = -1
				}
			}
		}
	}
}

orbital_naval_logistics_office_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = 0 y = -20 }
	prerequisites = { giga_tech_orbital_naval_logistics }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1080
	resources = {
		category = giga_kilostructures
		cost = {
			influence = 100
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_orbital_naval_logistics
		NOT = { has_global_flag = orbital_naval_logistics_disabled }
		OR = {
			has_global_flag = orbital_naval_logistics_capped_u
			check_variable = {
				which = giga_current_orbital_naval_logistics
				value < value:orbital_naval_logistics_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = orbital_naval_logistics_capped_u
					check_variable = {
						which = giga_current_orbital_naval_logistics
						value < value:orbital_naval_logistics_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_surveyed_planet"			is_surveyed = { who = prev.from status = yes } }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			custom_tooltip = {
				fail_text = "must_build_around_developed_planet"
				or = {
					and = {
						is_colony = yes
						exists = owner
						exists = controller
						has_upgraded_capital = yes
					}
				}
			}
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|25|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_militarist

		modifier = { factor = 2.00	from = { has_federation = yes federation = { has_federation_type = research_federation } } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			create_message = {
				type = MEGASTRUCTURE_BUILT
				localization = MESSAGE_MEGASTRUCTURE_BUILT
				days = 30
				target = from 
				variable = {
					type = name
					localization = MEGASTRUCTURE
					scope = from
				}
				variable = {
					type = name
					localization = SYSTEM
					scope = root
				}
			}
			change_variable = { which = giga_current_orbital_naval_logistics value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

planetary_seeder_nexus_0 = {
	entity = "giga_zoo_new_1"
	construction_entity = "giga_zoo_new_1_part"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	scales_with_planet = yes
	use_planet_resource = yes
	prerequisites = { giga_tech_planetary_seeder_nexus }
	country_modifier = {
		custom_tooltip = planetary_seeder_nexus_1_mod_tooltip
	}
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	construction_blocks_and_blocked_by = none

	build_time = 360
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @science_kilo_cost_1
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @science_kilo_cost_1
		}
		upkeep = {
			energy = 10
		}
		upkeep = {
			trigger = { 
				exists = owner
				owner = { 
					is_gestalt = no
				}
			}
			consumer_goods = 5
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = no
				}
			}
			minerals = 15
		}
		upkeep = {
			trigger = {
				exists = owner
				owner = { 
					is_gestalt = yes
					is_machine_empire = yes
				}
			}
			energy = 10
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_planetary_seeder_nexus
		NOT = { has_global_flag = planetary_seeder_nexus_disabled }
		OR = {
			has_global_flag = planetary_seeder_nexus_capped_u
			check_variable = {
				which = giga_current_planetary_seeder_nexus
				value < value:giga_planetary_seeder_nexus_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_no_anomaly" 				NOT = { any_system_planet = { has_anomaly = yes } } }
		custom_tooltip = { fail_text = "requires_no_arc_furnace" 			system_has_arc_furnace = no }
		custom_tooltip = { fail_text = "requires_no_planetary_seeder_nexus"			NOT = { any_system_megastructure = { ehof_giga_new_is_artificial_eco = yes } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = planetary_seeder_nexus_capped_u
					check_variable = {
						which = giga_current_planetary_seeder_nexus
						value < value:giga_planetary_seeder_nexus_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = { fail_text = "must_build_around_gas" 				giga_is_gas_giant = yes }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			OR = {
				from = { is_ai = no }
				solar_system = {
					count_system_planet = {
						count >= 8
						limit = {
							giga_is_food_candidate = yes
						}
					}
				}
			}
		}
	}
	
	ai_weight = {
		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|25|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_large_system
		mult = value:giga_ai_deposit_stack
		mult = value:giga_ai_prevent_spam|MEGA|planetary_seeder_nexus|
		mult = value:giga_ai_materialist_plus
	}


	on_build_start = {
		from = {
			set_country_flag = is_currently_building_planetary_seeder_nexus
		}
		set_star_flag = planetary_seeder_nexus_construction
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_planetary_seeder_nexus
		}
		remove_star_flag = planetary_seeder_nexus_construction
	}
	on_build_complete = {
		save_event_target_as = giga_system
		remove_star_flag = planetary_seeder_nexus_construction
		fromfrom.planet = {
			set_planet_flag = has_planetary_seeder_nexus
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_planetary_seeder_nexus years = 10 }
			remove_country_flag = is_currently_building_planetary_seeder_nexus
			create_message = {
				type = MEGASTRUCTURE_BUILT
				localization = MESSAGE_MEGASTRUCTURE_BUILT
				days = 30
				target = from 
				variable = {
					type = name
					localization = MEGASTRUCTURE
					scope = from
				}
				variable = {
					type = name
					localization = SYSTEM
					scope = root
				}
			}
			change_variable = { which = giga_current_planetary_seeder_nexus value = 1 }
		}
		every_system_planet = {
			limit = {
				giga_is_food_candidate = yes
			}
			remove_trade_deposits = yes
			set_planet_flag = giga_planetary_seeder_nexus_stage_1
			save_event_target_as = target_planet
			add_deposit = d_giga_food_1
			add_modifier = {
				modifier = planetary_seeder_nexus_1_mod
				days = -1
			}
		}
		fromfrom = {
			set_megastructure_flag = giga_dismantle_ready
		}
	}
	
	dismantle_cost = {
		category = giga_kilostructures
		cost = {
			energy = 500
		}
	}

	dismantle_time = 360

	dismantle_potential = {
		always = yes
	}

	dismantle_possible = {
		can_dismantle_megastructure = {
			TECH = giga_tech_planetary_seeder_nexus
		}
		
		
		
		
	}
	on_dismantle_start = { 
		every_system_planet = {
			limit = {
				giga_is_food_candidate = yes
				NOT = { has_planet_flag = giga_planetary_seeder_nexus_stage_1 }
			}
			set_planet_flag = giga_planetary_seeder_nexus_stage_1
		}
		fromfrom.planet = {
			set_planet_flag = has_planetary_seeder_nexus
		}
	}
	on_dismantle_complete = {
		every_system_planet = {
			limit = {
				giga_is_food_candidate = yes
			}
			giga_dismantle_planetary_seeder_nexus_effect = yes
		}
		random_system_planet = {
			limit = {
				has_planet_flag = has_planetary_seeder_nexus
			}
			remove_planet_flag = has_megastructure
			remove_planet_flag = has_planetary_seeder_nexus
			giga_dismantle_planetary_seeder_nexus_effect = yes
		}
		from = {
			add_resource = {
				alloys = 500
				mult = modifier:megastructure_dismantle_refund_mult
			}
			if = {
				limit = {
					check_variable = {
						which = giga_current_planetary_seeder_nexus
						value >= 1
					}
				}
				change_variable = {
					which = giga_current_planetary_seeder_nexus
					value = -1
				}
			}
		}
	}
}

succ_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_succ }
	construction_blocks_and_blocked_by = none

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_succ
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_small_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		from = {
			set_country_flag = is_currently_building_succ
		}
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_small_mega_unity_cost }
	}
	on_build_cancel = {
		from = {
			remove_country_flag = is_currently_building_succ
		}
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_succ
		NOT = { has_global_flag = succ_disabled }
		OR = {
			has_global_flag = succ_capped_u
			check_variable = {
				which = giga_current_succ
				value < value:giga_succ_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = succ_capped_u
					check_variable = {
						which = giga_current_succ
						value < value:giga_succ_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_larger_planet"				planet_size >= 6 }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_gas"				giga_is_gas_giant = yes }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|35|
		mult = value:giga_ai_output|RESOURCE|energy|AMOUNT|250|MIN|0.75|
		mult = value:giga_ai_output|RESOURCE|exotic_gases|AMOUNT|20|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|volatile_motes|AMOUNT|20|MIN|0.5|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|succ|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|14500|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_succ years = 20 }
			remove_country_flag = is_currently_building_succ
			country_event = { id = giga_dialog.1901 }	
			change_variable = { which = giga_current_succ value = 1 }
		}
	}
}

anti_sirens_shield = {
	entity = "giga_eawaf_sirens_panopticon_entity"
	construction_entity = "giga_eawaf_sirens_panopticon_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	build_type = inside_gravity_well
	construction_blocks_and_blocked_by = self_type
	prerequisites = { giga_tech_eawaf_disenchanter_4 }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 2000
	resources = {
		category = megastructures
		cost = {
			unity = @giga_small_mega_unity_cost
			rare_crystals = 1000
			exotic_gases = 1000
			volatile_motes = 1000
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 10000
		}
		upkeep = {
			energy = 100
			rare_crystals = 3
			exotic_gases = 3
			volatile_motes = 3
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		is_ai = no
		has_technology = giga_tech_eawaf_disenchanter_4
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_anti_sirens_shield"
			NOT = {
				has_megastructure = anti_sirens_shield
			}
		}
	}

	ai_weight = {
		weight = 0
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		if = {
			limit = {
				NOT = { has_global_flag = giga_eawaf_shroudsonic_enthraller_destroyed }
				exists = event_target:giga_eawaf_country
			}
			event_target:giga_eawaf_country = {
				giga_eawaf_apply_strife_field_effects = yes
			}
		}
	}
}

war_moon_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_war_moon_2 }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_attack_moon
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = military RESOURCE = alloys AMOUNT = 3500 }
		giga_ai_savings_withdraw = { CATEGORY = military RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = military RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = military RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_war_moon_2
		NOT = { has_global_flag = warmoon_disabled }
		OR = {
			has_global_flag = warmoon_capped_u
			check_variable = {
				which = giga_current_warmoon
				value < value:giga_warmoon_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = warmoon_capped_u
					check_variable = {
						which = giga_current_warmoon
						value < value:giga_warmoon_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "must_build_size_567"
				OR = {
					AND = {
						planet_size >= 5
						planet_size <= 7
						NOT = { is_planet_class = pc_core_mined }
					}
					AND = {
						planet_size >= 1
						planet_size <= 4
						is_planet_class = pc_core_mined
					}
				}
			}
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_crisis_planet"			NOT = { has_planet_flag = crisis_vital_planet } }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "must_build_around_molten_barren_stripmined"
				OR = {
					giga_is_molten = yes
					giga_is_frozen = yes
					giga_is_barren_cn = yes
					
					is_planet_class = pc_core_mined
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		

		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega
		
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|800|MIN|0.25|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|250|MIN|0.1|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_prevent_spam|MEGA|war_moon|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_cap_availability_boost
		mult = value:giga_ai_weight_savings|CATEGORY|military|RESOURCE|alloys|AMOUNT|20000|
		mult = value:giga_ai_militarist_plus

		modifier = { factor = 10	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_war_moon years = 5 }
			country_event = { id = giga_dialog.2601 }	
			change_variable = { which = giga_current_warmoon value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = megastructure
			set_planet_size = 6
		}
	}
}

behemoth_egg = {
	entity = "kaiju_01_egg_entity"
	construction_entity = "kaiju_01_egg_entity"
	portrait = "GFX_megastructure_behemoth_egg_background"
	show_galactic_map_icon = yes
	show_in_outliner = yes
	place_entity_on_planet_plane = yes
	entity_offset = { x = @position_offset_x y = @position_offset_y }
	plane_offset = -3
	build_time = 3600

	resources = {
		category = giga_megastructures
		cost = {
			food = 50000
			influence = 300
		}
	}

	construction_blocks_and_blocked_by = none

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		owner = { has_crisis_perk = menp_behemoth_egg }
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			has_no_non_gate_megastructure = yes
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_surveyed_planet"
				is_surveyed = {			
					who = prev.from
					status = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				
				NOR = {
					has_planet_flag = megastructure
					has_planet_flag = has_megastructure
					solar_system = {
						has_star_flag = ring_world_built
					}
					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
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
			custom_tooltip = {
				fail_text = "requires_gas_giant"
				is_planet_class = pc_gas_giant
			}
		}
	}

	
	
	ai_weight = {
		factor = 5
	}

	on_build_start = {}

	on_build_cancel = {}

	on_build_complete = {
		from = {
			set_country_flag = behemoth_egg_built
			complete_crisis_objective = crisobj_build_behemoth_egg
		}
		fromfrom.planet = { set_planet_flag = has_megastructure }
	}
}

the_vat_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	entity_offset = { x = -20 y = -20 }
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_the_vat }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 2700
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_the_vat
		NOT = { has_global_flag = the_vat_disabled }
		OR = {
			has_global_flag = the_vat_capped_u
			check_variable = {
				which = giga_current_the_vat
				value < value:giga_the_vat_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = the_vat_capped_u
					check_variable = {
						which = giga_current_the_vat
						value < value:giga_the_vat_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		weight = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|160|MIN|0.1|
		weight = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|150|MIN|0.25|
		weight = value:giga_ai_upkeep|RESOURCE|food|AMOUNT|300|MIN|0.1|
		weight = value:giga_ai_prevent_spam|MEGA|the_vat|
		weight = value:giga_ai_core_territory
		weight = value:giga_ai_unlocks_galwonders
		weight = value:giga_ai_militarist_plus
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_the_vat years = 20 }
			country_event = { id = giga_dialog.11301 }	
			change_variable = { which = giga_current_the_vat value = 1 }
		}
		fromfrom = {
			set_megastructure_flag = giga_vat_01_fauna
			set_megastructure_flag = giga_vat_01_scourge
			set_megastructure_flag = giga_vat_01_leviathans
			set_megastructure_flag = giga_vat_02_fauna
			set_megastructure_flag = giga_vat_03_fauna
			set_megastructure_flag = giga_vat_04_fauna
			set_megastructure_flag = giga_vat_05_fauna
			set_megastructure_flag = giga_vat_06_fauna
			set_megastructure_flag = giga_vat_07_fauna
		}
	}
}

eq_shipyard_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_equatorial_shipyard }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_equatorial_shipyard
		cost = {
			influence = 100
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2500
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|alloys|AMOUNT|2500| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = alloys AMOUNT = 2500 }
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_equatorial_shipyard
		NOT = { has_global_flag = shipyard_disabled }
		giga_can_use_habitables = yes
		OR = {
			has_global_flag = shipyard_capped_u
			check_variable = {
				which = giga_current_shipyard
				value < value:giga_shipyard_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = shipyard_capped_u
					check_variable = {
						which = giga_current_shipyard
						value < value:giga_shipyard_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_smaller_than_25"			planet_size <= 25 }
			custom_tooltip = {
				fail_text = "requires_survey_not_habitable"
				is_surveyed = {
					who = prev.from status = yes
				}
				is_planet_habitable = no
				NOT = { any_moon = { is_colony = yes } }
			}
			custom_tooltip = { fail_text = "must_build_around_molten"			giga_is_molten = yes }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			

			custom_tooltip = { 
				fail_text = "requires_no_existing_megastructure"	
				if = {
					limit = { has_moon = yes }
					any_moon = {
						planet_has_no_megastructure = yes 
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|50|MIN|0.25|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|eq_shipyard|
		mult = value:giga_ai_weight_savings|CATEGORY|resource|RESOURCE|alloys|AMOUNT|12500|

		modifier = {
			not = { has_global_flag = @giga_amb_flag }
			mult = 0.25
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_eq_shipyard years = 20 }
			country_event = { id = giga_dialog.3601 }	
			change_variable = { which = giga_current_shipyard value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

ehof_megastructure_phase0 = {
	entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	construction_entity = "construction_platform_entity"
	
	entity_offset = { x = -15 y = 15 }
	show_galactic_map_icon = yes
	place_entity_on_planet_plane = no

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = @phase_0_build_time
	resources = {
		category = giga_megastructures
		cost = {
			influence = @phase_0_influence_cost
			energy = @phase_0_energy_cost
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @phase_0_alloy_cost
		}
		upkeep = {
			energy = @phase_0_energy_upkeep
		}
	}

	prerequisites = { "tech_ehof_phase_01" }
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		check_variable = { which = ehof_phase value < 1 }
		NOT = { has_global_flag = ehof_disabled }
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_existing_ehof"				from = { NOT = { any_owned_megastructure = { is_any_ehof = yes } } } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_gargantua"					NOT = { has_star_flag = guardians_technosphere_system } }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"				is_star = yes }
			custom_tooltip = { fail_text = "must_build_around_primary_star"		is_primary_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_black_hole"		giga_black_hole = yes }
		}
	}

	ai_weight = {
		factor = 50

		modifier = {
			factor = 0.1
			any_neighbor_system = {
				exists = owner
				NOT = { owner = { is_same_value = from } }
			}
		}

		modifier = { factor = 0		has_global_flag = ehof_disabled }
		modifier = { factor = 0		has_global_flag = ehof_ai_disabled }
		modifier = {
			factor = 0
			any_country = {
				is_country_type = global_event
				check_variable = { which = amount_of_ehofs value >= giga_ehof_ai_cap }
			}
		}
	}

	on_build_start = {
		random_country = {
			limit = { is_country_type = global_event }
			change_variable = { which = amount_of_ehofs value = 1 }
		}
	}
	on_build_cancel = {
		random_country = {
			limit = { is_country_type = global_event }
			subtract_variable = { which = amount_of_ehofs value = 1 }
		}
	}
	on_build_complete = {
		fromfrom = {
			giga_remove_ehof_mega_flags = yes
			set_megastructure_flag = ehof_phase_00
			planet = {
				giga_set_has_mega_flag = yes
				if = { limit = { has_orbital_station = yes } orbital_station = { dismantle = yes } }
			}
		}
		set_star_flag = ehof_megastructure_system@from
		save_event_target_as = ehof_megastructure_system

		
		every_system_planet = {
			set_planet_flag = cant_build_here
			set_planet_flag = cant_target_this_planet
		}

		from = {
			set_variable = { which = ehof_phase value = 0 }
			country_event = { id = ehof_megastructure.101 }
		}
	}
}

fusion_suppressor_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_fusion_suppressor }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 500
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_big_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_fusion_suppressor
		NOT = { has_global_flag = suppressor_disabled }
		OR = {
			has_global_flag = suppressor_capped_u
			check_variable = {
				which = giga_current_suppressor
				value < value:giga_suppressor_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_binary_trinary"				giga_is_bitrinary = no }
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				NOT = { any_system_planet = { is_surveyed = { who = prev.from status = no } } } }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"			NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = suppressor_capped_u
					check_variable = {
						which = giga_current_suppressor
						value < value:giga_suppressor_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "requires_standard_planet_class"			giga_is_standard_star = yes }
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|100|MIN|0.1|
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|200|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|energy|AMOUNT|500|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|giga_sr_iodizium|AMOUNT|10|
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_no_colony
		mult = value:giga_ai_prevent_spam|MEGA|fusion_suppressor|
		mult = value:giga_ai_cap_availability_boost

		
		mult = 0.15
		mult = trigger:num_planets_in_system
	}

	on_build_complete = {
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		save_event_target_as = giga_system
		from = {
			set_timed_country_flag = { flag = has_recently_built_fusion_suppressor years = 20 }
			country_event = { id = giga_dialog.3401 }	
			change_variable = { which = giga_current_suppressor value = 1 }
		}
	}
}

galactic_crucible_0 = {
    entity = "infernal_01_galactic_crucible_phase_01_entity"
    construction_entity = "infernal_01_galactic_crucible_construction_frame_entity"
    portrait = "GFX_megastructure_crucible_background"
    build_time = 720

    outliner_trigger = {
        exists = owner
        NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
    }

    resources = {
        category = megastructures
        cost = {
            entropy_crystals = 500
            alloys = 2500
        }
    }
    potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
        has_crisis_level = crisis_hyperthermia_level_1
        NOT = { has_country_flag = built_galactic_crucible }
    }
    possible = {
        hidden_trigger = {
            exists = starbase
        }
        custom_tooltip = {
            fail_text = "requires_inside_border"
            is_inside_border = from
        }
        custom_tooltip = {
            fail_text = "requires_surveyed_system"
            NOT = {
                any_system_planet = {
                    is_surveyed = {
                        who = prev.from
                        status = no
                    }
                }
            }
        }
        custom_tooltip = {
            fail_text = "requires_no_arc_furnace"
            system_has_arc_furnace = no
        }
        custom_tooltip = {
            fail_text = "requires_no_arc_furnace_construction"
            if = {
                limit = { system_has_arc_furnace = no }
                NOT = { solar_system = { has_star_flag = arc_furnace_construction } }
            }
        }
        custom_tooltip = {
            fail_text = "requires_no_black_hole_neutron_star_pulsar"
            NOT = {
                is_star_class = sc_black_hole
                is_star_class = sc_neutron_star
                is_star_class = sc_pulsar
            }
        }
        custom_tooltip = {
            fail_text = "requires_no_binary_trinary"
            is_binary_star = no
            is_trinary_star = no
        }
        custom_tooltip = {
            fail_text = "requires_no_existing_megastructure"
            has_no_non_gate_megastructure = yes
            NOR = {
                any_system_planet = { is_planet_class = pc_cosmogenesis_world }
                has_star_flag = ring_world_built
            }
        }
        custom_tooltip = {
            fail_text = "requires_no_colonies"
            NOT = {
                any_system_planet = {
                    is_colony = yes
                    is_artificial = no
                    exists = owner
                    owner = { is_primitive = no }
                }
            }
        }
    }

    placement_rules = {
        planet_possible = {
            custom_tooltip = {
                fail_text = "must_build_around_star"
                is_star = yes
            }
            custom_tooltip = {
                fail_text = "requires_no_anomaly"
                NOT = { has_anomaly = yes }
            }
        }
    }

    on_build_complete = {
        fromfrom.planet = {
            set_planet_flag = megastructure
            set_planet_flag = has_megastructure
        }
        every_system_planet = {
            limit = {
                is_star = no
                distance = {
                    source = solar_system.star
                    min_distance >= 10
                    max_distance <= 75
                    same_solar_system = yes
                }
            }
            every_moon = { remove_planet = yes }
            remove_planet = yes
        }
        from = { set_country_flag = built_galactic_crucible }
        fromfrom = {
            set_megastructure_flag = galactic_crucible
            set_megastructure_flag = galactic_crucible@owner
        }
    }

    ai_weight = {
        factor = 3
        modifier = {
            factor = 3
            exists = sector
            sector = { has_sector_type = core_sector }
        }
        modifier = {
            factor = 0.1
            starbase = { NOT = { has_starbase_size >= starbase_starfortress } }
        }
        modifier = {
            factor = 0
            any_neighbor_system = {
                exists = owner
                NOT = { owner = { is_same_value = from } }
            }
        }
    }
}

terraform_shattered_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_terraform_shattered }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1260
	resources = {
		category = giga_kilostructures
		cost = {
			unity = @giga_kilo_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_terraform_shattered
		NOT = { has_global_flag = glue_disabled }
		OR = {
			has_global_flag = glue_capped_u
			check_variable = {
				which = giga_current_glue
				value < value:giga_glue_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = glue_capped_u
					check_variable = {
						which = giga_current_glue
						value < value:giga_glue_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "must_build_around_shattered"
				OR = {
					is_planet_class = pc_shattered
					is_planet_class = pc_shattered_2
					is_planet_class = pc_broken
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOT = { has_planet_flag = giga_terraforming_megastructure }
			}
		}
	}

	ai_weight = {
		

		

		

		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_planet_size
		mult = value:giga_ai_prevent_spam|MEGA|terraform_shattered|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_overpopulation_boost
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = giga_terraforming_megastructure
		}
		from = {
			change_variable = { which = giga_current_glue value = 1 }
			set_timed_country_flag = { flag = has_recently_built_terraform_shattered years = 20 }
			country_event = { id = giga_dialog.11201 }	
		}
	}
}

interstellar_assembly_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	prerequisites = { "tech_interstellar_assembly" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_interstellar_disabled }
		OR = {
			has_global_flag = vanilla_interstellar_capped_u
			check_variable = {
				which = giga_current_vanilla_interstellar
				value < value:giga_vanilla_interstellar_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_interstellar_capped_u
					check_variable = {
						which = giga_current_interstellar_assembly
						value < value:giga_vanilla_interstellar_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|40|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_xenophile
		mult = value:giga_ai_prevent_spam|MEGA|interstellar_assembly|
	}

	on_build_complete = {
		from = {
			set_timed_country_flag = { flag = has_recently_built_interstellar_assembly years = 20 }
			set_country_flag = built_interstellar_assembly_site
			change_variable = { which = giga_current_vanilla_interstellar value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
		}
	}
}

interstellar_habitat_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	show_galactic_map_icon = yes
	prerequisites = { giga_tech_interstellar_habitat }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			influence = 75
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2500
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		always = no 
		has_technology = giga_tech_interstellar_habitat
		NOT = { has_global_flag = stellarhabitat_disabled }
		giga_can_use_habitables = yes
		OR = {
			has_global_flag = stellarhabitat_capped_u
			check_variable = {
				which = giga_current_stellarhabitat
				value < value:giga_stellarhabitat_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"		NOT = { any_system_planet = { is_surveyed = { who = prev.from status = no } } } }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"			planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"						is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"						has_anomaly = no }
			custom_tooltip = { fail_text = "cant_build_on_interstellar_habitat"			NOT = { solar_system = { has_star_flag = habitat_system } } }
			custom_tooltip = {
				fail_text = "requires_not_capped"
				from = {
					OR = {
						has_global_flag = stellarhabitat_capped_u
						check_variable = {
							which = giga_current_stellarhabitat
							value < value:giga_stellarhabitat_limit
						}
					}
				}
			}
		}
	}

	ai_weight = {
		

		

		

		
		
		

		

		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_prevent_spam|MEGA|interstellar_habitat|
		mult = value:giga_ai_core_territory
	}

	on_build_complete = {
		set_star_flag = habitat_system
		set_star_flag = habitat_hyperlane_needed
		save_event_target_as = giga_system
		set_variable = { which = i_ring_segments value = 0 }
		save_event_target_as = interstellar_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_interstellar_habitat years = 20 }
			set_country_flag = giga_started_i_ringworld
			change_variable = { which = giga_current_stellarhabitat value = 1 }
			country_event = { id = giga_dialog.2901 }	
		}
		remove_megastructure = fromfrom
	}
}

lunar_disco_ball_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_disco_moon }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2500
		}
		upkeep = {
			energy = 5
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_disco_moon
		NOT = { has_global_flag = disco_moon_disabled }
		OR = {
			has_global_flag = disco_moon_capped_u
			check_variable = {
				which = giga_current_disco_moon
				value < value:giga_disco_moon_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = disco_moon_capped_u
					check_variable = {
						which = giga_current_disco_moon
						value < value:giga_disco_moon_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_moon"				is_moon = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes NOT = { is_planet_class = pc_disco_moon } }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_crisis_planet"			NOT = { has_planet_flag = crisis_vital_planet } }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}

			
			
			
			custom_tooltip = {
				fail_text = "must_build_around_habitable_planet"
				OR = {
					prev.from = { is_ai = no }
					and = {
						is_colony = no 
						is_colonizable = no 

						
						exists = orbit
						orbit = {
							or = {
								and = {
									is_colony = yes
									exists = owner
									owner = {
										is_same_empire = prevprevprev.from
									}
								}
								any_moon = {
									is_colony = yes
									exists = owner
									owner = {
										is_same_empire = prevprevprevprev.from
									}
								}
							}
						}
						
						solar_system = {
							
							not = {
								any_system_planet = {
									
									not = { is_same_value = prevprev }
									
									is_astral_scar = no
									is_star = no
									is_asteroid = no
									is_moon = yes
									is_colony = no
									is_colonizable = no
									custom_tooltip = {
										text = "not habitable"
										not = { is_planet_habitable = yes }
									}
									has_anomaly = no
									custom_tooltip = {
										text = "no mega"
										planet_has_no_megastructure = yes 
									}
									NOT = { is_planet_class = pc_disco_moon }
									is_surveyed = { who = prev.from status = yes } 
									
									exists = orbit
									orbit = {
										or = {
											
											and = {
												is_colony = yes
												exists = owner
												owner = {
													is_same_empire = prevprevprevprev.prev.from
												}
											}
											
											any_moon = {
												is_colony = yes
												exists = owner
												owner = {
													is_same_empire = prevprevprevprev.prevprev.from
												}
											}
										}
									}
									
									check_variable_arithmetic = {
										which = event_target:global_event_country.giga_zero
										add = value:giga_ai_disco_moon_evaluation
										value > prevprev.value:giga_ai_disco_moon_evaluation
									}
								}
							}
						}
					}
				}
			}
		}
	}

	ai_weight = {
		

		

		

		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|75|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|25|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_prevent_spam|MEGA|lunar_disco_ball|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlock_low_priority

	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_lunar_disco_ball years = 20 }
			country_event = { id = giga_dialog.201 }	
			change_variable = { which = giga_current_disco_moon value = 1 }
		}
	}
}

macro_stabilizer_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_terraform_gas }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_kilostructures
		cost = {
			influence = 50
			unity = @giga_kilo_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_terraform_gas
		NOT = { has_global_flag = terraform_gasgiant_disabled }
		OR = {
			has_global_flag = terraform_gasgiant_capped_u
			check_variable = {
				which = giga_current_terraform_gasgiant
				value < value:giga_terraform_gasgiant_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border" is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = terraform_gasgiant_capped_u
					check_variable = {
						which = giga_current_terraform_gasgiant
						value < value:giga_terraform_gasgiant_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_gas"				giga_is_gas_giant = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_crisis_planet"			NOT = { has_planet_flag = crisis_vital_planet } }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOT = { has_planet_flag = giga_terraforming_megastructure }
			}
		}
	}

	ai_weight = {
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		

		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_output|RESOURCE|exotic_gases|AMOUNT|30|MIN|0.1|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|macro_stabilizer|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = giga_terraforming_megastructure
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_macro_stabilizer years = 20 }
			country_event = { id = giga_dialog.301 }	
			change_variable = { which = giga_current_terraform_gasgiant value = 1 }
		}
	}
}

maginot_world_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	place_entity_on_planet_plane = no
	entity_offset = { x = 0 y = 0 }
	portrait = "GFX_megastructure_construction_background"

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	prerequisites = { giga_tech_maginot_world }

	build_time = @maginot_platform_build_time
	resources = {
		category = giga_maginot_world
		cost = {
			influence = @maginot_platform_influence
			unity = @giga_big_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = @maginot_platform_alloys
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|alloys|AMOUNT|@maginot_platform_alloys| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|unity|AMOUNT|@giga_big_mega_start_unity_cost| }
		upkeep = { energy = @maginot_platform_upkeep_energy alloys = @maginot_platform_upkeep_alloys }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = military RESOURCE = alloys AMOUNT = @maginot_platform_alloys }
		giga_ai_savings_withdraw = { CATEGORY = military RESOURCE = unity  AMOUNT = @giga_big_mega_start_unity_cost }
		apply_giga_bulwark_trad_build_speed = yes
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = military RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = military RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		
		has_technology = giga_tech_maginot_world 
		NOT = { has_global_flag = maginot_disabled }
		giga_can_use_habitables = yes
		OR = {
			has_global_flag = maginot_capped_u
			check_variable = {
				which = giga_current_maginot
				value < value:giga_maginot_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = maginot_capped_u
					check_variable = {
						which = giga_current_maginot
						value < value:giga_maginot_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			
			custom_tooltip = {
				fail_text = "requires_maginotable_planet_type"
				is_maginotable_planet_or_structure = yes
			}
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			
			custom_tooltip = { fail_text = "requires_not_asteroid"					is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"						is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_no_birch"						NOT = { is_planet_class = pc_birch } }
			
			custom_tooltip = {
				fail_text = "requires_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			
			custom_tooltip = {
				fail_text = "requires_not_hostile_or_primitive"
				NOR = {
					planet_is_hostile_or_crisis = yes
					AND = {
						exists = owner
						owner = {
							is_country_type = primitive
						}
					}
				}
			}
			
			custom_tooltip = {
				fail_text = "requires_not_maginot_world"					
				NOR = {
					is_giga_maginot_world = yes
					has_planet_flag = giga_maginot_world
				}
			}
			
			
			custom_tooltip = { 
				fail_text = "requires_no_existing_megastructure"		
				NOR = {
					has_planet_flag = has_planet_mw_mega 
					is_maginotable_restricted = yes
				}
			}
			
			custom_tooltip = { fail_text = "requires_surveyed_planet"				is_surveyed = { who = prev.from status = yes } }

			
			custom_tooltip = { fail_text = "requires_no_crisis_planet" 				NOT = { has_planet_flag = crisis_vital_planet  } }

			
			custom_tooltip = {
				fail_text = "requires_maginot_stronghold_built"			
				has_building = building_giga_maginot_stronghold
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_mega
		mult = 0.5 

		mult = value:giga_ai_output|RESOURCE|influence|AMOUNT|2|MIN|0.1|

		mult = value:giga_ai_strategic_location

		mult = value:giga_ai_prevent_spam|MEGA|maginot_world|
		mult = value:giga_ai_build_low_priority
		
		
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_cap_availability_boost

		
		
		modifier = {
			from = { country_uses_consumer_goods = yes }
			mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|460|
		}
		modifier = {
			from = { country_uses_consumer_goods = yes }
		 	mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|55|
		}
		modifier = {
			from = { country_uses_consumer_goods = yes }
		 	mult = value:giga_ai_upkeep|RESOURCE|consumer_goods|AMOUNT|50|
		}
		
		modifier = {
			from = { country_uses_consumer_goods = no }
			mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|510|
		}
		modifier = {
			from = { country_uses_consumer_goods = no }
			mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|85|
		}
		
		
		modifier = { factor = 5  starbase = { has_starbase_size >= starbase_starfortress } }

		
		
		
		
		
		
		
		
		

		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		modifier = { factor = 5	any_system_planet = { habitable_planet = yes planet_size >= 25 } }
		modifier = { factor = 0.1
			AND = {
				any_system_planet = { 			habitable_planet = yes 	planet_size < 18 }
				NOT = { any_system_planet = { 	habitable_planet = yes 	planet_size >= 20 } }
			}
		}
		
		modifier = { factor = 10
			count_system_planet = {
				limit = {
					habitable_planet = yes
				}
				count >= 5
			}
		}
		
		modifier = {
			factor = 3
			solar_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
				count_system_planet = {
					limit = {
						habitable_planet = yes
					}
					count >= 2
				}
			}
		}
		
		modifier = {
			factor = 0
			solar_system = {
				exists = owner
				is_same_value = owner.capital_scope.solar_system
				count_system_planet = {
					limit = {
						habitable_planet = yes
					}
					count = 1
				}
			}
		}
		
		modifier = { factor = 5.00	any_system_planet = { has_designation = col_fortress } }

		
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = hegemony_federation } } }
		modifier = { factor = 3		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 5		from = { has_ethic = ethic_fanatic_militarist } }
		modifier = { factor = 3		from = { has_ethic = ethic_militarist } }
		modifier = { factor = 2		from = { has_ethic = ethic_fanatic_xenophobe } }
		modifier = { factor = 1.5	from = { has_ethic = ethic_xenophobe } }
		modifier = { factor = 0.1	from = { has_ethic = ethic_fanatic_xenophile } }
		modifier = { factor = 0.5	from = { has_ethic = ethic_xenophile } }
		modifier = { factor = 0.5	from = { has_ethic = ethic_fanatic_pacifist } }
		modifier = { factor = 0.1	from = { has_ethic = ethic_pacifist } }
		modifier = { factor = 1.5	from = { has_civic = civic_citizen_service } }
		modifier = { factor = 20	from = { has_civic = civic_inwards_perfection } }

		

		
		
		
		modifier = {
			factor = 0
			from = {
				has_maginot_megastructure = yes
			}
		}
	}

	

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_planet_mw_mega			
			add_deposit = d_maginot_construction_blocker 	
			
			every_system_megastructure = {
				limit = {
					giga_is_orbital_ring = yes
					
					exists = planet
					planet = {
						is_same_value = prevprev
					}
				}
				remove_megastructure = this
			}
			if = {
				limit = { exists = orbital_defence }
				delete_fleet = orbital_defence
			}
		}
		
		if = {
			limit = { fromfrom.planet = { is_ringworld = yes } }
			spawn_megastructure = { type = "maginot_world_ringworld_0" owner = from coords_from = fromfrom.planet planet = event_target:giga_planet }
			remove_megastructure = fromfrom
		}
		
		else = {
			from = { country_event = { id = giga_dialog.5001 } } 
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_maginot years = 10 }
			change_variable = { which = giga_current_maginot value = 1 }
		}
	}
}

matter_decompressor_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -20 y = -20 }
	rotate_to_center = no
	scale_offset = yes
	prerequisites = { "tech_matter_decompressor" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_matter_decompressor
		cost = {
			unity = @giga_big_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_big_mega_start_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_big_mega_start_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_matter_disabled }
		has_gw_matter_decompressor = yes
		OR = {
			has_global_flag = vanilla_matter_capped_u
			check_variable = {
				which = giga_current_vanilla_matter
				value < value:giga_vanilla_matter_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"						is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"					giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_habitable_planets"				giga_any_hab_planets = no }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_matter_capped_u
					check_variable = {
						which = giga_current_vanilla_matter
						value < value:giga_vanilla_matter_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_black_hole"			giga_black_hole = yes }
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|100|
		mult = value:giga_ai_output|RESOURCE|minerals|AMOUNT|2000|
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|55000|
		mult = value:giga_ai_prevent_spam|MEGA|matter_decompressor|
	}

	on_build_complete = {
		from = {
			set_timed_country_flag = { flag = has_recently_built_matter_decompressor years = 20 }
			set_country_flag = built_matter_decompressor_site
			change_variable = { which = giga_current_vanilla_matter value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
			if = { limit = { has_orbital_station = yes } orbital_station = { dismantle = yes } }
		}
	}
}

mega_art_installation_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = -27 y = -27 }
	prerequisites = { "tech_mega_art" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_mega_art_installation
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_art_disabled }
		OR = {
			has_global_flag = vanilla_art_capped_u
			check_variable = {
				which = giga_current_vanilla_art
				value < value:giga_vanilla_art_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_art_capped_u
					check_variable = {
						which = giga_current_vanilla_art
						value < value:giga_vanilla_art_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = {
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_unity_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|30|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|mega_art_installation|
		mult = value:giga_ai_weight_savings|CATEGORY|resource|RESOURCE|alloys|AMOUNT|50000|
	}

	on_build_complete = {
		from = {
			set_timed_country_flag = { flag = has_recently_built_mega_art_installation years = 20 }
			set_country_flag = built_mega_art_installation_site
			change_variable = { which = giga_current_vanilla_art value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
		}
	}
}

mega_shipyard_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	prerequisites = { "tech_mega_shipyard" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_mega_shipyard
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 3000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|alloys|AMOUNT|3000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = alloys AMOUNT = 3000 }
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_shipyard_disabled }
		OR = {
			has_global_flag = vanilla_shipyard_capped_u
			check_variable = {
				which = giga_current_vanilla_shipyard
				value < value:giga_vanilla_shipyard_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"		giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_binary_trinary"		giga_is_bitrinary = no }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_shipyard_capped_u
					check_variable = {
						which = giga_current_vanilla_shipyard
						value < value:giga_vanilla_shipyard_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "requires_standard_planet_class"			giga_is_standard_star = yes }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|40|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|mega_shipyard|
		mult = value:giga_ai_weight_savings|CATEGORY|utility|RESOURCE|alloys|AMOUNT|33000|
		mult = value:giga_ai_militarist_plus

		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		from = {
			set_timed_country_flag = { flag = has_recently_built_mega_shipyard years = 20 }
			set_country_flag = built_mega_shipyard_site
			change_variable = { which = giga_current_vanilla_shipyard value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
			if = { limit = { has_orbital_station = yes } orbital_station = { dismantle = yes } }
		}
	}
}

neutronium_gigaforge_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_neutronium_gigaforge }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_neutronium_gigaforge
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 3500
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|3500| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 3500 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_neutronium_gigaforge
		NOT = { has_global_flag = gigaforge_disabled }
		OR = {
			has_global_flag = gigaforge_capped_u
			check_variable = {
				which = giga_current_gigaforge
				value < value:giga_gigaforge_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			NOT = { any_system_planet = { is_surveyed = { who = prev.from status = no } } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = gigaforge_capped_u
					check_variable = {
						which = giga_current_gigaforge
						value < value:giga_gigaforge_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_neutron_star"			OR = { is_planet_class = pc_neutron_star is_planet_class = pc_pulsar is_planet_class = pc_magnetar } }
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				OR = {
					planet_has_no_megastructure = yes
					AND = {
						has_planet_flag = has_nidavellir
						NOT = { has_planet_flag = has_gigaforge }
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|780|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|alloys|AMOUNT|420|MIN|0.5|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_prevent_spam|MEGA|neutronium_gigaforge|
		mult = value:giga_ai_cap_availability_boost
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|21000|
		mult = value:giga_ai_militarist
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_gigaforge
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_neutronium_gigaforge years = 20 }
			country_event = { id = giga_dialog.701 }	
			change_variable = { which = giga_current_gigaforge value = 1 }
		}
	}
}

penrose_sphere_0 = {
	entity = "giga_consite_10_10_entity"
	construction_entity = "giga_consite_10_10_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_penrose_sphere_1 }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			influence = 150
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_penrose_sphere_1
		NOT = { has_global_flag = penrose_sphere_disabled }
		OR = {
			has_global_flag = penrose_sphere_capped_u
			check_variable = {
				which = giga_current_penrose_sphere
				value < value:giga_penrose_sphere_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = penrose_sphere_capped_u
					check_variable = {
						which = giga_current_penrose_sphere
						value < value:giga_penrose_sphere_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_black_hole"		giga_black_hole = yes }
			custom_tooltip = { fail_text = "must_build_around_primary_star"		is_primary_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				OR = {
					planet_has_no_megastructure = yes
					AND = {
						has_planet_flag = has_hrae_mc
						NOT = { has_planet_flag = has_penrose }
					}
				}
			}
		}
	}

	ai_weight = {
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|25|
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|penrose_sphere|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_penrose
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_penrose_sphere years = 20 }
			country_event = { id = giga_dialog.1201 }	
			change_variable = { which = giga_current_penrose_sphere value = 1 }
		}
	}
}

planetary_computer_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_planetary_computer }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_planetary_computer
		cost = {
			influence = 150
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2500
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|alloys|AMOUNT|2500| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = alloys AMOUNT = 2500 }
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		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
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = planetary_computer_capped_u
					check_variable = {
						which = giga_current_planetary_computer
						value < value:giga_planetary_computer_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_no_colonized_planets"
				NOT = { is_colony = yes }
			}
			custom_tooltip = { fail_text = "requires_no_crisis_planet"			NOT = { has_planet_flag = crisis_vital_planet } }
			custom_tooltip = {
				fail_text = "requires_habitable"
				NOR = {
					is_planet_class = pc_giga_planetary_computer
					has_planet_flag = has_planet_pc_mega
				}
				habitable_structure = no
				is_planet_habitable = yes
			}
			custom_tooltip = {
				fail_text = "requires_surveyed_planet"
				OR = {
					AND = {
						is_surveyed = { who = prev.from status = yes }
						prev.from = { is_ai = no }
					}
					AND = {
						is_surveyed = { who = prev.from status = yes }
						prev.from = { is_ai = yes }
						is_planet_habitable = no
					}
				}
			}
			custom_tooltip = {
				fail_text = "requires_owned_colony"
				OR = {
					NOT = { exists = owner }
					owner = {
						is_same_value = prev.space_owner
					}
				}
			}
		}
	}

	ai_weight = {
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		

		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_planet_size
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_prevent_spam|MEGA|planetary_computer|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_cap_availability_boost
		mult = value:giga_ai_materialist
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_planet_pc_mega
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_planetary_computer years = 230 }
			country_event = { id = giga_dialog.1301 }	
			change_variable = { which = giga_current_planetary_computer value = 1 }
		}
	}
}

planetary_drive_yard_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_planetary_drive_yard }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 900
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 1750
		}
		upkeep = {
			energy = 5
			alloys = 5
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_planetary_drive_yard
		NOT = { has_global_flag = planetshipyard_disabled }
		OR = {
			has_global_flag = planetshipyard_capped_u
			check_variable = {
				which = giga_current_planetshipyard
				value < value:giga_planetshipyard_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
		OR = {
			has_global_flag = planetshipyard_capped_u
			check_variable = {
				which = giga_current_planetshipyard
				value < value:giga_planetshipyard_limit
			}
		}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_surveyed_planet"				is_surveyed = { who = prev.from status = yes } }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"					is_asteroid = no }
			
			
			
			
			
			custom_tooltip = {
				fail_text = "requires_colonized_planet_orbital_ring"
				is_colony = yes
				exists = owner
				exists = controller
				controller = { is_same_value = prev.owner }
			}
			custom_tooltip = {
				fail_text = "requires_not_hostile_or_primitive"
				NOR = {
					planet_is_hostile_or_crisis = yes
					AND = {
						exists = owner
						owner = {
							is_country_type = primitive
						}
					}
				}
			}
			custom_tooltip = { fail_text = "requires_not_star" is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_non_giga_habitable_structure"
				OR = { 
					giga_habitable_structure = no
					habitable_structure = no
					is_planet_class = pc_giga_planetary_computer
					is_planet_class = pc_habitable_gas_giant
					is_regular_giga_maginot_world = yes
				}
			}
			custom_tooltip = { fail_text = "requires_nothing_in_orbit"			
				NOR = {
					has_planet_flag = orbital_arcology
					has_planet_flag = giga_drive_yard
				} 
			}
			custom_tooltip = { fail_text = "requires_no_birch" giga_is_birch_world = no }
			custom_tooltip = {
				fail_text = "requires_no_orbital_debris"
				NOR = {
					has_planet_flag = has_orbital_debris
				}
			}
			
			or = {
				from = {
					is_ai = no
				}
				and = {
					exists = owner
					exists = controller
					is_colony = yes
					controller = { is_same_empire = from }
					or = {
						is_planet_class = pc_city
						is_regular_giga_maginot_world = yes
						pop_amount > 2000
					}
				}
			}
		}
	}

	ai_weight = {
		

		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		

		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_core_territory
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_prevent_spam|MEGA|planetary_drive_yard|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			giga_set_has_mega_flag = yes
			set_planet_flag = giga_drive_yard
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_planetary_drive_yard years = 20 }
			country_event = { id = giga_dialog.13400 }	
			change_variable = { which = giga_current_planetshipyard value = 1 }
		}
	}
}

psychic_beacon_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -5 y = -5 }
	prerequisites = { giga_tech_psychic_beacon }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 20 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_psychic_beacon
		NOT = { has_global_flag = psychic_beacon_disabled }
		OR = {
			has_global_flag = psychic_beacon_capped_u
			check_variable = {
				which = giga_current_psychic_beacon
				value < value:giga_psychic_beacon_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = psychic_beacon_capped_u
					check_variable = {
						which = giga_current_psychic_beacon
						value < value:giga_psychic_beacon_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = { 
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|100|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_build_low_priority
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_psychic_beacon years = 20 }
			country_event = { id = giga_dialog.11001 }	
			change_variable = { which = giga_current_psychic_beacon value = 1 }
		}
	}
}

psychic_hypersiphon_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_psychic_hypersiphon }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_small_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2500
		}
		upkeep = {
			energy = 5
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_finished_psionic_tradition = yes
		NOT = { has_global_flag = siphon_disabled }
		OR = {
			has_global_flag = siphon_capped_u
			check_variable = {
				which = giga_current_siphon
				value < value:giga_siphon_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"						is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"					giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = siphon_capped_u
					check_variable = {
						which = giga_current_siphon
						value < value:giga_siphon_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "requires_standard_planet_class"			giga_is_standard_star = yes }
		}
	}

	ai_weight = { 
		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|30|
		mult = value:giga_ai_output|RESOURCE|energy|AMOUNT|500|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|hypersiphon|

		
		modifier = {
			from = {
				check_modifier_value = {
					modifier = giga_shroud_conduit_instability
					value >= 5
				}
			}
			multiply = 0
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_hypersiphon years = 20 }
			country_event = { id = giga_dialog.1401 }	
			change_variable = { which = giga_current_siphon value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

ring_world_1 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { "tech_ring_world" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			influence = 300
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_RING_WORLD"

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_ringworld_disabled }
		giga_can_use_habitables = yes
		OR = {
			has_global_flag = vanilla_ringworld_capped_u
			check_variable = {
				which = giga_current_vanilla_ringworld
				value < value:giga_vanilla_ringworld_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"						is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"					giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_habitable_planets"				giga_any_hab_planets = no }
		custom_tooltip = { fail_text = "requires_no_binary_trinary"					giga_is_bitrinary = no }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure" 		has_no_non_gate_megastructure = yes }
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			NOT = {
				any_system_planet = {
					OR = {
						is_planet_class = pc_ringworld_habitable_damaged
						is_planet_class = pc_ringworld_tech_damaged
						is_planet_class = pc_ringworld_seam_damaged
						is_planet_class = pc_shattered_ring_habitable
						is_planet_class = pc_ringworld_habitable
					}
				}
			}
		} 
		custom_tooltip = { fail_text = "requires_no_crisis_system"					NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_ringworld_capped_u
					check_variable = {
						which = giga_current_vanilla_ringworld
						value < value:giga_vanilla_ringworld_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			
			custom_tooltip = { fail_text = "requires_standard_planet_class"			giga_is_standard_star = yes }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_pacifist_plus
	}

    on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
    }

    on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
    }
	
	on_build_complete = {
		set_variable = { which = ring_segments value = 0 }

		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @ring_world_2_intermediate_bm_cost
		}

		from = {
			set_timed_country_flag = { flag = has_recently_built_vanilla_ring years = 20 }
			set_country_flag = giga_started_ringworld
			change_variable = { which = giga_current_vanilla_ringworld value = 1 }
		}

		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

think_tank_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = 0 y = -20 }
	prerequisites = { "tech_science_nexus" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_science_nexus
		cost = {
			unity = @giga_big_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_big_mega_start_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_big_mega_start_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_nexus_disabled }
		OR = {
			has_global_flag = vanilla_nexus_capped_u
			check_variable = {
				which = giga_current_vanilla_nexus
				value < value:giga_vanilla_nexus_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"						is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"					giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_nexus_capped_u
					check_variable = {
						which = giga_current_vanilla_nexus
						value < value:giga_vanilla_nexus_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = {
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_science_mult
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|100|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|50000|
		mult = value:giga_ai_prevent_spam|MEGA|think_tank|
		mult = value:giga_ai_materialist_plus
	}

	on_build_complete = {
		set_star_flag = think_tank_built
		from = {
			set_timed_country_flag = { flag = has_recently_built_think_tank years = 20 }
			set_country_flag = built_think_tank
			change_variable = { which = giga_current_vanilla_nexus value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
		}
	}
}

ehof_sm_forge_phase0 = {
	entity = "construction_platform_entity"
	construction_entity = construction_platform_entity
	
	portrait = "GFX_megastructure_construction_background"
	entity_offset = { x = -25 y = 25 }
	show_galactic_map_icon = yes
	place_entity_on_planet_plane = no

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			influence = 150
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = {
			energy = 5
		}
	}

	prerequisites = { tech_sm_megastructure }
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga NOT = { any_owned_megastructure = { has_megastructure_flag = sm_forge } } }

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_cplanet"
				is_planet_class = pc_ehof_cplanet
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega
		mult = 20 

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|4400|MIN|0.5|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|2000|MIN|0.1|
		mult = value:giga_ai_output|RESOURCE|giga_sr_sentient_metal|AMOUNT|2000|MIN|0.5|
		mult = value:giga_ai_output|RESOURCE|giga_sr_negative_mass|AMOUNT|300|MIN|0.5|
	}

	on_build_complete = {
		spawn_megastructure = {
			type = ehof_sm_forge_phase00
			coords_from = fromfrom.planet
			owner = from
			planet = fromfrom.planet
			orbit_angle = 315
			orbit_distance = 35
			graphical_culture = fromfrom
			init_effect = { set_megastructure_flag = sm_forge }
		}
		remove_megastructure = fromfrom
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			country_event = { id = giga_dialog.11101 }	
		}
	}
}

spy_orb_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -15 y = -5 }
	prerequisites = { "tech_sentry_array" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_sentry_array
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 20 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_array_disabled }
		OR = {
			has_global_flag = vanilla_array_capped_u
			check_variable = {
				which = giga_current_vanilla_array
				value < value:giga_vanilla_array_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_array_capped_u
					check_variable = {
						which = giga_current_vanilla_array
						value < value:giga_vanilla_array_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|100|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|spy_orb|
		mult = value:giga_ai_weight_savings|CATEGORY|utility|RESOURCE|alloys|AMOUNT|45000|
		mult = value:giga_ai_xenophobe_plus
		mult = value:giga_ai_militarist_plus
	}

	on_build_complete = {
		set_star_flag = spy_orb_built
		from = {
			set_timed_country_flag = { flag = has_recently_built_spy_orb years = 20 }
			set_country_flag = built_spyorb
			change_variable = { which = giga_current_vanilla_array value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
		}
	}
}

star_lifter_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_star_lifter }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_star_lifter
		cost = {
			unity = @giga_big_mega_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 3500
		}
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 3500 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_big_mega_start_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_star_lifter
		NOT = { has_global_flag = lifters_disabled }
		OR = {
			has_global_flag = lifters_capped_u
			check_variable = {
				which = giga_current_lifters
				value < value:giga_lifters_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"		giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = lifters_capped_u
					check_variable = {
						which = giga_current_lifters
						value < value:giga_lifters_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "requires_further_stars" 				NOR = { AND = { giga_is_close_pair_star = yes is_primary_star = no } giga_is_close_pair_primary = yes } }
			custom_tooltip = {
				fail_text = "requires_standard_planet_class_o_star"
				giga_brown_dwarf = no
				OR = {
					giga_is_standard_star = yes
					AND = {
						giga_is_o_star_for_megas = yes
						from = { has_technology = giga_tech_lifter_o_star }
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|@starlifter_p5_upkeep_energy_g_star|
		mult = value:giga_ai_output|RESOURCE|minerals|AMOUNT|@starlifter_p5_produces_minerals_g_star|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|star_lifter|
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|50000|
		mult = value:giga_ai_unlocks_gigastructures
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		if = {	limit = { fromfrom.planet = { giga_is_o_star_for_megas = yes } }	spawn_megastructure = { type = "star_lifter_0_o_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
		if = {
			limit = { has_global_flag = giga_lifter_scaling }
			if = {		limit = { fromfrom.planet = { giga_is_b_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_b_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_m_giant_star_for_megas = yes } }	spawn_megastructure = { type = "star_lifter_0_m_giant_star"	owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_a_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_a_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_f_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_f_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_g_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_g_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_k_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_k_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
			else_if = {	limit = { fromfrom.planet = { giga_is_m_star_for_megas = yes } }		spawn_megastructure = { type = "star_lifter_0_m_star"		owner = from coords_from = fromfrom.planet planet = fromfrom.planet } remove_megastructure = fromfrom }
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_star_lifter years = 20 }
			country_event = { id = giga_dialog.1601 }	
			change_variable = { which = giga_current_lifters value = 1 }
		}
	}
}

stellarite_kaiser_moon_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_megastructures
		cost = {
			influence = 100
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 10000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_stellarite_kaiser_moon
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_size_567"				planet_size >= 5 planet_size <= 7 }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "must_build_around_molten_barren_stripmined"
				OR = {
					giga_is_frozen = yes
					giga_is_barren_cn = yes
					giga_is_molten = yes
					is_planet_class = pc_core_mined
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		

		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega
		
		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|800|MIN|0.25|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|250|MIN|0.1|
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_prevent_spam|MEGA|war_moon|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_cap_availability_boost
		mult = value:giga_ai_militarist_plus

		modifier = { factor = 10	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			country_event = { id = giga_katzen.0905 }	
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_size = 6
		}
	}
}

strategic_coordination_center_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	prerequisites = { "tech_strategic_coordination" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_strategic_coordination
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		NOT = { has_global_flag = vanilla_strategic_disabled }
		OR = {
			has_global_flag = vanilla_strategic_capped_u
			check_variable = {
				which = giga_current_vanilla_strategic
				value < value:giga_vanilla_strategic_limit
			}
		}
	}

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = vanilla_strategic_capped_u
					check_variable = {
						which = giga_current_vanilla_strategic
						value < value:giga_vanilla_strategic_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { fail_text = "requires_not_ring_world"			is_ringworld = no }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|75|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|strategic_coordination_center|
		mult = value:giga_ai_weight_savings|CATEGORY|utility|RESOURCE|alloys|AMOUNT|65000|
		mult = value:giga_ai_militarist_plus

		modifier = { factor = 10	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
	}

	on_build_complete = {
		from = {
			set_timed_country_flag = { flag = has_recently_built_strategic_coordination_center years = 20 }
			set_country_flag = built_strategic_coordination_center_site
			change_variable = { which = giga_current_vanilla_strategic value = 1 }
		}
		fromfrom.planet = {
			giga_set_has_mega_flag = yes
		}
	}
}

substellar_compressor_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_substellar_compressor }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 2700
	resources = {
		category = giga_megastructures
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_substellar_compressor
		NOT = { has_global_flag = compressor_disabled }
		OR = {
			has_global_flag = compressor_capped_u
			check_variable = {
				which = giga_current_compressor
				value < value:giga_compressor_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = compressor_capped_u
					check_variable = {
						which = giga_current_compressor
						value < value:giga_compressor_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure_system"
				solar_system = {
					NOT = {
						any_system_megastructure = {
							OR = {
								is_megastructure_type = ring_world_1
								is_megastructure_type = alderson_disk_0
								is_megastructure_type = nidavellir_forge_0
								is_megastructure_type = nicoll_beam_0
								is_megastructure_type = matrioshka_brain_0_a_star
								is_megastructure_type = matrioshka_brain_0_b_star
								is_megastructure_type = matrioshka_brain_0_f_star
								is_megastructure_type = matrioshka_brain_0_g_star
								is_megastructure_type = matrioshka_brain_0_k_star
								is_megastructure_type = matrioshka_brain_0_m_giant_star
								is_megastructure_type = matrioshka_brain_0_m_star
								is_megastructure_type = matrioshka_brain_0_o_star
							}
						}
					}
				}
			}
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = {
				fail_text = "must_build_around_dwarf"
				OR = {
					giga_brown_dwarf = yes
					AND = {
						has_modifier = helioforming_candidate
						giga_is_gas_giant = yes
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_output|RESOURCE|energy|AMOUNT|350|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_cap_availability_boost
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			country_event = { id = giga_dialog.1701 }	
			change_variable = { which = giga_current_compressor value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

terraform_site_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	build_time = 1260
	resources = {
		category = giga_kilostructures
		cost = {
			influence = 50
			unity = @giga_kilo_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 2000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		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
				}
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_not_capped"
				OR = {
					AND = {
						is_planet_class = pc_molten
						from = {
							OR = {
								has_global_flag = geothermal_capped_u
								check_variable = {
									which = giga_current_geothermal
									value < value:giga_geothermal_limit
								}
							}
						}
					}
					AND = {
						is_planet_class = pc_toxic
						from = {
							OR = {
								OR = {
									has_global_flag = terraform_toxic_capped_u
									check_variable = {
										which = giga_current_terraform_toxic
										value < value:giga_terraform_toxic_limit
									}
								}
							}
						}
					}
					AND = {
						OR = {
							is_planet_class = pc_barren
							is_planet_class = pc_barren_cold
							is_planet_class = pc_frozen
						}
						from = {
							OR = {
								OR = {
									has_global_flag = terraform_barren_capped_u
									check_variable = {
										which = giga_current_terraform_barren
										value < value:giga_terraform_barren_limit
									}
								}
							}
						}
					}
				}
			}
			custom_tooltip = {
				fail_text = "planet_is_already_terraformable"
				NOR = {
					
					AND = {
						has_modifier = terraforming_candidate
						giga_is_barren_cn = yes
					}
					AND = {
						has_modifier = toxic_terraforming_candidate
						giga_is_toxic = yes
						from = { has_ascension_perk = ap_detox }
					}
					AND = {
						has_modifier = frozen_terraforming_candidate
						giga_is_frozen = yes
						from = { has_ascension_perk = ap_hydrocentric }
					}
				}
			}
			custom_tooltip = { 
				fail_text = "must_build_around_world_we_can_terraform"
				OR = {
					AND = {
						is_planet_class = pc_molten
						from = { has_technology = giga_tech_terraform_molten }
					}
					AND = {
						is_planet_class = pc_barren_cold
						from = { has_technology = giga_tech_terraform_barren }
					}
					AND = {
						is_planet_class = pc_barren
						from = { has_technology = giga_tech_terraform_barren }
					}
					AND = {
						is_planet_class = pc_frozen
						from = { has_technology = giga_tech_terraform_barren }
					}
					AND = {
						is_planet_class = pc_toxic
						from = { has_technology = giga_tech_terraform_toxic }
					}
				}
				NOT = { has_planet_flag = legendary_leader_planet }
			}
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOT = { has_planet_flag = giga_terraforming_megastructure }
			}
		}
	}

	ai_weight = {
		

		

		

		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_kilo

		mult = value:giga_ai_planet_size
		mult = value:giga_ai_prevent_spam|MEGA|terraform_molten|
		mult = value:giga_ai_prevent_spam|MEGA|terraform_barren|
		mult = value:giga_ai_prevent_spam|MEGA|terraform_toxic|
		mult = value:giga_ai_build_low_priority
		mult = value:giga_ai_unlock_low_priority
		mult = value:giga_ai_overpopulation_boost
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = {
			limit = { fromfrom.planet = { is_planet_class = pc_barren } }
			fromfrom = { upgrade_megastructure_to = terraform_barren_0 finish_upgrade = yes }
		}
		if = {
			limit = { fromfrom.planet = { is_planet_class = pc_barren_cold } }
			fromfrom = { upgrade_megastructure_to = terraform_barren_0 finish_upgrade = yes }
		}
		if = {
			limit = { fromfrom.planet = { is_planet_class = pc_frozen } }
			fromfrom = { upgrade_megastructure_to = terraform_barren_0 finish_upgrade = yes }
		}
		else_if = {
			limit = { fromfrom.planet = { is_planet_class = pc_toxic } }
			fromfrom = { upgrade_megastructure_to = terraform_toxic_0 finish_upgrade = yes }
		}
		else_if = {
			limit = { fromfrom.planet = { is_planet_class = pc_molten } }
			fromfrom = { upgrade_megastructure_to = terraform_molten_0 finish_upgrade = yes }
		}
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = giga_terraforming_megastructure
			giga_save_lifeless_resources = yes
			
			remove_modifier = terraforming_candidate
			remove_modifier = toxic_terraforming_candidate
			remove_modifier = frozen_terraforming_candidate
		}
	}
}

ringworld_titanic_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { "giga_tech_ringworld_titanic_2" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 3600
	resources = {
		category = giga_megastructures
		cost = {
			influence = 300
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 10000
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_ringworld_titanic_2
		NOT = { has_global_flag = ring_titanic_disabled }
		giga_can_use_habitables = yes
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"			is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"		giga_system_is_surveyed = yes }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"		is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"		has_anomaly = no }
			custom_tooltip = {
				fail_text = "requires_base_ringworld"
				hidden:solar_system = { has_star_flag = ring_world_built }
				
				
				
				
				
				
				
			}
			custom_tooltip = {
				fail_text = "already_have_tit_ringworld"
				hidden:solar_system = { NOT = { has_star_flag = giga_has_titanic_ring } }
				hidden:solar_system = { not = { any_system_megastructure = { is_megastructure_type = ring_world_titanic_ruined  } } }
			}
		}
	}

	ai_weight = {
		

		

		

		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_prevent_spam|MEGA|titanic_ring|
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_core_territory

		modifier = {
			factor = 0
			from = {
				OR = {
					has_country_flag = giga_started_ringworld
					has_country_flag = giga_started_t_ringworld
					has_country_flag = giga_started_b_ringworld
					has_country_flag = giga_started_g_ringworld
				}
			}
		}
	
	}

	on_build_complete = {
		save_event_target_as = giga_system
		set_star_flag = giga_has_titanic_ring 
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_titanic_ring years = 20 }
			country_event = { id = giga_dialog.2101 }	
			set_country_flag = giga_started_t_ringworld
		}
		set_variable = { which = t_ring_segments value = 0 }
	}
}

yggdrasil_orchid_0 = {
	entity = "giga_consite_5_5_entity"
	construction_entity = "giga_consite_5_5_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_yggdrasil_orchid }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 2700
	resources = {
		category = giga_yggdrasil_orchid
		cost = {
			influence = 75
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|resource|RESOURCE|unity|AMOUNT|@giga_mega_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = resource RESOURCE = unity  AMOUNT = @giga_mega_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = resource RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_yggdrasil_orchid
		NOT = { has_global_flag = orchid_disabled }
		OR = {
			has_global_flag = orchid_capped_u
			check_variable = {
				which = giga_current_orchid
				value < value:giga_orchid_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = orchid_capped_u
					check_variable = {
						which = giga_current_orchid
						value < value:giga_orchid_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_gas"				giga_is_gas_giant = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_minor_planetary_body"	is_asteroid = no is_moon = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_mega

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|150|MIN|0.25|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|50|MIN|0.25|
		mult = value:giga_ai_output|RESOURCE|food|AMOUNT|650|MIN|0.1|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_unlocks_galwonders
		mult = value:giga_ai_weight_savings|CATEGORY|resource|RESOURCE|alloys|AMOUNT|22500|
		mult = value:giga_ai_cap_availability_boost

		modifier = { factor = 0 	from = { country_uses_food = no } }
		modifier = { factor = 3		from = { is_hive_empire = yes } }
		modifier = { factor = 0.1	from = { is_machine_empire = yes NOR = { has_civic = civic_machine_servitor has_civic = civic_machine_assimilator } } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = megastructure
			set_planet_flag = giga_planet_mega
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_yggdrasil_orchid years = 20 }
			country_event = { id = giga_dialog.2001 }	
			change_variable = { which = giga_current_orchid value = 1 }
		}
	}
}

alderson_disk_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { giga_tech_alderson_disk }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1200
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_alderson_disk
		has_ascension_perk = ap_gigastructural_constructs
		NOT = { has_global_flag = alderson_disabled }
		giga_can_use_habitables = yes
		OR = {
			has_global_flag = alderson_capped_u
			check_variable = {
				which = giga_current_alderson
				value < value:giga_alderson_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_binary_trinary"							giga_is_bitrinary = no }
		custom_tooltip = { fail_text = "requires_no_habitable_planets"						giga_any_hab_planets = no }
		custom_tooltip = { fail_text = "requires_standard_star_class"						giga_is_standard_star_system = yes }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"					has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"							NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = alderson_capped_u
					check_variable = {
						which = giga_current_alderson
						value < value:giga_alderson_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"				planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"							is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"							has_anomaly = no }
		}
	}

	ai_weight = {
		

		

		

		
		
		

		

		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_core_territory
		mult = value:giga_ai_overpopulation_boost

		modifier = { factor = 0.00 from = { has_country_flag = giga_started_alderson } }
	}

    on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
    }

    on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
    }

	on_build_complete = {
		save_event_target_as = giga_system
		from = { country_event = { id = giga_dialog.2502 } }	
		from = {
			set_country_flag = giga_started_alderson
			change_variable = { which = giga_current_alderson value = 1 }
		}
		set_variable = { which = alderson_slices value = 0 }
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @alderson_disk_1_bm_cost
		}
	}
}

planetcraft_printer_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_planet_assembly }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_planet_assembly
		NOT = { has_global_flag = warplanet_disabled }
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_standard_planet_class"			giga_is_standard_star = yes }
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|1500|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|600|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_militarist_plus

		modifier = { factor = 10	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			country_event = { id = giga_printer.2010 }	
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}

		
		spawn_megastructure = {
			type = planetcraft_printer_0_real
			owner = from
			planet = fromfrom.planet
		}
		remove_megastructure = fromfrom
	}
}

war_planet_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_war_planet }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 150
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 10000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_war_planet
		NOT = { has_global_flag = warplanet_disabled }
		OR = {
			has_global_flag = warplanet_capped_u
			check_variable = {
				which = giga_current_warplanet
				value < value:giga_warplanet_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = warplanet_capped_u
					check_variable = {
						which = giga_current_warplanet
						value < value:giga_warplanet_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "must_build_around_barren_ship"
				OR = {
					giga_is_frozen = yes
					giga_is_barren_cn = yes
					giga_is_molten = yes
					giga_is_toxic = yes
				}
			}
			custom_tooltip = { fail_text = "must_build_size_25"					planet_size >= 24 }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_asteroid"				is_asteroid = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		

		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|500|MIN|0.2|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|250|MIN|0.1|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_prevent_spam|MEGA|war_planet|
		mult = value:giga_ai_militarist_plus

		modifier = { factor = value:giga_ai_base_continue	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_war_planet years = 10 }
			country_event = { id = giga_dialog.2701 }	
			change_variable = { which = giga_current_warplanet value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			set_planet_flag = megastructure
			giga_set_has_mega_flag = yes
			set_planet_size = 25
		}
	}
}

ringworld_behemoth_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { "giga_tech_ringworld_behemoth" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 5400
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 100
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 15000
		}
		upkeep = { energy = 15 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_ringworld_behemoth
		giga_can_use_habitables = yes
		NOR = {
			has_global_flag = ring_behemoth_disabled
			has_global_flag = ring_titanic_disabled
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			giga_system_is_surveyed = yes }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"			is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"			has_anomaly = no }
			custom_tooltip = { 
				fail_text = "requires_base_ringworld_one"	
				hidden:solar_system = { 
					or = {
						has_star_flag = ring_world_built_one 
						has_star_flag = matrioshka_brain_built
					}
					not = { has_star_flag = matrioshka_brain_o_built }
				} 
			}
			custom_tooltip = {
				fail_text = "already_have_beh_ringworld"
				hidden:solar_system = { NOT = { has_star_flag = giga_has_behemoth_ring } }
				hidden:solar_system = { not = { any_system_megastructure = { is_megastructure_type = ring_world_behemoth_ruined  } } }
			}
		}
	}

	ai_weight = {
		

		

		

		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_prevent_spam|MEGA|behemoth_ring|
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_core_territory

		modifier = {
			factor = 0
			from = {
				OR = {
					has_country_flag = giga_started_ringworld
					has_country_flag = giga_started_t_ringworld
					has_country_flag = giga_started_b_ringworld
					has_country_flag = giga_started_g_ringworld
				}
			}
		}
	}

	on_build_complete = {
		set_star_flag = giga_has_behemoth_ring 
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			set_timed_country_flag = { flag = has_recently_built_behemoth_ring years = 20 }
			country_event = { id = giga_dialog.2201 }	
			set_country_flag = giga_started_b_ringworld
		}
		set_variable = { which = b_ring_segments value = 0 }
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

ringworld_gargantuan_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	prerequisites = { "giga_tech_ringworld_gargantuan_2" }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 7200
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 20000
		}
		upkeep = { energy = 20 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_ringworld_titanic_2
		has_technology = giga_tech_ringworld_behemoth
		has_technology = giga_tech_ringworld_gargantuan_2
		giga_can_use_habitables = yes
		NOR = {
			has_global_flag = ring_gargantuan_disabled
			has_global_flag = ring_behemoth_disabled
			has_global_flag = ring_titanic_disabled
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			giga_system_is_surveyed = yes }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "must_build_around_star"			is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"			has_anomaly = no }
			custom_tooltip = { fail_text = "requires_base_ringworld_two"	hidden:solar_system = { has_star_flag = ring_world_built_two } }
			custom_tooltip = {
				fail_text = "already_have_gar_ringworld"
				hidden:solar_system = { NOT = { has_star_flag = giga_has_gargantuan_ring } }
				hidden:solar_system = { not = { any_system_megastructure = { is_megastructure_type = ring_world_gargantuan_ruined   } } }
			}
		}
	}

	ai_weight = {
		

		

		

		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_prevent_spam|MEGA|gargantuan_ring|
		mult = value:giga_ai_overpopulation_boost
		mult = value:giga_ai_unlocks_gigastructures
		mult = value:giga_ai_core_territory

		modifier = {
			factor = 0
			from = {
				OR = {
					has_country_flag = giga_started_ringworld
					has_country_flag = giga_started_t_ringworld
					has_country_flag = giga_started_b_ringworld
					has_country_flag = giga_started_g_ringworld
				}
			}
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		set_star_flag = giga_has_gargantuan_ring 
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_gargantuan_ring years = 20 }
			country_event = { id = giga_dialog.2301 }	
			set_country_flag = giga_started_g_ringworld
		}
		set_variable = { which = g_ring_segments value = 0 }
	}
}

hrae_mc_0 = {
	entity = "giga_consite_10_10_entity"
	construction_entity = "giga_consite_10_10_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_hrae_mc }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_hrae_mc
		cost = {
			influence = 300
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_giga_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 5000 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_giga_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_hrae_mc
		NOT = { has_global_flag = hraemc_disabled }
		OR = {
			has_global_flag = hraemc_capped_u
			check_variable = {
				which = giga_current_hraemc
				value < value:giga_hraemc_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = hraemc_capped_u
					check_variable = {
						which = giga_current_hraemc
						value < value:giga_hraemc_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_black_hole"		is_planet_class = pc_black_hole }
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				OR = {
					planet_has_no_megastructure = yes
					AND = {
						has_planet_flag = has_penrose
						NOT = { has_planet_flag = has_hrae_mc }
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|175|
		mult = value:giga_ai_output|RESOURCE|energy|AMOUNT|3500|MIN|0.25|
		mult = value:giga_ai_output|RESOURCE|sr_dark_matter|AMOUNT|15|MIN|0.75|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|85000|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_hrae_mc
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_hrae_mc years = 20 }
			country_event = { id = giga_dialog.3101 }	
			change_variable = { which = giga_current_hraemc value = 1 }
		}
	}
}

hyperstructural_ass_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_hyperstructural_ass }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 500
	resources = {
		category = giga_hyperstructural_ass
		cost = {
			influence = 300
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 4000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|alloys|AMOUNT|4000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|utility|RESOURCE|unity|AMOUNT|@giga_giga_unity_cost| }
		upkeep = { energy = 10 }
	}

	on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = alloys AMOUNT = 4000 }
		giga_ai_savings_withdraw = { CATEGORY = utility RESOURCE = unity  AMOUNT = @giga_giga_unity_cost }
	}
	on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = utility RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_hyperstructural_ass
		NOT = { has_global_flag = hyperstructural_ass_disabled }
		OR = {
			has_global_flag = hyperstructural_ass_capped_u
			check_variable = {
				which = giga_current_hyperstructural_ass
				value < value:giga_hyperstructural_ass_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"						NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_big_star"									OR = { is_star_class = sc_b is_star_class = sc_a } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"					has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"							NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = hyperstructural_ass_capped_u
					check_variable = {
						which = giga_current_hyperstructural_ass
						value < value:giga_hyperstructural_ass_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		

		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|3000|MIN|0.5|
		mult = value:giga_ai_upkeep|RESOURCE|engineering_research|AMOUNT|3000|
		mult = value:giga_ai_output|RESOURCE|minerals|AMOUNT|1500|MIN|0.75|
		mult = value:giga_ai_prevent_spam|MEGA|hyperstructural_ass|
		mult = value:giga_ai_militarist_plus

		modifier = { factor = value:giga_ai_base_continue	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_hyperstructural_ass years = 20 }
			country_event = { id = giga_dialog.3701 }	
			change_variable = { which = giga_current_hyperstructural_ass value = 1 }
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @hyperstructural_ass_1_bm_cost
		}
	}
}

lunar_macroreplicator_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_lunar_assembly }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_lunar_macroreplicator
		cost = {
			influence = 100
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|alloys|AMOUNT|5000| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|military|RESOURCE|unity|AMOUNT|@giga_giga_unity_cost| }
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_lunar_assembly
		NOT = { has_global_flag = warmoon_disabled }
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_survey_not_habitable"		is_surveyed = { who = prev.from status = yes } is_planet_habitable = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|energy|AMOUNT|400|MIN|0.5|
		mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|50|MIN|0.1|
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_militarist_plus
		mult = value:giga_ai_weight_savings|CATEGORY|military|RESOURCE|alloys|AMOUNT|65000|

		modifier = { factor = 10	from = { has_country_flag = pangalactic_defense_league } }
		modifier = { factor = 2		from = { has_federation = yes federation = { has_federation_type = military_federation } } }
		modifier = { factor = 1.5	from = { is_homicidal = yes } }
		modifier = { factor = 2		from = { is_at_war = yes } }
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			country_event = { id = giga_printer.1010 }	
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		
		
		spawn_megastructure = {
			type = lunar_macroreplicator_0_real
			owner = from
			planet = fromfrom.planet
		}
		remove_megastructure = fromfrom
	}
}

matrioshka_brain_0_g_star = {
    entity = "giga_consite_7_7_entity"
    construction_entity = "giga_consite_7_7_entity"
    
    portrait = "GFX_megastructure_construction_background"
    place_entity_on_planet_plane = no
    prerequisites = { giga_tech_matrioshka_brain_1 }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
    build_time = 500
    resources = {
        category = giga_matrioshka_brain
        cost = {
            unity = @giga_giga_unity_cost
            influence = 300
            inline_script = {
                script = megastructures/generic_parts/giga_mega_alloy_cost
                alloys = 10000
            }
        }
        cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|10000| }
        cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_giga_unity_cost| }
        upkeep = { energy = 10 }
    }

    on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
        giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 10000 }
        giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_giga_unity_cost }
    }
    on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
        giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
        giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
    }

    potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
        has_gigastructural_constructs = yes
        has_technology = giga_tech_matrioshka_brain_1
        NOT = { has_global_flag = matrioshka_brain_disabled }
        OR = {
            has_global_flag = matrioshka_brain_capped_u
            check_variable = {
                which = giga_current_matrioshka_brain
                value < value:giga_matrioshka_brain_limit
            }
        }
    }

    possible = {
        custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
        custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
        custom_tooltip = { fail_text = "requires_no_binary_trinary"				giga_is_bitrinary = no }
        custom_tooltip = { fail_text = "requires_no_colonized_planets"			NOT = { any_system_planet = { is_colony = yes } } }
        custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
        custom_tooltip = { fail_text = "requires_no_crisis_system"							NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
        custom_tooltip = {
            fail_text = "requires_not_capped"
            from = {
                OR = {
                    has_global_flag = matrioshka_brain_capped_u
                    check_variable = {
                        which = giga_current_matrioshka_brain
                        value < value:giga_matrioshka_brain_limit
                    }
                }
            }
        }
    }

    placement_rules = {
        planet_possible = {
            custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
            custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
            custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
            custom_tooltip = {
                fail_text = "requires_standard_planet_class_o_star"
                OR = {
                    giga_is_standard_star = yes
                    AND = {
                        giga_is_o_star_for_megas = yes
                        from = { has_technology = giga_tech_brain_o_star }
                    }
                }
            }
        }
    }

    ai_weight = {
        weight = value:giga_ai_base_giga

        mult = value:giga_ai_science_mult
        mult = value:giga_ai_upkeep|RESOURCE|alloys|AMOUNT|@matrioshka_p5_upkeep_alloys_g_star|
        mult = value:giga_ai_no_colony
        mult = value:giga_ai_cap_availability_boost
        mult = value:giga_ai_materialist_plus
        mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|50000|
    }

    on_build_complete = {
        save_event_target_as = giga_system
        fromfrom.planet = {
            save_event_target_as = giga_planet
            if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
            giga_set_has_mega_flag = yes
        }
        if = {	limit = { fromfrom.planet = { giga_is_o_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_o_star finish_upgrade = yes } }
        if = {
            limit = { has_global_flag = giga_matroishka_scaling }
            if = {		limit = { fromfrom.planet = { giga_is_b_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_b_star finish_upgrade = yes } }
            else_if = {	limit = { fromfrom.planet = { giga_is_m_giant_star_for_megas = yes } }	fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_m_giant_star finish_upgrade = yes } }
            else_if = {	limit = { fromfrom.planet = { giga_is_a_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_a_star finish_upgrade = yes } }
            else_if = {	limit = { fromfrom.planet = { giga_is_f_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_f_star finish_upgrade = yes }}
            else_if = {	limit = { fromfrom.planet = { giga_is_k_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_k_star finish_upgrade = yes } }
            else_if = {	limit = { fromfrom.planet = { giga_is_m_star_for_megas = yes } } fromfrom = { upgrade_megastructure_to = matrioshka_brain_0_m_star finish_upgrade = yes } }
        }
		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @matrioskha_brain_1_bm_cost
		}
        from = {
            set_timed_country_flag = { flag = has_recently_built_matrioshka_brain years = 20 }
            country_event = { id = giga_dialog.501 }	
            change_variable = { which = giga_current_matrioshka_brain value = 1 }
        }
    }
}

nicoll_beam_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	ai_weight = { factor = 0 }
	prerequisites = { giga_tech_ndb_1 }

	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 500
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 12500
		}
		upkeep = { energy = 10 }
	}

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_ndb_1
		NOR = {
			has_global_flag = ndb_disabled
			has_country_flag = giga_has_a_ndb
			has_megastructure = nicoll_beam_0
			has_megastructure = nicoll_beam_1
			has_megastructure = nicoll_beam_2
			has_megastructure = nicoll_beam_3
			has_megastructure = nicoll_beam_4
			has_megastructure = nicoll_beam_cooldown
			has_megastructure = nicoll_beam_firing
			has_megastructure = nicoll_beam_menu
			has_megastructure = nicoll_beam_ready
			
			
			
			
			
			has_megastructure = nicoll_beam_targetting
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_binary_trinary"			giga_is_bitrinary = no }
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			NOT = { any_system_planet = { is_surveyed = { who = prev.from status = no } } } }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"		NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_big_star"					OR = { is_star_class = sc_b is_star_class = sc_a } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"	has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"			NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
		}
	}

    on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
    }

    on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
    }

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = cant_build_here
			set_planet_flag = cant_target_this_planet
		}
		every_system_planet = {
			set_planet_flag = cant_build_here
			set_planet_flag = cant_target_this_planet
		}
		from = {
			set_country_flag = giga_has_a_ndb
			country_event = { id = giga_dialog.3201 }	
			change_variable = { which = giga_current_ndb value = 1 }
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @nicoll_beam_1_bm_cost
		}
	}
}

nidavellir_forge_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_nidavellir }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_nidavellir_forge
		cost = {
			influence = 150
			unity = @giga_giga_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 3500
		}
		cost = { alloys = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|alloys|AMOUNT|3500| }
		cost = { unity = -1 multiplier = value:giga_ai_savings_cost|CATEGORY|important|RESOURCE|unity|AMOUNT|@giga_giga_unity_cost| }
		upkeep = { energy = 5 }
	}

	on_build_start = {
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = alloys AMOUNT = 3500 }
		giga_ai_savings_withdraw = { CATEGORY = important RESOURCE = unity  AMOUNT = @giga_giga_unity_cost }
	}
	on_build_cancel = {
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = alloys }
		giga_ai_savings_refund = { CATEGORY = important RESOURCE = unity }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_gigastructural_constructs = yes
		has_technology = giga_tech_nidavellir
		NOT = { has_global_flag = nidavellir_disabled }
		OR = {
			has_global_flag = nidavellir_capped_u
			check_variable = {
				which = giga_current_nidavellir
				value < value:giga_nidavellir_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"						is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"					giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"				NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_no_crisis_system"					NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = nidavellir_capped_u
					check_variable = {
						which = giga_current_nidavellir
						value < value:giga_nidavellir_limit
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_binary_trinary"
			NOR = {
				is_trinary_star = yes
				is_binary_star = yes
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_larger_star"					planet_size >= 10 }
			custom_tooltip = { fail_text = "must_build_around_neutron_star"			OR = { is_planet_class = pc_neutron_star is_planet_class = pc_pulsar is_planet_class = pc_magnetar } }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				OR = {
					planet_has_no_megastructure = yes
					AND = {
						has_planet_flag = has_gigaforge
						NOT = { has_planet_flag = has_nidavellir }
					}
				}
			}
		}
	}

	ai_weight = {
		

		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		

		
		
		

		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		weight = value:giga_ai_base_giga

		mult = value:giga_ai_upkeep|RESOURCE|minerals|AMOUNT|3500|MIN|0.2|
		mult = value:giga_ai_output|RESOURCE|alloys|AMOUNT|1500|MIN|0.5|
		mult = value:giga_ai_no_colony
		mult = value:giga_ai_core_territory
		mult = value:giga_ai_weight_savings|CATEGORY|important|RESOURCE|alloys|AMOUNT|50000|
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = has_nidavellir
		}
		from = {
			set_timed_country_flag = { flag = has_recently_built_nidavellir_forge years = 20 }
			country_event = { id = giga_dialog.801 }	
			change_variable = { which = giga_current_nidavellir value = 1 }
		}
	}
}

war_system_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_war_system_1 }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	ai_weight = { factor = 0 }
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 10000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_war_system_1
		has_ascension_perk = ap_celestial_printing
		NOT = { has_global_flag = systemcraft_disabled }
		OR = {
			has_global_flag = systemcraft_capped_u
			check_variable = {
				which = giga_current_systemcraft
				value < value:giga_systemcraft_limit
			}
		}
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_habitable_planets"		NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_no_crisis_system"			NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					has_global_flag = systemcraft_capped_u
					check_variable = {
						which = giga_current_systemcraft
						value < value:giga_systemcraft_limit
					}
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"				planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"							is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"							has_anomaly = no }
			custom_tooltip = { 
				fail_text = "requires_standard_planet_class"			
				giga_is_standard_star = yes
				NOT = {
					giga_is_bitrinary = yes
				}
			}
		}
	}

	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = {
			country_event = { id = giga_dialog.2802 }	
			change_variable = { which = giga_current_systemcraft value = 1 }
		}
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			set_planet_flag = megastructure
			if = { limit = { NOT = { has_planet_flag = shroud_storm_changed } } } set_planet_flag = shroud_storm_changed
			giga_set_has_mega_flag = yes
		}
	}
}

birch_world_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -150 y = -7 }
	prerequisites = { giga_tech_birch_world_1 }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 100000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_ascension_perk = ap_vast_expanses
		has_technology = giga_tech_birch_world_1
		NOT = { has_global_flag = birch_disabled }
		giga_can_use_habitables = yes
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_existing_birch"			from = { giga_has_birch_world = no } }
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			giga_system_is_surveyed = yes }
		
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"				planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"							has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_core_black_hole"				is_planet_class = pc_core_black_hole }
		}
	}

	ai_weight = { factor = 10 } 
	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = { country_event = { id = giga_dialog.4102 } }	
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

quasi_stellar_obliterator_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -150 y = -7 }
	prerequisites = { giga_tech_quasi_stellar_1 }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 100000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_ascension_perk = ap_qso
		has_technology = giga_tech_quasi_stellar_1
		NOT = { has_global_flag = quasistellar_disabled }
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_existing_quasistellar"					from = { NOT = { has_country_flag = built_quasistellar } } }
		custom_tooltip = { fail_text = "requires_inside_border"								is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"							giga_system_is_surveyed = yes }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_core_quasar"			is_planet_class = pc_core_quasar }
		}
	}

	ai_weight = { factor = 0 }

	on_build_complete = {
		save_event_target_as = giga_system
		set_global_flag = quasistellar_construction
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
			set_planet_flag = cant_build_here
			set_planet_flag = cant_target_this_planet
		}
		every_system = {
			limit = {
				distance = {
					source = prev
					use_bypasses = no
					min_jumps = 1
					max_jumps = 4
				}
			}
			every_system_planet = {
				set_planet_flag = cant_build_here
				set_planet_flag = cant_target_this_planet
			}
		}
		from = {
			country_event = { id = giga_qso.2000 }	
			set_country_flag = built_quasistellar
		}

		
		if = { limit = { OR = { has_global_flag = giga_galactic_fed_shuffle} } remove_global_flag = giga_galactic_fed_shuffle set_global_flag = giga_galactic_fed_disabled }
		if = { limit = { OR = { has_global_flag = giga_galactic_fed_always} } remove_global_flag = giga_galactic_fed_always set_global_flag = giga_galactic_fed_disabled }
	}
}

supermassive_ehof_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -150 y = -7 }
	prerequisites = { giga_tech_supermassive_ehof }

	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}

	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 100000
		}
		upkeep = { energy = 5 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_ascension_perk = ap_supermassive_ehof
		has_technology = giga_tech_supermassive_ehof
		NOT = { has_global_flag = supermassive_ehof_disabled }
	}

	possible = {
		custom_tooltip = { fail_text = "requires_no_existing_supermassive_ehof"			from = { giga_has_supermassive_ehof = no } }
		custom_tooltip = { fail_text = "requires_inside_border"				is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"			giga_system_is_surveyed = yes }
		
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"				planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"							has_anomaly = no }
			custom_tooltip = { fail_text = "must_build_around_core_black_hole"				is_planet_class = pc_core_black_hole }
		}
	}

	ai_weight = { factor = 10 } 
	on_build_complete = {
		save_event_target_as = giga_system
		if = { limit = { exists = fromfrom.planet } fromfrom.planet = { save_event_target_as = giga_planet } }
		from = { country_event = { id = giga_dialog.4201 } }	
		fromfrom.planet = {
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
	}
}

blokkat_gigarelay_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			alloys = 50000
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_country_flag = blokkat_building_gigarelay
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"			NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"				NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = { 
			fail_text = "requires_no_existing_blokkat_gigarelay"
			from = {
				NOR = {
					any_owned_megastructure = { is_megastructure_type = blokkat_gigarelay_0 }
					any_owned_megastructure = { is_megastructure_type = blokkat_gigarelay_1 }
					any_owned_megastructure = { is_megastructure_type = blokkat_gigarelay_2 }
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { 
				fail_text = "requires_standard_planet_class"			
				giga_is_standard_star = yes
				NOT = {
					giga_is_bitrinary = yes
				}
			}
		}
	}

	ai_weight = {
		weight = 0
	}

	on_build_complete = {
		save_event_target_as = giga_system
		set_star_flag = has_blokkat_gigarelay
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_country_flag = has_blokkat_gigarelay
			country_event = { id = giga_blokkat_join.2041 }	
		}
	}
}

blokkat_prison_1_empty = {
	entity = "blokkat_prison_empty_entity"
	construction_entity = "blokkat_prison_empty_entity"
	
	portrait = "GFX_megastructure_blokkat_prison"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_blokkat_snare }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 3600
	resources = {
		category = giga_megastructures
		cost = {
			alloys = 50000
			influence = 50
			unity = @giga_mega_unity_cost
		}
		upkeep = {
			energy = 100
		}
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_blokkat_snare
		is_ai = no
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border" is_inside_border = from }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"	planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"				has_anomaly = no }
			custom_tooltip = { fail_text = "requires_not_star"					is_star = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
		}
	}

	ai_weight = {
		weight = 0
	}

	on_build_complete = {
		save_event_target_as = giga_system
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			if = {
				limit = { NOT = { has_country_flag = just_released_blokkat } }
				country_event = { id = giga_blokkat.3236 }	
			}
			if = {
				limit = { has_country_flag = just_released_blokkat }
				remove_country_flag = just_released_blokkat
			}
		}
	}
}

blokkat_shield_killer_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_blokkat_mega_stage_0 }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			alloys = 50000
			influence = 300
			unity = @giga_tera_start_unity_cost
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_blokkat_mega_stage_0
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"					is_inside_border = from }
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"			NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"				NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
		custom_tooltip = { 
			fail_text = "requires_no_existing_blokkat_destabilizer"
			from = {
				NOR = {
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_0 }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_1 }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_2 }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_3 }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_4 }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_activate }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_activate_chrono }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_energy }
					any_owned_megastructure = { is_megastructure_type = blokkat_shield_killer_influence }
				}
			}
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { fail_text = "requires_no_existing_megastructure"		planet_has_no_megastructure = yes }
			custom_tooltip = { fail_text = "must_build_around_star"					is_star = yes }
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = { 
				fail_text = "requires_standard_planet_class"			
				giga_is_standard_star = yes
				NOT = {
					giga_is_bitrinary = yes
				}
			}
		}
	}

	ai_weight = {
		weight = 0
	}

    on_build_start = {
        set_star_flag = giga_forbid_planet_dismantlement
    }

    on_build_cancel = {
        remove_star_flag = giga_forbid_planet_dismantlement
    }

	on_build_complete = {
		save_event_target_as = giga_system
		set_star_flag = has_blokkat_shield_killer
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			set_country_flag = has_blokkat_shieldkiller
			country_event = { id = giga_blokkat.30681 }	
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_bulk_matter_calculations
			giga_system_bm_cost = @blokkat_shield_killer_1_bm_cost
		}
	}
}

blokkat_star_fix_0 = {
	entity = "giga_consite_7_7_entity"
	construction_entity = "giga_consite_7_7_entity"
	
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = { giga_tech_blokkat_fix_systems }
	
	outliner_trigger = {
		exists = owner
		NOT = { has_megastructure_flag = giga_outliner_hidden_by_@owner }
	}
	
	build_time = 1800
	resources = {
		category = giga_gigastructures
		cost = {
			alloys = 50000
		}
		upkeep = { energy = 10 }
	}

	potential = {
		NOT = { has_country_flag = compat_mega_hide_giga } # compat: AoW-only build-menu tab hides Giga
		has_technology = giga_tech_blokkat_fix_systems
	}

	possible = {
		custom_tooltip = { fail_text = "requires_surveyed_system"				giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"			NOT = { any_system_planet = { is_colony = yes } } }
		custom_tooltip = { fail_text = "requires_no_existing_megastructure"		has_no_non_gate_megastructure = yes }
		custom_tooltip = { fail_text = "requires_no_crisis_system"				NOT = { any_system_planet = { has_planet_flag = crisis_vital_planet } } }
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = { 
				fail_text = "requires_no_existing_megastructure"
				AND = {
					planet_has_no_megastructure = yes
					solar_system = { NOT = { has_star_flag = blokkat_star_fix } }
				} 
			}
			custom_tooltip = { fail_text = "requires_no_anomaly"					has_anomaly = no }
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = { 
				fail_text = "requires_destroyed_system"			
				OR = {
					is_star_class = sc_blokkat_stripmined
					is_star_class = sc_empty_space
				}
			}
		}
	}

	ai_weight = {
		weight = 0
	}
	
	on_build_complete = {
		save_event_target_as = giga_system
		set_star_flag = blokkat_star_fix
		create_starbase = {
			size = starbase_outpost
			owner = ROOT.from
		}
		fromfrom.planet = {
			save_event_target_as = giga_planet
			if = { limit = { exists = orbital_station } orbital_station = { dismantle = yes } }
			giga_set_has_mega_flag = yes
		}
		from = {
			country_event = { id = giga_blokkat.3353 }	
		}
	}
}

