# SPDX-FileCopyrightText: 2023 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
# SPDX-FileCopyrightText: 2025 Aviu00 <93730715+Aviu00@users.noreply.github.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Specific Root compound tasks being used for NPCs.

# Tries to shoot a target in LOS in range.
- type: htnCompound
  id: TurretCompound
  branches:
    - tasks:
        - !type:HTNPrimitiveTask
          operator: !type:UtilityOperator
            proto: NearbyGunTargets

        - !type:HTNPrimitiveTask
          preconditions:
            - !type:KeyExistsPrecondition
              key: Target
            - !type:TargetInRangePrecondition
              targetKey: Target
              # TODO: Non-scuffed
              rangeKey: RangedRange
            - !type:TargetInLOSPrecondition
              targetKey: Target
              rangeKey: RangedRange
          operator: !type:GunOperator
            targetKey: Target
            requireLOS: true
          services:
            - !type:UtilityService
              id: RangedService
              proto: NearbyGunTargets
              key: Target

    - tasks:
        - !type:HTNCompoundTask
          task: IdleSpinCompound
          
- type: htnCompound
  id: EnergyTurretCompound
  branches:
    - tasks:
        - !type:HTNPrimitiveTask
          operator: !type:UtilityOperator
            proto: NearbyGunTargets
        
        - !type:HTNPrimitiveTask
          preconditions:
            - !type:KeyExistsPrecondition
              key: Target
            - !type:TargetInRangePrecondition
              targetKey: Target
              # TODO: Non-scuffed
              rangeKey: RangedRange
            - !type:TargetInLOSPrecondition
              targetKey: Target
              rangeKey: RangedRange
              opaqueKey: true
          operator: !type:GunOperator
            targetKey: Target
            opaqueKey: true
          services:
            - !type:UtilityService
              id: RangedService
              proto: NearbyGunTargets
              key: Target

    - tasks:
        - !type:HTNCompoundTask
          task: IdleSpinCompound

- type: htnCompound
  id: SimpleRangedHostileCompound
  branches:
    - tasks:
        - !type:HTNCompoundTask
          task: InnateRangedCombatCompound
    - tasks:
        - !type:HTNCompoundTask
          task: MeleeCombatCompound
    - tasks:
        - !type:HTNCompoundTask
          task: IdleCompound

- type: htnCompound
  id: SimpleHumanoidHostileCompound
  branches:
    - tasks:
        - !type:HTNCompoundTask
          task: RangedCombatCompound
    - tasks:
        - !type:HTNCompoundTask
          task: MeleeCombatCompound
    - tasks:
        - !type:HTNCompoundTask
          task: IdleCompound