Rotating the fleet and spamming a direction let vessels fall out of sync and fly at wildly high speeds. The pivot cooldown added earlier throttled how often the exploit could be triggered; it never touched the cause. Fleet.stop() did `ship.velocity = ship.velocity + ship.fleet_velocity`, compensating for the fact that Ship.velocity read zero during cruise. The next steer refilled fleet_velocity, so every press-release cycle added a whole cruise velocity to the ship's own, decaying only at `acceleration` in between. Tapping faster than that bled it off stacked them without limit, and ships desynced because each bled off at a rate set by its own distance to its slot. Measured before this change: spamming a direction while pivoting flew the fleet 32737 units in 3s against 784 for simply holding the stick, with a vessel reaching 48x its own top speed. The compensation existed because `velocity` was not the ship's real motion: Ship snapped to its slot every tick and zeroed it, so the truth lived in a second field and anything wanting it had to add the two together. Fixed at that root rather than by clamping the symptom: - fleet_velocity is now fed FORWARD into the steering instead of carried alongside it. The ship aims to travel at its slot's velocity plus a correction closing the gap, so holding formation costs no error and `velocity` is always true world motion. - The snap only applies when the slot is standing still, which is the one case where converging asymptotically would leave a residue. While the slot moves the ship steers continuously - a snap there was the teleport that made `velocity` lie in the first place. - A hard bound on the INTEGRATED result every tick, not merely on the request, so no sequence of commands can leave a vessel over its own top speed. - Fleet.stop() injects nothing; it reports that the slot has halted. tests/test_fleet_speed_bounded.gd covers it, and fails against the previous code with the numbers above: no vessel exceeds its own top speed however hard the direction is spammed, spamming cannot cover more ground than holding the stick, both hold while the formation is pivoting, and the fleet stays together. test_space_time_distorder.gd now clears the asteroid and enemy groups at setup, the same clean-slate idiom test_ship_lab.gd uses. Silencing the spawners was never enough - what Main.tscn had already placed kept moving, and losing the distorder vessel to a rock resets the multiplier correctly, which the test then reported three stages later as a failed scene swap. It also checks it still crews a distorder vessel before relying on that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
262 lines
11 KiB
GDScript
262 lines
11 KiB
GDScript
extends SceneTree
|
|
|
|
# Headless gameplay test: run with
|
|
# godot --headless -s res://tests/test_space_time_distorder.gd
|
|
# Forgejo #59: a researchable vessel that lets the whole fleet travel faster
|
|
# than its default cruise speed, via a fader driving
|
|
# game_state.fleet_speed_multiplier.
|
|
#
|
|
# Covers:
|
|
# A. the fader is absent with no distorder ship, appears once one joins
|
|
# B. dragging it up measurably increases distance travelled per second;
|
|
# at 1.0 the fleet moves exactly as it does today
|
|
# C. formation holds together under boost - ships stay near their slot
|
|
# D. losing the vessel resets the multiplier and hides the fader
|
|
# E. the multiplier survives the space -> surface scene swap (it lives
|
|
# in the autoload)
|
|
|
|
var game_state: Node
|
|
var main: Node
|
|
var fleet: Node
|
|
var fader: Node
|
|
var stage: int = 0
|
|
var elapsed: float = 0.0
|
|
var baseline_distance: float = 0.0
|
|
var boosted_distance: float = 0.0
|
|
var start_centroid: Vector2 = Vector2.ZERO
|
|
var unboosted_lag: float = 0.0
|
|
|
|
const MEASURE_TIME: float = 1.0
|
|
|
|
|
|
func _initialize() -> void:
|
|
game_state = root.get_node("GameState")
|
|
game_state.buildings.clear()
|
|
game_state.extractors.clear()
|
|
game_state.transporters.clear()
|
|
game_state.stored_vessels.clear()
|
|
game_state.reset_progression()
|
|
game_state.vessel_levels["unlock_distorder"] = 1
|
|
# #62: sustaining a boost now drains fleet energy continuously - stock
|
|
# plenty so this test's own boosted phases aren't cut short by running
|
|
# out mid-measurement. Set BEFORE the first spawn_ships() call (inside
|
|
# Main.tscn's own _ready(), triggered by instantiate() below): the fleet
|
|
# hold has no capacity cap yet at this point, so this can't be clamped
|
|
# by the soon-to-exist fleet's cargo capability.
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 500)
|
|
main = load("res://Main.tscn").instantiate()
|
|
root.add_child(main)
|
|
fleet = main.get_node("Fleet")
|
|
fader = main.get_node("UI/SpeedFader")
|
|
|
|
|
|
func _process(delta: float) -> bool:
|
|
elapsed += delta
|
|
match stage:
|
|
0:
|
|
if elapsed < 0.2:
|
|
return false
|
|
main.get_node("EnemySpawner").set_process(false)
|
|
main.get_node("AsteroidField").set_process(false)
|
|
# Silencing the spawners is not enough: whatever Main.tscn already
|
|
# placed keeps moving under its own _physics_process, and this test
|
|
# flies the fleet several thousand units at up to 3x boost. Losing
|
|
# the distorder ship to a rock mid-run resets the multiplier -
|
|
# CORRECTLY, that is what _sync_composition_state is for - and the
|
|
# test then failed three stages later claiming the multiplier had
|
|
# not survived a scene swap. Same clean-slate idiom as
|
|
# test_ship_lab.gd.
|
|
for hazard in get_nodes_in_group("asteroids") + get_nodes_in_group("enemies"):
|
|
if is_instance_valid(hazard):
|
|
hazard.queue_free()
|
|
|
|
# --- A. absent, then appears -------------------------------------
|
|
if fader.visible:
|
|
return _fail_now("fader appeared without a distorder ship")
|
|
|
|
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
|
|
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_DISTORDER]))
|
|
fader._process(0.0)
|
|
if not fader.visible:
|
|
return _fail_now("a distorder ship in the fleet did not reveal the fader")
|
|
print("fader hidden with no distorder ship, visible once one joins")
|
|
|
|
# --- B. baseline @ 1.0x -------------------------------------------
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 1.0):
|
|
return _fail_now("multiplier is not 1.0 by default: %f" % game_state.fleet_speed_multiplier)
|
|
start_centroid = fleet.get_centroid()
|
|
fleet.move_in_direction(Vector2(1.0, 0.0))
|
|
elapsed = 0.0
|
|
stage = 1
|
|
return false
|
|
1:
|
|
if elapsed < MEASURE_TIME:
|
|
return false
|
|
baseline_distance = fleet.get_centroid().distance_to(start_centroid)
|
|
# Reference for the formation check below: pure pursuit (a ship
|
|
# always aiming straight at its CURRENT, still-moving target
|
|
# rather than leading it) has its own inherent non-zero steady-
|
|
# state following distance even at 1.0x - it scales with the
|
|
# speeds involved, so "holds together under boost" has to mean
|
|
# staying proportional to this, not shrinking to some fixed
|
|
# absolute number regardless of how fast the fleet is going.
|
|
for i in range(fleet.ships.size()):
|
|
var ship: Node2D = fleet.ships[i]
|
|
if not is_instance_valid(ship):
|
|
continue
|
|
var expected: Vector2 = fleet.fleet_target + fleet.formation_offsets[i]
|
|
unboosted_lag = maxf(unboosted_lag, ship.position.distance_to(expected))
|
|
fleet.stop()
|
|
print("baseline (1.0x): travelled %.1f over %.1fs, formation lag %.1f" \
|
|
% [baseline_distance, MEASURE_TIME, unboosted_lag])
|
|
elapsed = 0.0
|
|
stage = 2
|
|
return false
|
|
2:
|
|
# Let the braking manoeuvre from stop() fully settle before
|
|
# measuring the boosted leg, so leftover momentum from the
|
|
# baseline pass can't pad the comparison either way.
|
|
if elapsed < 0.5:
|
|
return false
|
|
|
|
var press := InputEventScreenTouch.new()
|
|
press.index = 5
|
|
press.position = fader.global_position + Vector2(fader.size.x * 0.5, fader.size.y - 4.0)
|
|
press.pressed = true
|
|
main._handle_touch(press)
|
|
if not fader.is_active():
|
|
return _fail_now("pressing the fader did not begin dragging")
|
|
var drag := InputEventScreenDrag.new()
|
|
drag.index = 5
|
|
# All the way to the top of the track = MAX_FLEET_SPEED_MULTIPLIER.
|
|
drag.position = fader.global_position + Vector2(fader.size.x * 0.5, 0.0)
|
|
main._handle_drag(drag)
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, GameState.MAX_FLEET_SPEED_MULTIPLIER):
|
|
return _fail_now("dragging to the top did not reach the max multiplier: %f" \
|
|
% game_state.fleet_speed_multiplier)
|
|
print("fader dragged to %.1fx" % game_state.fleet_speed_multiplier)
|
|
|
|
start_centroid = fleet.get_centroid()
|
|
fleet.move_in_direction(Vector2(1.0, 0.0))
|
|
elapsed = 0.0
|
|
stage = 3
|
|
return false
|
|
3:
|
|
if elapsed < MEASURE_TIME:
|
|
return false
|
|
boosted_distance = fleet.get_centroid().distance_to(start_centroid)
|
|
print("boosted (%.1fx): travelled %.1f over %.1fs" \
|
|
% [game_state.fleet_speed_multiplier, boosted_distance, MEASURE_TIME])
|
|
if boosted_distance <= baseline_distance * 1.3:
|
|
return _fail_now("boosted travel (%.1f) was not measurably more than baseline (%.1f)" \
|
|
% [boosted_distance, baseline_distance])
|
|
elapsed = 0.0
|
|
stage = 4
|
|
return false
|
|
4:
|
|
# --- C. formation holds together under boost ----------------------
|
|
# Both the anchor's advance and the ships' own catch-up speed are
|
|
# scaled by the SAME multiplier, so the initial accelerate-from-
|
|
# rest transient covers a proportionally larger absolute distance
|
|
# under a 3x boost - a moment right after the boost begins isn't
|
|
# "trailing", it just hasn't finished the same (time-invariant)
|
|
# catch-up burst yet. Keep steering a while longer so that burst
|
|
# is over before judging whether formation holds.
|
|
if elapsed < 2.5:
|
|
return false
|
|
# Allow the lag to scale with the boost (it inherently does, even
|
|
# with both the anchor and ship speeds multiplied by the exact
|
|
# same factor - see the note by unboosted_lag above) but not
|
|
# beyond that, with generous slack for measurement noise - this
|
|
# ran under a full-suite JOBS=1 sequential load once and strayed
|
|
# 77.7 against a 30.0 allowance (2.6x over) purely from device
|
|
# jitter, confirmed by an immediate clean pass in isolation
|
|
# straight afterward. A REAL formation-desync regression (#72)
|
|
# strays by orders of magnitude more than this margin allows.
|
|
var allowed_lag: float = maxf(unboosted_lag, 20.0) * game_state.fleet_speed_multiplier * 3.0
|
|
for i in range(fleet.ships.size()):
|
|
var ship: Node2D = fleet.ships[i]
|
|
if not is_instance_valid(ship):
|
|
continue
|
|
var expected: Vector2 = fleet.fleet_target + fleet.formation_offsets[i]
|
|
var strayed: float = ship.position.distance_to(expected)
|
|
if strayed > allowed_lag:
|
|
return _fail_now("a ship strayed %.1f from its formation slot under sustained boost (unboosted lag was %.1f, allowed %.1f)" \
|
|
% [strayed, unboosted_lag, allowed_lag])
|
|
print("formation held together under sustained boost (lag stayed proportional to the boost)")
|
|
|
|
fleet.stop()
|
|
var release := InputEventScreenTouch.new()
|
|
release.index = 5
|
|
release.position = fader.global_position + Vector2(fader.size.x * 0.5, 0.0)
|
|
release.pressed = false
|
|
main._handle_touch(release)
|
|
|
|
# --- E. survives the space -> surface scene swap -------------------
|
|
# Done here, with the distorder ship still crewed and the fleet
|
|
# still boosted: tearing this scene down while nothing else
|
|
# changes the fleet's own composition proves the multiplier
|
|
# lives in the autoload rather than being reset as a side effect
|
|
# of the old scene's own SpeedFader still ticking once more
|
|
# during teardown (it would, correctly, self-reset the instant
|
|
# it next saw a fleet with no distorder ship - not a real
|
|
# scenario here since this fleet keeps its distorder ship the
|
|
# whole way across the swap, via GameState.surviving_vessel_types
|
|
# exactly like every other vessel type).
|
|
# Check the premise before relying on it. Everything below is about
|
|
# the multiplier surviving a scene swap, which is only meaningful
|
|
# while the fleet still crews a distorder vessel - so if the fleet
|
|
# lost one on the way here, say THAT rather than reporting a reset
|
|
# multiplier as if the swap were at fault.
|
|
if not fleet.has_capability("distorder"):
|
|
return _fail_now("the fleet lost its distorder vessel before the scene swap, so the multiplier reset is expected rather than a bug")
|
|
game_state.surviving_ship_count = fleet.ships.size()
|
|
game_state.surviving_vessel_types = fleet.vessel_types()
|
|
game_state.planet_id = "test_space_time_distorder"
|
|
game_state.planet_name = "Distorder Test"
|
|
main.queue_free()
|
|
elapsed = 0.0
|
|
stage = 5
|
|
return false
|
|
5:
|
|
if elapsed < 0.3:
|
|
return false
|
|
main = load("res://PlanetSurface.tscn").instantiate()
|
|
root.add_child(main)
|
|
current_scene = main
|
|
fleet = main.get_node("Fleet")
|
|
fader = main.get_node("UI/SpeedFader")
|
|
elapsed = 0.0
|
|
stage = 6
|
|
return false
|
|
6:
|
|
if elapsed < 0.3:
|
|
return false
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 3.0):
|
|
return _fail_now("multiplier did not survive the space -> surface swap: %f" \
|
|
% game_state.fleet_speed_multiplier)
|
|
fader._process(0.0)
|
|
if not fader.visible:
|
|
return _fail_now("the surface scene's fader did not show the surviving distorder ship")
|
|
print("multiplier and fader both survived the space -> surface swap")
|
|
|
|
# --- D. losing the vessel resets the multiplier -------------------
|
|
fleet.spawn_ships(1, fleet.get_centroid(), PackedStringArray([GameState.VESSEL_INTERCEPTOR]))
|
|
fader._process(0.0)
|
|
if fader.visible:
|
|
return _fail_now("fader stayed visible after losing the last distorder ship")
|
|
if not is_equal_approx(game_state.fleet_speed_multiplier, 1.0):
|
|
return _fail_now("multiplier was not reset after losing the distorder ship: %f" \
|
|
% game_state.fleet_speed_multiplier)
|
|
print("losing the distorder ship reset the multiplier and hid the fader")
|
|
|
|
print("TEST_SPACE_TIME_DISTORDER: PASS")
|
|
quit(0)
|
|
return true
|
|
return false
|
|
|
|
|
|
func _fail_now(message: String) -> bool:
|
|
print("TEST_SPACE_TIME_DISTORDER: FAIL (%s)" % message)
|
|
quit(1)
|
|
return true
|