spaceship/tests/test_crafter_availability.gd

92 lines
3.9 KiB
GDScript3
Raw Normal View History

extends SceneTree
# A ship crafter offers what can actually be ordered there, and nothing else.
#
# Two rules:
# - a hull whose research is not done is not on offer (it never was
# orderable; it was drawn greyed, which is a row that says nothing the
# absence does not)
# - a support vessel needs the structure that USES it. #216 made
# transporters and repair drones ordinary craft, and one with no hub or
# no workshop has nowhere to be assigned - it would sit in the hangar as
# spent resources.
#
# Covers:
# A. with no hub and no workshop, neither support craft can be ordered
# B. building a hub offers the transporter, and only the transporter
# C. building a workshop offers the drone
# D. the model refuses the order too, not just the menu
# E. an unresearched fleet hull is not on offer either
var state: Node
var crafter_id: int
func _initialize() -> void:
state = root.get_node("GameState")
state.buildings.clear()
state.extractors.clear()
state.transporters.clear()
state.repair_drones.clear()
state.reset_progression()
state.rocks = 900
state.unlocked = ["shipyards", "logistics", "freight"]
crafter_id = state.add_building(state.BUILDING_SHIP_CRAFTER, Vector2(400.0, 0.0))
func _process(_delta: float) -> bool:
# --- A. nothing to assign them to, so nothing on offer ------------
if state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
return _fail("a transporter is orderable with no hub to put it in")
if state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
return _fail("a repair drone is orderable with no workshop to put it in")
# --- D. and the model refuses, not merely the menu ----------------
if state.queue_order(crafter_id, GameState.VESSEL_TRANSPORTER):
return _fail("the crafter queued a transporter with nowhere to send it")
print("no hub, no workshop: neither support craft is on offer")
# --- B. a hub offers the transporter ------------------------------
var hub_id: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(900.0, 0.0))
if not state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
return _fail("a hub is standing and the transporter is still not orderable")
if state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
return _fail("a transport hub made the repair drone orderable")
if not state.queue_order(crafter_id, GameState.VESSEL_TRANSPORTER):
return _fail("the crafter refused a transporter with a hub standing")
state.find_building(crafter_id).orders.clear()
print("a hub offers the transporter, and only that")
# --- C. and a workshop the drone ----------------------------------
state.add_building(GameState.BUILDING_WORKSHOP, Vector2(-900.0, 0.0))
if not state.vessel_can_be_crafted(GameState.REPAIR_DRONE):
return _fail("a workshop is standing and the drone is still not orderable")
print("a workshop offers the repair drone")
# Taking the hub away takes the offer with it - there is nowhere to
# assign one again.
state.remove_buildings_of_type(state.BUILDING_TRANSPORT_HUB)
if state.vessel_can_be_crafted(GameState.VESSEL_TRANSPORTER):
return _fail("the last hub came down and the transporter is still on offer")
print("the last hub down: the transporter is off the menu again")
# --- E. an unresearched hull is not on offer ----------------------
var locked: String = ""
for definition in load("res://vessels/VesselDefinitions.gd").fleet():
if not state.vessel_is_unlocked(String(definition.definition_id)):
locked = String(definition.definition_id)
break
if locked == "":
return _fail("every fleet hull is already unlocked, so this proves nothing")
if state.vessel_can_be_crafted(locked):
return _fail("'%s' is unresearched and still on offer" % locked)
print("an unresearched hull ('%s') is not on offer" % locked)
print("TEST_CRAFTER_AVAILABILITY: PASS")
quit(0)
return true
func _fail(message: String) -> bool:
print("TEST_CRAFTER_AVAILABILITY: FAIL (%s)" % message)
quit(1)
return true