
### plnmg_colossus_assist space mega ###
planetmega_colossus_assistant_0 = { #planetmega_aeg_support_mult will be presented in modules
    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
    #scales_with_planet = yes
    #use_planet_resource = yes
    outliner_trigger = { owner? = { has_technology = tech_planetmega_colossus } }

    build_time = 1260
    resources = {
        category = megastructures
        cost = {
            alloys = 10000
            influence = 100
        }
        cost = {
            trigger = { country_uses_bio_ships = yes }
            alloys = -5000
            food = 9000
        }
        upkeep = { energy = 5 }
    }

    #construction_blocks_and_blocked_by = self_type
    custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_SINGLE_COMMON_STAR"

    dismantle_potential = { always = no }

    potential = {
        is_ai = no
        has_technology = tech_planetmega_colossus
    }

    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_single_common_star
            is_plnmg_single_common_star_system = yes
        }
        custom_tooltip = {
            fail_text = requires_ap_galactic_wonders
            from = { has_galactic_wonders = yes }
        }
        custom_tooltip = {
            fail_text = requires_plnmg_ca_not_nomadic
            from = { is_nomadic = 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 }
            }
            custom_tooltip = {
                fail_text = "requires_no_existing_megastructure"
                NOR = {
                    has_planet_flag = megastructure
                    has_planet_flag = has_megastructure
                    has_planet_flag = plnmg_ca_spacemega_plnt
                    has_any_megastructure = yes
                }
            }
        }
    }

    # root = system
    # from = country
    ai_weight = { factor = 0 }

    on_build_complete = {
        fromfrom.planet = {
            set_planet_flag = has_megastructure
            set_planet_flag = plnmg_ca_spacemega_plnt
        }
    }
}

planetmega_colossus_assistant_1 = {
    entity = "matter_decompressor_stage_2_entity"
    construction_entity = "matter_decompressor_stage_2_construction_entity"
    portrait = "GFX_megastructure_construction_background"
    entity_offset = { x = -20 y = -20 }
    rotate_to_center = yes
    scale_offset = yes
    scales_with_planet = yes
    place_entity_on_planet_plane = no
    use_planet_resource = yes
    outliner_trigger = { owner? = { has_technology = tech_planetmega_colossus } }

    build_time = 3600
    resources = {
        category = megastructures
        cost = { alloys = 12500 }
        cost = {
            trigger = { country_uses_bio_ships = yes }
            alloys = -5000
            food = 7500
        }

        produces = { energy = 500 }
        produces = {
            trigger = { from = { has_menace_perk = menp_hyperthermia_crystals } }
            entropy_crystals = 85
        }
        upkeep = { minerals = 10 }
    }
    country_modifier = {
        dyson_gun_plnmg_damage_mult = 0.1
        planetmega_aeg_support_base = 3
    }

    dismantle_cost = {
        category = megastructures
        cost = { energy = 20000 }
    }
    dismantle_time = 1080
    dismantle_potential = { is_upgrading = no }
    dismantle_possible = { can_dismantle_megastructure = { TECH = tech_planetmega_colossus } }
    on_dismantle_complete = {
        from = {
            add_resource = {
                alloys = 10000
                mult = modifier:megastructure_dismantle_refund_mult
            }
        }
        every_system_planet = {
            limit = { has_planet_flag = plnmg_ca_spacemega_plnt }
            remove_planet_flag = has_megastructure
            remove_planet_flag = plnmg_ca_spacemega_plnt
        }
    }

    #construction_blocks_and_blocked_by = self_type
    upgrade_from = { planetmega_colossus_assistant_0 }
    possible = {
        from = {
            is_nomadic = no
            has_technology = tech_planetmega_colossus
        }
    }

    on_build_start = {
        fromfrom.planet = {
            if = {
                limit = { has_orbital_station = yes }
                orbital_station = { dismantle = yes }
            }
        }
    }
    on_build_complete = {
        #from = { country_event = { id = mega.9011 } }
    }
}

planetmega_colossus_assistant_2 = {
    entity = "matter_decompressor_stage_4_entity"
    construction_entity = "matter_decompressor_stage_4_construction_entity"
    portrait = "GFX_megastructure_plnmg_ca_background"
    entity_offset = { x = -20 y = -20 }
    rotate_to_center = yes
    scale_offset = yes
    scales_with_planet = yes
    place_entity_on_planet_plane = no
    use_planet_resource = yes
    show_in_outliner = no

    build_time = 3600
    resources = {
        category = megastructures
        cost = { alloys = 12500 }
        cost = {
            trigger = { country_uses_bio_ships = yes }
            alloys = -5000
            food = 7500
        }

        inline_script = megastructures/planetmega_ca_prods
        #upkeep = { energy = 30 }
    }
    country_modifier = {
        dyson_gun_plnmg_damage_mult = 0.2
        planetmega_aeg_support_base = 10
    }

    dismantle_cost = {
        category = megastructures
        cost = { energy = 50000 }
    }
    dismantle_time = 1800
    dismantle_potential = { is_upgrading = no }
    dismantle_possible = { can_dismantle_megastructure = { TECH = tech_planetmega_colossus } }
    on_dismantle_complete = {
        from = {
            add_resource = {
                alloys = 25000
                mult = modifier:megastructure_dismantle_refund_mult
            }
        }
        every_system_planet = {
            limit = { has_planet_flag = plnmg_ca_spacemega_plnt }
            remove_planet_flag = has_megastructure
            remove_planet_flag = plnmg_ca_spacemega_plnt
        }
    }

    #construction_blocks_and_blocked_by = self_type
    upgrade_from = { planetmega_colossus_assistant_1 }
    prerequisites = { "tech_planetmega_colossus" }
    possible = { from = { is_nomadic = no } }
    show_prereqs = yes

    on_build_complete = {
        set_variable = { which = var_plnmg_origin_sun_size value = star.trigger:planet_size }
        from = {
            set_country_flag = has_built_or_repaired_megastructure
            #country_event = { id = mega.9013 }
        }
    }

    inline_script = "megastructures/planetmega_ca_oc_cycle"
}

planetmega_colossus_assistant_ruined = {
    entity = "matter_decompressor_destroyed_01_entity"
    construction_entity = "matter_decompressor_stage_4_construction_entity"
    portrait = "GFX_megastructure_construction_background"
    entity_offset = { x = -20 y = -20 }
    rotate_to_center = yes
    scale_offset = yes
    scales_with_planet = yes
    place_entity_on_planet_plane = no
    show_galactic_map_icon = no
    outliner_trigger = { owner? = { has_technology = tech_planetmega_colossus } }
    potential = { always = no }
}

planetmega_colossus_assistant_restored = {
    entity = "matter_decompressor_stage_4_entity"
    construction_entity = "matter_decompressor_stage_4_construction_entity"
    portrait = "GFX_megastructure_plnmg_ca_background"
    entity_offset = { x = -20 y = -20 }
    rotate_to_center = yes
    scale_offset = yes
    scales_with_planet = yes
    place_entity_on_planet_plane = no
    use_planet_resource = yes
    build_time = 4800
    resources = {
        category = megastructures
        cost = { alloys = 20000 }
        cost = {
            trigger = { country_uses_bio_ships = yes }
            alloys = -10000
            food = 17500
        }

        inline_script = megastructures/planetmega_ca_prods
        upkeep = { energy = 30 }
    }
    country_modifier = {
        dyson_gun_plnmg_damage_mult = 0.2
        planetmega_aeg_support_base = 10
    }

    dismantle_cost = {
        category = megastructures
        cost = { energy = 50000 }
    }
    dismantle_time = 1800
    dismantle_potential = { is_upgrading = no }
    dismantle_possible = { can_dismantle_megastructure = { TECH = tech_planetmega_colossus } }
    on_dismantle_complete = {
        from = {
            add_resource = {
                alloys = 25000
                mult = modifier:megastructure_dismantle_refund_mult
            }
        }
        every_system_planet = {
            limit = { has_planet_flag = plnmg_ca_spacemega_plnt }
            remove_planet_flag = has_megastructure
            remove_planet_flag = plnmg_ca_spacemega_plnt
        }
    }

    upgrade_from = { planetmega_colossus_assistant_ruined }
    possible = {
        from = {
            is_nomadic = no
            has_technology = tech_planetmega_colossus
        }
    }

    on_build_complete = {
        set_variable = { which = var_plnmg_origin_sun_size value = star.trigger:planet_size }
        from = {
            set_country_flag = has_built_or_repaired_megastructure
            #country_event = { id = mega.9013 }
        }
    }

    inline_script = "megastructures/planetmega_ca_oc_cycle"
}
