# Core logic shared between regular and wall-mount substation
- type: entity
  abstract: true
  id: CoreSubstation
  components:
  # Core power behavior
  - type: Battery
    # Very important:
    # Disable networking to prevent the battery getting continuously dirtied every tick as it interacts with the power network.
    # This can not be done by changing the charge rate as the power supply ramps up over time.
    # This disables prediction for this battery.
    netsync: false
  - type: ExaminableBattery
  - type: NodeContainer
    examinable: true
    nodes:
      input:
        !type:CableDeviceNode
        nodeGroupID: HVPower
      output:
        !type:CableDeviceNode
        nodeGroupID: MVPower
  - type: BatteryCharger
    voltage: High
  - type: BatteryDischarger
    voltage: Medium
  - type: PowerNetworkBattery
    maxSupply: 150000
    maxChargeRate: 5000
    supplyRampTolerance: 5000
    supplyRampRate: 1000
  - type: StationInfiniteBatteryTarget

  # Interface
  - type: BatteryInterface
    minChargeRate: 5000
    maxChargeRate: 150000
    minSupply: 5000
    maxSupply: 150000
  - type: UserInterface
    interfaces:
      enum.BatteryUiKey.Key:
        type: BatteryBoundUserInterface
  - type: ActivatableUI
    key: enum.BatteryUiKey.Key

  - type: PowerMonitoringDevice
    group: Substation
    sourceNode: input
    loadNode: output
    collectionName: substation

  # Damage
  - type: PacifismDangerousAttack

  # Guidebook
  - type: GuideHelp
    guides:
    - VoltageNetworks
    - Power

  # Ambient sound
  - type: AmbientOnPowered
  - type: AmbientSound
    volume: -5
    sound:
      path: /Audio/Ambience/Objects/buzzing.ogg

# Base substation
- type: entity
  abstract: true
  id: BaseSubstation
  parent: [ CoreSubstation, BaseMachine, ConstructibleMachine, BaseConstructibleMachineDestructible ]
  name: substation
  description: Reduces the voltage of electricity put into it.
  placement:
    mode: SnapgridCenter
  components:
  - type: Sprite # TODO: add sprite for maintenance panel open
    sprite: Structures/Power/substation.rsi
    snapCardinals: true
    layers:
    - state: substation
    - state: screen
      shader: unshaded
    - state: full
      shader: unshaded
  - type: Battery
    maxCharge: 2500000
    startingCharge: 0
  - type: PointLight
    radius: 1.5
    energy: 1
    color: "#ff6900"
    castShadows: false
  - type: PowerMonitoringDevice
    sprite: Structures/Power/substation.rsi
    state: substation_static
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 175
      behaviors:
      - !type:PlaySoundBehavior
        sound:
          collection: MetalGlassBreak
      - !type:ExplodeBehavior
      - !type:SpawnGasBehavior
        gasMixture:
          volume: 1000
          moles:
            CarbonDioxide: 340.5701689 # carbon dioxide
          temperature: 373.15
  - type: Explosive
    explosionType: Default
    maxIntensity: 100
    intensitySlope: 2
    totalIntensity: 200
  - type: WiresPanel
  - type: Machine
    board: SubstationMachineCircuitboard
  - type: AmbientSound
    range: 3
  - type: Electrified
    onHandInteract: false
    onInteractUsing: false
    onBump: false
    requirePower: true
    highVoltageNode: input
    mediumVoltageNode: output

# Compact Wall Substation Base
- type: entity
  parent: [ CoreSubstation, StructureHealthMachine ]
  id: BaseSubstationWall
  categories: [ HideSpawnMenu ]
  name: wallmount substation
  description: A substation designed for compact shuttles and spaces.
  placement:
    mode: SnapgridCenter
  components:
  - type: AmbientSound
    range: 2
  - type: PointLight
    radius: 1.5
    energy: 1
    color: "#ff6900"
    netsync: false
    castShadows: false
    offset: 0, -0.2
  - type: Clickable
  - type: ContainerFill
    containers:
      board: [ WallmountSubstationElectronics ]
  - type: ContainerContainer
    containers:
      board: !type:Container
  - type: InteractionOutline
  - type: Physics
    bodyType: Static
    canCollide: false
  - type: Fixtures
  - type: Transform
    anchored: true
  - type: Sprite # TODO: add sprite for maintenance panel open
    drawdepth: WallMountedItems
    sprite: Structures/Power/substation.rsi
    layers:
    - state: substation_wall
    - state: screen_wall
      shader: unshaded
  - type: Battery
    maxCharge: 2000000
    startingCharge: 0
  - type: PowerMonitoringDevice
    sprite: Structures/Power/substation.rsi
    state: substation_wall_static
  - type: Damageable
    damageModifierSet: SteelMod
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 175
      behaviors:
      - !type:ExplodeBehavior
      - !type:PlaySoundBehavior
        sound:
          collection: MetalGlassBreak
  - type: Construction
    graph: WallmountSubstation
    node: substation
  - type: Explosive
    explosionType: Default
    maxIntensity: 50
    intensitySlope: 2
    totalIntensity: 100
  - type: WallMount

# Substations in use

- type: entity
  parent: BaseSubstation
  id: SubstationBasic
  suffix: Basic, 2.5MJ
  components:
  - type: Battery
    maxCharge: 2500000
    startingCharge: 2500000

- type: entity
  parent: SubstationBasic
  id: SubstationBasicEmpty
  suffix: Empty
  components:
  - type: Battery
    startingCharge: 0

- type: entity
  parent: BaseSubstationWall
  id: SubstationWallBasic
  suffix: Basic, 2MJ
  components:
  - type: Battery
    maxCharge: 2000000
    startingCharge: 2000000
  - type: ContainerFill
    containers:
      board: [ WallmountSubstationElectronics ]
      manipulator: [ MicroManipulatorStockPart ]
      powercell: [ PowerCellSmall ]
  - type: ContainerContainer
    containers:
      board: !type:Container
      manipulator: !type:Container
      powercell: !type:Container

      # Construction Frame
- type: entity
  id: BaseSubstationWallFrame
  categories: [ HideSpawnMenu ]
  name: wallmount substation frame
  description: A substation frame for construction.
  placement:
    mode: SnapgridCenter
  components:
  - type: Clickable
  - type: InteractionOutline
  - type: Physics
    bodyType: Static
    canCollide: false
  - type: Fixtures
  - type: Transform
    anchored: true
  - type: Sprite
    drawdepth: WallMountedItems
    sprite: Structures/Power/substation.rsi
    layers:
    - state: substation_wall
  - type: Construction
    graph: WallmountSubstation
    node: frame
  - type: WallMount
