Part
    name = "SR_TENTACLE"
    description = "SR_TENTACLE_DESC"
    class = ShortRange
    damage = 5
    shots = 2
    // destroyFightersPerBattleMax = default, can shoot fighters starting from bout 2
    damageStructurePerBattleMax =
        max(0,ShipPartMeter part = "SR_TENTACLE" meter = Capacity object = Source.ID - Value(Target.Shield))
        * ShipPartMeter part = "SR_TENTACLE" meter = SecondaryStat object = Source.ID
        * NamedRealLookup name = "NUM_REAL_COMBAT_ROUNDS_IN_CLOSE_TARGETING_RANGE"

    combatTargets = And [
        Not System
        Not Fleet
        [[COMBAT_TARGETS_VISIBLE_ENEMY]]
        OrderedAlternativesOf [
           And [
               // Ships are also in reach starting from bout 3
               (CombatBout >= NamedIntegerLookup name = "FIRST_COMBAT_ROUND_IN_CLOSE_TARGETING_RANGE")
               [[COMBAT_TARGETS_VISIBLE_ENEMY]] [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]]
           ]
           And [
               // if no ships, fighters and planets are fair game
               (CombatBout >= NamedIntegerLookup name = "FIRST_COMBAT_ROUND_IN_CLOSE_TARGETING_RANGE")
               [[COMBAT_TARGETS_VISIBLE_ENEMY]]
               Or [
                    Fighter
                    [[COMBAT_TARGETS_PLANET_WITH_DEFENSE]]
               ]
           ]
           And [
               // Attack fighters starting from bout 2 until FIRST_COMBAT_ROUND_IN_CLOSE_TARGETING_RANGE
               (CombatBout >= 2)
               [[COMBAT_TARGETS_VISIBLE_ENEMY]] Fighter
           ]
        ]
    ]
    mountableSlotTypes = External
    buildcost = 30 * [[FLEET_UPKEEP_MULTIPLICATOR]] * [[SHIP_PART_COST_MULTIPLIER]]
    buildtime = 2
    tags = [ "PEDIA_PC_DIRECT_WEAPON" ]
    location = And [
        Planet
        OwnedBy empire = Source.Owner
    ]
    icon = "icons/ship_parts/tentacle.png"

#include "shortrange.macros"

#include "/scripting/macros/upkeep.macros"
#include "/scripting/ship_parts/targeting.macros"
