#
# You can use this Desmos sheet to calculate fuel burn rate values:
# https://www.desmos.com/calculator/qcektq5dqs
#

- type: entity
  abstract: true
  id: PortableGeneratorBase
  parent: [ BaseMachine, SmallConstructibleMachine, StructureWheeled]
  components:
    # Basic properties
    - type: Transform
      anchored: False
    - type: Physics
      bodyType: Dynamic
    - type: StaticPrice
      price: 500
    - type: AmbientSound
      range: 5
      volume: -5
      sound:
        path: /Audio/Ambience/Objects/engine_hum.ogg
      enabled: false
    - type: Fixtures
      fixtures:
        fix1:
          shape:
            !type:PhysShapeAabb
            bounds: "-0.40,-0.40,0.40,0.40"
          # Despite the heavy weight, it has wheels, so it's still fairly portable.
          density: 155
          mask:
            - MachineMask
          layer:
            - MachineLayer

    # Visuals
    - type: Appearance
    - type: Sprite
      sprite: Structures/Power/Generation/portable_generator.rsi
      noRot: true

    # Construction, interaction
    - type: WiresPanel
    - type: UserInterface
      interfaces:
        enum.GeneratorComponentUiKey.Key:
          type: PortableGeneratorBoundUserInterface
    - type: ActivatableUI
      key: enum.GeneratorComponentUiKey.Key
    - type: Electrified
      onHandInteract: false
      onInteractUsing: false
      onBump: false
      requirePower: true
      highVoltageNode: output

    - type: Destructible
      thresholds:
        - trigger:
            !type:DamageTrigger
            damage: 200
          behaviors:
            - !type:DoActsBehavior
              acts: [ "Destruction" ]
        - trigger:
            !type:DamageTrigger
            damage: 100
          behaviors:
            - !type:PlaySoundBehavior
              sound:
                collection: MetalBreak
            - !type:ChangeConstructionNodeBehavior
              node: machineFrame
            - !type:DoActsBehavior
              acts: ["Destruction"]
    - type: GuideHelp
      guides:
      - PortableGenerator
      - Power

    # Core functionality
    - type: PortableGenerator
      startSoundEmpty: { collection: GeneratorTugEmpty }
      startSound: { collection: GeneratorTug }
    - type: FuelGenerator
    - type: PowerSupplier
      supplyRate: 3000
      supplyRampRate: 500
      supplyRampTolerance: 500
      enabled: false
    - type: DeviceLinkSink
      ports:
      - On
      - Off
      - Toggle
    - type: GeneratorSignalControl
    - type: DeviceNetwork
      deviceNetId: Wireless
      receiveFrequencyId: BasicDevice
    - type: WirelessNetworkConnection
      range: 200

- type: entity
  abstract: true
  parent: PortableGeneratorBase
  id: PortableGeneratorSwitchableBase
  components:
  - type: PowerSwitchable
    examineText: power-switchable-generator-examine
    switchText: power-switchable-generator-switched
    cables:
    - voltage: HV
      node: output_hv
    - voltage: MV
      node: output_mv
  - type: UseDelay
    delay: 1
  - type: NodeContainer
    examinable: true
    nodes:
      output_hv:
        !type:CableDeviceNode
        nodeGroupID: HVPower
      output_mv:
        !type:CableDeviceNode
        nodeGroupID: MVPower
        enabled: false

- type: entity
  name: P.A.C.M.A.N. portable generator # Frontier: no -type
  description: |-
    A flexible backup generator for powering a variety of equipment.
    Runs off solid plasma sheets and is rated for up to 25 kW.
  parent: PortableGeneratorSwitchableBase
  id: PortableGeneratorPacman
  suffix: Plasma, 15 kW
  components:
    - type: Sprite
      layers:
        - state: portgen0
          map: [ "enum.GeneratorVisualLayers.Body" ]
        - state: portgen_on_unlit
          map: [ "enum.GeneratorVisualLayers.Unlit" ]
          shader: unshaded
          visible: false
    - type: GenericVisualizer
      visuals:
        enum.GeneratorVisuals.Running:
          enum.GeneratorVisualLayers.Body:
            True: { state: portgen0on }
            False: { state: portgen0 }
          enum.GeneratorVisualLayers.Unlit:
            True: { visible: true }
            False: { visible: false }

    - type: Machine
      board: PortableGeneratorPacmanMachineCircuitboard
    - type: FuelGenerator
      minTargetPower: 1000
      maxTargetPower: 25000
      targetPower: 15000
      optimalPower: 15000
      # 45 minutes at max output
      optimalBurnRate: 0.011111
      # a decent curve
      fuelEfficiencyConstant: 0.95
    - type: SolidFuelGeneratorAdapter
      fuelMaterial: FuelGradePlasma # Frontier: Plasma<FuelGradePlasma
      multiplier: 0.01
    - type: MaterialStorage
      storageLimit: 3000
      materialWhiteList: [Plasma, FuelGradePlasma, RawPlasma, Skrungle] # Frontier: add FuelGradePlasma, RawPlasma, Scrungle
    - type: PortableGenerator
      startChance: 0.8
    - type: UpgradePowerSupplier
      powerSupplyMultiplier: 1.25
      scaling: Exponential
    - type: GeneratorExhaustGas
      gasType: CarbonDioxide
      # 0.5 moles of gas for every sheet of plasma.
      moleRatio: 0.5
    - type: PowerMonitoringDevice
      group: Generator
      loadNodes:
        - output_hv
        - output_mv
      sprite: Structures/Power/Generation/portable_generator.rsi
      state: portgen0
    - type: PowerSupplier
      supplyRampRate: 5000
      supplyRampTolerance: 1500
    # Frontier: magnet pickup, fuel adapter
    - type: MaterialStorageMagnetPickup
      range: 0.30
    - type: FuelGradeAdapter
      conversions:
      - input: Plasma
        output: FuelGradePlasma
        rate: 1
      - input: RawPlasma
        output: FuelGradePlasma
        rate: 0.5
      - input: Skrungle
        output: FuelGradePlasma
        rate: 1
    # End Frontier: magnet pickup, fuel adapter

- type: entity
  name: S.U.P.E.R.P.A.C.M.A.N. portable generator # Frontier: no -type
  description: |-
    An advanced generator for powering departments.
    Runs off uranium sheets and is rated for up to 50 kW.
  parent: PortableGeneratorSwitchableBase
  id: PortableGeneratorSuperPacman
  suffix: Uranium, 30 kW
  components:
    - type: Sprite
      layers:
        - state: portgen1
          map: [ "enum.GeneratorVisualLayers.Body" ]
        - state: portgen_on_unlit
          map: [ "enum.GeneratorVisualLayers.Unlit" ]
          shader: unshaded
          visible: false
    - type: GenericVisualizer
      visuals:
        enum.GeneratorVisuals.Running:
          enum.GeneratorVisualLayers.Body:
            True: { state: portgen1on }
            False: { state: portgen1 }
          enum.GeneratorVisualLayers.Unlit:
            True: { visible: true }
            False: { visible: false }

    - type: Machine
      board: PortableGeneratorSuperPacmanMachineCircuitboard
    - type: FuelGenerator
      minTargetPower: 5000
      maxTargetPower: 50000
      targetPower: 30000
      optimalPower: 30000
      # 45 minutes at full power
      optimalBurnRate: 0.0111111
      # still decent power curve
      fuelEfficiencyConstant: 0.75
    - type: SolidFuelGeneratorAdapter
      fuelMaterial: FuelGradeUranium # Frontier: Uranium<FuelGradeUranium
      multiplier: 0.01
    - type: MaterialStorage
      storageLimit: 3000
      materialWhiteList: [Uranium, FuelGradeUranium, RawUranium, Skrungle] # Frontier: add FuelGradeUranium, RawUranium, Skrungle
    - type: PortableGenerator
    - type: UpgradePowerSupplier
      powerSupplyMultiplier: 1.25
      scaling: Exponential
    - type: PowerMonitoringDevice
      group: Generator
      loadNodes:
        - output_hv
        - output_mv
      sprite: Structures/Power/Generation/portable_generator.rsi
      state: portgen1
    - type: PowerSupplier
      supplyRampRate: 7500
      supplyRampTolerance: 2500
    # Frontier: magnet pickup, fuel adapter
    - type: MaterialStorageMagnetPickup
      range: 0.30
    - type: FuelGradeAdapter
      conversions:
      - input: Uranium
        output: FuelGradeUranium
        rate: 1
      - input: RawUranium
        output: FuelGradeUranium
        rate: 0.5
      - input: Skrungle
        output: FuelGradeUranium
        rate: 0.5
    # End Frontier: magnet pickup, fuel adapter

- type: entity
  name: J.R.P.A.C.M.A.N. portable generator # Frontier: no -type
  description: |-
    A small generator capable of powering individual rooms, in case of emergencies.
    Runs off welding fuel and is rated for up to 15 kW.
    Rated ages 3 and up.
  parent: PortableGeneratorBase
  id: PortableGeneratorJrPacman
  suffix: Welding Fuel, 5 kW
  components:
    - type: AmbientSound
      range: 4
      volume: -8

    - type: Fixtures
      fixtures:
        fix1:
          shape:
            !type:PhysShapeAabb
            bounds: "-0.30,-0.30,0.30,0.30"
          density: 80
          mask:
            - MachineMask
          layer:
            - MachineLayer

    - type: Sprite
      layers:
        - state: portgen3
          map: [ "enum.GeneratorVisualLayers.Body" ]
        - state: portgen3on_unlit
          map: [ "enum.GeneratorVisualLayers.Unlit" ]
          shader: unshaded
          visible: false
    - type: GenericVisualizer
      visuals:
        enum.GeneratorVisuals.Running:
          enum.GeneratorVisualLayers.Body:
            True: { state: portgen3on }
            False: { state: portgen3 }
          enum.GeneratorVisualLayers.Unlit:
            True: { visible: true }
            False: { visible: false }

    - type: Machine
      board: PortableGeneratorJrPacmanMachineCircuitboard
    - type: FuelGenerator
      targetPower: 6000 # Frontier - 2000<6000
      minTargetPower: 1000
      optimalPower: 6000 # Frontier - 2000<6000
      maxTargetPower: 15000
      # 30~ minutes at full tank.
      optimalBurnRate: 0.11111111
      # Shallow curve
      fuelEfficiencyConstant: 0.5
    - type: ChemicalFuelGeneratorAdapter
      solution: tank
      reagents:
        WeldingFuel: 1
    - type: SolutionContainerManager
      solutions:
        tank:
          maxVol: 200 # Frontier - 50<200
    - type: RefillableSolution
      solution: tank
    - type: PortableGenerator
      # Unreliable bugger
      startChance: 0.4
    - type: NodeContainer
      examinable: true
      nodes:
        output:
          !type:CableDeviceNode
          nodeGroupID: Apc
    - type: PowerMonitoringDevice
      group: Generator
      loadNode: output
      sprite: Structures/Power/Generation/portable_generator.rsi
      state: portgen3
    - type: PowerSupplier
      # No ramping needed on this bugger.
      voltage: Apc
      supplyRampTolerance: 2000
    - type: GeneratorExhaustGas
      gasType: CarbonDioxide
      # Full tank is 25 moles of gas
      moleRatio: 0.5
    - type: Explosive
      explosionType: Default
      tileBreakScale: 0
    - type: Destructible
      thresholds:
        - trigger:
            !type:DamageTrigger
            damage: 200
          behaviors:
            - !type:DoActsBehavior
              acts: [ "Destruction" ]
        - trigger:
            !type:DamageTrigger
            damage: 100
          behaviors:
            - !type:SpillBehavior
              solution: tank
            - !type:PlaySoundBehavior
              sound:
                collection: MetalBreak
            - !type:ChangeConstructionNodeBehavior
              node: machineFrame
            - !type:DoActsBehavior
              acts: ["Destruction"]
        - trigger:
            !type:DamageTypeTrigger
            damageType: Piercing
            damage: 75
          behaviors:
            - !type:SolutionExplosionBehavior
              solution: tank
    - type: BindToStation # Frontier
      enabled: false # Frontier - should be draggable between stations
