spaceship/tests/test_ability_button_layout.gd
Loïc Wisniewski 1f5fecd371 Buy fleet berths with Fleet Offices
#219: fleet capacity is a built, supplied thing rather than a researched
one. The eight fleet-size doctrines are gone; capacity is one berth free
plus one per Fleet Office standing. An office charges every 25s for the
vessel in its berth, priced off that vessel's own build cost so an expensive
hull is expensive to keep, and drawn from its own store the way a gas burner
draws gas. An office that cannot pay goes dark, its vessel is scuttled, and
the player is told through the same queue quest lines use - which reaches
them on a planet surface too.

An empty berth is idle rather than starved: an office is only failing while
there is something in it to fail, and holding it disabled would leave a
berth that could never be crewed and so could never be paid for again.

Ships have no hit points and a shield absorbs a hit wholesale, so the lost
vessel is scuttled rather than damaged - otherwise a shielded hull would
survive its own eviction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
2026-09-05 17:09:27 +02:00

94 lines
3.5 KiB
GDScript

extends SceneTree
# The three aimed abilities share one responsive quarter-circle layout around
# the fire stick in both playable scenes. This exercises the real space HUD;
# PlanetSurface carries the same layout node and is checked structurally.
var main: Node
var fleet: Node
var stage: int = 0
var elapsed: float = 0.0
func _initialize() -> void:
var state: Node = root.get_node("GameState")
state.reset_new_game()
state.intro_active = false
state.vessel_levels["unlock_laser"] = 1
state.vessel_levels["unlock_gas_bomber"] = 1
state.vessel_levels["unlock_distorder"] = 1
state.fleet_inventory.total_capacity = -1
state.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 500)
state.deposit_fleet_resource(GameState.RESOURCE_GAS, 500)
# #219: fleet capacity is built now - one berth free, one per Fleet
# Office. This test flies more than one vessel, so it needs the offices
# standing before the fleet spawns into them.
load("res://tests/_berths.gd").grant(root.get_node("GameState"), 6)
main = load("res://world/Main.tscn").instantiate()
root.add_child(main)
current_scene = main
fleet = main.get_node("Fleet")
func _process(delta: float) -> bool:
elapsed += delta
if stage == 0 and elapsed >= 0.2:
main.get_node("EnemySpawner").set_process(false)
main.get_node("AsteroidField").set_process(false)
fleet.spawn_ships(3, Vector2.ZERO, PackedStringArray([
GameState.VESSEL_DISTORDER,
GameState.VESSEL_GAS_BOMBER,
GameState.VESSEL_LASER,
]))
_refresh_layout()
var layout: Node = main.get_node("AbilityButtonLayout")
var center: Vector2 = _fire_center()
var previous_angle: float = -INF
for path in ["UI/DashButton", "UI/GasBombButton", "UI/LaserButton"]:
var button: Control = main.get_node(path)
if not button.visible:
return _fail("%s is hidden in a fleet that provides every ability" % path)
var offset: Vector2 = button.global_position + button.size * 0.5 - center
if absf(offset.length() - layout.arc_radius) > 1.0 \
or offset.x > 0.1 or offset.y > 0.1:
return _fail("%s is not on the fire stick's upper-left quarter circle" % path)
var angle: float = offset.angle()
if angle < 0.0:
angle += TAU
if previous_angle != -INF and angle <= previous_angle:
return _fail("ability buttons do not follow the quarter-circle order")
previous_angle = angle
fleet.spawn_ships(1, Vector2.ZERO, PackedStringArray([GameState.VESSEL_LASER]))
_refresh_layout()
var laser: Control = main.get_node("UI/LaserButton")
var single_offset: Vector2 = laser.global_position + laser.size * 0.5 - _fire_center()
if absf(single_offset.x) > 1.0 or single_offset.y >= 0.0:
return _fail("a single ability does not sit directly above the fire stick")
var surface: Node = load("res://surface/PlanetSurface.tscn").instantiate()
if surface.get_node_or_null("AbilityButtonLayout") == null:
return _fail("planet surface is missing the shared ability layout")
surface.free()
print("abilities fan through the fire stick's upper-left quarter circle")
print("TEST_ABILITY_BUTTON_LAYOUT: PASS")
quit(0)
return true
return false
func _refresh_layout() -> void:
main.get_node("DashController")._process(0.0)
main.get_node("GasBombController")._process(0.0)
main.get_node("LaserController")._process(0.0)
main.get_node("AbilityButtonLayout")._process(0.0)
func _fire_center() -> Vector2:
var stick: Control = main.get_node("UI/FireStick")
return stick.global_position + stick.size * 0.5
func _fail(message: String) -> bool:
print("TEST_ABILITY_BUTTON_LAYOUT: FAIL (%s)" % message)
quit(1)
return true