spaceship/tests/test_gas_bomber_ammo.gd

150 lines
5.7 KiB
GDScript3
Raw Normal View History

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_gas_bomber_ammo.gd
# Forgejo #60: gas bomb shots draw ammunition from the FLEET HOLD
# (GameState.fleet_inventory), not the bank - the fleet has to be carrying
# its own gas.
#
# Covers:
# A. gas sitting in the bank does not enable firing - only the fleet
# hold counts
# B. with insufficient fleet gas the button is disabled, pressing it
# explains why, and no projectile is created / no cooldown consumed
# C. firing drains exactly GAS_PER_SHOT from the fleet hold and nothing
# from the bank
var game_state: Node
var main: Node
var fleet: Node
var skill: Node
var bomber_component: Node
var stage: int = 0
var elapsed: float = 0.0
# Mirrors GasBombController.GAS_PER_SHOT's value rather than referencing
# the class constant directly - a bare ClassName.CONST reference elsewhere
# in a test
# script has been observed to corrupt method resolution for the WHOLE
# script (an unrelated skill._process() call earlier in the same file then
# fails with "Nonexistent function '_process' in base 'Nil'"), root cause
# unconfirmed. See tests/test_gas_bomber_cooldowns.gd's identical fix.
const GAS_PER_SHOT: int = 5
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_gas_bomber"] = 1
game_state.rocks = 0
game_state.gas = 0
game_state.fleet_gas_cargo = 0
#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()
root.add_child(main)
fleet = main.get_node("Fleet")
skill = main.get_node("GasBombController")
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)
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 are shootable now, and the laser and the bomb both
# sweep them alongside enemies - so whatever the field already
# spawned would be counted as a hit. Silencing the spawner is not
# enough; what it placed before that has to go too. Same
# clean-slate idiom as test_ship_lab.gd.
for hazard in get_nodes_in_group("asteroids"):
if is_instance_valid(hazard):
hazard.free()
# An interceptor rides along purely for its "cargo" capability
# (#56): a fleet made only of a gas bomber has zero cargo
# capacity, which would silently clamp every fleet_gas_cargo
# assignment below to 0.
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_GAS_BOMBER]))
bomber_component = fleet.ships[1].get_component("gas_bomber")
skill._process(0.0)
# --- A. bank gas does not count -----------------------------------
game_state.gas = 500
game_state.fleet_gas_cargo = 0
skill._process(0.0)
if skill.button.enabled:
return _fail_now("500 banked gas (0 in the fleet hold) left the control enabled")
print("500 banked gas, 0 fleet gas: control correctly disabled")
# --- B. insufficient fleet gas --------------------------------------
game_state.fleet_gas_cargo = GAS_PER_SHOT - 1
skill._process(0.0)
if skill.button.enabled:
return _fail_now("fleet gas one short of GAS_PER_SHOT left the control enabled")
var press := InputEventScreenTouch.new()
press.index = 3
press.position = skill.button.global_position + skill.button.size * 0.5
press.pressed = true
main._handle_touch(press)
if skill.aiming:
return _fail_now("aiming began despite insufficient fleet gas")
if skill.status.text == "":
return _fail_now("an unaffordable press did not explain itself")
print("insufficient fleet gas: disabled, press explains itself, no aiming began")
if not bomber_component.is_ready():
return _fail_now("a refused press consumed the bomber's cooldown")
if game_state.fleet_resource(GameState.RESOURCE_GAS) != GAS_PER_SHOT - 1:
return _fail_now("a refused press spent fleet gas anyway")
print("no cooldown consumed, no gas spent on a refused press")
# --- C. exact ammo cost on a real shot ------------------------------
game_state.fleet_gas_cargo = GAS_PER_SHOT + 7
skill._process(0.0)
if not skill.button.enabled:
return _fail_now("enough fleet gas still left the control disabled")
var press2 := InputEventScreenTouch.new()
press2.index = 4
press2.position = skill.button.global_position + skill.button.size * 0.5
press2.pressed = true
main._handle_touch(press2)
if not skill.aiming:
return _fail_now("an affordable press did not begin aiming")
var drag := InputEventScreenDrag.new()
drag.index = 4
drag.position = press2.position + Vector2(-300.0, 0.0)
main._handle_drag(drag)
var release := InputEventScreenTouch.new()
release.index = 4
release.position = drag.position
release.pressed = false
main._handle_touch(release)
if skill.projectiles.size() != 1:
return _fail_now("a paid-for shot did not launch a projectile")
if bomber_component.is_ready():
return _fail_now("firing did not consume the bomber's cooldown")
if game_state.fleet_resource(GameState.RESOURCE_GAS) != 7:
return _fail_now("fleet gas after firing is %d, expected 7 (paid exactly %d)" \
% [game_state.fleet_resource(GameState.RESOURCE_GAS), GAS_PER_SHOT])
if game_state.gas != 500:
return _fail_now("firing touched the bank (%d), expected it untouched at 500" % game_state.gas)
print("firing drained exactly %d from the fleet hold, bank untouched" % GAS_PER_SHOT)
print("TEST_GAS_BOMBER_AMMO: PASS")
quit(0)
return true
return false
func _fail_now(message: String) -> bool:
print("TEST_GAS_BOMBER_AMMO: FAIL (%s)" % message)
quit(1)
return true