BuildingType
    name = "BLD_ABANDON_OUTPOST"
    description = "BLD_ABANDON_OUTPOST_DESC"
    captureresult = Destroy
    buildcost = 20
    buildtime = 1
    location = And [
        Planet
        OwnedBy empire = Source.Owner
        Population high = 0
    ]

    effectsgroups = [
         // PREPARE FOR TWO TURNS
         EffectsGroup
            scope = Source
            activation = Turn high = Source.CreationTurn + 2
            stackinggroup = "ABANDON_OUTPOST_STACK"
            effects = GenerateSitRepMessage
                message = "SITREP_OUTPOST_ABANDONED_PREPARATION"
                label = "SITREP_OUTPOST_ABANDONED_PREPARATION_LABEL"
                icon = "icons/tech/environmental_encapsulation.png"
                parameters = [
                    tag = "planet" data = Source.PlanetID
                    tag = "rawtext" data = Source.CreationTurn + 4
                ]
                empire = Source.Owner

         // THEN CANT ABANDON IF BATTLE
         EffectsGroup
            scope = Source
            activation = Turn low = 3 + Source.CreationTurn  high = Source.System.LastTurnBattleHere
            stackinggroup = "ABANDON_OUTPOST_STACK"
            effects = GenerateSitRepMessage
                message = "SITREP_OUTPOST_ABANDONED_PREVENTED_BY_BATTLE"
                label = "SITREP_OUTPOST_ABANDONED_LABEL"
                icon = "icons/tech/environmental_encapsulation.png"
                parameters = [
                    tag = "planet" data = Target.PlanetID
                    tag = "system" data = Target.SystemID
                ]
                empire = Source.Owner

         // ELSE ABANDON OUTPOST
         EffectsGroup
            scope = And [
                Object id = Source.PlanetID
                Planet
            ]
            activation = Turn low = max(1 + Source.System.LastTurnBattleHere, 3 + Source.CreationTurn)
            stackinggroup = "ABANDON_OUTPOST_STACK"
            priority = [[POPULATION_OVERRIDE_PRIORITY]]
            effects = [
                SetOwner empire = [[UNOWNED_EMPIRE_ID]]
                GenerateSitRepMessage
                    message = "SITREP_OUTPOST_ABANDONED"
                    label = "SITREP_OUTPOST_ABANDONED_LABEL"
                    icon = "icons/tech/environmental_encapsulation.png"
                    parameters =  [
                        tag = "planet" data = Target.ID
                    ]
                    empire = Source.Owner
                SetVisibility empire = Source.Owner visibility = Max(Value, Partial)
            ]
         EffectsGroup
            scope = And [
                (LocalCandidate.PlanetID == Source.PlanetID)
                Building
                Not Building name = ThisBuilding
            ]
            activation = Turn low = max(1 + Source.System.LastTurnBattleHere, 3 + Source.CreationTurn)
            priority = [[POPULATION_OVERRIDE_PRIORITY]]
            effects = SetOwner empire = [[UNOWNED_EMPIRE_ID]]

        EffectsGroup
            scope = Source
            activation = Turn low = max(1 + Source.System.LastTurnBattleHere, 3 + Source.CreationTurn)
            effects = Destroy
    ]
    icon = "icons/tech/environmental_encapsulation.png"

#include "/scripting/common/enqueue.macros"
#include "/scripting/common/upkeep.macros"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
#include "/scripting/common/misc.macros"
