#region Base Nuclear Reactors
- type: entity
  id: BaseNuclearReactor
  parent: BaseStructure
  abstract: true
  name: Nuclear Reactor
  description: A nuclear reactor vessel, with slots for fuel rods and other components. Hey wait, didn't one of these explode once?
  components:
  - type: Sprite
    sprite: _FarHorizons/Structures/Power/Generation/FissionGenerator/nuclear_reactor.rsi
    layers:
    - state: reactor
      visible: true
      map: [ "enum.ReactorVisualLayers.Sprite" ]
    - state: reactor_status_active
      shader: unshaded
      visible: false
      map: [ "enum.ReactorVisualLayers.Status" ]
    - state: reactor_gas_input_lights
      shader: unshaded
      visible: false
      map: [ "enum.ReactorVisualLayers.Input" ]
    - state: reactor_gas_output_lights
      shader: unshaded
      visible: false
      map: [ "enum.ReactorVisualLayers.Output" ]
    - state: reactor_lights_warning
      shader: unshaded
      visible: false
      map: [ "enum.ReactorVisualLayers.Lights" ]
    - state: reactor_fire
      visible: false
      map: [ "enum.ReactorVisualLayers.Smoke" ]
    - state: reactor_smoke
      visible: false
      map: [ "enum.ReactorVisualLayers.Fire" ]
  - type: GenericVisualizer
    visuals:
      enum.ReactorVisuals.Sprite:
        enum.ReactorVisualLayers.Sprite:
          Normal: { state: reactor }
          Melted: { state: reactorbroken }
      enum.ReactorVisuals.Status:
        enum.ReactorVisualLayers.Status:
          Off: { visible: false}
          Active: { state: reactor_status_active, visible: true }
          Overheat: { state: reactor_status_overheat, visible: true }
          Meltdown: { state: reactor_status_meltdown, visible: true }
      enum.ReactorVisuals.Input:
        enum.ReactorVisualLayers.Input:
          True: { visible: true }
          False: { visible: false }
      enum.ReactorVisuals.Output:
        enum.ReactorVisualLayers.Output:
          True: { visible: true }
          False: { visible: false }
      enum.ReactorVisuals.Lights:
        enum.ReactorVisualLayers.Lights:
          LightsOff: { visible: false }
          LightsWarning: { state: reactor_lights_warning, visible: true }
          LightsMeltdown: { state: reactor_lights_meltdown, visible: true }
      enum.ReactorVisuals.Smoke:
        enum.ReactorVisualLayers.Smoke:
          True: { visible: true }
          False: { visible: false }
      enum.ReactorVisuals.Fire:
        enum.ReactorVisualLayers.Fire:
          True: { visible: true }
          False: { visible: false }
  - type: Appearance
  - type: InteractionOutline
  - type: Rotatable
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-2.5,-2.5,2.5,2"
        density: 190
        mask:
        - MachineMask
        layer:
        - MachineLayer
        - HighImpassable
  - type: Damageable
    damageContainer: StructuralInorganic
    damageModifierSet: StructuralReactorCasing
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 1000
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          NuclearReactorMelted:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: ["Destruction"]
      - !type:PlaySoundBehavior
        sound:
          collection: MetalBreak
  - type: Anchorable
    delay: 9
  - type: AtmosDevice
  - type: AtmosMonitoringConsoleDevice # TODO: this doesn't work?
    navMapBlip: Thermoregulator
  - type: RadiationSource
    intensity: 0
  - type: ContainerContainer
    containers:
      part_slot: !type:ContainerSlot {}
      part_storage: !type:Container
  - type: ItemSlots
  - type: NuclearReactor
    part_slot:
      whitelist:
        components:
          - ReactorPart
  - type: DeviceNetwork
    deviceNetId: Wireless
    receiveFrequencyId: BasicDevice
  - type: WirelessNetworkConnection
    range: 200
  - type: DeviceLinkSource
    range: 50
    ports:
      - NuclearReactorDataSender
  - type: DeviceLinkSink
    ports:
      - InsertControlRods
      - RetractControlRods
  - type: ActivatableUI
    key: enum.NuclearReactorUiKey.Key
  - type: ActivatableUIRequiresAnchor
  - type: UserInterface
    interfaces:
      enum.NuclearReactorUiKey.Key:
        type: NuclearReactorBoundUserInterface
  - type: GuideHelp
    guides:
    - NuclearReactor
    - Power

- type: entity
  id: BaseNuclearReactorSmall
  parent: BaseNuclearReactor
  abstract: true
  name: Small Nuclear Reactor
  components:
  - type: Sprite
    sprite: _FarHorizons/Structures/Power/Generation/FissionGenerator/small_nuclear_reactor.rsi
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-1.5,-1.5,1.5,1.5"
        density: 190
        mask:
        - MachineMask
        layer:
        - MachineLayer
        - HighImpassable
  - type: NuclearReactor
    thermalMass: 302400
    reactorGridWidth: 5
    reactorGridHeight: 5
    inletPos: -1, 1
    inletRot: 180
    outletPos: 1, 1
    outletRot: 180
    arrowPrototype: ReactorSmallFlowArrow
    gridbounds: [ 12, 11, 0, 0 ]
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 700
      behaviors:
      - !type:SpawnEntitiesBehavior
        spawn:
          NuclearReactorSmallMelted:
            min: 1
            max: 1
      - !type:DoActsBehavior
        acts: ["Destruction"]
      - !type:PlaySoundBehavior
        sound:
          collection: MetalBreak

- type: entity
  id: NuclearReactorCrew
  abstract: true
  components:
  - type: AccessReader # You got a permit for that meltdown?
    access: [["Engineering"]]
  - type: Lock
    unlockOnClick: false
  - type: WarpPoint
    location: Nuclear Reactor
    blacklist:
      tags:
      - GhostOnlyWarp

- type: entity
  id: NuclearReactorSalvage # Kind of an empty shell, but if there's something special about salvage reactors, put it here
  abstract: true
#endregion

#region Nuclear Reactor Variants
- type: entity
  id: ReactorPrefabEmpty
  abstract: true
  components:
  - type: NuclearReactor
    prefab: ReactorPrefabEmpty

- type: entity
  id: ReactorPrefabRandom
  abstract: true
  components:
  - type: NuclearReactor
    prefab: random

- type: entity
  id: ReactorPrefab7x7Meltdown
  abstract: true
  components:
  - type: NuclearReactor
    prefab: ReactorPrefab7x7Meltdown

- type: entity
  id: ReactorPrefab5x5Normal
  abstract: true
  components:
  - type: NuclearReactor
    prefab: ReactorPrefab5x5Normal
#endregion

#region Crew Nuclear Reactors
- type: entity
  id: NuclearReactorNormal
  parent: [BaseNuclearReactor, NuclearReactorCrew]

- type: entity
  id: NuclearReactorEmpty
  parent: [BaseNuclearReactor, NuclearReactorCrew, ReactorPrefabEmpty]
  suffix: "Empty"

- type: entity
  id: NuclearReactorRandom
  parent: [BaseNuclearReactor, NuclearReactorCrew, ReactorPrefabRandom]
  suffix: "Random"

- type: entity
  id: NuclearReactorMeltdown
  parent: [BaseNuclearReactor, NuclearReactorCrew, ReactorPrefab7x7Meltdown]
  suffix: "Meltdown"
#endregion

#region Crew Small Nuclear Reactors
- type: entity
  id: NuclearReactorSmall
  parent: [BaseNuclearReactorSmall, NuclearReactorCrew, ReactorPrefab5x5Normal]
  
- type: entity
  id: NuclearReactorSmallRandom
  parent: [BaseNuclearReactorSmall, NuclearReactorCrew, ReactorPrefabRandom]
  suffix: "Random"
#endregion

#region Salvage Nuclear Reactors
- type: entity
  id: NuclearReactorNormalSalvage
  parent: [BaseNuclearReactor, NuclearReactorSalvage]
  suffix: "Salvage"

- type: entity
  id: NuclearReactorEmptySalvage
  parent: [BaseNuclearReactor, NuclearReactorSalvage, ReactorPrefabEmpty]
  suffix: "Salvage, Empty"

- type: entity
  id: NuclearReactorRandomSalvage
  parent: [BaseNuclearReactor, NuclearReactorSalvage, ReactorPrefabRandom]
  suffix: "Salvage, Random"
#endregion

#region Salvage Small Nuclear Reactors
- type: entity
  id: NuclearReactorSmallSalvage
  parent: [BaseNuclearReactorSmall, NuclearReactorSalvage, ReactorPrefab5x5Normal]
  suffix: "Salvage"

- type: entity
  id: NuclearReactorSmallRandomSalvage
  parent: [BaseNuclearReactorSmall, NuclearReactorSalvage, ReactorPrefabRandom]
  suffix: "Salvage, Random"

- type: entity
  id: NuclearReactorSmallEmptySalvage
  parent: [BaseNuclearReactorSmall, NuclearReactorSalvage, ReactorPrefabEmpty]
  suffix: "Salvage, Empty"
#endregion

#region Melted Reactors
- type: entity
  id: NuclearReactorMelted # This is more of a decoration than anything else
  parent: BaseStructure
  suffix: "Melted"
  name: Nuclear Reactor
  description: A broken nuclear reactor vessel. It glows with heat and radiation.
  components:
  - type: Sprite
    sprite: _FarHorizons/Structures/Power/Generation/FissionGenerator/nuclear_reactor.rsi
    layers:
    - state: reactorbroken
  - type: Rotatable
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-2.5,-2.5,2.5,2"
        density: 190
        mask:
        - MachineMask
        layer:
        - MachineLayer
        - HighImpassable
  - type: RadiationSource
    intensity: 7
  - type: InteractionOutline
  - type: PointLight
    energy: 0.1
    falloff: 2
    radius: 3.5
    color: "#FFAAAAFF"

- type: entity
  id: NuclearReactorSmallMelted
  parent: NuclearReactorMelted
  suffix: "Melted"
  name: Small Nuclear Reactor
  description: A broken nuclear reactor vessel. It glows with heat and radiation.
  components:
  - type: Sprite
    sprite: _FarHorizons/Structures/Power/Generation/FissionGenerator/small_nuclear_reactor.rsi
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-1.5,-1.5,1.5,1.5"
        density: 190
        mask:
        - MachineMask
        layer:
        - MachineLayer
        - HighImpassable
  - type: RadiationSource
    intensity: 5
  - type: PointLight
    radius: 2.5

- type: entity
  id: NuclearReactorMeltedSalvage
  parent: NuclearReactorMelted
  suffix: "Salvage, Melted"
  description: A nuclear reactor vessel, long since melted down. It still glows with residual heat and radiation.
  components:
  - type: RadiationSource
    intensity: 3.5
  - type: PointLight
    energy: 0.025

- type: entity
  id: NuclearReactorSmallMeltedSalvage
  parent: NuclearReactorSmallMelted
  suffix: "Salvage, Melted"
  description: A nuclear reactor vessel, long since melted down. It still glows with residual heat and radiation.
  components:
  - type: RadiationSource
    intensity: 2.5
  - type: PointLight
    energy: 0.025
#endregion

#region Support Entities
# Nuclear debris resultant from a meltdown
- type: entity
  id: NuclearDebrisChunk
  parent: BaseItem
  name: Nuclear Debris
  description: You do not see the graphite on the floor. You're in shock. Report to medical.
  categories: [ HideSpawnMenu ]
  components:
  - type: Sprite
    sprite: _FarHorizons/Objects/Power/FissionGenerator/nuclear_debris.rsi
    layers:
      - state: graphite_damaged_0
        map: [ "base" ]
  - type: Item
    size: Huge
  - type: RandomSprite
    available:
    - base:
        graphite_damaged_0: ""
        graphite_damaged_0_mirrored: ""
        graphite_damaged_1: ""
        graphite_damaged_1_mirrored: ""
        graphite_damaged_2: ""
        graphite_damaged_2_mirrored: ""
        graphite_damaged_3: ""
        graphite_damaged_3_mirrored: ""
        graphite_damaged_4: ""
        graphite_damaged_4_mirrored: ""
  - type: RadiationSource
    intensity: 1.6

# Arrows to indicate flow
- type: entity
  id: ReactorFlowArrow
  categories: [ HideSpawnMenu ]
  components:
    - type: Sprite
      sprite: Markers/teg_arrow.rsi
      color: "#FFFFFFBB"
      layers:
        - state: arrow
          rotation: 90
          offset: 3, 1
        - state: arrow
          rotation: 90
          offset: -3, -1
    - type: TimedDespawn
      lifetime: 2
    - type: Tag
      tags:
        - HideContextMenu

- type: entity
  id: ReactorSmallFlowArrow
  parent: ReactorFlowArrow
  categories: [ HideSpawnMenu ]
  components:
    - type: Sprite
      layers:
        - state: arrow
          rotation: 0
          offset: -1, 2
        - state: arrow
          rotation: 180
          offset: 1, 2

# Pipes the reactor uses to connect to the pipe network
- type: entity
  id: ReactorGasPipe
  categories: [ HideSpawnMenu ]
  components:
  - type: Transform
    anchored: true
  - type: Anchorable
  - type: NodeContainer
    nodes:
      pipe:
        !type:PipeNode
        nodeGroupID: Pipe
        pipeDirection: South
        volume: 1000
        pipeLayer: 0
      pipe1:
        !type:PipeNode
        nodeGroupID: Pipe
        pipeDirection: South
        volume: 1000
        pipeLayer: 1
      pipe2:
        !type:PipeNode
        nodeGroupID: Pipe
        pipeDirection: South
        volume: 1000
        pipeLayer: 2
      # Starlight Start: 5 Pipe layers
      pipe3:
        !type:PipeNode
        nodeGroupID: Pipe
        pipeDirection: South
        volume: 1000
        pipeLayer: 3
      pipe4:
        !type:PipeNode
        nodeGroupID: Pipe
        pipeDirection: South
        volume: 1000
        pipeLayer: 4
      # Starlight End
  - type: GasPipeManifold
    inlets:
    - pipe1
    - pipe2
    # Starlight Start: 5 Pipe layers
    - pipe3
    - pipe4
    # Starlight End
    outlets:
    - pipe
  - type: PipeRestrictOverlap
  - type: Tag
    tags:
      - HideContextMenu

- type: entity
  id: ReactorAlarmEntity
  categories: [ HideSpawnMenu ]
  components:
  - type: AmbientSound
    volume: -3
    range: 15
    enabled: false
    sound:
      path: /Audio/_FarHorizons/Machines/reactor_alarm_1.ogg
#endregion
