Policy
    name = "PLC_CHECKPOINTS"
    description = "PLC_CHECKPOINTS_DESC"
    short_description = "PLC_CHECKPOINTS_SHORT_DESC"
    category = "ECONOMIC_CATEGORY"
    adoptioncost = 5 + floor(5.0 * [[PLANETS_OWNED_BY_EMPIRE]]^0.5)
    exclusions = [ "PLC_BLACK_MARKET" ]
    unlock = Item type = Policy name = "PLC_MARTIAL_LAW"
    effectsgroups = [
        [[SPECIES_LIKES_OR_DISLIKES_POLICY_STABILITY_EFFECTS]]

        EffectsGroup
            scope = And [
                Planet
                OwnedBy empire = Source.Owner
                Species
            ]
            priority = [[TARGET_LATE_AFTER_2ND_SCALING_PRIORITY]]
            effects = [
                SetTargetInfluence value = Value
                   + (NamedReal name = "PLC_CHECKPOINTS_TARGET_INFLUENCE_FLAT" value = -0.5)
            ]

        EffectsGroup
            scope = And [
                Ship
                // own and allied ships should not be affected
                Not Or [
                    OwnedBy empire = Source.Owner
                    OwnedBy affiliation = AllyOf empire = Source.Owner
                ]

                // check in system and on starlanes if in own supply lines (allied ones dont count)
                Or [
                   And [
                       InSystem
                       (LocalCandidate.SupplyingEmpire == Source.Owner)
                   ]
                   And [
                       // TODO add .SupplyingEmpire for ships on starlanes
                       Not InSystem
                       (2 == Statistic Count condition = And [
                          System
                          (LocalCandidate.SupplyingEmpire == Source.Owner)
                          Or [
                            (RootCandidate.Fleet.NextSystemID == LocalCandidate.ID)
                            (RootCandidate.Fleet.PreviousSystemID == LocalCandidate.ID)
                          ]
                       ])
                   ]
                ]
            ]

            effects = SetStealth value = Value - min((NamedReal name = "PLC_CHECKPOINTS_MAX_STEALTH_MALUS" value = 20.0),
                                    TurnsSincePolicyAdopted empire = Source.Owner name = ThisPolicy)
    ]
    graphic = "icons/policies/economic_checkpoints.png"

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