spaceship/tests/test_black_hole.gd

226 lines
10 KiB
GDScript3
Raw Normal View History

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_black_hole.gd
# Forgejo #55: a rare landable body yielding dark matter, obtainable only
# through an extractor - never a surface pickup.
#
# Covers:
# A. WorldGen.planet_data_at_chunk() is a pure, deterministic function of
# chunk coordinates, and black holes are noticeably rarer than gas
# giants across a wide scan
# B. dark matter is fully generic - in resource_types(), its own
# ResourceDefinition/glyph/colour, distinct from every other resource
# C. landing on a black hole spawns no resource provider and no capture
# points at all (void's features_scene is null, and it has no
# authored PlanetSetup) - yet the planet is immediately conquered
# (a garrison of zero is vacuously already beaten),
# so an extractor is buildable there right away
# D. an extractor on a black hole mines dark matter locally exactly like
# any other extractor, and a hub transporter banks it through the
# normal collection path with no black-hole-specific code
var game_state: Node
var stage: int = 0
var elapsed: float = 0.0
var scene: Node
var extractor_index: int = 0
var load_limit: int = 0
var baseline: Dictionary = {}
const BLACK_HOLE_AT := Vector2(500.0, 0.0)
const MOTHERSHIP_AT := Vector2.ZERO
const HUB_AT := Vector2(150.0, 0.0)
func _initialize() -> void:
game_state = root.get_node("GameState")
# --- A. deterministic and rare -----------------------------------------
var black_hole_count: int = 0
var gas_giant_count: int = 0
var total_planets: int = 0
for x in range(-40, 40):
for y in range(-40, 40):
var chunk: Vector2i = Vector2i(x, y)
if not WorldGen.has_planet_at_chunk(chunk):
continue
total_planets += 1
var first: Dictionary = WorldGen.planet_data_at_chunk(chunk)
var second: Dictionary = WorldGen.planet_data_at_chunk(chunk)
if first.definition_id != second.definition_id or first.local_pos != second.local_pos \
or first.shape_seed != second.shape_seed or first.name != second.name:
_fail("planet_data_at_chunk(%s) is not deterministic" % chunk)
return
if first.definition_id == "black_hole":
black_hole_count += 1
elif first.definition_id == "gas_giant":
gas_giant_count += 1
print("scanned %d planet chunks: %d black holes, %d gas giants" % [
total_planets, black_hole_count, gas_giant_count
])
if black_hole_count == 0:
_fail("no black holes generated across a wide scan - the rare outcome never fires")
return
if black_hole_count >= gas_giant_count:
_fail("black holes (%d) are not rarer than gas giants (%d)" % [black_hole_count, gas_giant_count])
return
# --- B. dark matter is fully generic -----------------------------------
if not game_state.resource_types().has(GameState.RESOURCE_DARK_MATTER):
_fail("dark_matter is not in resource_types() - every resource menu would miss it")
return
var definition: Resource = game_state.resource_definition(GameState.RESOURCE_DARK_MATTER)
if definition == null or definition.glyph_scene == null:
_fail("dark_matter has no ResourceDefinition or glyph_scene")
return
var dm_color: Color = game_state.resource_color(GameState.RESOURCE_DARK_MATTER)
for other in [GameState.RESOURCE_ORE, GameState.RESOURCE_GAS, GameState.RESOURCE_ENERGY]:
if dm_color == game_state.resource_color(other):
_fail("dark_matter shares a colour with %s" % other)
return
print("dark matter is generic: in resource_types(), own definition, own colour %s" % dm_color)
# --- structural: the black hole definition itself -----------------------
#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 black_hole_def: Resource = load("res://planets/PlanetDefinitions.gd").get_definition("black_hole")
if black_hole_def.resource_id != "dark_matter":
_fail("black_hole planet's resource_id is '%s', expected 'dark_matter'" % black_hole_def.resource_id)
return
if black_hole_def.surface_profile_id != "void":
_fail("black_hole planet's surface_profile_id is '%s', expected 'void'" % black_hole_def.surface_profile_id)
return
#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 void_profile: Resource = load("res://surface/PlanetSurfaceProfiles.gd").get_profile("void")
if void_profile.features_scene != null:
_fail("void surface profile has a features_scene - dark matter must never be a surface pickup")
return
game_state.buildings.clear()
game_state.extractors.clear()
game_state.transporters.clear()
game_state.planet_capture.clear()
game_state.planet_id = "test_black_hole"
game_state.planet_name = "Event Zero"
game_state.planet_definition_id = "black_hole"
#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
scene = load("res://surface/PlanetSurface.tscn").instantiate()
root.add_child(scene)
current_scene = scene
func _process(delta: float) -> bool:
elapsed += delta
match stage:
0:
# --- C. no resource provider, no capture points, yet conquered ---
if elapsed < 0.3:
return false
Sharpen fleet handling, widen the laser, and fix the map editor's file identity The fleet had a second of inertia in it: every vessel's acceleration sat at roughly its own top speed, so flipping the stick while cruising took 0.58s to take effect and let go coasted 222 units, while the formation anchor the ships chase turns instantly. Acceleration is now ~3x top speed, chosen by measuring rather than taste - past 3x the reversal time stops improving because max_speed becomes the limit. Measured after: 0.18s and 23 units. test_fleet_agility guards all three numbers and proves the bounds discriminate by re-running the same measurement at the old value. The laser reaches 1450 instead of 950 and strikes 38 units either side instead of 22. Its drawn width is now derived from the hit width: the two were independent numbers that had drifted, so the beam killed things it visibly missed. LaserController's aim range also stopped hardcoding a second copy of 950. Tapping the laser button without dragging used to do nothing at all - the press was claimed, the aim begun, then thrown away on release. It now fires at the nearest enemy in range; dragging still aims precisely. That lives in the shared aimed-ability controller, so the gas bomb gains it too. Planets sat one per ~29 chunks - some 35,000 units of nothing between them. Now one per ~12, measured over 14,641 chunks. The two thresholds moved by different amounts deliberately: every SPACE-biome planet is a gas giant, so lowering both equally would have tripled the gas-giant share as well. This changes how often you find a planet, not what you find. Extractors produce half as fast to match, so expanding is what grows the economy. The research screen gave its tree 386px of 1280 and the text below it 520. The text is now at the bottom, the tree has 550, and the resource table has room and legible type - and its LOCAL column is no longer hidden behind the close button. Two map-editor bugs turned out to be one cause: a setup's id and its FILENAME are not the same thing, and both save and delete rebuilt the path from the id. ResearchLabSetup.tres holds setup_id "research_lab_1", so deleting it looked for a file that does not exist and silently refused - which read as "the first item in the list cannot be deleted" - while saving it wrote a second file under the derived name and left the original behind, so the pool served the stale twin. A third bug hid behind those: rescan() re-read through Godot's resource cache and handed back pre-save values even when the file on disk was correct. All three present to a player as "my change was not saved". Research labs no longer grant a point of their own; what conquering one is worth comes entirely from its authored map, as asked. The shipped lab map carries 1 so the balance is unchanged - only where it is configured moved. Suite 109/109. Four tests changed because the behaviour they pinned changed: the joystick coast is now derived from cruise_speed^2/(2*acceleration) rather than a constant tuned to one acceleration; the extractor wait derives from EXTRACTOR_RATE; the research-point test asserts the delegation; and the black hole test no longer assumes nobody will ever author a void-profile map. test_planet_setups and test_planet_map_assignment stopped depending on which maps happen to be in the content folder, which was making them fail when maps were added or deleted elsewhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:55:11 +02:00
# What must never appear is a RESOURCE PROVIDER - dark matter is
# not a surface pickup, which is this test's actual subject and is
# guaranteed above by void's features_scene being null.
#
# This used to demand zero children outright, which quietly assumed
# nobody would ever author a PlanetSetup for the void profile. That
# is a fact about the content folder, not a rule about black holes,
# and it stopped being true the moment someone saved a map under
# the void profile in the editor. An authored setup here is legal;
# a resource provider is not.
var feature_host: Node = scene.get_node("SurfaceFeatures")
Sharpen fleet handling, widen the laser, and fix the map editor's file identity The fleet had a second of inertia in it: every vessel's acceleration sat at roughly its own top speed, so flipping the stick while cruising took 0.58s to take effect and let go coasted 222 units, while the formation anchor the ships chase turns instantly. Acceleration is now ~3x top speed, chosen by measuring rather than taste - past 3x the reversal time stops improving because max_speed becomes the limit. Measured after: 0.18s and 23 units. test_fleet_agility guards all three numbers and proves the bounds discriminate by re-running the same measurement at the old value. The laser reaches 1450 instead of 950 and strikes 38 units either side instead of 22. Its drawn width is now derived from the hit width: the two were independent numbers that had drifted, so the beam killed things it visibly missed. LaserController's aim range also stopped hardcoding a second copy of 950. Tapping the laser button without dragging used to do nothing at all - the press was claimed, the aim begun, then thrown away on release. It now fires at the nearest enemy in range; dragging still aims precisely. That lives in the shared aimed-ability controller, so the gas bomb gains it too. Planets sat one per ~29 chunks - some 35,000 units of nothing between them. Now one per ~12, measured over 14,641 chunks. The two thresholds moved by different amounts deliberately: every SPACE-biome planet is a gas giant, so lowering both equally would have tripled the gas-giant share as well. This changes how often you find a planet, not what you find. Extractors produce half as fast to match, so expanding is what grows the economy. The research screen gave its tree 386px of 1280 and the text below it 520. The text is now at the bottom, the tree has 550, and the resource table has room and legible type - and its LOCAL column is no longer hidden behind the close button. Two map-editor bugs turned out to be one cause: a setup's id and its FILENAME are not the same thing, and both save and delete rebuilt the path from the id. ResearchLabSetup.tres holds setup_id "research_lab_1", so deleting it looked for a file that does not exist and silently refused - which read as "the first item in the list cannot be deleted" - while saving it wrote a second file under the derived name and left the original behind, so the pool served the stale twin. A third bug hid behind those: rescan() re-read through Godot's resource cache and handed back pre-save values even when the file on disk was correct. All three present to a player as "my change was not saved". Research labs no longer grant a point of their own; what conquering one is worth comes entirely from its authored map, as asked. The shipped lab map carries 1 so the balance is unchanged - only where it is configured moved. Suite 109/109. Four tests changed because the behaviour they pinned changed: the joystick coast is now derived from cruise_speed^2/(2*acceleration) rather than a constant tuned to one acceleration; the extractor wait derives from EXTRACTOR_RATE; the research-point test asserts the delegation; and the black hole test no longer assumes nobody will ever author a void-profile map. test_planet_setups and test_planet_map_assignment stopped depending on which maps happen to be in the content folder, which was making them fail when maps were added or deleted elsewhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:55:11 +02:00
for child in feature_host.get_children():
if not child.has_method("apply_setup"):
return _fail("black hole surface spawned %s under SurfaceFeatures - only an authored PlanetSetupHost belongs here" % child.name)
# Through the autoload NODE, not the bare GameState identifier: a
# global class-name lookup inside a -s entry-point script is
# resolved at compile time, before autoloads are registered. Same
# hazard the header of test_planet_setups.gd documents.
if not game_state.is_planet_conquered(game_state.planet_id) \
and int(game_state.garrison_total(game_state.planet_id)) == 0:
return _fail("a black hole with no capture points required is not marked conquered")
Sharpen fleet handling, widen the laser, and fix the map editor's file identity The fleet had a second of inertia in it: every vessel's acceleration sat at roughly its own top speed, so flipping the stick while cruising took 0.58s to take effect and let go coasted 222 units, while the formation anchor the ships chase turns instantly. Acceleration is now ~3x top speed, chosen by measuring rather than taste - past 3x the reversal time stops improving because max_speed becomes the limit. Measured after: 0.18s and 23 units. test_fleet_agility guards all three numbers and proves the bounds discriminate by re-running the same measurement at the old value. The laser reaches 1450 instead of 950 and strikes 38 units either side instead of 22. Its drawn width is now derived from the hit width: the two were independent numbers that had drifted, so the beam killed things it visibly missed. LaserController's aim range also stopped hardcoding a second copy of 950. Tapping the laser button without dragging used to do nothing at all - the press was claimed, the aim begun, then thrown away on release. It now fires at the nearest enemy in range; dragging still aims precisely. That lives in the shared aimed-ability controller, so the gas bomb gains it too. Planets sat one per ~29 chunks - some 35,000 units of nothing between them. Now one per ~12, measured over 14,641 chunks. The two thresholds moved by different amounts deliberately: every SPACE-biome planet is a gas giant, so lowering both equally would have tripled the gas-giant share as well. This changes how often you find a planet, not what you find. Extractors produce half as fast to match, so expanding is what grows the economy. The research screen gave its tree 386px of 1280 and the text below it 520. The text is now at the bottom, the tree has 550, and the resource table has room and legible type - and its LOCAL column is no longer hidden behind the close button. Two map-editor bugs turned out to be one cause: a setup's id and its FILENAME are not the same thing, and both save and delete rebuilt the path from the id. ResearchLabSetup.tres holds setup_id "research_lab_1", so deleting it looked for a file that does not exist and silently refused - which read as "the first item in the list cannot be deleted" - while saving it wrote a second file under the derived name and left the original behind, so the pool served the stale twin. A third bug hid behind those: rescan() re-read through Godot's resource cache and handed back pre-save values even when the file on disk was correct. All three present to a player as "my change was not saved". Research labs no longer grant a point of their own; what conquering one is worth comes entirely from its authored map, as asked. The shipped lab map carries 1 so the balance is unchanged - only where it is configured moved. Suite 109/109. Four tests changed because the behaviour they pinned changed: the joystick coast is now derived from cruise_speed^2/(2*acceleration) rather than a constant tuned to one acceleration; the extractor wait derives from EXTRACTOR_RATE; the research-point test asserts the delegation; and the black hole test no longer assumes nobody will ever author a void-profile map. test_planet_setups and test_planet_map_assignment stopped depending on which maps happen to be in the content folder, which was making them fail when maps were added or deleted elsewhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:55:11 +02:00
print("no resource provider; %d authored feature host(s)" % feature_host.get_child_count())
# Snapshot rather than assert > 0: bank_inventory starts with 500
# ore by default (a fresh game's starting stock), unrelated to
# this planet - "nothing was picked up" has to mean "unchanged",
# not "still zero".
for resource_type in game_state.resource_types():
baseline[resource_type] = game_state.banked_resource(resource_type) + game_state.fleet_resource(resource_type)
var fleet: Node = scene.get_node("Fleet")
for ship in fleet.ships:
ship.position += Vector2(300.0, 200.0)
fleet.move_to(fleet.get_centroid())
elapsed = 0.0
stage = 1
return false
1:
# --- C continued: flying around picks up nothing, ever -----------
if elapsed < 2.0:
return false
for resource_type in game_state.resource_types():
var total: int = game_state.banked_resource(resource_type) + game_state.fleet_resource(resource_type)
if total != baseline.get(resource_type, 0):
return _fail("something (%s) was picked up over a black hole surface" % resource_type)
print("flew around for %.1fs, nothing picked up" % elapsed)
# --- D: extractor mining + transporter banking --------------------
game_state.buildings.clear()
game_state.extractors.clear()
game_state.transporters.clear()
game_state.reset_progression()
for node in GameState.SKILL_TREE:
game_state.unlocked.append(node.id)
game_state.add_building(GameState.BUILDING_MOTHERSHIP, MOTHERSHIP_AT)
game_state.add_building(GameState.BUILDING_TRANSPORT_HUB, HUB_AT)
# #216: a hub arrives empty now - its transporters are built and
# flown in. This test is about the ROUTE, so the crew is put
# straight at its post; test_transporter_supply.gd owns the journey.
load("res://tests/_staff.gd").staff_all(game_state)
game_state.add_extractor("Event Zero", BLACK_HOLE_AT, GameState.RESOURCE_DARK_MATTER, "test_black_hole_extractor")
extractor_index = game_state.extractor_index_at("test_black_hole_extractor")
if extractor_index < 0:
return _fail("add_extractor did not register the black hole extractor")
load_limit = game_state.transporter_load_limit()
elapsed = 0.0
stage = 2
return false
2:
# Mining is local, exactly like ore - no black-hole-specific code.
Recentre a released stick, slow extractors again, and unbreak the lab layout Both sticks float - the base jumps to wherever the finger lands, so a player does not have to hit an exact spot on a screen they cannot feel. Releasing put only the KNOB back onto the base and left the base parked wherever that touch had been, so an idle stick sat off-centre in a different place every time and read as a control still in use. Release now returns base and knob to the middle of the rect. Extractors produce at 0.5 ore per second, halved again: at 1.0 they still outran the rest of the economy. An extractor now pays back its 25-ore cost in fifty seconds rather than twelve. The ship lab and the crafter were both overlapping themselves. Enlarging the shared resource table to 136px (so it could breathe and show bigger type) pushed its bottom edge 34px into the vessel row beneath it in one and the status text in the other - my regression, visible immediately on a real screen and not at all in any test. The lab's second row of upgrade cards was also already running into the detail text below it, by 13px, before any of this. Both menus are re-spaced end to end rather than nudged, since moving one collision into another is how the second one got there. Two tests carried waits tuned to an extraction rate that has now changed twice. Both derive them from EXTRACTOR_RATE instead, so the next balance pass does not report a broken extractor that is working perfectly - the same fix test_extractor_income already needed one round ago, in the file next to it. Suite 112/112. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 13:31:46 +02:00
# DERIVED from the extraction rate, not a fixed 1.2s. That was
# long enough only while an extractor produced 2 a second; the
# rate has since been quartered, and a wait tuned to the old one
# reported a broken extractor that was working perfectly. What is
# under test is that dark matter accumulates LOCALLY rather than
# banking itself - not how quickly it arrives.
if elapsed < 1.0 / GameState.EXTRACTOR_RATE + 0.4:
return false
var mined: int = game_state.extractor_resource(extractor_index, GameState.RESOURCE_DARK_MATTER)
if mined <= 0:
return _fail("extractor mined no dark matter locally after %.1fs" % elapsed)
print("extractor mined %d dark matter locally, bank still %d" % [
mined, game_state.banked_resource(GameState.RESOURCE_DARK_MATTER)
])
# Force a full load directly (bypasses waiting out the real
# mining rate for the rest) so the transporter pickup dispatch
# fires without a long extra wait.
game_state.extractors[extractor_index].inventory.set_amount(GameState.RESOURCE_DARK_MATTER, load_limit)
elapsed = 0.0
stage = 3
return false
3:
# --- a transporter collects the full load and banks it -----------
if game_state.banked_resource(GameState.RESOURCE_DARK_MATTER) >= load_limit:
print("transporter banked %d dark matter" % game_state.banked_resource(GameState.RESOURCE_DARK_MATTER))
print("TEST_BLACK_HOLE: PASS")
quit(0)
return true
if elapsed > 10.0:
return _fail("dark matter was never collected to the bank (extractor=%d bank=%d)" % [
game_state.extractor_resource(extractor_index, GameState.RESOURCE_DARK_MATTER),
game_state.banked_resource(GameState.RESOURCE_DARK_MATTER),
])
return false
return false
func _fail(message: String) -> bool:
print("TEST_BLACK_HOLE: FAIL (%s)" % message)
quit(1)
return true