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

55 lines
1.4 KiB
GDScript3
Raw Normal View History

2022-10-06 22:34:33 +00:00
extends Unit
2022-10-26 18:29:17 +00:00
var current_command := WeakRef.new()
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-26 18:29:17 +00:00
if is_chief:
var command := current_command.get_ref() as Command
if command and command.global_position.distance_to(global_position) > 100.0:
# go near current command
move_to(Tools.jitter(command.global_position, 50.0, 100.0))
return
else:
var chief = get_chief()
if chief and chief.global_position.distance_to(global_position) > 100.0:
# go near chief
move_to(Tools.jitter(chief.global_position, 50.0, 100.0))
return
var enemy := Tools.get_nearest(self, get_tree().get_nodes_in_group("unit"),
func filter(unit): return unit is Unit and unit.player != player)
2022-10-06 22:34:33 +00:00
if enemy:
2022-10-26 18:29:17 +00:00
# go near current target enemy
move_to(Tools.jitter(enemy.global_position, 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:
2022-10-26 18:29:17 +00:00
set_chief(chiefs[0])
2022-10-19 21:23:47 +00:00
else:
promote_chief()
_compose()
2022-10-26 18:29:17 +00:00
func _on_commands_changed(commands):
if is_chief:
var defend := Tools.get_nearest(self, commands,
func filter(command): return command.player == player and command.code == "defend")
if defend:
current_command = weakref(defend)