#162 - a single tap bought a research node outright. One physical tap arrives TWICE: Godot emulates a mouse button from every touch AND a touch from every mouse button, both project settings are on, and the menu's dispatcher routes InputEventScreenTouch and InputEventMouseButton alike to the tree. The second arrival found the node already selected and took itself for the confirming tap. Measured, not reasoned about - one tap produced two picks and two confirms. What is ignored is specifically the TWIN: same frame, same place, arriving through the other input kind. Deduping on frame and position alone also swallowed two genuine taps in one frame, which the test caught. #164 - the build menu predicted a caption's height from the COLUMN WIDTH: wide column, assume one line. Right for most names and wrong for the long ones, so "Spacial Workshop" wrapped onto the price beneath it. Captions are now measured against the font that draws them, and prices sized from PriceTag.wanted_height(), which existed for exactly this and was not being asked. Prices are set before anything is measured, because the old order laid out first and priced afterwards. The ship lab: its buy button is gone and a second tap on an option buys it, the same rule as the research tree; the explanation drops into the room that freed; research points move up into the resource table, where everything else being spent already is; the second row of options is placed from the first row's measured bottom rather than a constant; and the vessel strip is spaced from the panel's own width, so the eighth vessel is no longer half off the right edge. #160 - the quest panel was drawn BEFORE the sticks and the pivot pair, so they sat on top of it. Moved after them, under the narration banner. Its title rule ran straight through the close button; the header band is now as tall as that button. #161 - the prologue widens the formation into a freight convoy by writing over GameState.formation, and nothing put it back. The player flew the convoy's 600-unit spread for the rest of the game - a shape nobody chose, which reads as the fleet having drifted apart. #163 - a quest to station a vessel at the outpost, after the one that asks for the outpost. Building one and crewing it are different acts, and an empty outpost holds nothing. #165 - the gas bomb's blast and a vessel arriving fast both damage a structure. The blast used to stop politely at anything the player owned, which made a bomb dropped on a besieged mothership a free way to sweep the attackers off it. Collisions are caught on ENTRY, not on the 0.7s strike tick: a vessel is only moving fast for the instant it arrives, and a ship sent in at 900 did no damage at all until this moved. Docking is free - the fleet sits on its own mothership constantly to bank ore - and garrison vessels are exempt outright, because they launch from their outpost and re-dock with it at speed. The suite caught that one: the ram rule was destroying the garrison as it launched. Suite 153/153. Four tests changed because what they pinned moved: the lab's buy button, the intro's formation, the research tree's tap delivery, and the build menu's own preview. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
101 lines
3.4 KiB
GDScript
101 lines
3.4 KiB
GDScript
extends Node2D
|
|
|
|
# #105 (#97g): keeps the vessels stationed at outposts in step with what
|
|
# GameState says is stationed there.
|
|
#
|
|
# Garrison vessels are NOT in Fleet.ships. They are spawned here, under a
|
|
# node of their own, so the formation, the fleet's speed fader and
|
|
# max_fleet_size() all continue to be about the fleet - a garrison that
|
|
# counted against the fleet's slots would mean stationing a vessel cost the
|
|
# player a place in their own wedge, which is the opposite of what an outpost
|
|
# is for.
|
|
#
|
|
# The record is the truth, as everywhere else: this node is rebuilt from
|
|
# GameState.garrison_crew() when the space scene loads, so a garrison
|
|
# survives a trip to a planet surface.
|
|
|
|
var ship_scene: PackedScene = preload("res://vessels/Ship.tscn")
|
|
const GARRISON_COMPONENT = preload("res://vessels/VesselGarrisonComponent.gd")
|
|
|
|
# {outpost_id: [ship, ...]}
|
|
var stationed: Dictionary = {}
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("garrison_field")
|
|
sync()
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
sync()
|
|
|
|
|
|
func ships_at(outpost_id: int) -> Array:
|
|
var out: Array = []
|
|
for ship in stationed.get(outpost_id, []):
|
|
if is_instance_valid(ship) and not ship.is_queued_for_deletion():
|
|
out.append(ship)
|
|
return out
|
|
|
|
|
|
func all_ships() -> Array:
|
|
var out: Array = []
|
|
for outpost_id in stationed:
|
|
out.append_array(ships_at(outpost_id))
|
|
return out
|
|
|
|
|
|
func sync() -> void:
|
|
# Retire whole outposts that no longer exist, then reconcile the rest.
|
|
for outpost_id in stationed.keys():
|
|
if GameState.find_building(outpost_id).is_empty():
|
|
for ship in ships_at(outpost_id):
|
|
ship.queue_free()
|
|
stationed.erase(outpost_id)
|
|
|
|
for outpost_id in GameState.outpost_ids():
|
|
var record: Dictionary = GameState.find_building(outpost_id)
|
|
var crew: Array = GameState.garrison_crew(outpost_id)
|
|
var here: Array = ships_at(outpost_id)
|
|
stationed[outpost_id] = here
|
|
if here.size() == crew.size():
|
|
continue
|
|
if here.size() > crew.size():
|
|
# The record shrank under us - a vessel was released or lost
|
|
# while this node was not looking.
|
|
for i in range(crew.size(), here.size()):
|
|
here[i].queue_free()
|
|
stationed[outpost_id] = here.slice(0, crew.size())
|
|
continue
|
|
for i in range(here.size(), crew.size()):
|
|
here.append(_spawn(outpost_id, String(crew[i]), record.position, i))
|
|
|
|
|
|
func _spawn(outpost_id: int, vessel_type: String, at: Vector2, index: int) -> Node2D:
|
|
var ship: Area2D = ship_scene.instantiate()
|
|
# Before add_child, so Ship._ready() builds the right vessel - the same
|
|
# order Fleet.add_ship() relies on.
|
|
ship.vessel_type = vessel_type
|
|
var spread: float = TAU * float(index) / 4.0
|
|
ship.position = at + Vector2(cos(spread), sin(spread)) * 170.0
|
|
add_child(ship)
|
|
# #165: marked as belonging to an outpost, so the ram rule leaves it
|
|
# alone. A stationed vessel orbits and re-docks with its own structure
|
|
# constantly; without this the collision damage meant for a charging
|
|
# fleet vessel destroyed the garrison the moment it launched.
|
|
ship.add_to_group("garrison_ships")
|
|
var component: Node = GARRISON_COMPONENT.new()
|
|
component.outpost_id = outpost_id
|
|
component.station = at
|
|
ship.add_child(component)
|
|
component.setup()
|
|
# A garrison vessel that dies frees its berth, so #104 sends another.
|
|
ship.destroyed.connect(_on_garrison_lost.bind(outpost_id, vessel_type))
|
|
return ship
|
|
|
|
|
|
func _on_garrison_lost(outpost_id: int, vessel_type: String) -> void:
|
|
var crew: Array = GameState.garrison_crew(outpost_id)
|
|
var index: int = crew.find(vessel_type)
|
|
if index >= 0:
|
|
crew.remove_at(index)
|