- type: entity
  abstract: true
  id: CablePhysBase
  placement:
    mode: SnapgridCenter
  components:
  - type: Visibility
    layer: 1
  - type: Cable
    cuttingDelay: 1
  - type: Clickable
  - type: InteractionOutline
  - type: Transform
    anchored: true
    noRot: true
    # TODO: Remove both of these, same with CollideOnAnchor
  - type: Physics
    bodyType: Static
    canCollide: false
  - type: Fixtures
  - type: CollideOnAnchor
  - type: Appearance

- type: entity
  abstract: true
  parent: CablePhysBase
  id: CableBase
  components:
  - type: Visibility
    layer: 1
  - type: Sprite
    drawdepth: ThinWire
    visible: false
  - type: Damageable
    damageContainer: Inorganic
    damageModifierSet: Metallic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:DoActsBehavior
        acts: ["Destruction"]
  - type: SubFloorHide
  - type: Electrified
    onHandInteract: false
    onInteractUsing: false # wire-cutting handled separately.
    onBump: false
    requirePower: true
    highVoltageNode: power
    mediumVoltageNode: power
    lowVoltageNode: power
  - type: CableVis
    node: power
  - type: RCDDeconstructable
    cost: 2
    delay: 0
    fx: EffectRCDConstruct0
  # Sunrise edit start - mapping replacement rules
  - type: MappingReplacement
    usePrototypeId: true
  # Sunrise edit end

- type: entity
  parent: CableBase
  id: CableHV
  name: HV power cable
  description: An orange high voltage power cable.
  components:
  - type: Sprite
    sprite: Structures/Power/Cables/hv_cable.rsi
    state: hvcable_0
    drawdepth: ThickWire
  - type: Icon
    sprite: Structures/Power/Cables/hv_cable.rsi
    state: hvcable_4
  - type: NodeContainer
    nodes:
      power:
        !type:CableNode
        nodeGroupID: HVPower
  - type: Cable
    cableDroppedOnCutPrototype: CableHVStack1
    cableType: HighVoltage
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 100
      behaviors: #excess damage (nuke?). avoid computational cost of spawning entities.
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          CableHVStack1:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: CableVisualizer
    statePrefix: hvcable_
  # TODO make this change on power
  - type: AmbientSound
    enabled: false
    volume: -14
    range: 2
    sound:
      path: /Audio/Ambience/Objects/emf_buzz.ogg

- type: entity
  id: CableHVUncuttable
  parent: CableHV
  suffix: uncuttable
  components:
  - type: Cable
    cuttingQuality: null

- type: entity
  parent: CableBase
  id: CableMV
  name: MV power cable
  description: A medium voltage power cable.
  components:
  - type: Sprite
    sprite: Structures/Power/Cables/mv_cable.rsi
    layers:
    - state: mvcable_0
      color: Yellow
    - state: mvstripes_0
  - type: Icon
    sprite: Structures/Power/Cables/mv_cable.rsi
    state: mvcable_4
  - type: NodeContainer
    nodes:
      power:
        !type:CableNode
        nodeGroupID: MVPower
  - type: Cable
    cableDroppedOnCutPrototype: CableMVStack1
    cableType: MediumVoltage
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 100
      behaviors: #excess damage (nuke?). avoid computational cost of spawning entities.
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          CableMVStack1:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: CableVisualizer
    statePrefix: mvcable_
    extraLayerPrefix: mvstripes_

- type: entity
  id: CableMVUncuttable
  parent: CableMV
  suffix: uncuttable
  components:
  - type: Cable
    cuttingQuality: null

- type: entity
  parent: CableBase
  id: CableApcExtension
  name: LV power cable
  description: A cable used to connect machines to an APC. #APCs aren't area defined anymore so need this cable to connect things to the APC. This description should be dynamic in future.
  components:
  - type: Sprite
    color: Green
    sprite: Structures/Power/Cables/lv_cable.rsi
    state: lvcable_0
  - type: Icon
    sprite: Structures/Power/Cables/lv_cable.rsi
    state: lvcable_4
  - type: NodeContainer
    nodes:
      power:
        !type:CableNode
        nodeGroupID: Apc
  - type: PowerProvider
    voltage: Apc
  - type: ExtensionCableProvider
  - type: Cable
    cableDroppedOnCutPrototype: CableApcStack1
    cableType: Apc
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 100
      behaviors: #excess damage (nuke?). avoid computational cost of spawning entities.
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          CableApcStack1:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
  - type: CableVisualizer
    statePrefix: lvcable_

- type: entity
  id: CableApcExtensionUncuttable
  parent: CableApcExtension
  suffix: uncuttable
  components:
  - type: Cable
    cuttingQuality: null

# Explosive cable below
- type: entity
  id: CableDet
  parent: [ CablePhysBase, BaseSecurityContraband ]
  name: explosive cord
  description: Spaghetti for people who hate walls.
  components:
  - type: Cable
    cableDroppedOnCutPrototype: CableDetStack1
    cableType: ExCable
  - type: Sprite
#    color: white # maybe change this later and move the stripes to the CableVisualizerComp layer instead
    sprite: Structures/Power/Cables/ex_cable.rsi
    state: excable_0
  - type: Icon
    sprite: Structures/Power/Cables/ex_cable.rsi
    state: excable_4
  - type: Damageable
    damageContainer: StructuralInorganic
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTypeTrigger
        damageType: Structural #this is as close as we can get to only letting explosives set it off.
        damage: 33 # Sunrise-Edit
      behaviors:
      - !type:DoActsBehavior
        acts: ["Destruction"]
      - !type:ExplodeBehavior
    - trigger: # Sunrise-Edit: non-explosive destruction (slash-only, not from explosions)
        !type:DamageTypeTrigger
        damageType: Slash
        damage: 50
      behaviors:
      - !type:DoActsBehavior
        acts: ["Destruction"]
    - trigger: # Sunrise-Edit: non-explosive stack spawn (slash-only, not from explosions)
        !type:DamageTypeTrigger
        damageType: Slash
        damage: 35
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          CableDetStack1:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: [ "Destruction" ]
    # - trigger: # Sunrise-Edit: disable non-explosive destruction
    #     !type:DamageTrigger #A fallback that deletes it but doesnt explode in case something somehow gets here without exploding violently enough.
    #     damage: 50
    #   behaviors:
    #   - !type:DoActsBehavior
    #     acts: ["Destruction"]
    # - trigger: # Sunrise-Edit: disable stack spawn on non-explosive damage
    #     !type:DamageTrigger
    #     damage: 35
    #   behaviors:
    #   - !type:SpawnEntitiesBehavior
    #     spawn:
    #       CableDetStack1:
    #         min: 1
    #         max: 1
    #   - !type:DoActsBehavior
    #     acts: [ "Destruction" ]
  - type: CableVis
    node: cordage
  - type: NodeContainer
    nodes:
      cordage:
        !type:CableNode
        nodeGroupID: ExCable
  - type: CableVisualizer
    statePrefix: excable_
  - type: Explosive
    explosionType: DemolitionCharge
    totalIntensity: 10
    intensitySlope: 5
    maxIntensity: 5
    canCreateVacuum: false
  - type: ExplodeOnTrigger
  - type: Construction
    graph: DetCable
    node: detonationCable
  - type: Tag
    tags:
    - ExCable
