Skip to content

Commit

Permalink
Make 'ManagingProduction' a 'ProductionQueue' trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Nov 19, 2023
1 parent ab49385 commit a762def
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 77 deletions.
5 changes: 2 additions & 3 deletions source/match/hud/ProductionQueue.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends MarginContainer

const ManagingProductionAction = preload("res://source/match/units/actions/ManagingProduction.gd")
const ProductionQueueElement = preload("res://source/match/hud/ProductionQueueElement.tscn")

var _production_manager = null
Expand Down Expand Up @@ -37,9 +36,9 @@ func _try_observing_production_manager():
if selected_controlled_units.size() != 1:
return false
var selected_unit = selected_controlled_units[0]
if selected_unit.action == null or not selected_unit.action is ManagingProductionAction:
if not "production_queue" in selected_unit or selected_unit.production_queue == null:
return false
_observe(selected_unit.action)
_observe(selected_unit.production_queue)
return true


Expand Down
7 changes: 2 additions & 5 deletions source/match/hud/unit-menus/AircraftFactoryMenu.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends GridContainer

const ManagingProductionAction = preload("res://source/match/units/actions/ManagingProduction.gd")
const HelicopterUnit = preload("res://source/match/units/Helicopter.tscn")
const DroneUnit = preload("res://source/match/units/Drone.tscn")

Expand Down Expand Up @@ -40,10 +39,8 @@ func _ready():


func _on_produce_helicopter_button_pressed():
if unit.action != null and unit.action is ManagingProductionAction:
unit.action.produce(HelicopterUnit)
unit.production_queue.produce(HelicopterUnit)


func _on_produce_drone_button_pressed():
if unit.action != null and unit.action is ManagingProductionAction:
unit.action.produce(DroneUnit)
unit.production_queue.produce(DroneUnit)
4 changes: 1 addition & 3 deletions source/match/hud/unit-menus/CommandCenterMenu.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends GridContainer

const ManagingProductionAction = preload("res://source/match/units/actions/ManagingProduction.gd")
const WorkerUnit = preload("res://source/match/units/Worker.tscn")

var unit = null
Expand All @@ -23,5 +22,4 @@ func _ready():


func _on_produce_worker_button_pressed():
if unit.action != null and unit.action is ManagingProductionAction:
unit.action.produce(WorkerUnit)
unit.production_queue.produce(WorkerUnit)
4 changes: 1 addition & 3 deletions source/match/hud/unit-menus/VehicleFactoryMenu.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends GridContainer

const ManagingProductionAction = preload("res://source/match/units/actions/ManagingProduction.gd")
const TankUnit = preload("res://source/match/units/Tank.tscn")

var unit = null
Expand All @@ -25,5 +24,4 @@ func _ready():


func _on_produce_tank_button_pressed():
if unit.action != null and unit.action is ManagingProductionAction:
unit.action.produce(TankUnit)
unit.production_queue.produce(TankUnit)
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func provision(resources, metadata):
"unexpected amount of resources"
)
_number_of_pending_worker_resource_requests -= 1
if _ccs.is_empty() or _ccs[0].action == null:
if _ccs.is_empty():
return
_ccs[0].action.produce(WorkerScene)
_number_of_pending_workers += 1
if _ccs[0].production_queue.produce(WorkerScene) != null:
_number_of_pending_workers += 1
elif metadata == "cc":
assert(
resources == Constants.Match.Units.CONSTRUCTION_COSTS[CommandCenterScene.resource_path],
Expand Down
10 changes: 5 additions & 5 deletions source/match/players/simple-clairvoyant-ai/OffenseController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func _provision_unit(unit_scene, structure_producing_unit, resources, metadata):
if structure_producing_unit == null:
return
_number_of_pending_unit_resource_requests[metadata] -= 1
structure_producing_unit.action.produce(unit_scene)
structure_producing_unit.production_queue.produce(unit_scene)


func _try_creating_new_battlegroup():
Expand All @@ -111,7 +111,7 @@ func _try_creating_new_battlegroup():
if _battlegroups.size() == _ai.expected_number_of_battlegroups:
var primary_structure = _primary_structure()
if primary_structure != null:
primary_structure.action.cancel_all()
primary_structure.production_queue.cancel_all()
_battlegroup_under_forming = null
return false
var adversary_players = find_parent("Match").players.filter(
Expand Down Expand Up @@ -202,7 +202,7 @@ func _enforce_secondary_units_production():
func _enforce_units_production(structure, unit_scene, type):
if structure == null or not structure.is_constructed() or not _is_units_production_allowed():
return
var number_of_pending_units = structure.action.queue.size()
var number_of_pending_units = structure.production_queue.size()
if number_of_pending_units + _number_of_pending_unit_resource_requests.get(type, 0) == 0:
_number_of_pending_unit_resource_requests[type] = (
_number_of_pending_unit_resource_requests.get(type, 0) + 1
Expand Down Expand Up @@ -248,12 +248,12 @@ func _is_units_production_allowed():
> (
Utils.Arr.sum(_number_of_pending_unit_resource_requests.values())
+ (
primary_structure.action.queue.size()
primary_structure.production_queue.size()
if primary_structure != null and primary_structure.is_constructed()
else 0
)
+ (
secondary_structure.action.queue.size()
secondary_structure.production_queue.size()
if secondary_structure != null and secondary_structure.is_constructed()
else 0
)
Expand Down
16 changes: 0 additions & 16 deletions source/match/units/AircraftFactory.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
extends "res://source/match/units/Structure.gd"

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


func _ready():
await super()
if not is_constructed():
await constructed
action = ManagingProduction.new()


func _set_action(action_node):
if not _action_locked and action == null:
super(action_node)
elif action_node != null:
action_node.queue_free()
5 changes: 4 additions & 1 deletion source/match/units/AircraftFactory.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://cxilu6668nda6"]
[gd_scene load_steps=11 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"]
Expand All @@ -7,6 +7,7 @@
[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://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_c3qd5"]
[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 @@ -46,4 +47,6 @@ radius = 1.5

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

[node name="ProductionQueue" parent="." instance=ExtResource("9_c3qd5")]

[editable path="Geometry"]
16 changes: 0 additions & 16 deletions source/match/units/CommandCenter.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
extends "res://source/match/units/Structure.gd"

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


func _ready():
await super()
if not is_constructed():
await constructed
action = ManagingProduction.new()


func _set_action(action_node):
if not _action_locked and action == null:
super(action_node)
elif action_node != null:
action_node.queue_free()
5 changes: 4 additions & 1 deletion source/match/units/CommandCenter.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://ct0ejt0trkhrf"]
[gd_scene load_steps=11 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"]
Expand All @@ -7,6 +7,7 @@
[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://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_y6bg8"]
[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 @@ -46,4 +47,6 @@ radius = 2.0

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

[node name="ProductionQueue" parent="." instance=ExtResource("9_y6bg8")]

[editable path="Geometry"]
4 changes: 4 additions & 0 deletions source/match/units/Structure.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const UNDER_CONSTRUCTION_MATERIAL = preload(

var _construction_progress = 1.0

@onready var production_queue = find_child("ProductionQueue"):
set(_value):
pass


func mark_as_under_construction():
assert(not is_under_construction(), "structure already under construction")
Expand Down
16 changes: 0 additions & 16 deletions source/match/units/VehicleFactory.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
extends "res://source/match/units/Structure.gd"

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


func _ready():
await super()
if not is_constructed():
await constructed
action = ManagingProduction.new()


func _set_action(action_node):
if not _action_locked and action == null:
super(action_node)
elif action_node != null:
action_node.queue_free()
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=10 format=3 uid="uid://h5lqor1xl2sf"]
[gd_scene load_steps=11 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 @@ -8,6 +8,7 @@
[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"]
[ext_resource type="PackedScene" uid="uid://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_3s532"]

[sub_resource type="CylinderShape3D" id="CylinderShape3D_2mws5"]
height = 1.0
Expand Down Expand Up @@ -46,4 +47,6 @@ radius = 1.5

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

[node name="ProductionQueue" parent="." instance=ExtResource("9_3s532")]

[editable path="Geometry"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends "res://source/match/units/actions/Action.gd"
extends Node

signal queue_changed

Expand All @@ -20,7 +20,7 @@ class ProductionQueueElement:

var queue = []

@onready var _unit = Utils.NodeEx.find_parent_with_group(self, "units")
@onready var _unit = get_parent()


func _process(delta):
Expand All @@ -35,8 +35,8 @@ func _process(delta):
delta = max(0.0, delta - current_queue_element.time_left)


func _to_string():
return "{0}({1} in queue)".format([super(), str(queue.size())])
func size():
return queue.size()


func produce(unit_prototype):
Expand Down
6 changes: 6 additions & 0 deletions source/match/units/traits/ProductionQueue.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cd3v6508vjcu3"]

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

[node name="ProductionQueue" type="Node"]
script = ExtResource("1_krjoq")

0 comments on commit a762def

Please sign in to comment.