class_name DeployedUnit extends Node2D enum UnitState { ALIVE, DEAD } @export var unit: Unit var current_stats: DeployedUnitStats var tactics: Array[CombatTactic] = [] var state: UnitState = UnitState.ALIVE signal unit_selected_changed(deployed: DeployedUnit, selected: bool) signal unit_allegiance_changed(deployed: DeployedUnit, allegiance: UnitAllegiance) signal unit_died(deployed: DeployedUnit) func _ready() -> void: current_stats = DeployedUnitStats.from_unit_stats(unit.stats) tactics = unit.tactics.duplicate() _append_builtin_tactics() unit_allegiance_changed.emit(self, unit.allegiance) func _append_builtin_tactics() -> void: var attack := AttackCombatTactic.new() attack.tactic_name = "Attack" attack.tactic_range = UnitMatchingCombatTacticRange.new() tactics.append(attack) var defend := DefendCombatTactic.new() defend.tactic_name = "Defend" defend.tactic_range = AnyCombatTacticRange.new() tactics.append(defend) func set_selected(selected: bool) -> void: unit_selected_changed.emit(self, selected) func is_alive() -> bool: return state == UnitState.ALIVE func take_damage(amount: int) -> void: if state != UnitState.ALIVE: return current_stats.current_hp -= amount if current_stats.current_hp <= 0: current_stats.current_hp = 0 _die() func _die() -> void: state = UnitState.DEAD unit_died.emit(self) queue_free()