BuildingType
    name = "BLD_LIGHTHOUSE"
    description = "BLD_LIGHTHOUSE_DESC"
    buildcost = 25 * [[BUILDING_COST_MULTIPLIER]]
    buildtime = 10
    location = And [
        Planet
        Not Contains Building name = "BLD_LIGHTHOUSE"
        OwnedBy empire = Source.Owner
    ]
    enqueuelocation = [[ENQUEUE_BUILD_ONE_PER_PLANET]]
    effectsgroups = [
        [[SPECIES_LIKES_OR_DISLIKES_BUILDING_STABILITY_EFFECTS]]

        EffectsGroup
            scope = And [
                Ship
                WithinDistance distance = 0.00001 condition = Source
            ]
            stackinggroup = "LIGHTHOUSE_IMMEDIATE_STEALTH_STACK"
            effects = SetStealth value = Value - NamedReal name = "BLD_LIGHTHOUSE_IMMEDIATE_STEALTH_MALUS" value = 20

        // Highly Self Illuminated, automatically "registered in catalog"
        EffectsGroup
            scope = Source
            stackinggroup = "LIGHTHOUSE_CATALOG_STEALTH_STACK"
            accountinglabel = "BLD_LIGHTHOUSE_CATALOG_STEALTH_LABEL"
            effects = SetStealth value = Value - NamedReal name = "BLD_LIGHTHOUSE_SELF_STEALTH_MALUS" value = 20

        // takes the maximum age of all lighthouse buildings in the system regardless of owner (by just triggering for the oldest ones)
        EffectsGroup
            scope = WithinDistance distance = 0.00001 condition = Source
            activation = (Source.Age >= (Statistic Max value = LocalCandidate.Age condition = And [
                InSystem id = Source.SystemID
                Building name = "BLD_LIGHTHOUSE"
            ]))
            stackinggroup = "LIGHTHOUSE_CATALOG_STEALTH_STACK"
            accountinglabel = "BLD_LIGHTHOUSE_CATALOG_STEALTH_LABEL"
            effects = SetStealth value = Value - min(Source.Age, NamedReal name = "BLD_LIGHTHOUSE_CATALOG_STEALTH_MALUS" value = 10)

        EffectsGroup
            scope = And [
                Ship
                Not Or [
                    OwnedBy affiliation = EnemyOf empire = Source.Owner
                    Unowned
                ]
                WithinDistance distance = NamedReal name = "BLD_LIGHTHOUSE_SPEEDUP_DISTANCE" value = 50 condition = Source
                Speed low = 1 // Immobile objects do not get the starlane speed boost.
            ]
            stackinggroup = "LIGHTHOUSE_SPEED_STACK"
            effects = SetSpeed value = Value + NamedReal name = "BLD_LIGHTHOUSE_SPEEDUP" value = 20
    ]
    icon = "icons/building/lighthouse.png"

#include "/scripting/macros/enqueue.macros"
#include "/scripting/macros/base_prod.macros"
#include "/scripting/buildings/buildings.macros"
#include "/scripting/macros/priorities.macros"
