spaceship/tests/test_fleet_agility.gd
Loïc Wisniewski 8ba2cca6b6 Sharpen fleet handling, widen the laser, and fix the map editor's file identity
The fleet had a second of inertia in it: every vessel's acceleration sat at
roughly its own top speed, so flipping the stick while cruising took 0.58s to
take effect and let go coasted 222 units, while the formation anchor the ships
chase turns instantly. Acceleration is now ~3x top speed, chosen by measuring
rather than taste - past 3x the reversal time stops improving because
max_speed becomes the limit. Measured after: 0.18s and 23 units.
test_fleet_agility guards all three numbers and proves the bounds discriminate
by re-running the same measurement at the old value.

The laser reaches 1450 instead of 950 and strikes 38 units either side instead
of 22. Its drawn width is now derived from the hit width: the two were
independent numbers that had drifted, so the beam killed things it visibly
missed. LaserController's aim range also stopped hardcoding a second copy of
950. Tapping the laser button without dragging used to do nothing at all - the
press was claimed, the aim begun, then thrown away on release. It now fires at
the nearest enemy in range; dragging still aims precisely. That lives in the
shared aimed-ability controller, so the gas bomb gains it too.

Planets sat one per ~29 chunks - some 35,000 units of nothing between them.
Now one per ~12, measured over 14,641 chunks. The two thresholds moved by
different amounts deliberately: every SPACE-biome planet is a gas giant, so
lowering both equally would have tripled the gas-giant share as well. This
changes how often you find a planet, not what you find. Extractors produce
half as fast to match, so expanding is what grows the economy.

The research screen gave its tree 386px of 1280 and the text below it 520.
The text is now at the bottom, the tree has 550, and the resource table has
room and legible type - and its LOCAL column is no longer hidden behind the
close button.

Two map-editor bugs turned out to be one cause: a setup's id and its FILENAME
are not the same thing, and both save and delete rebuilt the path from the id.
ResearchLabSetup.tres holds setup_id "research_lab_1", so deleting it looked
for a file that does not exist and silently refused - which read as "the first
item in the list cannot be deleted" - while saving it wrote a second file
under the derived name and left the original behind, so the pool served the
stale twin. A third bug hid behind those: rescan() re-read through Godot's
resource cache and handed back pre-save values even when the file on disk was
correct. All three present to a player as "my change was not saved".

Research labs no longer grant a point of their own; what conquering one is
worth comes entirely from its authored map, as asked. The shipped lab map
carries 1 so the balance is unchanged - only where it is configured moved.

Suite 109/109. Four tests changed because the behaviour they pinned changed:
the joystick coast is now derived from cruise_speed^2/(2*acceleration) rather
than a constant tuned to one acceleration; the extractor wait derives from
EXTRACTOR_RATE; the research-point test asserts the delegation; and the black
hole test no longer assumes nobody will ever author a void-profile map.
test_planet_setups and test_planet_map_assignment stopped depending on which
maps happen to be in the content folder, which was making them fail when maps
were added or deleted elsewhere.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:55:11 +02:00

184 lines
6.3 KiB
GDScript

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_fleet_agility.gd
# The fleet handled with too much inertia: flipping the stick left while
# cruising right took most of a second to take effect, and letting go coasted
# the ships several lengths further.
#
# The cause was every vessel's acceleration sitting at roughly its own top
# speed - a time constant of about a second to change velocity at all, while
# the formation anchor the ships chase turns instantly. Acceleration is now
# ~3x top speed, measured rather than guessed: past 3x the reversal time stops
# improving, because max_speed becomes the limit instead of acceleration.
#
# Feel is not directly assertable, but the three things that PRODUCE it are,
# so this measures them:
# A. how long after the stick reverses before a ship is actually travelling
# the new way
# B. how far past the turn it drifts first
# C. how far it coasts after the stick is released
#
# Plus D: the same measurement at the OLD acceleration must BREACH these
# bounds. Without that, quietly restoring the sluggish handling would still
# pass, and so would bounds so loose they mean nothing.
#
# The bounds are roughly double what the tuned values measure. This suite runs
# several Godot processes at once on a phone, and a physics-timing measurement
# under that load strays (see the note in test_space_time_distorder.gd); real
# regression here means going back towards a second, which is far outside this
# margin.
const MAX_REVERSE_TIME: float = 0.35
const MAX_OVERSHOOT: float = 45.0
const MAX_STOP_COAST: float = 60.0
# What the acceleration was before, as a fraction of what it is now.
const OLD_ACCELERATION_FRACTION: float = 1.0 / 3.0
var main: Node
var fleet: Node
var elapsed: float = 0.0
var stage: int = 0
var flip_x: float = 0.0
var reverse_time: float = -1.0
var overshoot: float = 0.0
var stop_x: float = 0.0
# Second pass re-runs the identical measurement with the old acceleration.
var measuring_old: bool = false
var tuned: Dictionary = {}
func _initialize() -> void:
var game_state: Node = root.get_node("GameState")
game_state.reset_progression()
main = load("res://Main.tscn").instantiate()
root.add_child(main)
current_scene = main
fleet = main.get_node("Fleet")
func _process(delta: float) -> bool:
elapsed += delta
match stage:
0:
if elapsed < 0.3:
return false
main.get_node("AsteroidField").set_process(false)
main.get_node("EnemySpawner").set_process(false)
# A rock or an enemy destroying the ship being measured would
# read as a handling failure. Same clean-slate idiom as
# test_space_time_distorder.gd.
for hazard in get_nodes_in_group("asteroids") + get_nodes_in_group("enemies"):
if is_instance_valid(hazard):
hazard.queue_free()
_begin_pass()
return false
1:
# Reach steady state travelling right before disturbing anything.
if elapsed < 2.0:
return false
if fleet.ships.is_empty():
return _fail("the fleet lost its ships before anything could be measured")
flip_x = fleet.ships[0].position.x
fleet.move_in_direction(Vector2(-1.0, 0.0))
stage = 2
elapsed = 0.0
return false
2:
var ship: Node2D = fleet.ships[0]
overshoot = maxf(overshoot, ship.position.x - flip_x)
if reverse_time < 0.0 and ship.velocity.x < 0.0:
reverse_time = elapsed
if elapsed < 2.0:
return false
if reverse_time < 0.0:
return _fail("the fleet never reversed at all within 2s of the stick flipping")
# Settle going one way again, so the coast below is measured from
# a steady cruise rather than mid-catch-up.
fleet.move_in_direction(Vector2(1.0, 0.0))
stage = 3
elapsed = 0.0
return false
3:
if elapsed < 2.0:
return false
stop_x = fleet.ships[0].position.x
fleet.stop()
stage = 4
elapsed = 0.0
return false
4:
if elapsed < 2.5:
return false
var result: Dictionary = {
"reverse_time": reverse_time,
"overshoot": overshoot,
"coast": fleet.ships[0].position.x - stop_x,
}
if not measuring_old:
tuned = result
if not _check_tuned(result):
return true
# --- D: the same measurement, sluggish again ----------------
measuring_old = true
_begin_pass()
return false
return _check_old_breaches(result)
return false
func _begin_pass() -> void:
reverse_time = -1.0
overshoot = 0.0
for ship in fleet.ships:
# apply_vessel_stats() has already put the definition's value on the
# ship, so the old handling is reproduced by scaling that field
# directly - no need to edit a resource mid-test.
if measuring_old:
ship.acceleration *= OLD_ACCELERATION_FRACTION
ship.position = Vector2.ZERO
ship.velocity = Vector2.ZERO
fleet.move_to(Vector2.ZERO)
fleet.move_in_direction(Vector2(1.0, 0.0))
stage = 1
elapsed = 0.0
func _check_tuned(r: Dictionary) -> bool:
print("tuned (acceleration %.0f): reversed in %.3fs, overshot %.1f, coasted %.1f" \
% [fleet.ships[0].acceleration, r.reverse_time, r.overshoot, r.coast])
if r.reverse_time > MAX_REVERSE_TIME:
return _fail("the fleet took %.3fs to obey a reversed stick (allowed %.2f)" \
% [r.reverse_time, MAX_REVERSE_TIME])
if r.overshoot > MAX_OVERSHOOT:
return _fail("the fleet drifted %.1f units past the turn (allowed %.1f)" \
% [r.overshoot, MAX_OVERSHOOT])
if r.coast > MAX_STOP_COAST:
return _fail("the fleet coasted %.1f units after the stick was released (allowed %.1f)" \
% [r.coast, MAX_STOP_COAST])
return true
func _check_old_breaches(r: Dictionary) -> bool:
print("old (acceleration %.0f): reversed in %.3fs, overshot %.1f, coasted %.1f" \
% [fleet.ships[0].acceleration, r.reverse_time, r.overshoot, r.coast])
var breaches: int = 0
if r.reverse_time > MAX_REVERSE_TIME:
breaches += 1
if r.overshoot > MAX_OVERSHOOT:
breaches += 1
if r.coast > MAX_STOP_COAST:
breaches += 1
if breaches == 0:
return _fail("the OLD, sluggish acceleration passed every bound too (reversed %.3fs, overshot %.1f, coasted %.1f) - these thresholds do not discriminate and would not catch a regression" \
% [r.reverse_time, r.overshoot, r.coast])
print("bounds discriminate: the old acceleration breaches %d of 3" % breaches)
print("TEST_FLEET_AGILITY: PASS")
quit(0)
return true
func _fail(message: String) -> bool:
print("TEST_FLEET_AGILITY: FAIL (%s)" % message)
quit(1)
return true