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
|
|
@ -104,6 +104,12 @@ func fleet_resource(resource_type: String) -> int:
|
|||
return fleet_inventory.amount(resource_type)
|
||||
|
||||
|
||||
# #60: consumed outright (ammunition), not moved to another inventory like
|
||||
# transfer_resource_to_building/_fleet - returns the amount actually taken.
|
||||
func withdraw_fleet_resource(resource_type: String, amount: int) -> int:
|
||||
return fleet_inventory.withdraw(resource_type, amount)
|
||||
|
||||
|
||||
# #56: total across every resource type in the hold, and the combined cap
|
||||
# that limits it - a HUD readout wants both, not any one resource's amount.
|
||||
func fleet_cargo_used() -> int:
|
||||
|
|
|
|||
|
|
@ -10,11 +10,17 @@ const AIM_DEADZONE := 22.0
|
|||
const PROJECTILE_SPEED := 720.0
|
||||
const DAMAGE := 3
|
||||
const COOLDOWN := 5.0
|
||||
# #60: ammunition from the fleet hold, not the bank - the fleet has to be
|
||||
# carrying its own gas to fire.
|
||||
const GAS_PER_SHOT: int = 5
|
||||
|
||||
@export var minimum_zoom: float = 0.4
|
||||
@onready var fleet: Node2D = get_node("../Fleet")
|
||||
@onready var camera: Camera2D = get_node("../Camera2D")
|
||||
@onready var button: IconButton = get_node("../UI/GasBombButton")
|
||||
@onready var status: Label = get_node("../UI/GasBombStatus")
|
||||
|
||||
var status_message_until: int = 0
|
||||
|
||||
var aiming := false
|
||||
var aim_touch := -1
|
||||
|
|
@ -40,15 +46,27 @@ var explosion_time: float:
|
|||
|
||||
func _ready() -> void:
|
||||
button.visible = false
|
||||
status.text = ""
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _can_afford_shot() -> bool:
|
||||
return GameState.fleet_resource(GameState.RESOURCE_GAS) >= GAS_PER_SHOT
|
||||
|
||||
|
||||
func _say(message: String) -> void:
|
||||
status.text = message
|
||||
status_message_until = Time.get_ticks_msec() + 3000
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var had_visuals := aiming or not projectiles.is_empty() or not explosions.is_empty()
|
||||
button.visible = fleet.has_capability("gas_bomber")
|
||||
button.enabled = _next_ready_bomber() != null
|
||||
button.enabled = _next_ready_bomber() != null and _can_afford_shot()
|
||||
if not button.visible and aiming:
|
||||
_cancel_aim()
|
||||
if status.text != "" and Time.get_ticks_msec() >= status_message_until:
|
||||
status.text = ""
|
||||
|
||||
if restoring_zoom and not aiming:
|
||||
var z := move_toward(camera.zoom.x, saved_zoom, maxf(saved_zoom, 0.1) * delta * 5.0)
|
||||
|
|
@ -81,14 +99,23 @@ func _process(delta: float) -> void:
|
|||
|
||||
|
||||
func can_begin_aim() -> bool:
|
||||
return button.visible and button.enabled and not button._blocked_by_modal() \
|
||||
and not aiming
|
||||
# Deliberately NOT button.enabled: an unaffordable shot still needs the
|
||||
# press to reach here so it can explain itself (IconButton's own "greyed
|
||||
# but still pressable" convention) rather than the touch silently
|
||||
# falling through to whatever's behind it. A wholly unready fleet (no
|
||||
# bomber at all) has nothing more useful to say than "greyed out".
|
||||
return button.visible and not button._blocked_by_modal() \
|
||||
and not aiming and _next_ready_bomber() != null
|
||||
|
||||
|
||||
func handle_touch(event: InputEventScreenTouch) -> bool:
|
||||
if event.pressed:
|
||||
if not can_begin_aim() or not Rect2(button.global_position, button.size).has_point(event.position):
|
||||
return false
|
||||
if not _can_afford_shot():
|
||||
_say("Need %d gas in the fleet hold to fire (have %d)" \
|
||||
% [GAS_PER_SHOT, GameState.fleet_resource(GameState.RESOURCE_GAS)])
|
||||
return true
|
||||
aiming = true
|
||||
aim_touch = event.index
|
||||
aim_start_screen = event.position
|
||||
|
|
@ -156,17 +183,23 @@ func _fire() -> void:
|
|||
if bomber == null:
|
||||
_cancel_aim()
|
||||
return
|
||||
if not _can_afford_shot():
|
||||
_say("Need %d gas in the fleet hold to fire (have %d)" \
|
||||
% [GAS_PER_SHOT, GameState.fleet_resource(GameState.RESOURCE_GAS)])
|
||||
_cancel_aim()
|
||||
return
|
||||
var component: Node = bomber.get_component("gas_bomber")
|
||||
if not component.consume_shot(COOLDOWN):
|
||||
_cancel_aim()
|
||||
return
|
||||
GameState.withdraw_fleet_resource(GameState.RESOURCE_GAS, GAS_PER_SHOT)
|
||||
projectiles.append({
|
||||
"position": bomber.global_position,
|
||||
"target": aim_target,
|
||||
"trail": PackedVector2Array([bomber.global_position]),
|
||||
})
|
||||
_finish_aim()
|
||||
button.enabled = _next_ready_bomber() != null
|
||||
button.enabled = _next_ready_bomber() != null and _can_afford_shot()
|
||||
|
||||
|
||||
func _next_ready_bomber() -> Node2D:
|
||||
|
|
|
|||
16
Main.tscn
16
Main.tscn
|
|
@ -287,6 +287,22 @@ script = ExtResource("10")
|
|||
icon = 32
|
||||
glow_color = Color(0.96, 0.22, 0.72, 1)
|
||||
|
||||
[node name="GasBombStatus" type="Label" parent="UI"]
|
||||
mouse_filter = 2
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -344
|
||||
offset_right = -24
|
||||
offset_top = -480
|
||||
offset_bottom = -430
|
||||
theme_override_font_sizes/font_size = 18
|
||||
theme_override_colors/font_color = Color(0.96, 0.22, 0.72, 1)
|
||||
autowrap_mode = 2
|
||||
horizontal_alignment = 1
|
||||
text = ""
|
||||
|
||||
[node name="PivotCWButton" type="Control" parent="UI"]
|
||||
mouse_filter = 2
|
||||
anchor_left = 1.0
|
||||
|
|
|
|||
|
|
@ -229,6 +229,22 @@ icon = 32
|
|||
glow_color = Color(0.82, 0.08, 0.48, 1)
|
||||
core_color = Color(0.02, 0.09, 0.15, 1)
|
||||
|
||||
[node name="GasBombStatus" type="Label" parent="UI"]
|
||||
mouse_filter = 2
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -344
|
||||
offset_right = -24
|
||||
offset_top = -480
|
||||
offset_bottom = -430
|
||||
theme_override_font_sizes/font_size = 18
|
||||
theme_override_colors/font_color = Color(0.82, 0.08, 0.48, 1)
|
||||
autowrap_mode = 2
|
||||
horizontal_alignment = 1
|
||||
text = ""
|
||||
|
||||
[node name="PivotCWButton" type="Control" parent="UI"]
|
||||
mouse_filter = 2
|
||||
anchor_left = 1.0
|
||||
|
|
|
|||
|
|
@ -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