Route extractor ore through transporters
This commit is contained in:
parent
13492a52e2
commit
5755568346
3 changed files with 141 additions and 140 deletions
|
|
@ -1,28 +1,17 @@
|
|||
extends SceneTree
|
||||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_extractor_income.gd
|
||||
# Covers the extractor's automated hauler:
|
||||
# 1. income accrues with NOTHING about the route loaded (no scene showing
|
||||
# it), because the simulation lives in the GameState autoload
|
||||
# 2. ore is delivered exactly when the hauler reaches the mothership -
|
||||
# the payout and the drawn arrival are the same event, driven by the
|
||||
# same `progress` value, so they cannot drift apart
|
||||
# 3. no mothership means no route and therefore no income
|
||||
# 4. the hauler's drawn position tracks that progress along the route
|
||||
# Extractors now mine into local stock. A hub-stationed transporter is the
|
||||
# only route to the bank, and it waits for a full researched-size load.
|
||||
|
||||
var game_state: Node
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
# The test has to sit through a whole there-and-back hauler cycle, and the
|
||||
# cycle length is distance/HAULER_SPEED - so this fixture distance IS the
|
||||
# test's runtime. 600 units is ~4.6s of simulated round trip, against ~31s
|
||||
# for the 4000 it used to be. Nothing here asserts on the distance itself,
|
||||
# only on payout and drawn position tracking the same `progress`, so a short
|
||||
# route exercises exactly the same code.
|
||||
var mothership_pos: Vector2 = Vector2(600.0, 0.0)
|
||||
var planet_pos: Vector2 = Vector2.ZERO
|
||||
var rocks_before_arrival: int = 0
|
||||
var extractor_index: int = 0
|
||||
var base_load: int = 0
|
||||
var upgraded_load: int = 0
|
||||
const MOTHERSHIP_AT := Vector2.ZERO
|
||||
const HUB_AT := Vector2(100.0, 0.0)
|
||||
const EXTRACTOR_AT := Vector2(300.0, 0.0)
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
|
|
@ -30,83 +19,83 @@ func _initialize() -> void:
|
|||
game_state.rocks = 0
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
|
||||
# An extractor with NO mothership: there is nowhere to deliver, so it
|
||||
# must not pay out.
|
||||
game_state.add_extractor("Test Planet", planet_pos)
|
||||
game_state.transporters.clear()
|
||||
game_state.reset_progression()
|
||||
game_state.add_extractor("Test Planet", EXTRACTOR_AT)
|
||||
extractor_index = 0
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
match stage:
|
||||
0:
|
||||
if elapsed < 1.0:
|
||||
# Mining is local even without a mothership or transporter.
|
||||
if elapsed < 1.2:
|
||||
return false
|
||||
if game_state.rocks != 0:
|
||||
print("earned %d rocks with no mothership" % game_state.rocks)
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (income without a delivery point)")
|
||||
quit(1)
|
||||
if game_state.extractor_stock(extractor_index) < 2 or game_state.rocks != 0:
|
||||
_fail("extractor did not hold locally: stock=%d bank=%d" % [
|
||||
game_state.extractor_stock(extractor_index), game_state.rocks])
|
||||
return true
|
||||
print("no mothership -> no income (rocks=%d)" % game_state.rocks)
|
||||
|
||||
# Give it somewhere to deliver.
|
||||
game_state.add_building(GameState.BUILDING_MOTHERSHIP, mothership_pos)
|
||||
game_state.extractors[0].progress = 0.0
|
||||
print("extractor mined locally: stock=%d bank=%d" % [
|
||||
game_state.extractor_stock(extractor_index), game_state.rocks])
|
||||
game_state.add_building(GameState.BUILDING_MOTHERSHIP, MOTHERSHIP_AT)
|
||||
var hub_id: int = game_state.add_building(GameState.BUILDING_TRANSPORT_HUB, HUB_AT)
|
||||
# A manually seeded idle transporter is enough to exercise the same
|
||||
# simulation used by a produced one.
|
||||
game_state.transporters.append({"hub_id": hub_id, "state": GameState.TRANSPORTER_IDLE,
|
||||
"target_id": 0, "extractor_index": -1, "carrying": 0, "progress": 1.0,
|
||||
"from": HUB_AT, "to": HUB_AT})
|
||||
base_load = game_state.transporter_load_limit()
|
||||
game_state.extractors[extractor_index].stock = base_load - 1
|
||||
elapsed = 0.0
|
||||
stage = 1
|
||||
return false
|
||||
1:
|
||||
var e: Dictionary = game_state.extractors[0]
|
||||
var cycle: float = game_state.get_hauler_route_time(e)
|
||||
if cycle <= 0.0:
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (route never established)")
|
||||
quit(1)
|
||||
return true
|
||||
|
||||
# Nothing in this scene tree draws the route at all - no Main
|
||||
# scene, no HaulerField, no hauler node. Income must still tick.
|
||||
if e.progress < GameState.HAULER_ARRIVAL:
|
||||
rocks_before_arrival = game_state.rocks
|
||||
# The drawn position must track progress along the route.
|
||||
var pos: Variant = game_state.get_hauler_position(e)
|
||||
var expected: Vector2 = planet_pos.lerp(mothership_pos, e.progress / GameState.HAULER_ARRIVAL)
|
||||
if pos == null or pos.distance_to(expected) > 1.0:
|
||||
print("hauler at %s, expected %s" % [pos, expected])
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (drawn position does not follow the simulation)")
|
||||
quit(1)
|
||||
return true
|
||||
# No partial pickup: it stays local until it can fill the hold.
|
||||
if elapsed < 0.2:
|
||||
return false
|
||||
|
||||
# Just crossed the arrival point: the payout must have landed on
|
||||
# the very same step, and the hauler must be AT the mothership.
|
||||
var paid: bool = game_state.rocks == rocks_before_arrival + GameState.HAULER_YIELD
|
||||
var at_mothership: Variant = game_state.get_hauler_position(e)
|
||||
var arrived: bool = at_mothership != null and at_mothership.distance_to(mothership_pos) < 40.0
|
||||
print("arrival: rocks %d -> %d (paid=%s) hauler at %s (arrived=%s)" % [
|
||||
rocks_before_arrival, game_state.rocks, paid, at_mothership, arrived
|
||||
])
|
||||
if not (paid and arrived):
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (payout and arrival did not coincide)")
|
||||
quit(1)
|
||||
if game_state.transporters[0].state != GameState.TRANSPORTER_IDLE or game_state.rocks != 0:
|
||||
_fail("transporter left for a partial load")
|
||||
return true
|
||||
|
||||
rocks_before_arrival = game_state.rocks
|
||||
game_state.extractors[extractor_index].stock = base_load
|
||||
elapsed = 0.0
|
||||
stage = 2
|
||||
return false
|
||||
2:
|
||||
# It must not pay again until it has been back and returned.
|
||||
var e2: Dictionary = game_state.extractors[0]
|
||||
if e2.progress > GameState.HAULER_ARRIVAL:
|
||||
if game_state.rocks != rocks_before_arrival:
|
||||
print("paid %d extra mid-return" % (game_state.rocks - rocks_before_arrival))
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (paid while returning empty)")
|
||||
quit(1)
|
||||
# It must lift exactly the capacity amount, then bank it only when
|
||||
# it reaches the mothership.
|
||||
if game_state.rocks >= base_load:
|
||||
print("full transporter load banked: %d ore" % base_load)
|
||||
# Fund the lab purchase independently of the delivery assertion.
|
||||
game_state.rocks = 100
|
||||
game_state.add_building(GameState.BUILDING_SHIP_LAB, Vector2(-100.0, 0.0))
|
||||
if not game_state.buy_upgrade("trn_capacity"):
|
||||
_fail("could not research Expanded Hold at a ship lab")
|
||||
return true
|
||||
upgraded_load = game_state.transporter_load_limit()
|
||||
if upgraded_load <= base_load:
|
||||
_fail("Expanded Hold did not raise capacity")
|
||||
return true
|
||||
game_state.extractors[extractor_index].stock = upgraded_load
|
||||
elapsed = 0.0
|
||||
stage = 3
|
||||
return false
|
||||
# Wrapped past the planet and started a new outbound leg.
|
||||
print("returned empty without paying again (rocks=%d)" % game_state.rocks)
|
||||
print("TEST_EXTRACTOR_INCOME: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
if elapsed > 10.0:
|
||||
_fail("full extractor load was never collected")
|
||||
return true
|
||||
return false
|
||||
3:
|
||||
if game_state.rocks >= 100 - 30 + upgraded_load:
|
||||
print("Expanded Hold %d -> %d, upgraded load banked" % [base_load, upgraded_load])
|
||||
print("TEST_EXTRACTOR_INCOME: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
if elapsed > 10.0:
|
||||
_fail("upgraded load was not transported")
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _fail(message: String) -> void:
|
||||
print("TEST_EXTRACTOR_INCOME: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue