# SPDX-FileCopyrightText: 2022 Alex Evgrashin <aevgrashin@yandex.ru>
# SPDX-FileCopyrightText: 2022 Errant <35878406+dmnct@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Paul Ritter <ritter.paul1@googlemail.com>
# SPDX-FileCopyrightText: 2022 Peptide90 <78795277+Peptide90@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 Profane McBane <profanedbane+github@gmail.com>
# SPDX-FileCopyrightText: 2022 Visne <39844191+Visne@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 keronshb <54602815+keronshb@users.noreply.github.com>
# SPDX-FileCopyrightText: 2022 metalgearsloth <comedian_vs_clown@hotmail.com>
# SPDX-FileCopyrightText: 2022 stopka-html <85645977+stopka-html@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Cody ~ Aexxie <125095677+Aexxie@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Nairod <110078045+Nairodian@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
# SPDX-FileCopyrightText: 2023 TemporalOroboros <TemporalOroboros@gmail.com>
# SPDX-FileCopyrightText: 2023 Tom Leys <tom@crump-leys.com>
# SPDX-FileCopyrightText: 2023 chromiumboy <50505512+chromiumboy@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 lzk <124214523+lzk228@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
# SPDX-FileCopyrightText: 2023 qwerltaz <69696513+qwerltaz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Ben Velie <veliebm@gmail.com>
# SPDX-FileCopyrightText: 2024 Ilya246 <57039557+Ilya246@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 Kara <lunarautomaton6@gmail.com>
# SPDX-FileCopyrightText: 2024 Plykiya <58439124+Plykiya@users.noreply.github.com>
# SPDX-FileCopyrightText: 2024 plykiya <plykiya@protonmail.com>
# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Base Generator

- type: entity
  abstract: true
  id: BaseGenerator
  description: A high efficiency thermoelectric generator.
  name: generator
  placement:
    mode: SnapgridCenter
  components:
  - type: AmbientSound
    range: 5
    sound:
      path: /Audio/Ambience/Objects/engine_hum.ogg
  - type: Clickable
  - type: InteractionOutline
  - type: Physics
    bodyType: Static
  - type: Fixtures
    fixtures:
      fix1:
        shape:
          !type:PhysShapeAabb
          bounds: "-0.4,-0.5,0.4,0.3"
        density: 190
        mask:
        - MachineMask
        layer:
        - MachineLayer
  - type: Transform
    anchored: true
    noRot: true
  - type: Sprite
    sprite: Structures/Power/power.rsi
    state: generator
    snapCardinals: true
  - type: NodeContainer
    examinable: true
    nodes:
      output:
        !type:CableDeviceNode
        nodeGroupID: HVPower
  - type: PowerMonitoringDevice
    group: Generator
    loadNode: output
    sprite: Structures/Power/power.rsi
    state: generator
  - type: PowerSupplier
    supplyRate: 3000
    supplyRampRate: 500
    supplyRampTolerance: 500
  - type: Anchorable
  - type: Pullable
  - type: Damageable
    damageContainer: StructuralInorganic
    damageModifierSet: Metallic
  - type: PacifismDangerousAttack
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 200
      behaviors:
        - !type:DoActsBehavior
          acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 100
      behaviors:
      - !type:DoActsBehavior
        acts: ["Destruction"]
      - !type:PlaySoundBehavior
        sound:
          collection: MetalBreak
      - !type:ExplodeBehavior
  - type: Explosive
    explosionType: Default
    # Same as AME, but numbers still picked from a hat.
    maxIntensity: 100
    intensitySlope: 2
    totalIntensity: 200
  - type: StaticPrice
    price: 500
  - type: Electrified
    onHandInteract: false
    onInteractUsing: false
    onBump: false
    requirePower: true
    highVoltageNode: output
  - type: GuideHelp
    guides:
    - ShuttleCraft

# Base Wallmount Generator

- type: entity
  abstract: true
  id: BaseGeneratorWallmount
  parent: BaseGenerator
  name: wallmount generator
  description: A high efficiency thermoelectric generator stuffed in a wall cabinet.
  placement:
    mode: SnapgridCenter
  components:
  - type: AmbientOnPowered
  - type: AmbientSound
    volume: -15
    range: 2
    sound:
      path: /Audio/Ambience/Objects/hdd_buzz.ogg
  - type: PointLight
    radius: 1.5
    energy: 1.6
    color: "#3db83b"
    castShadows: false
    netsync: false
  - type: Fixtures
  - type: Transform
    anchored: true
  - type: Physics
    bodyType: Static
    canCollide: false
  - type: Sprite
    drawdepth: WallMountedItems
    sprite: Structures/Power/Generation/wallmount_generator.rsi
    layers:
    - state: panel
    - state: on
      shader: unshaded
  - type: NodeContainer
    examinable: true
    nodes:
      output:
        !type:CableDeviceNode
        nodeGroupID: HVPower
  - type: PowerMonitoringDevice
    group: Generator
    loadNode: output
    sprite: Structures/Power/Generation/wallmount_generator.rsi
    state: static
  - type: PowerSupplier
    supplyRate: 3000
    supplyRampRate: 500
    supplyRampTolerance: 500
  - type: WallMount
  - type: GuideHelp
    guides:
    - ShuttleCraft

# Construction Frames

- type: entity
  categories: [ HideSpawnMenu ]
  id: BaseGeneratorWallmountFrame
  name: wallmount generator frame
  description: A construction frame for a wallmount generator.
  placement:
    mode: SnapgridCenter
  components:
  - type: Clickable
  - type: InteractionOutline
  - type: Physics
    canCollide: false
  - type: Fixtures
  - type: Transform
    anchored: true
  - type: Sprite
    drawdepth: WallMountedItems
    sprite: Structures/Power/Generation/wallmount_generator.rsi
    layers:
    - state: panel
  - type: Construction
    graph: WallmountGenerator
    node: frame
  - type: WallMount

# Generators in use

- type: entity
  parent: BaseGenerator
  id: GeneratorBasic
  suffix: Basic, 3kW
  components:
  - type: PowerSupplier
    supplyRate: 3000

- type: entity
  parent: BaseGenerator
  id: GeneratorBasic15kW
  suffix: Basic, 15kW
  components:
    - type: PowerSupplier
      supplyRate: 15000

- type: entity
  parent: BaseGeneratorWallmount
  id: GeneratorWallmountBasic
  suffix: Basic, 3kW
  components:
  - type: PowerSupplier
    supplyRate: 3000
  - type: Construction
    graph: WallmountGenerator
    node: generator
  - type: StaticPrice
    price: 14
  - type: ContainerFill
    containers:
      board: [ WallmountGeneratorElectronics ]
  - type: ContainerContainer
    containers:
      board: !type:Container

- type: entity
  parent: BaseGeneratorWallmount
  id: GeneratorWallmountAPU
  name: shuttle APU
  description: An auxiliary power unit for a shuttle - 6kW.
  suffix: APU, 6kW
  components:
  - type: PowerSupplier
    supplyRate: 6000
  - type: Construction
    graph: WallmountGenerator
    node: APU
  - type: StaticPrice
    price: 38
  - type: ContainerFill
    containers:
      board: [ WallmountGeneratorAPUElectronics ]
  - type: ContainerContainer
    containers:
      board: !type:Container
  - type: GuideHelp
    guides:
    - ShuttleCraft

# RTG - no fuel requirement

- type: entity
  parent: BaseGenerator
  id: GeneratorRTG
  name: RTG
  description: A Radioisotope Thermoelectric Generator for long term power.
  suffix: 10kW
  components:
  - type: PowerSupplier
    supplyRate: 10000 # supposed to be low power at no fuel cost to power derelicts
  - type: Sprite
    sprite: Structures/Power/Generation/rtg.rsi
    state: rtg
  - type: PowerMonitoringDevice
    sprite: Structures/Power/Generation/rtg.rsi
    state: rtg
  - type: AmbientSound
    range: 5
    sound:
      path: /Audio/Ambience/Objects/buzzing.ogg
  - type: GuideHelp
    guides:
    - RTG
    - Power
  - type: Destructible
    thresholds:
      - trigger:
          !type:DamageTrigger
          damage: 600
        behaviors:
          - !type:DoActsBehavior
            acts: [ "Destruction" ]
      - trigger:
          !type:DamageTrigger
          damage: 300
        behaviors:
          - !type:PlaySoundBehavior
            sound:
              collection: MetalBreak
          - !type:SpawnEntitiesBehavior
            spawn:
              GeneratorRTGDamaged:
                min: 1
                max: 1
          - !type:DoActsBehavior
            acts: [ "Destruction" ]

# TODO: need radioactive fallout when destroyed

- type: entity
  parent: GeneratorRTG
  id: GeneratorRTGDamaged
  name: damaged RTG
  description: A Radioisotope Thermoelectric Generator for long term power. This one has damaged shielding.
  suffix: 10kW
  components:
  - type: PowerSupplier
    supplyRate: 10000
  - type: Sprite
    sprite: Structures/Power/Generation/rtg.rsi
    layers:
      - state: rtg_damaged
      - state: rtg_glow
  - type: PowerMonitoringDevice
    sprite: Structures/Power/Generation/rtg.rsi
    state: rtg_damaged
  - type: RadiationSource # ideally only when opened.
    intensity: 2
  - type: Destructible
    thresholds:
    - trigger:
        !type:DamageTrigger
        damage: 100
      behaviors:
        - !type:DoActsBehavior
          acts: [ "Destruction" ]
    - trigger:
        !type:DamageTrigger
        damage: 50
      behaviors:
      - !type:PlaySoundBehavior
        sound:
          collection: MetalBreak
      - !type:SpawnEntitiesBehavior
        spawn:
          SheetSteel1:
            min: 1
            max: 5
          SheetUranium1:
            min: 1
            max: 5
      - !type:DoActsBehavior
        acts: [ "Destruction" ]