Policy
    name = "PLC_METROPOLES"
    description = "PLC_METROPOLES_DESC"
    short_description = "PLC_METROPOLES_SHORT_DESC"
    category = "ECONOMIC_CATEGORY"
    adoptioncost = 1.0 * floor(15 + 0.25 * Statistic Sum value = LocalCandidate.Population
                                           condition = And [ Planet OwnedBy empire = Source.Owner ])
    exclusions = [ "PLC_COLONIZATION" "PLC_CONFEDERATION" ]
    effectsgroups = [
        [[SPECIES_LIKES_OR_DISLIKES_POLICY_STABILITY_EFFECTS]]

        // Boost largest-population planets, provided they have enough population and stability.
        // Metropoles need some "umland", so no more than 1 in 4 can become a metropole.
        // Note that to raise a planet to a metropole, you have to reach the minimum stability
        // while suffering from the non-metropole penalty below.
        EffectsGroup
            scope = MaximumNumberOf number = min((NamedInteger name = "METROPOLES_PLANET_LIMIT" value = 6),
                                                 floor(Statistic Count condition = And [
                                                           Planet
                                                           OwnedBy empire = Source.Owner
                                                           Species
                                                       ] / (NamedInteger name = "METROPOLES_MIN_PLANETS" value = 4)))
                                    sortkey = LocalCandidate.Population
                                    condition = And [
                                        Planet
                                        OwnedBy empire = Source.Owner
                                        Population low = (NamedReal name = "METROPOLES_MINIMUM_POPULATION" value = 20.0)
                                        Happiness low = (NamedReal name = "METROPOLES_MIN_STABILITY" value = 12)
                                    ]
            priority = [[TARGET_AFTER_SCALING_PRIORITY]]
            effects = [
                SetTargetIndustry value = Value + Target.Population
                    * (NamedReal name = "METROPOLES_TARGET_INDUSTRY_PERPOP"
                                 value = [[INDUSTRY_PER_POP]])
                SetTargetResearch value = Value + Target.Population
                    * (NamedReal name = "METROPOLES_TARGET_RESEARCH_PERPOP"
                                 value = [[RESEARCH_PER_POP]])
                SetTargetConstruction value = Value
                    + (NamedReal name = "METROPOLES_TARGET_CONSTRUCTION_FLAT" value = 10)
                SetMaxSupply value = Value
                    + (NamedReal name = "METROPOLES_MAX_SUPPLY_FLAT" value = 2)
                SetMaxStockpile value = Value
                    + (NamedReal name = "METROPOLES_MAX_STOCKPILE_FLAT" value = -2)
            ]

        // reduce stability on all other planets
        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
                Species // excludes non-populated planets
                Not MaximumNumberOf number = min((NamedIntegerLookup name = "METROPOLES_PLANET_LIMIT"),
                                                 floor(Statistic Count condition = And [
                                                           Planet
                                                           OwnedBy empire = Source.Owner
                                                           Species
                                                       ] / (NamedIntegerLookup name = "METROPOLES_MIN_PLANETS")))
                                    sortkey = LocalCandidate.Population condition = And [
                    Planet
                    OwnedBy empire = Source.Owner
                    Population low = (NamedRealLookup name = "METROPOLES_MINIMUM_POPULATION")
                    Happiness low = (NamedRealLookup name = "METROPOLES_MIN_STABILITY")
                ]
            ]
            effects =
                SetTargetHappiness value = Value - (NamedReal name = "METROPOLES_STABILITY_PENALTY" value = 5.0)
    ]
    graphic = "icons/policies/economic_metropoles.png"

#include "/scripting/macros/base_prod.macros"
#include "/scripting/policies/policies.macros"
#include "/scripting/macros/priorities.macros"
