spaceship/core/CombatTarget.gd
2026-09-03 00:12:08 +02:00

26 lines
925 B
GDScript

class_name CombatTarget
extends RefCounted
# One opt-in contract for anything a player weapon may deliberately attack.
# Aim assist, autonomous garrisons and projectile impacts all consume the same
# group, so a new target composition does not need a concrete-type branch in
# each combat system.
const GROUP: StringName = &"player_weapon_targets"
const PRIORITY_META: StringName = &"player_weapon_target_priority"
# A garrison protects its post before mining nearby debris. Distances still
# decide between targets at the same priority.
const RESOURCE_PRIORITY: int = 0
const DANGER_PRIORITY: int = 100
static func register(node: Node, priority: int = RESOURCE_PRIORITY) -> void:
if node == null:
return
node.add_to_group(GROUP)
node.set_meta(PRIORITY_META, priority)
static func priority(node: Node) -> int:
return int(node.get_meta(PRIORITY_META, RESOURCE_PRIORITY)) if node != null \
else RESOURCE_PRIORITY