89 lines
3.2 KiB
GDScript
89 lines
3.2 KiB
GDScript
extends SceneTree
|
|
|
|
# Hub-owned transporters supply an unfunded combat-vessel order without ever
|
|
# being crafted, stored at the mothership, or added to the player fleet.
|
|
|
|
var state: Node
|
|
var crafter_id: int
|
|
var initial_transporters: int
|
|
var total_at_start: int
|
|
var consumed: int = 0
|
|
var elapsed: float = 0.0
|
|
var conservation_broken: bool = false
|
|
|
|
|
|
func _initialize() -> void:
|
|
state = root.get_node("GameState")
|
|
state.buildings.clear()
|
|
state.extractors.clear()
|
|
state.transporters.clear()
|
|
state.stored_vessels.clear()
|
|
state.vessel_deliveries.clear()
|
|
state.reset_progression()
|
|
state.rocks = 200
|
|
state.build_time_scale = 0.02
|
|
state.unlocked = ["shipyards", "logistics", "freight"]
|
|
state.add_building(state.BUILDING_MOTHERSHIP, Vector2.ZERO)
|
|
crafter_id = state.add_building(state.BUILDING_SHIP_CRAFTER, Vector2(900, -300))
|
|
|
|
if state.queue_order(crafter_id, state.VESSEL_TRANSPORTER):
|
|
return _fail("the crafter accepted a logistics transporter order")
|
|
var hub_id: int = state.add_building(state.BUILDING_TRANSPORT_HUB, Vector2(600, 200))
|
|
initial_transporters = state.hub_capacity()
|
|
if state.transporters.size() != initial_transporters:
|
|
return _fail("hub provisioned %d transporters, expected %d" % [
|
|
state.transporters.size(), initial_transporters])
|
|
for transporter in state.transporters:
|
|
if int(transporter.hub_id) != hub_id or transporter.state != state.TRANSPORTER_IDLE:
|
|
return _fail("a provisioned transporter was not idle at its hub")
|
|
|
|
var bank_before: int = state.rocks
|
|
if not state.queue_order(crafter_id, state.PRODUCT_SHIP):
|
|
return _fail("crafter refused the combat-vessel order")
|
|
if state.rocks != bank_before:
|
|
return _fail("placing the order changed the bank before a transporter loaded")
|
|
state.order_completed.connect(_on_order_completed)
|
|
total_at_start = _total()
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
elapsed += delta
|
|
if _total() + consumed != total_at_start:
|
|
conservation_broken = true
|
|
if state.pending_orders(crafter_id) > 0:
|
|
if elapsed > 25.0:
|
|
return _fail("hub transporters never supplied the queued order")
|
|
return false
|
|
if conservation_broken:
|
|
return _fail("ore was created or destroyed on the automatic route")
|
|
if state.transporters.size() != initial_transporters:
|
|
return _fail("transporters accumulated during delivery")
|
|
if state.stored_vessels.has(state.VESSEL_TRANSPORTER):
|
|
return _fail("a transporter appeared in the mothership hangar")
|
|
print("%d hub-owned transporters supplied the crafter automatically" % initial_transporters)
|
|
print("TEST_TRANSPORTER_SUPPLY: PASS")
|
|
quit(0)
|
|
return true
|
|
|
|
|
|
func _on_order_completed(_building_id: int, product: String) -> void:
|
|
consumed += state.product_cost(product)
|
|
|
|
|
|
func _total() -> int:
|
|
var sum: int = state.rocks + state.fleet_cargo
|
|
for building in state.buildings:
|
|
if building.type != state.BUILDING_MOTHERSHIP:
|
|
sum += state.building_resource(int(building.id), state.RESOURCE_ORE)
|
|
for order in building.get("orders", []):
|
|
if bool(order.started):
|
|
sum += state.product_cost(String(order.product))
|
|
for transporter in state.transporters:
|
|
sum += int(transporter.get("carrying", 0))
|
|
return sum
|
|
|
|
|
|
func _fail(message: String) -> bool:
|
|
print("TEST_TRANSPORTER_SUPPLY: FAIL (%s)" % message)
|
|
quit(1)
|
|
return true
|