spaceship/tests/test_gas_bomber_cooldowns.gd

87 lines
3.2 KiB
GDScript3
Raw Normal View History

2026-08-15 10:12:33 +02:00
extends SceneTree
var main: Node
var fleet: Node
var skill: Node
2026-08-15 10:12:33 +02:00
var elapsed := 0.0
func _initialize() -> void:
var state: Node = root.get_node("GameState")
state.buildings.clear()
state.extractors.clear()
state.transporters.clear()
state.vessel_levels["unlock_gas_bomber"] = 1
# #60: shots draw from the fleet hold now - stock enough for both fires.
state.fleet_gas_cargo = 20
# #219: fleet capacity is built now - one berth free, one per Fleet
# Office. This test flies more than one vessel, so it needs the offices
# standing before the fleet spawns into them.
load("res://tests/_berths.gd").grant(root.get_node("GameState"), 6)
#84: move 215 root files into a folder hierarchy Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
main = load("res://world/Main.tscn").instantiate()
2026-08-15 10:12:33 +02:00
root.add_child(main)
fleet = main.get_node("Fleet")
skill = main.get_node("GasBombController")
func _process(delta: float) -> bool:
elapsed += delta
if elapsed < 0.2:
return false
main.get_node("EnemySpawner").set_process(false)
main.get_node("AsteroidField").set_process(false)
Asteroids can be shot apart for the ore inside them Asteroids were pure hazard: the only thing one could ever do was cost you a ship. They now take damage like anything else and break open, dropping ore the fleet can fly over and collect - the one resource reachable in open space without conquering anything, and something for the new fire stick to do out there. Two ways to destroy one, deliberately not equivalent. Shot apart yields the ore; flown into does not - the rock shatters against a hull rather than being mined, and a ship or a shield charge has just been spent on it. Without that split a shield vessel could farm asteroids by ramming them. Asteroid.take_damage() matches Enemy's contract exactly, so every weapon that already knew how to hurt an enemy hurts an asteroid through the same branch rather than a second special case: bolts, the laser sweep, and the gas bomb's blast all pick both groups up together. Dropped ore carries the asteroid's own drift, so it reads as debris rather than as a spawned pickup, and it expires after a minute. Rock grew an optional lifetime for that, defaulting to 0 (never) so hand-placed surface rocks are unchanged - a planet surface is bounded and authored, open space is not, and a field shot up and abandoned would otherwise leak nodes for the session. Rock's header note that asteroids and rocks are never on screen together is no longer true and now says so; the hexagon-versus-lump shape language matters more now that they sit side by side, not less. Five weapon tests silenced the asteroid field but never cleared what it had already placed. That was harmless while asteroids were untouchable and is not any more - two of them assert exact hit counts, and a drifting rock in the beam would have made those fail intermittently. Suite 111/111. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 10:27:40 +02:00
# Asteroids take damage now, so anything the field already placed
# would soak a bomb meant for the enemies under test.
for hazard in get_nodes_in_group("asteroids"):
if is_instance_valid(hazard):
hazard.free()
2026-08-15 10:12:33 +02:00
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
GameState.VESSEL_GAS_BOMBER, GameState.VESSEL_GAS_BOMBER]))
skill._process(0.0)
var first: Node = fleet.ships[0].get_component("gas_bomber")
var second: Node = fleet.ships[1].get_component("gas_bomber")
if not first.is_ready() or not second.is_ready() or not skill.button.enabled:
return _fail("two fresh bombers did not each begin ready")
skill.aim_target = Vector2(500, 0)
skill._fire()
skill._process(0.0)
if first.is_ready() or not second.is_ready() or not skill.button.enabled:
return _fail("the first shot disabled more than its firing bomber")
# _filled_hull returns a LIST of polygons: a notched hull fills as two
# separate puddles until the level rises past the notch, and the gas
# bomber's tail is exactly such a notch.
var hull: PackedVector2Array = fleet.ships[0].definition.hull_points
var empty: Array = first._filled_hull(hull, 0.0)
var half: Array = first._filled_hull(hull, 0.5)
var half_points: int = 0
for piece in half:
half_points += piece.size()
if not empty.is_empty() or half_points < 3:
2026-08-15 10:41:24 +02:00
return _fail("bomber cooldown did not produce an empty-to-filling hull")
2026-08-15 10:12:33 +02:00
if skill.projectiles.size() != 1:
return _fail("the first bomber did not launch exactly one projectile")
skill.aim_target = Vector2(-500, 0)
skill._fire()
skill._process(0.0)
if first.is_ready() or second.is_ready() or skill.button.enabled:
return _fail("the skill stayed available after both bombers fired")
if skill.projectiles.size() != 2:
return _fail("independent bombers could not have shots in flight together")
# Rearming one bomber restores one available shot without touching the
# other bomber's cooldown.
first.tick(5.0) # matches GasBombController.COOLDOWN
2026-08-15 10:12:33 +02:00
skill._process(0.0)
if not first.is_ready() or second.is_ready() or not skill.button.enabled:
return _fail("one completed cooldown did not restore exactly one shot")
print("TEST_GAS_BOMBER_COOLDOWNS: PASS")
quit(0)
return true
func _fail(message: String) -> bool:
print("TEST_GAS_BOMBER_COOLDOWNS: FAIL (%s)" % message)
quit(1)
return true