1
0
Fork 0
spacetac/tac/units/fighter.gd
2022-10-19 23:23:47 +02:00

38 lines
868 B
GDScript

extends Unit
func _compose():
$chief.visible = is_chief
super._compose()
func tick():
chief_maintenance()
# go to nearest enemy
var enemy: Unit = null
var closest := INF
for unit in get_tree().get_nodes_in_group("unit"):
if unit is Unit and unit.player != player:
var distance := global_position.distance_to(unit.global_position)
if distance < closest:
closest = distance
enemy = unit
if enemy:
move_to(enemy.global_position + Vector2.from_angle(randf_range(0.0, PI * 2.0)) * randf_range(100.0, 300.0))
$turret.set_target(enemy)
func chief_maintenance():
if is_chief:
# already chief
return
var chief = get_chief()
if chief == null:
# find a chief
var chiefs = list_chiefs()
# TODO sort by distance, experience and subordinate count
if chiefs.size() > 0:
chief = chiefs[0]
else:
promote_chief()
_compose()