spaceship/vessels/Fleet.gd

388 lines
14 KiB
GDScript3
Raw Normal View History

extends Node2D
# Formation slots come from GameState.formation (editable at a command
# centre) rather than being fixed here, so a layout the player arranged
# survives scene swaps and fleet rebuilds. Ships are always
# spawned programmatically (spawn_ships), using however many of these
# offsets are needed. The optional vessel-type list preserves the exact
# mixed fleet through scene swaps; a fresh start still defaults each slot
# to an interceptor.
# The fleet's cruise speed. This is the speed of the FLEET as a whole: the
# anchor below advances at exactly this rate, and individual ships are
# allowed to fly faster than it (Ship.max_speed) so they can close on their
# formation slot - which is what makes a pivot while under way look sharp
# instead of sluggish.
Implement #85, #86, #87 and #88 #85 - on a computer the sticks and the pivot pair are dead weight: WASD steers, the mouse aims, Q/E pivot. All four go together the first time a keyboard or a mouse is used, and only where there is no touchscreen. A touch device with a keyboard attached keeps everything, because a finger is still a way to play it. #86 - the default gun shoots faster (500 -> 850) and further (320 -> 620). The interesting half is that a bolt now STOPS where the gun's range ends. Projectile lifetime is derived from fire_range at launch rather than set independently, so the distance a shot covers and the distance the aim guide draws are one number. They were two, and they disagreed: the guide promised 320 while a bolt actually flew speed * lifetime = 750, so shots landed on things well past the line saying where they would stop. #87 - the ship that fires throws sparks, so a shot is visibly attached to the vessel it came from; with a whole fleet shooting there was nothing tying the two together, which started mattering once the player had to aim. Enemy deaths gained a shockwave ring and roughly double the debris - a kill used to read as a small red puff that was easy to miss in a fight. #88 - everything moves 1.5x faster: fleet cruise, every vessel's max_speed and acceleration, and every enemy's. Scaling the enemies too keeps it a change of TEMPO rather than a difficulty cut, and scaling acceleration alongside speed keeps the handling from #77's tuning intact. Three tests carried assertions that were really about one balance pass: test_enemy_mothership pinned a literal 35.0 and now compares against the chaser, which is what "never reaches ramming speed" actually means; test_planet_atmosphere_transition flew far enough at the new speed to reach the landed garrison, and now clears it, since that test is about the handoff and not about a fight it never meant to pick. Also repaired real data loss, caught only because test_gas_burner failed: Godot had silently re-serialised GasBurnerBuildingDefinition.tres and dropped collected_outputs, capabilities, map_radius and map_phase, and had recreated a stale copy of it at the pre-#84 root path. Without collected_outputs no transporter ever collects a burner's energy. Both files restored from git. It had also resurrected pre-#84 SNAPSHOTS of Main.tscn, Planet.tscn and lunar_surface.gdshader at their old root paths - the root Main.tscn still carried 27 references to the flat layout. They are dead weight the engine never loads, since project.godot and every preload point into the folders, but they are exactly the kind of thing that wastes an hour later when someone edits the wrong copy. Deleted, and the root is now down to ui_theme.tres, icon.svg, web_shell.html and the two config files. Suite 119/119. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 02:19:14 +02:00
# #88: the whole game moves 1.5x faster. This is the figure the pace is
# actually set by - vessel max_speed and acceleration were scaled with it,
# and so were the enemies, so it is a change of TEMPO rather than a
# difficulty cut.
@export var cruise_speed: float = 390.0
# Per-scene neon palette for the fleet. PlanetSurface.tscn overrides these
# with darker values, since the lunar surface is bright grey and the default
# near-white core would wash out against it. See NeonDraw.
@export var ship_glow_color: Color = Color(0.25, 0.85, 1.0)
@export var ship_core_color: Color = Color(1.0, 1.0, 1.0)
#84: move 215 root files into a folder hierarchy Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:44:14 +02:00
var ship_scene: PackedScene = preload("res://vessels/Ship.tscn")
var ships: Array = []
var formation_offsets: Array = []
var fleet_target: Vector2 = Vector2.ZERO
# Formation centre while under joystick steering, and the heading it is
# travelling along. Zero heading means the fleet is not being steered.
var anchor: Vector2 = Vector2.ZERO
var steer_direction: Vector2 = Vector2.ZERO
2026-09-02 13:43:56 +02:00
# An aimed Propulser burst translates the complete formation as one body.
var dash_direction: Vector2 = Vector2.ZERO
var dash_remaining: float = 0.0
const DASH_SPEED: float = 1400.0
func _ready() -> void:
# Lets anything resolve "the fleet" without a hardcoded ../Fleet sibling
# path - enemies parented under different hosts (e.g. a planet surface's
# SurfaceFeatures) need this to find their target.
add_to_group("player_fleet")
# Researching a vessel upgrade improves the ships already flying, not
# just the next one built (#5).
GameState.vessel_upgraded.connect(_on_vessel_upgraded)
func _on_vessel_upgraded(_id: String) -> void:
for ship in ships:
if is_instance_valid(ship):
ship.apply_vessel_stats()
func spawn_ships(count: int, center: Vector2 = Vector2.ZERO,
vessel_types: PackedStringArray = PackedStringArray()) -> void:
for ship in ships:
if is_instance_valid(ship):
ship.queue_free()
ships.clear()
formation_offsets.clear()
2026-08-15 00:09:10 +02:00
var spawn_types: PackedStringArray = PackedStringArray()
if vessel_types.is_empty():
for i in range(count):
spawn_types.append(GameState.VESSEL_INTERCEPTOR)
else:
for vessel_type in vessel_types:
if GameState.vessel_is_fleet_eligible(vessel_type):
spawn_types.append(vessel_type)
if spawn_types.is_empty():
spawn_types.append(GameState.VESSEL_INTERCEPTOR)
var n: int = clamp(spawn_types.size(), 1, GameState.max_fleet_size())
for i in range(n):
var offset: Vector2 = GameState.formation[i]
var ship: Area2D = ship_scene.instantiate()
2026-08-15 00:09:10 +02:00
ship.vessel_type = spawn_types[i]
ship.position = center + offset
ship.glow_color = ship_glow_color
ship.core_color = ship_core_color
add_child(ship)
ships.append(ship)
formation_offsets.append(offset)
if ship.has_signal("destroyed"):
ship.destroyed.connect(_on_ship_destroyed.bind(ship))
fleet_target = center
_sync_composition_state()
func vessel_types() -> PackedStringArray:
var result: PackedStringArray = PackedStringArray()
for ship in ships:
if is_instance_valid(ship):
result.append(String(ship.vessel_type))
return result
func _sync_composition_state() -> void:
#106/#107 (#98a/#98b): the Planning Center Landed together: a board of standing orders nothing acts on is a notepad, and a planner with nowhere to read the plan from has nothing to do. The targets are GLOBAL, not per building. There is one plan for the whole game, and a second planning centre is another place to read and edit it rather than a competing one - per-building targets would let two centres hold contradictory orders and tell the crafters to satisfy both. The census is the harder half. Every vessel is counted exactly once wherever it happens to be: flying in the fleet, parked in the hangar, stationed at an outpost, or in the air between any two of those. Miss the in-flight ones and the planner queues a replacement for a vessel that is merely en route. The fleet is the one place GameState cannot see, so Fleet pushes its composition on every change, alongside the cargo capacity and distorder count that already went that way. Three rules keep the planner from fighting the player. It tops up and never rewrites, so an order placed by hand stays exactly where it is. Everything counts, including what is already queued, or it re-queues the same shortfall every tick and buries the player in hulls. And nothing happens without a planning centre - though the plan is remembered when one is destroyed, so rebuilding picks up where it left off. Vessels on order are counted separately from the census on purpose: they do not exist yet, so the readout can say "4 of 6, 2 building" rather than claiming six. The per-row note says where the vessels actually are, because a plan can look unmet while everything it asked for is sitting at an outpost. The build menu goes to three columns past eight entries. #54 already tightened its rows to 223px to fit a fourth, explicitly to avoid a scrollable menu, and a ninth structure needs a fifth row that will not fit at any spacing a button, a label and a cost can share. Three columns take nine into three rows - fewer than it uses today, not more. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 14:21:52 +02:00
# #106: the Planning Center counts vessels across the whole game, and
# the fleet is the one place it cannot see - the ships are scene nodes
# and GameState outlives the scene. Pushed here rather than polled,
# alongside the cargo capacity and distorder count that already are,
# and for the same reason: composition changes are authoritative, and
# this is the one function every one of them goes through.
GameState.fleet_vessel_types = vessel_types()
GameState.sync_fleet_cargo_capacity(vessel_types())
# Composition changes are authoritative; scene teardown is not. Keeping
# this out of SpeedFader prevents an outgoing scene's empty fleet from
# resetting a boost while the same vessels are being restored on a surface.
Stacking distorders, menu layouts, lab rewards, enemy detail, artillery cross DISTORDER STACKING. Each space-time distorder vessel past the first raises the fleet's speed ceiling by 1.0, so a second one is worth crewing instead of being dead weight. GameState gains max_fleet_speed_multiplier, pushed by Fleet whenever composition changes - the same direction as every other fleet-derived figure, since GameState does not reach into the scene tree to count ships. The energy drain is normalised against the CURRENT ceiling, so full boost costs the same per second however wide it is: extra vessels buy more speed, not cheaper speed. Losing one re-clamps an over-ceiling boost rather than leaving the fleet travelling faster than its crew can sustain. TRANSFER MENU. Rows overlapped, and the last one ran into the hint text. row_height is divided from the available space, but each row's contents used a fixed pixel ladder - glyph at +10, buttons at +88, selector at +142 - which needs about 244px. Three resources fit; the fourth cut rows to 180 and every one spilled 64px into the next. Every offset is now a fraction of the row, so it cannot overflow. Also dropped the per-row AMOUNT caption (four copies of a word the footer hint already explains) and moved each glyph and name to the TOP of its row, where they read as its heading rather than the next row's. HANGAR. Six vessel types in one row gave each about 100px for a 155px label, so the names ran together. Now a 3x2 grid per section, sized from the space between the first heading and the status line, using the empty lower half. LAB RESEARCH REWARD. A harder enemy lab is worth more research points, and how hard a lab is depends on the layout authored for it - how many capture points, how many defenders - which the planet TYPE cannot know. PlanetSetup carries research_point_reward, set in the map editor, overriding the planet type's flat rate. 0 means "no opinion", so every map authored before this keeps its old value. RESEARCH LAB BACKGROUND. Its own shader instead of the crater field with a red tint, which read as "rocky planet, tinted" rather than someone's facility: plated floor, seams, service conduits, lit junctions. Loop-free by construction (#68's lesson applied up front) - conduits stay continuous across cells by keying a horizontal run to cell.y and a vertical to cell.x, so neighbouring cells agree without any cell scanning its neighbours. ENEMY DETAIL. Every enemy was a single flat outline, which left the artillery and the turret spawner as the same octagon at two sizes - the silhouette carried no information about what the thing did. EnemyDefinition gains detail_lines and detail_rings as DATA, so adding an enemy still means adding a definition rather than editing Enemy.gd, and the four non-default hulls are redrawn: a long-barrelled sniper, a squat mortar, a hive with launch bays, a capital ship with spine and ribs. Three things drew an enemy from its definition - the enemy, the map editor's markers, and the palette buttons - each reimplementing it from hull_points alone, so the new detail appeared in the game and nowhere else and an editor marker stopped matching what it placed. They now share EnemyDefinitions.draw_definition(). ARTILLERY. The 1.8s charge-up before the tower fired arrived long before the threat was legible and mostly read as the tower being stuck. It fires immediately now; the warning is the shell you can see in the air plus a small cross on the ground at the impact point. Deliberately not a blast-radius ring - a large translucent area was easy to read as the explosion having already happened, where the cross says "move off this spot". MAIN MENU. No Quit in any build (a web build has nothing to quit to, and Android's back gesture already does it), a plain black background, and the game is "Spaceship" - in the title and in config/name, which is what drives the browser tab for the web export. change_scene_to_file() returns an error and otherwise fails silently, leaving the menu up, which is indistinguishable from an unpressed button; it is now checked and reported on screen. Full suite green at 99/99. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 16:54:46 +02:00
# Each distorder vessel past the first widens the speed ceiling, so the
# COUNT matters, not merely whether one is present.
GameState.set_distorder_vessel_count(count_ships_with_capability("distorder"))
if not has_capability("distorder"):
GameState.set_fleet_speed_multiplier(1.0)
2026-08-15 04:45:15 +02:00
func has_vessel_type(vessel_type: String) -> bool:
for ship in ships:
if is_instance_valid(ship) and String(ship.vessel_type) == vessel_type:
return true
return false
func first_vessel_of_type(vessel_type: String) -> Node2D:
for ship in ships:
if is_instance_valid(ship) and String(ship.vessel_type) == vessel_type:
return ship
return null
func has_capability(capability: String) -> bool:
return first_ship_with_capability(capability) != null
Stacking distorders, menu layouts, lab rewards, enemy detail, artillery cross DISTORDER STACKING. Each space-time distorder vessel past the first raises the fleet's speed ceiling by 1.0, so a second one is worth crewing instead of being dead weight. GameState gains max_fleet_speed_multiplier, pushed by Fleet whenever composition changes - the same direction as every other fleet-derived figure, since GameState does not reach into the scene tree to count ships. The energy drain is normalised against the CURRENT ceiling, so full boost costs the same per second however wide it is: extra vessels buy more speed, not cheaper speed. Losing one re-clamps an over-ceiling boost rather than leaving the fleet travelling faster than its crew can sustain. TRANSFER MENU. Rows overlapped, and the last one ran into the hint text. row_height is divided from the available space, but each row's contents used a fixed pixel ladder - glyph at +10, buttons at +88, selector at +142 - which needs about 244px. Three resources fit; the fourth cut rows to 180 and every one spilled 64px into the next. Every offset is now a fraction of the row, so it cannot overflow. Also dropped the per-row AMOUNT caption (four copies of a word the footer hint already explains) and moved each glyph and name to the TOP of its row, where they read as its heading rather than the next row's. HANGAR. Six vessel types in one row gave each about 100px for a 155px label, so the names ran together. Now a 3x2 grid per section, sized from the space between the first heading and the status line, using the empty lower half. LAB RESEARCH REWARD. A harder enemy lab is worth more research points, and how hard a lab is depends on the layout authored for it - how many capture points, how many defenders - which the planet TYPE cannot know. PlanetSetup carries research_point_reward, set in the map editor, overriding the planet type's flat rate. 0 means "no opinion", so every map authored before this keeps its old value. RESEARCH LAB BACKGROUND. Its own shader instead of the crater field with a red tint, which read as "rocky planet, tinted" rather than someone's facility: plated floor, seams, service conduits, lit junctions. Loop-free by construction (#68's lesson applied up front) - conduits stay continuous across cells by keying a horizontal run to cell.y and a vertical to cell.x, so neighbouring cells agree without any cell scanning its neighbours. ENEMY DETAIL. Every enemy was a single flat outline, which left the artillery and the turret spawner as the same octagon at two sizes - the silhouette carried no information about what the thing did. EnemyDefinition gains detail_lines and detail_rings as DATA, so adding an enemy still means adding a definition rather than editing Enemy.gd, and the four non-default hulls are redrawn: a long-barrelled sniper, a squat mortar, a hive with launch bays, a capital ship with spine and ribs. Three things drew an enemy from its definition - the enemy, the map editor's markers, and the palette buttons - each reimplementing it from hull_points alone, so the new detail appeared in the game and nowhere else and an editor marker stopped matching what it placed. They now share EnemyDefinitions.draw_definition(). ARTILLERY. The 1.8s charge-up before the tower fired arrived long before the threat was legible and mostly read as the tower being stuck. It fires immediately now; the warning is the shell you can see in the air plus a small cross on the ground at the impact point. Deliberately not a blast-radius ring - a large translucent area was easy to read as the explosion having already happened, where the cross says "move off this spot". MAIN MENU. No Quit in any build (a web build has nothing to quit to, and Android's back gesture already does it), a plain black background, and the game is "Spaceship" - in the title and in config/name, which is what drives the browser tab for the web export. change_scene_to_file() returns an error and otherwise fails silently, leaving the menu up, which is indistinguishable from an unpressed button; it is now checked and reported on screen. Full suite green at 99/99. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 16:54:46 +02:00
func count_ships_with_capability(capability: String) -> int:
var total: int = 0
for ship in ships:
if is_instance_valid(ship) and ship.has_capability(capability):
total += 1
return total
2026-08-15 04:45:15 +02:00
func first_ship_with_capability(capability: String) -> Node2D:
for ship in ships:
if is_instance_valid(ship) and ship.has_capability(capability):
return ship
return null
func add_ship(vessel_type: String = GameState.VESSEL_INTERCEPTOR) -> bool:
# Adds one vessel in the next free formation slot (bought from a ship
# crafter). Returns false when the wedge is already full.
2026-08-15 00:09:10 +02:00
if not GameState.vessel_is_fleet_eligible(vessel_type) \
or ships.size() >= GameState.max_fleet_size():
return false
var offset: Vector2 = GameState.formation[ships.size()]
var ship: Area2D = ship_scene.instantiate()
# Before add_child, so Ship._ready() builds the right vessel - the shield
# ring is created there and only for a shield vessel.
ship.vessel_type = vessel_type
# From the formation origin, not the centroid: with a lopsided layout the
# centroid is already displaced by the average offset, so adding the new
# ship's own offset to it would drop it well outside the wedge.
ship.position = get_formation_origin() + offset
ship.glow_color = ship_glow_color
ship.core_color = ship_core_color
add_child(ship)
ships.append(ship)
formation_offsets.append(offset)
if ship.has_signal("destroyed"):
ship.destroyed.connect(_on_ship_destroyed.bind(ship))
ship.set_move_target(fleet_target + offset)
_sync_composition_state()
return true
func store_ship(index: int) -> String:
# A fleet always keeps one ship deployed. Removing the last one would trip
# the wiped-out-fleet safety net on the next frame and immediately spawn a
# replacement, which is the opposite of storing it at the mothership.
if ships.size() <= 1 or index < 0 or index >= ships.size():
return ""
var ship: Node = ships[index]
if not is_instance_valid(ship):
return ""
var vessel_type: String = String(ship.vessel_type)
ships.remove_at(index)
formation_offsets.remove_at(index)
ship.queue_free()
apply_formation()
_sync_composition_state()
return vessel_type
func apply_formation() -> void:
# Re-seats the EXISTING ships into the current GameState.formation.
# Without this, editing the layout at a command centre (or pivoting it)
# only affected ships built later, which read as the edit doing nothing.
for i in range(ships.size()):
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
if i >= GameState.max_fleet_size():
break
formation_offsets[i] = GameState.formation[i]
_assign_slot_targets()
func move_to(world_pos: Vector2) -> void:
steer_direction = Vector2.ZERO
fleet_target = world_pos
anchor = world_pos
_assign_slot_targets()
func move_in_direction(direction: Vector2) -> void:
# Joystick steering. Sets the heading; _process advances the anchor.
#
# This used to park a target 2000 units ahead and let the ships chase
# it. That made formation changes barely register while flying: with
# the aim point that far away, a 60-unit formation offset moved a
# ship's heading by under two degrees, so pivoting mid-flight looked
# like it did almost nothing. Anchoring the formation and having each
# ship hold its own slot relative to it fixes that.
if direction == Vector2.ZERO:
stop()
return
if steer_direction == Vector2.ZERO:
anchor = get_formation_origin()
steer_direction = direction.normalized()
2026-09-02 13:43:56 +02:00
func dash(direction: Vector2, distance: float) -> bool:
if direction.length() < 0.001 or distance <= 0.0 or ships.is_empty():
return false
if dash_remaining <= 0.0:
anchor = get_formation_origin()
dash_direction = direction.normalized()
dash_remaining = distance
return true
func is_dashing() -> bool:
return dash_remaining > 0.0
func _process(delta: float) -> void:
#157, #158, #159: pay from the hold you flew in, and nothing is exempt from coming down #157 was already satisfied - second_hull is quest 7 and extractor is quest 11 - so this pins the property rather than adding a quest: nothing costing more than a single hold may be asked for before the chain has grown the fleet or taught banking. It fails if either is ever moved behind it. #158 - a building's local costs may now be paid out of the fleet's hold. #12 made production cost resources physically DELIVERED rather than money out of the bank, and that stands: the bank is still not raided here. The hold is simply the other place resources physically are, and making the player park, open the transfer menu and move cargo across by hand was ceremony rather than a decision. But only WHERE THE FLEET IS, and that qualifier is the whole design. The first draft had no range on it and test_manual_supply_route caught it immediately: a crafter three thousand units away reached into the hold and spent ore the player had just withdrawn to carry somewhere else - which is exactly the complaint that got automatic banking removed in #24, arriving from the other direction. The range is Building.interact_radius, the same distance that decides whether the transfer button appears, so the rule is not a hidden one: if you could hand the cargo over, the building can take it. #159 - the mothership floored at 1hp, so a battered one sat there reading as dead and never exploded. That exemption existed to prevent a soft-lock, and the soft-lock turns out not to exist: the bank is GameState.bank_inventory and the hangar is stored_vessels, both of which outlive any building; the mothership is the one structure research never gates; it costs exactly what a single interceptor's hold carries; and ore comes from asteroids, which do not run out. So the way back is always mine, fly, rebuild - and that is what test_building_health now asserts, in place of the exemption that used to stand in for it.
2026-08-29 15:51:34 +02:00
# #158: a building may pay a local cost out of the hold when the fleet is
# actually standing at it, and the autoload has no other way to know
# where that is. Written before the early return below - a parked fleet
# is exactly the case that matters.
GameState.fleet_position = get_centroid()
2026-09-02 13:43:56 +02:00
if is_dashing():
_advance_dash(delta)
return
if steer_direction == Vector2.ZERO:
return
# The anchor - the fleet's formation centre - travels at cruise_speed.
# Ships may exceed it individually to reach their slots. #59: multiplied
# at the point of use, not baked into cruise_speed itself, so the base
# value stays stable regardless of the current boost.
anchor += steer_direction * _effective_cruise_speed() * delta
fleet_target = anchor
_assign_slot_targets()
2026-09-02 13:43:56 +02:00
func _advance_dash(delta: float) -> void:
var step: float = minf(DASH_SPEED * delta, dash_remaining)
var displacement: Vector2 = dash_direction * step
dash_remaining -= step
anchor += displacement
fleet_target += displacement
for ship in ships:
if not is_instance_valid(ship):
continue
# Move the hull and its destination together. That preserves every
# formation offset and prevents normal steering from trying to "repair"
# the burst by pulling ships back toward their pre-dash targets.
ship.position += displacement
ship.move_target += displacement
ship.velocity = Vector2.ZERO
ship.fleet_velocity = Vector2.ZERO
ship.rotation = dash_direction.angle() + PI / 2.0
if dash_remaining <= 0.001:
dash_remaining = 0.0
if steer_direction != Vector2.ZERO:
_assign_slot_targets()
func _effective_cruise_speed() -> float:
return cruise_speed * GameState.fleet_speed_multiplier
func _assign_slot_targets() -> void:
var effective_cruise_speed: float = _effective_cruise_speed()
for i in range(ships.size()):
ships[i].set_move_target(fleet_target + formation_offsets[i])
# Context, not a command: the ship adds this to its own velocity to
# work out how it is really moving. See Ship.fleet_velocity.
ships[i].fleet_velocity = steer_direction * effective_cruise_speed
func stop() -> void:
steer_direction = Vector2.ZERO
# Aim each ship at the point where its own braking curve brings it to
# rest, so releasing the stick coasts to a halt instead of snapping to
# a dead stop (which is what targeting the current position would do,
# since that lands inside arrive_radius immediately).
fleet_target = get_formation_origin()
for ship in ships:
Bound individual vessel speed; stop Fleet.stop() accumulating it (#72) Rotating the fleet and spamming a direction let vessels fall out of sync and fly at wildly high speeds. The pivot cooldown added earlier throttled how often the exploit could be triggered; it never touched the cause. Fleet.stop() did `ship.velocity = ship.velocity + ship.fleet_velocity`, compensating for the fact that Ship.velocity read zero during cruise. The next steer refilled fleet_velocity, so every press-release cycle added a whole cruise velocity to the ship's own, decaying only at `acceleration` in between. Tapping faster than that bled it off stacked them without limit, and ships desynced because each bled off at a rate set by its own distance to its slot. Measured before this change: spamming a direction while pivoting flew the fleet 32737 units in 3s against 784 for simply holding the stick, with a vessel reaching 48x its own top speed. The compensation existed because `velocity` was not the ship's real motion: Ship snapped to its slot every tick and zeroed it, so the truth lived in a second field and anything wanting it had to add the two together. Fixed at that root rather than by clamping the symptom: - fleet_velocity is now fed FORWARD into the steering instead of carried alongside it. The ship aims to travel at its slot's velocity plus a correction closing the gap, so holding formation costs no error and `velocity` is always true world motion. - The snap only applies when the slot is standing still, which is the one case where converging asymptotically would leave a residue. While the slot moves the ship steers continuously - a snap there was the teleport that made `velocity` lie in the first place. - A hard bound on the INTEGRATED result every tick, not merely on the request, so no sequence of commands can leave a vessel over its own top speed. - Fleet.stop() injects nothing; it reports that the slot has halted. tests/test_fleet_speed_bounded.gd covers it, and fails against the previous code with the numbers above: no vessel exceeds its own top speed however hard the direction is spammed, spamming cannot cover more ground than holding the stick, both hold while the formation is pivoting, and the fleet stays together. test_space_time_distorder.gd now clears the asteroid and enemy groups at setup, the same clean-slate idiom test_ship_lab.gd uses. Silencing the spawners was never enough - what Main.tscn had already placed kept moving, and losing the distorder vessel to a rock resets the multiplier correctly, which the test then reported three stages later as a failed scene swap. It also checks it still crews a distorder vessel before relying on that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 23:20:34 +02:00
# A ship's `velocity` is already its true motion, including the
# fleet's travel, because Ship feeds the slot velocity forward into
# its own steering rather than carrying it in a separate field. So
# stopping is only a matter of telling it the slot has halted and
# aiming it at the point its own braking curve reaches.
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
#
Bound individual vessel speed; stop Fleet.stop() accumulating it (#72) Rotating the fleet and spamming a direction let vessels fall out of sync and fly at wildly high speeds. The pivot cooldown added earlier throttled how often the exploit could be triggered; it never touched the cause. Fleet.stop() did `ship.velocity = ship.velocity + ship.fleet_velocity`, compensating for the fact that Ship.velocity read zero during cruise. The next steer refilled fleet_velocity, so every press-release cycle added a whole cruise velocity to the ship's own, decaying only at `acceleration` in between. Tapping faster than that bled it off stacked them without limit, and ships desynced because each bled off at a rate set by its own distance to its slot. Measured before this change: spamming a direction while pivoting flew the fleet 32737 units in 3s against 784 for simply holding the stick, with a vessel reaching 48x its own top speed. The compensation existed because `velocity` was not the ship's real motion: Ship snapped to its slot every tick and zeroed it, so the truth lived in a second field and anything wanting it had to add the two together. Fixed at that root rather than by clamping the symptom: - fleet_velocity is now fed FORWARD into the steering instead of carried alongside it. The ship aims to travel at its slot's velocity plus a correction closing the gap, so holding formation costs no error and `velocity` is always true world motion. - The snap only applies when the slot is standing still, which is the one case where converging asymptotically would leave a residue. While the slot moves the ship steers continuously - a snap there was the teleport that made `velocity` lie in the first place. - A hard bound on the INTEGRATED result every tick, not merely on the request, so no sequence of commands can leave a vessel over its own top speed. - Fleet.stop() injects nothing; it reports that the slot has halted. tests/test_fleet_speed_bounded.gd covers it, and fails against the previous code with the numbers above: no vessel exceeds its own top speed however hard the direction is spammed, spamming cannot cover more ground than holding the stick, both hold while the formation is pivoting, and the fleet stays together. test_space_time_distorder.gd now clears the asteroid and enemy groups at setup, the same clean-slate idiom test_ship_lab.gd uses. Silencing the spawners was never enough - what Main.tscn had already placed kept moving, and losing the distorder vessel to a rock resets the multiplier correctly, which the test then reported three stages later as a failed scene swap. It also checks it still crews a distorder vessel before relying on that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 23:20:34 +02:00
# This used to do `ship.velocity += ship.fleet_velocity` here, to
# compensate for `velocity` reading zero while the ship was in fact
# cruising (Ship snapped to its slot every tick and zeroed it). That
# compensation was an unbounded ACCUMULATOR: every release added a
# whole cruise velocity, the next steer refilled fleet_velocity, and
# tapping a direction repeatedly stacked them up faster than
# `acceleration` could bleed them off - so a vessel could be flung
# along at many times its own top speed, and ships fell out of sync
# because each bled off at a rate set by its own distance to its
# slot. Ship now bounds its total speed every tick as well, so
# neither half of that can come back.
var motion: Vector2 = ship.velocity
# The fleet is not cruising any more, so the slot is standing still.
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
ship.fleet_velocity = Vector2.ZERO
var speed: float = motion.length()
if speed <= 0.001:
ship.set_move_target(ship.position)
continue
var braking_distance: float = (speed * speed) / (2.0 * ship.acceleration)
Skill tree, node-based building animation, bigger UI, and a 19x faster test suite Gameplay and UI - Research tree at the mothership gates which structures can be built and grants permanent fleet-capacity upgrades (GameState.SKILL_TREE, SkillTreeView). Node depth is derived from prerequisites, so the layout cannot drift out of step with the dependencies. - Building info popup before committing to a build, with per-building cost and description. - Ship crafter redrawn as a space factory with an assembly animation; mothership redrawn as a radial flagship; command centre as a plotting hub. - Keyboard and mouse support (WASD, Q/E pivot, wheel zoom) for the web build. - UI and font scaled up for phone use, via a custom Theme resource - gui/theme/default_font_size does not reach the default theme. - Asteroids no longer spawn on top of the fleet's start position. - Fleet formation origin derived from the layout's own offsets rather than the centroid, fixing the lurch when a lopsided formation started moving. - Fleet.stop() brakes from the ship's TRUE motion (velocity + fleet_velocity). Ship zeroes its velocity when seated in its slot even while the anchor drags that slot forward, so braking from velocity alone stopped the fleet dead instead of coasting - and whether it did depended on the frame rate. Animation architecture (issue #10) - Buildings, projectiles and explosion VFX no longer animate by redrawing. Static geometry is rasterised once in _draw(); moving parts are NeonPiece children animated through node properties, which reuse the cached geometry. Every NeonDraw call expands into four antialiased polylines, so redrawing to move something re-tessellated all of it. Test suite (issue #8): 1075s -> ~55s - Runs from a copy on Termux's own filesystem. The project lives on Android's FUSE bridge, read through proot, where load("res://Main.tscn") alone cost 8.5s per test against ~2s natively - and nearly every test loads it. - Runs 6 tests at a time, in a single proot-distro login, with output buffered per test and printed only on failure. - --fixed-fps 60 pins delta instead of measuring the wall clock, so a test's result no longer depends on how busy the machine is. Without it, parallelism made two tests fail on 2 of 3 runs. - A test passes only if it both exits 0 and prints ": PASS". - 38 tests, green on three consecutive runs. Bundles Carrois Gothic SC (Apache 2.0) with its licence text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 15:00:41 +02:00
ship.set_move_target(ship.position + motion.normalized() * braking_distance)
func get_move_targets() -> Array:
var result: Array = []
for ship in ships:
result.append(ship.move_target)
return result
func restore(previous_fleet_target: Vector2, previous_move_targets: Array) -> void:
fleet_target = previous_fleet_target
for i in range(ships.size()):
ships[i].move_target = previous_move_targets[i]
func _on_ship_destroyed(ship: Node) -> void:
var idx: int = ships.find(ship)
if idx != -1:
ships.remove_at(idx)
formation_offsets.remove_at(idx)
_sync_composition_state()
func get_centroid() -> Vector2:
if ships.is_empty():
return fleet_target
var sum: Vector2 = Vector2.ZERO
for ship in ships:
sum += ship.position
return sum / ships.size()
func get_formation_origin() -> Vector2:
# Where the anchor must be for the ships to be standing in their slots
# right now. This is NOT the centroid: ships sit at anchor + offset, so
# the centroid is anchor + the AVERAGE offset, and the two only coincide
# when the layout happens to be balanced around its origin.
#
# The default wedge is balanced, which is why using the centroid as the
# anchor looked fine - until a layout dragged off to one corner at a
# command centre made the average offset large. Seeding the anchor from
# the centroid then displaced every slot by that average the instant
# steering began, so the fleet lurched towards the formation's own
# lopsided side before the anchor caught up and it flew the right way.
if ships.is_empty():
return fleet_target
var sum: Vector2 = Vector2.ZERO
for offset in formation_offsets:
sum += offset
return get_centroid() - sum / formation_offsets.size()