Skip to content

Commit

Permalink
Make selected workers building ordered structure, closes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Jul 4, 2023
1 parent 2abb5ba commit bd2ec90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions source/match/players/human/UnitActionsController.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Node

const Structure = preload("res://source/match/units/Structure.gd")


class Actions:
const Moving = preload("res://source/match/units/actions/Moving.gd")
Expand All @@ -15,6 +17,7 @@ class Actions:
func _ready():
MatchSignals.terrain_targeted.connect(_on_terrain_targeted)
MatchSignals.unit_targeted.connect(_on_unit_targeted)
MatchSignals.unit_spawned.connect(_on_unit_spawned)


func _try_navigating_selected_units_towards_position(target_point):
Expand Down Expand Up @@ -56,6 +59,20 @@ func _try_setting_rally_points(target_point: Vector3):
rally_point.global_position = target_point


func _try_ordering_selected_workers_to_construct_structure(potential_structure):
if not potential_structure is Structure or potential_structure.is_constructed():
return
var structure = potential_structure
var selected_constructors = get_tree().get_nodes_in_group("selected_units").filter(
func(unit): return (
unit.is_in_group("controlled_units")
and Actions.Constructing.is_applicable(unit, structure)
)
)
for unit in selected_constructors:
unit.action = Actions.Constructing.new(structure)


func _navigate_selected_units_towards_unit(target_unit):
var units_navigated = 0
for unit in get_tree().get_nodes_in_group("selected_units"):
Expand Down Expand Up @@ -95,3 +112,7 @@ func _on_unit_targeted(unit):
var targetability = unit.find_child("Targetability")
if targetability != null:
targetability.animate()


func _on_unit_spawned(unit):
_try_ordering_selected_workers_to_construct_structure(unit)
7 changes: 6 additions & 1 deletion source/match/units/actions/Constructing.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ var _sub_action = null


static func is_applicable(source_unit, target_unit):
return source_unit is Worker and target_unit is Structure and not target_unit.is_constructed()
return (
source_unit is Worker
and target_unit is Structure
and not target_unit.is_constructed()
and source_unit.player == target_unit.player
)


func _init(target_unit):
Expand Down

0 comments on commit bd2ec90

Please sign in to comment.