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>
149 lines
5.9 KiB
GDScript
149 lines
5.9 KiB
GDScript
extends SceneTree
|
|
|
|
# Headless gameplay test: run with
|
|
# godot --headless -s res://tests/test_laser_ammo.gd
|
|
# Forgejo #61: laser shots draw ammunition from the FLEET HOLD
|
|
# (GameState.fleet_inventory), the same way gas bomb shots do (#60) - the
|
|
# fleet has to be carrying its own energy.
|
|
#
|
|
# Covers:
|
|
# A. banked energy does not enable firing - only the fleet hold counts
|
|
# B. with insufficient fleet energy the button is disabled, pressing it
|
|
# explains why, and no beam is fired / no cooldown consumed
|
|
# C. firing drains exactly ENERGY_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 laser_component: Node
|
|
var stage: int = 0
|
|
var elapsed: float = 0.0
|
|
|
|
# Mirrors LaserController.ENERGY_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 (#60).
|
|
const ENERGY_PER_SHOT: int = 8
|
|
|
|
|
|
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_laser"] = 1
|
|
game_state.rocks = 0
|
|
game_state.gas = 0
|
|
game_state.fleet_gas_cargo = 0
|
|
main = load("res://Main.tscn").instantiate()
|
|
root.add_child(main)
|
|
fleet = main.get_node("Fleet")
|
|
skill = main.get_node("LaserController")
|
|
|
|
|
|
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 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 laser ship has zero cargo
|
|
# capacity, which would silently clamp every fleet energy
|
|
# deposit below to 0.
|
|
fleet.spawn_ships(2, Vector2.ZERO, PackedStringArray([
|
|
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_LASER]))
|
|
laser_component = fleet.ships[1].get_component("laser")
|
|
skill._process(0.0)
|
|
|
|
# --- A. bank energy does not count ----------------------------
|
|
game_state.deposit_bank_resource(GameState.RESOURCE_ENERGY, 500)
|
|
skill._process(0.0)
|
|
if skill.button.enabled:
|
|
return _fail_now("500 banked energy (0 in the fleet hold) left the control enabled")
|
|
print("500 banked energy, 0 fleet energy: control correctly disabled")
|
|
|
|
# --- B. insufficient fleet energy -------------------------------
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, ENERGY_PER_SHOT - 1)
|
|
skill._process(0.0)
|
|
if skill.button.enabled:
|
|
return _fail_now("fleet energy one short of ENERGY_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 energy")
|
|
if skill.status.text == "":
|
|
return _fail_now("an unaffordable press did not explain itself")
|
|
print("insufficient fleet energy: disabled, press explains itself, no aiming began")
|
|
if not laser_component.is_ready():
|
|
return _fail_now("a refused press consumed the laser ship's cooldown")
|
|
if game_state.fleet_resource(GameState.RESOURCE_ENERGY) != ENERGY_PER_SHOT - 1:
|
|
return _fail_now("a refused press spent fleet energy anyway")
|
|
print("no cooldown consumed, no energy spent on a refused press")
|
|
|
|
# --- C. exact ammo cost on a real shot -----------------------------
|
|
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 8)
|
|
skill._process(0.0)
|
|
if not skill.button.enabled:
|
|
return _fail_now("enough fleet energy still left the control disabled")
|
|
var fleet_energy_before: int = game_state.fleet_resource(GameState.RESOURCE_ENERGY)
|
|
|
|
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 laser_component.is_ready():
|
|
return _fail_now("firing did not consume the laser ship's cooldown")
|
|
var fleet_energy_after: int = game_state.fleet_resource(GameState.RESOURCE_ENERGY)
|
|
if fleet_energy_before - fleet_energy_after != ENERGY_PER_SHOT:
|
|
return _fail_now("firing spent %d fleet energy, expected exactly %d" \
|
|
% [fleet_energy_before - fleet_energy_after, ENERGY_PER_SHOT])
|
|
if game_state.banked_resource(GameState.RESOURCE_ENERGY) != 500:
|
|
return _fail_now("firing touched the bank (%d), expected it untouched at 500" \
|
|
% game_state.banked_resource(GameState.RESOURCE_ENERGY))
|
|
print("firing drained exactly %d from the fleet hold, bank untouched" % ENERGY_PER_SHOT)
|
|
|
|
print("TEST_LASER_AMMO: PASS")
|
|
quit(0)
|
|
return true
|
|
return false
|
|
|
|
|
|
func _fail_now(message: String) -> bool:
|
|
print("TEST_LASER_AMMO: FAIL (%s)" % message)
|
|
quit(1)
|
|
return true
|