Gas bombers consume gas from the fleet hold when firing (#60)
Shots cost GAS_PER_SHOT (5) from GameState.fleet_inventory, not the bank - the fleet has to be carrying its own ammunition. The button's enabled rule now also requires affordability, and a press on a ready- but-unaffordable bomber still consumes the touch to explain itself via a new status label (GasBombStatus, IconButton's own "greyed but still pressable" convention) rather than either silently doing nothing or consuming the bomber's cooldown for a shot that never fires. Also documents a real, reproducible GDScript trap hit while writing tests/test_gas_bomber_ammo.gd: a bare `ClassName.SOME_CONST` reference anywhere in a -s entry test script can corrupt method resolution for the WHOLE script, making an unrelated, earlier `some_node._process()` call fail with "Nonexistent function '_process' in base 'Nil'" despite the node being valid and the method existing (confirmed via has_method()). Root cause unconfirmed; fixed by mirroring the constant 's value into a local const instead of referencing the class directly, in all three gas-bomber tests. tests/test_gas_bomber.gd and test_gas_bomber_cooldowns.gd updated to stock fleet gas first, since shots are no longer free.
This commit is contained in:
parent
116e0f97d3
commit
17d0cf7e66
8 changed files with 230 additions and 9 deletions
|
|
@ -3,7 +3,10 @@ extends SceneTree
|
|||
var game_state: Node
|
||||
var main: Node
|
||||
var fleet: Node
|
||||
var skill: GasBombController
|
||||
var skill: Node
|
||||
# Mirrors GasBombController.AOE_RADIUS's value rather than referencing the
|
||||
# class constant directly - see test_gas_bomber_cooldowns.gd's identical fix.
|
||||
const AOE_RADIUS_FOR_TEST: float = 180.0
|
||||
var inside_enemies: Array = []
|
||||
var outside_enemy: Node
|
||||
var stage := 0
|
||||
|
|
@ -24,6 +27,9 @@ func _initialize() -> void:
|
|||
game_state.fleet_cargo = 0
|
||||
game_state.fleet_gas_cargo = 0
|
||||
game_state.build_time_scale = 0.01
|
||||
# #60: after research/crafting resets the fleet hold below, top it up
|
||||
# with fleet-carried gas for the shot itself (ammunition, not the ore/gas
|
||||
# spent researching or crafting the bomber).
|
||||
|
||||
# Research is gas-only: any amount of ore and 29 gas must still leave it
|
||||
# waiting, then the thirtieth unit starts and completes the unlock.
|
||||
|
|
@ -69,6 +75,7 @@ func _initialize() -> void:
|
|||
_fail_now("crafting did not produce a typed Gas Bomber")
|
||||
return
|
||||
|
||||
game_state.fleet_gas_cargo = 20
|
||||
main = load("res://Main.tscn").instantiate()
|
||||
root.add_child(main)
|
||||
fleet = main.get_node("Fleet")
|
||||
|
|
@ -117,7 +124,7 @@ func _process(delta: float) -> bool:
|
|||
enemy.speed = 0.0
|
||||
inside_enemies.append(enemy)
|
||||
outside_enemy = load("res://Enemy.tscn").instantiate()
|
||||
outside_enemy.position = skill.aim_target + Vector2(GasBombController.AOE_RADIUS + 80.0, 0)
|
||||
outside_enemy.position = skill.aim_target + Vector2(AOE_RADIUS_FOR_TEST + 80.0, 0)
|
||||
main.add_child(outside_enemy)
|
||||
outside_enemy.speed = 0.0
|
||||
|
||||
|
|
|
|||
142
tests/test_gas_bomber_ammo.gd
Normal file
142
tests/test_gas_bomber_ammo.gd
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
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
|
||||
main = load("res://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)
|
||||
# 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
|
||||
|
|
@ -2,7 +2,7 @@ extends SceneTree
|
|||
|
||||
var main: Node
|
||||
var fleet: Node
|
||||
var skill: GasBombController
|
||||
var skill: Node
|
||||
var elapsed := 0.0
|
||||
|
||||
|
||||
|
|
@ -12,6 +12,8 @@ func _initialize() -> void:
|
|||
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
|
||||
main = load("res://Main.tscn").instantiate()
|
||||
root.add_child(main)
|
||||
fleet = main.get_node("Fleet")
|
||||
|
|
@ -53,7 +55,7 @@ func _process(delta: float) -> bool:
|
|||
|
||||
# Rearming one bomber restores one available shot without touching the
|
||||
# other bomber's cooldown.
|
||||
first.tick(GasBombController.COOLDOWN)
|
||||
first.tick(5.0) # matches GasBombController.COOLDOWN
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
uid://cwo6ake5taias
|
||||
Loading…
Reference in a new issue