Skip to content

Commit

Permalink
Add rally flag, closes lampe-games#52
Browse files Browse the repository at this point in the history
From now each unit factory shall have a RallyPoint node.
if its position is (0,0,0) the rally has no effect, otherwise the units will be sended to its position
  • Loading branch information
Bazsi1224 authored and Scony committed Jun 28, 2023
1 parent 593f08e commit 04bda65
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
13 changes: 13 additions & 0 deletions source/match/players/human/UnitActionsController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Actions:
)
const AutoAttacking = preload("res://source/match/units/actions/AutoAttacking.gd")
const Constructing = preload("res://source/match/units/actions/Constructing.gd")
const Rallying = preload("res://source/match/units/actions/Rallying.gd")


func _ready():
Expand Down Expand Up @@ -44,6 +45,17 @@ func _navigate_selected_units_towards_position(target_point):
unit.action = Actions.Moving.new(new_target)


func _set_rally_point(target_point: Vector3):
var structures = get_tree().get_nodes_in_group("selected_units").filter(
func(unit): return (
unit.is_in_group("controlled_units") and Actions.Rallying.is_applicable(unit)
)
)

for structure in structures:
Actions.Rallying._set_rally_point(structure, target_point)


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 @@ -75,6 +87,7 @@ func _navigate_selected_units_towards_unit(target_unit):

func _on_terrain_targeted(position):
_navigate_selected_units_towards_position(position)
_set_rally_point(position)


func _on_unit_targeted(unit):
Expand Down
5 changes: 4 additions & 1 deletion source/match/units/AircraftFactory.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=9 format=3 uid="uid://cxilu6668nda6"]
[gd_scene load_steps=10 format=3 uid="uid://cxilu6668nda6"]

[ext_resource type="Script" path="res://source/match/units/AircraftFactory.gd" id="1_n6n1v"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_r5i7t"]
[ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="2_56ml3"]
[ext_resource type="PackedScene" uid="uid://bklfapayb1ryk" path="res://source/match/units/structure-geometries/AircraftFactory.tscn" id="2_mlisu"]
[ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_j1buj"]
[ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_igtfr"]
[ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_opfgx"]
[ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="9_qqlap"]

[sub_resource type="CylinderShape3D" id="CylinderShape3D_uvm5u"]
Expand Down Expand Up @@ -44,4 +45,6 @@ size = Vector2(250, 10)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
radius = 1.5

[node name="RallyPoint" parent="." instance=ExtResource("8_opfgx")]

[editable path="Geometry"]
5 changes: 4 additions & 1 deletion source/match/units/CommandCenter.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=9 format=3 uid="uid://ct0ejt0trkhrf"]
[gd_scene load_steps=10 format=3 uid="uid://ct0ejt0trkhrf"]

[ext_resource type="Script" path="res://source/match/units/CommandCenter.gd" id="1_hpo2s"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="2_c41i5"]
[ext_resource type="PackedScene" uid="uid://bxx81l3t16rrs" path="res://source/match/units/structure-geometries/CommandCenter.tscn" id="2_hwq4d"]
[ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="3_slmue"]
[ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="4_f5u8t"]
[ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="5_xuulo"]
[ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_8qw5y"]
[ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="17_dco2r"]

[sub_resource type="CylinderShape3D" id="CylinderShape3D_pav5c"]
Expand Down Expand Up @@ -44,4 +45,6 @@ size = Vector2(380, 10)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
radius = 2.0

[node name="RallyPoint" parent="." instance=ExtResource("8_8qw5y")]

[editable path="Geometry"]
5 changes: 4 additions & 1 deletion source/match/units/VehicleFactory.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://h5lqor1xl2sf"]
[gd_scene load_steps=10 format=3 uid="uid://h5lqor1xl2sf"]

[ext_resource type="Script" path="res://source/match/units/VehicleFactory.gd" id="1_1a20j"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_8fcgb"]
Expand All @@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_cp6bx"]
[ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_xd2eg"]
[ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="7_j4kwk"]
[ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_h714l"]

[sub_resource type="CylinderShape3D" id="CylinderShape3D_2mws5"]
height = 1.0
Expand Down Expand Up @@ -44,4 +45,6 @@ size = Vector2(250, 10)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
radius = 1.5

[node name="RallyPoint" parent="." instance=ExtResource("8_h714l")]

[editable path="Geometry"]
9 changes: 9 additions & 0 deletions source/match/units/actions/ManagingProduction.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ extends "res://source/match/units/actions/Action.gd"

signal queue_changed

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


class ProductionQueueElement:
extends Resource
Expand Down Expand Up @@ -80,3 +82,10 @@ func _finalize_production(former_queue_element):
MatchSignals.setup_and_spawn_unit.emit(
produced_unit, Transform3D(Basis(), placement_position), _unit.player
)

# Handle rally point
if _unit.has_node("RallyPoint") and Moving.is_applicable(produced_unit):
var rally_point = _unit.get_node("RallyPoint").global_position

if rally_point != _unit.global_position:
produced_unit.action = Moving.new(rally_point)
10 changes: 10 additions & 0 deletions source/match/units/actions/Rallying.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends "res://source/match/units/actions/Action.gd"


static func is_applicable(unit):
return unit.find_child("RallyPoint") != null


static func _set_rally_point(unit, rally_point: Vector3):
var rally_node = unit.find_child("RallyPoint")
rally_node.global_position = rally_point
13 changes: 13 additions & 0 deletions source/match/units/traits/RallyPoint.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Node3D

@onready var _unit = get_parent()
@onready var _line = get_node("Line")
@onready var _marker = get_node("Marker")


func _ready():
get_node("AnimationPlayer").play("idle")


func _process(_delta):
visible = _unit.is_in_group("selected_units")
44 changes: 44 additions & 0 deletions source/match/units/traits/RallyPoint.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[gd_scene load_steps=6 format=3 uid="uid://b8jwlpdvxgrr6"]

[ext_resource type="Script" path="res://source/match/units/traits/RallyPoint.gd" id="1_jne3g"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_k3k1b"]
albedo_color = Color(0.054902, 1, 0.223529, 0.12549)
emission_enabled = true
emission = Color(0, 1, 0, 1)
emission_energy_multiplier = 1.65

[sub_resource type="CylinderMesh" id="CylinderMesh_phq1d"]
material = SubResource("StandardMaterial3D_k3k1b")
top_radius = 0.2
bottom_radius = 0.2
height = 0.1

[sub_resource type="Animation" id="Animation_ymm6i"]
resource_name = "idle"
loop_mode = 1
tracks/0/type = "scale_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Marker")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 1, 1, 1, 0.3, 1, 1.3, 1.3, 1.3, 0.7, 1, 0.6, 0.6, 0.6, 1, 1, 1, 1, 1)

[sub_resource type="AnimationLibrary" id="AnimationLibrary_bax6m"]
_data = {
"idle": SubResource("Animation_ymm6i")
}

[node name="RallyPoint" type="Node3D"]
script = ExtResource("1_jne3g")

[node name="Marker" type="MeshInstance3D" parent="."]
transform = Transform3D(0.845995, 0, 0, 0, 0.845995, 0, 0, 0, 0.845995, 0, 0, 0)
mesh = SubResource("CylinderMesh_phq1d")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
reset_on_save = false
libraries = {
"": SubResource("AnimationLibrary_bax6m")
}

0 comments on commit 04bda65

Please sign in to comment.