Supply lab research with transporters

This commit is contained in:
Loïc Wisniewski 2026-08-14 22:46:25 +02:00
commit 3fc04f816a
3 changed files with 56 additions and 1 deletions

View file

@ -670,6 +670,9 @@ func outstanding_cost(id: int) -> int:
# A started build has already paid, so it is not still owed. # A started build has already paid, so it is not still owed.
if not bool(o.started): if not bool(o.started):
need += product_cost(String(o.product)) need += product_cost(String(o.product))
for order in b.get("research_orders", []):
if not bool(order.started):
need += research_cost(String(order.id))
return maxi(need - _inventory_for_record(b).amount(RESOURCE_ORE), 0) return maxi(need - _inventory_for_record(b).amount(RESOURCE_ORE), 0)
@ -771,6 +774,11 @@ func lab_research_order(lab_id: int) -> Dictionary:
return {} if orders.is_empty() else orders[0] return {} if orders.is_empty() else orders[0]
func research_cost(id: String) -> int:
var unlock_definition: Resource = vessel_for_unlock(id)
return unlock_definition.unlock_cost if unlock_definition != null else upgrade_cost(id)
func _advance_lab_research(delta: float) -> void: func _advance_lab_research(delta: float) -> void:
for lab in buildings: for lab in buildings:
if not building_has_capability(lab, "vessel_research"): if not building_has_capability(lab, "vessel_research"):
@ -781,7 +789,7 @@ func _advance_lab_research(delta: float) -> void:
var order: Dictionary = orders[0] var order: Dictionary = orders[0]
var id: String = String(order.id) var id: String = String(order.id)
var unlock_definition: Resource = vessel_for_unlock(id) var unlock_definition: Resource = vessel_for_unlock(id)
var cost: int = unlock_definition.unlock_cost if unlock_definition != null else upgrade_cost(id) var cost: int = research_cost(id)
var inventory: RefCounted = _inventory_for_record(lab) var inventory: RefCounted = _inventory_for_record(lab)
if not bool(order.started): if not bool(order.started):
if inventory.amount(RESOURCE_ORE) < cost: if inventory.amount(RESOURCE_ORE) < cost:

View file

@ -0,0 +1,46 @@
extends SceneTree
var state: Node
var lab_id: int
var elapsed: float = 0.0
func _initialize() -> void:
state = root.get_node("GameState")
state.buildings.clear()
state.extractors.clear()
state.transporters.clear()
state.reset_progression()
state.rocks = 100
state.build_time_scale = 0.02
state.add_building(state.BUILDING_MOTHERSHIP, Vector2.ZERO)
var hub_id: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(50, 0))
lab_id = state.add_building(state.BUILDING_SHIP_LAB, Vector2(100, 0))
state.transporters.append({"hub_id": hub_id, "state": state.TRANSPORTER_IDLE,
"target_id": 0, "extractor_index": -1, "carrying": 0, "progress": 1.0,
"from": Vector2(50, 0), "to": Vector2(50, 0)})
if not state.queue_lab_research(lab_id, "int_damage"):
return _fail("could not queue lab research")
if state.outstanding_cost(lab_id) != state.upgrade_cost("int_damage"):
return _fail("queued research did not expose its ore demand")
func _process(delta: float) -> bool:
elapsed += delta
if state.upgrade_level("int_damage") == 1:
if state.lab_research_order(lab_id).is_empty():
print("transporter supplied queued lab research end to end")
print("TEST_LAB_TRANSPORTER_DELIVERY: PASS")
quit(0)
return true
if elapsed > 5.0:
return _fail("lab still waiting: demand=%d transporter=%s stock=%d" % [
state.outstanding_cost(lab_id), state.transporters[0].state,
state.building_stock(lab_id)])
return false
func _fail(message: String) -> bool:
print("TEST_LAB_TRANSPORTER_DELIVERY: FAIL (%s)" % message)
quit(1)
return true

View file

@ -0,0 +1 @@
uid://dmw83vfmot52d