FieldType
    name = "FLD_NEBULA_1"
    description = "FLD_NEBULA_1_DESC"
    stealth = 0.01
    effectsgroups = [
        EffectsGroup    // shrink slowly when in no-star system
            scope = Source
            activation = And [
                Size low = 2 high = 120
                Star type = NoStar
            ]
            effects =
                SetSize value = Value + RandomNumber(-0.8, 0.3)

        EffectsGroup    // shrink slowly when in no-star system
            scope = Source
            activation = And [
                Size low = 120
                Star type = NoStar
            ]
            effects =
                SetSize value = Value + RandomNumber(-0.8, 0)

        EffectsGroup    // spawn new star when small enough
            scope = And [ 
                System
                Object id = Source.SystemID
            ]
            activation = And [
                Size high = 5
                Star type = NoStar
            ]
            effects = [
                SetStarType type = OneOf(White, Yellow, Orange, Red)
                GenerateSitRepMessage
                    message = "EFFECT_NEBULA"
                    label = "EFFECT_NEBULA_LABEL"
                    icon = "icons/buttons/addstar.png"
                    parameters = [
                        tag = "system" data = Source.SystemID
                        ]
                    affiliation = CanSee condition = Source
                ]

        [[CREATE_PLANETS]]

        EffectsGroup    // make ships slower, reduce detection, increase stealth
            scope = And [
                Ship
                WithinDistance distance = Source.Size * 0.9 condition = Source
            ]
            stackinggroup = "NEBULA_SHIP_EFFECTS"
            effects = [
                SetSpeed value = max(5, Value - NamedRealLookup name = "FLD_NEBULA_SPEED_MALUS")
                SetStealth value = Value + NamedRealLookup name = "FLD_NEBULA_STEALTH_BONUS"
                SetDetection value = Value - NamedRealLookup name = "FLD_NEBULA_DETECTION_MALUS"
            ]

        EffectsGroup    // dissipate when small
            scope = Source
            activation = Size high = 5
            effects = [
                Destroy
                CreateField type = "FLD_ACCRETION_DISC" size = 20
                AddSpecial name = "ACCRETION_DISC_SPECIAL"
            ]
    ]
    graphic = "fields/star_forming_nebula_1.png"

#include "fields.macros"
