spaceship/tests/test_hub_capacity.gd
2026-08-16 21:38:07 +02:00

57 lines
2.3 KiB
GDScript

extends SceneTree
# A transport hub owns its logistics vessels directly. Building a hub
# provisions every researched slot immediately; Freight Yards provisions its
# extra slot on hubs that already exist.
func _initialize() -> void:
var state: Node = root.get_node("GameState")
state.buildings.clear()
state.extractors.clear()
state.transporters.clear()
state.reset_progression()
state.rocks = 900
state.research_points = state.skill_research_point_cost("freight_yards")
state.unlocked = ["shipyards", "logistics", "freight"]
var hub_a: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(-500, 0))
var per_hub: int = state.hub_capacity()
if state.transporters.size() != per_hub or _at_hub(state, hub_a) != per_hub:
return _fail("first hub did not immediately provision %d transporters" % per_hub)
print("first hub provisioned %d transporters" % per_hub)
var hub_b: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(-500, 600))
if state.transporters.size() != per_hub * 2 or _at_hub(state, hub_b) != per_hub:
return _fail("second hub did not bring its own transporters")
print("second hub raised logistics fleet to %d" % state.transporters.size())
var before: int = state.transporters.size()
if not state.unlock("freight_yards"):
return _fail("could not research Freight Yards")
var expected: int = state.hub_capacity() * state.hub_count()
if state.transporters.size() != expected or state.transporters.size() != before + 2:
return _fail("Freight Yards did not provision one transporter per existing hub")
if _at_hub(state, hub_a) != state.hub_capacity() \
or _at_hub(state, hub_b) != state.hub_capacity():
return _fail("researched transporters were assigned to the wrong hubs")
print("Freight Yards provisioned existing hubs: %d -> %d" % [before, expected])
if state.remove_buildings_of_type(state.BUILDING_TRANSPORT_HUB) != 2 \
or not state.transporters.is_empty():
return _fail("removing hubs left orphaned logistics transporters")
print("TEST_HUB_CAPACITY: PASS")
quit(0)
func _at_hub(state: Node, hub_id: int) -> int:
var count: int = 0
for transporter in state.transporters:
if int(transporter.hub_id) == hub_id:
count += 1
return count
func _fail(message: String) -> void:
print("TEST_HUB_CAPACITY: FAIL (%s)" % message)
quit(1)