BuildingType
    name = "BLD_INTERSPECIES_ACADEMY"
    description = "BLD_INTERSPECIES_ACADEMY_DESC"
    buildcost = 50 * [[BUILDING_COST_MULTIPLIER]]
    buildtime = 5
    location = AND [
        // Homeworld
        Species
        Not Contains Building name = "BLD_INTERSPECIES_ACADEMY"
        OwnedBy empire = Source.Owner
        Or [
            Happiness low = 15
            // The preferred focus happiness bonus helps only a bit
            And [
                Focus type = Source.PreferredFocus
                Happiness low = 19
            ]
        ]
        Not WithinStarlaneJumps jumps = 3 condition = And [
            System
            Contains And [
                Building name = "BLD_INTERSPECIES_ACADEMY"
                OwnedBy empire = Source.Owner
            ]
        ]
        Number low = 0 high = 0 condition = And [
            Building name = "BLD_INTERSPECIES_ACADEMY"
            Species name = RootCandidate.Species
            OwnedBy empire = RootCandidate.Owner
        ]
        Number low = 0 high = 0 condition = Described description = "CONDITION_INTERSPECIES_ACADEMY_SPECIES_ALREADY_EXISTS" condition = And [
            Planet
            Enqueued type = Building name = "BLD_INTERSPECIES_ACADEMY"
            Species name = RootCandidate.Species
            OwnedBy empire = RootCandidate.Owner
            Not Object id = RootCandidate.PlanetID
        ]
        Number low = 0 high = 6 condition = And [
            Building name = "BLD_INTERSPECIES_ACADEMY"
            OwnedBy empire = Source.Owner
        ]
        
    ]
    EnqueueLocation = [[ENQUEUE_BUILD_ONE_PER_PLANET]]
    effectsgroups = [
        // Destroy superfluous academies
        EffectsGroup 
            scope = NumberOf number = 1 condition = And [
                Building name = "BLD_INTERSPECIES_ACADEMY"
                OwnedBy empire = Source.Owner
                Not Object id = Source.ID
                Species name = Source.Planet.Species
            ]
            activation = Random probability = 0.3
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_INTERSPECIES_ACADEMY_DESTROY"
                    label = "EFFECT_INTERSPECIES_ACADEMY_DESTROY_LABEL"
                    icon = "icons/building/blackhole.png"
                    parameters = [
                        tag = "planet" data = Target.PlanetID
                    ]
                    empire = Source.Owner
                Destroy
            ]
        
        // Apply stockpile effects
        EffectsGroup
            scope = And [
                Object id = Source.PlanetID
                Planet
                Focus type = "FOCUS_STOCKPILE"
                OwnedBy empire = Source.Owner
                Species
            ]
            accountinglabel = "INTERSPECIES_ACADEMY_LABEL"
            priority = [[LATE_PRIORITY]]
            effects = SetMaxStockpile value = Value + 10
        EffectsGroup
            scope = And [
                Object id = Source.PlanetID
                Planet
                Focus type = "FOCUS_RESEARCH"
                OwnedBy empire = Source.Owner
                Species
            ]
            accountinglabel = "INTERSPECIES_ACADEMY_LABEL"
            priority = [[LATE_PRIORITY]]
            effects = SetTargetResearch value = Value + 5
            
    ]
    icon = "icons/building/science-institute.png"

#include "/scripting/common/base_prod.macros"

#include "/scripting/common/enqueue.macros"
#include "/scripting/common/priorities.macros"
