Policy
    name = "PLC_CAPITAL_MARKETS"
    description = "PLC_CAPITAL_MARKETS_DESC"
    short_description = "PLC_CAPITAL_MARKETS_SHORT_DESC"
    category = "ECONOMIC_CATEGORY"
    adoptioncost = floor(2.0 * [[POPULATION_OWNED_BY_EMPIRE]]^0.5)
    unlock = Item type = Policy name = "PLC_BLACK_MARKET"
    effectsgroups = [
        [[SPECIES_LIKES_OR_DISLIKES_POLICY_STABILITY_EFFECTS]]
        
        // boost influence focus output
        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
                Focus type = "FOCUS_INFLUENCE"
                Happiness low = (NamedReal name = "CAPITAL_MARKETS_INFLUENCE_MIN_STABILITY" value = 20.0)
            ]
            priority = [[TARGET_AFTER_2ND_SCALING_PRIORITY]]
            effects =
                SetTargetInfluence value = Value + min(Target.Construction, Target.Population) *
                    (NamedReal name = "CAPITAL_MARKETS_INFLUENCE_BONUS_SCALING" value = 0.1)

        // additionally penalize stability when empire has an influence debt
        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
                Species
                Not Species name = "SP_EXOBOT"
            ]
            activation = And [
                Source
                Not EmpireStockpile empire = Source.Owner resource = Influence low = 0
            ]
            priority = [[TARGET_EARLY_BEFORE_SCALING_PRIORITY]]
            effects = SetTargetHappiness value = Value - (NamedReal name = "CAPITAL_MARKETS_DEBT_INSTABILITY" value = 0.05)
                * abs(EmpireStockpile empire = Source.Owner resource = Influence)

        // grow influence and stability meters faster
        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
            ]
            priority = [[AFTER_ALL_TARGET_MAX_METERS_PRIORITY]]
            effects = [
                If condition = (Value(LocalCandidate.Influence) <= Value(LocalCandidate.TargetInfluence))
                    effects = SetInfluence value = min(Value + NamedReal name = "PLC_CAPITAL_MARKETS_INFLUENCE_RATE" value = 2.0, Value(Target.TargetInfluence))
                    else = SetInfluence value = max(Value - NamedRealLookup name = "PLC_CAPITAL_MARKETS_INFLUENCE_RATE", Value(Target.TargetInfluence))

                If condition = (Value(LocalCandidate.Happiness) <= Value(LocalCandidate.TargetHappiness))
                    effects = SetHappiness value = min(Value + NamedReal name = "PLC_CAPITAL_MARKETS_INFLUENCE_RATE" value = 2.0, Value(Target.TargetHappiness))
                    else = SetHappiness value = max(Value - NamedRealLookup name = "PLC_CAPITAL_MARKETS_INFLUENCE_RATE", Value(Target.TargetHappiness))

            ]
    ]
    graphic = "icons/policies/economic_capital_markets.png"

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