1
0
Fork 0
spacetac/tac/units/fighter.gd

38 lines
868 B
GDScript3
Raw Normal View History

2022-10-06 22:34:33 +00:00
extends Unit
2022-10-19 21:23:47 +00:00
func _compose():
$chief.visible = is_chief
super._compose()
2022-10-10 03:01:02 +00:00
func tick():
2022-10-19 21:23:47 +00:00
chief_maintenance()
2022-10-06 22:34:33 +00:00
# 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:
2022-10-10 03:01:02 +00:00
move_to(enemy.global_position + Vector2.from_angle(randf_range(0.0, PI * 2.0)) * randf_range(100.0, 300.0))
2022-10-06 22:34:33 +00:00
$turret.set_target(enemy)
2022-10-19 21:23:47 +00:00
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()