BuildingType
    name = "BLD_INTERSPECIES_ACADEMY"
    description = "BLD_INTERSPECIES_ACADEMY_DESC"
    buildcost = 50 * [[BUILDING_COST_MULTIPLIER]]
    buildtime = 5
    location = And [
        // Homeworld
        Planet
        Species
        Not Contains Building name = "BLD_INTERSPECIES_ACADEMY"
        OwnedBy empire = Source.Owner
        Happiness low = (NamedReal name = "BLD_INTERSPECIES_ACADEMY_MIN_STABILITY_BUILD" value = 15)
        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 = [
        [[SPECIES_LIKES_OR_DISLIKES_BUILDING_STABILITY_EFFECTS]]
    
        // 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 = [[TARGET_AFTER_SCALING_PRIORITY]]
            effects = SetMaxStockpile value = Value
                        + (NamedReal name = "BLD_INTERSPECIES_ACADEMY_MAX_STOCKPILE_FLAT" value = 10)
        
        // Research bonus    
        EffectsGroup
            scope = And [
                Object id = Source.PlanetID
                Planet
                Focus type = "FOCUS_RESEARCH"
                OwnedBy empire = Source.Owner
                Species
                Happiness low = (NamedReal name = "BLD_INTERSPECIES_ACADEMY_MIN_STABILITY_RESEARCH" value = 12)
            ]
            accountinglabel = "INTERSPECIES_ACADEMY_LABEL"
            priority = [[TARGET_AFTER_SCALING_PRIORITY]]
            effects = SetTargetResearch value = Value
                        + (NamedReal name = "BLD_INTERSPECIES_ACADEMY_TARGET_RESEARCH_FLAT" value = 5)
            
        // Influence bonus    
        EffectsGroup
            scope = And [
                Object id = Source.PlanetID
                Planet
                Focus type = "FOCUS_INFLUENCE"
                OwnedBy empire = Source.Owner
                Species
            ]
            accountinglabel = "INTERSPECIES_ACADEMY_LABEL"
            priority = [[TARGET_AFTER_SCALING_PRIORITY]]
            effects = SetTargetInfluence value = Value
                        + (NamedReal name = "BLD_INTERSPECIES_ACADEMY_TARGET_INFLUENCE_FLAT" value = 2)
    ]
    icon = "icons/building/science-institute.png"

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