Laser shooters consume energy from the fleet hold when firing (#61)

Mirrors #60's gas bomber ammunition exactly: ENERGY_PER_SHOT (8) drawn
from GameState.fleet_inventory before consuming the firing ship's
cooldown, the button's enabled rule requires affordability too, and an
unaffordable-but-otherwise-ready press still explains itself through a
new LaserStatus label rather than silently doing nothing.

Added two small generic GameState helpers this needed:
deposit_fleet_resource()/deposit_bank_resource(), counterparts to
#60's withdraw_fleet_resource() for resources (energy) with no
dedicated fleet_cargo/fleet_gas_cargo-style property. Along the way,
confirmed deposit_resource_to_building() on a "bank" building deposits
into that building's own per-record inventory, NOT bank_inventory
itself - only building_resource()/building_inventory() special-case
the "bank" capability to redirect there.

test_laser_vessel.gd (#58) updated to stock fleet energy first, since
shots are no longer free - same fix #60 required for the gas bomber's
own pre-existing tests. Also fixed test_laser_vessel.gd's own instance
of the bare-ClassName.CONST script-corruption trap (documented in
#60's commit): var skill: LaserController and a bare
LaserController.BEAM_HALF_WIDTH reference, mirrored into a local const
instead.
This commit is contained in:
Loïc Wisniewski 2026-08-16 19:11:31 +02:00
commit facbd83dd2
6 changed files with 236 additions and 6 deletions

View file

@ -20,7 +20,12 @@ extends SceneTree
var game_state: Node
var main: Node
var fleet: Node
var skill: LaserController
var skill: Node
# Mirrors LaserController.BEAM_HALF_WIDTH'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. See tests/test_gas_bomber_cooldowns.gd's identical fix (#60).
const BEAM_HALF_WIDTH: float = 22.0
var on_line_enemies: Array = []
var off_line_enemy: Node
var beyond_range_enemy: Node
@ -42,6 +47,13 @@ func _initialize() -> void:
# this ticket is about the laser's own behaviour, not re-proving the
# ship-lab research flow (already covered generically elsewhere).
game_state.vessel_levels["unlock_laser"] = 1
# #61: shots draw energy from the fleet hold now - stock enough for two
# fires. 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 (#56's cap is only computed once a
# fleet composition exists), so this deposit can't be clamped by the
# soon-to-exist all-laser fleet having zero "cargo" capability.
game_state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 20)
main = load("res://Main.tscn").instantiate()
root.add_child(main)
fleet = main.get_node("Fleet")
@ -106,7 +118,7 @@ func _process(delta: float) -> bool:
off_line_enemy = load("res://Enemy.tscn").instantiate()
off_line_enemy.position = first_shooter.global_position \
+ Vector2(200.0, LaserController.BEAM_HALF_WIDTH + 60.0)
+ Vector2(200.0, BEAM_HALF_WIDTH + 60.0)
main.add_child(off_line_enemy)
off_line_enemy.speed = 0.0