A ship crafter shows what can actually be ordered there: a hull whose research is done, and - for the support craft - one with somewhere to be assigned. A transporter with no hub and a drone with no workshop have nowhere to go and would sit in the hangar as spent resources, so the structure that uses one is part of its availability. Hidden rather than greyed, as the build menu already treats an unresearched structure, and gated in queue_order() too so the model refuses what the menu declines to show. The craft buttons bound their handlers to a definition captured at startup. With a list that changes length that is a live bug - a slot would order whatever hull was there when the menu was built - so they bind to the slot and resolve through the current offer. The hub and workshop crew menus now NAME what is left in each vessel: "TRANSPORTER 2 9 / 20 RUNS", worst first, with one wide bar for the vessel closest to spent. The per-vessel bars they replaced drew about seven pixels tall on a phone and carried no figure, so the number the player is deciding on could not be read. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
92 lines
3.9 KiB
GDScript
92 lines
3.9 KiB
GDScript
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
|