Ship Lab: per-vessel research, and the shield vessel
Forgejo #5. A new building gated behind a "Vessel Science" research node. Its own screen upgrades each vessel type - weapon, movement, shield and freight - and unlocks the shield vessel, which the ship crafter can then build. Vessel research is deliberately NOT more nodes in the mothership tree: that tree gates what may be built at all and is a strategic spine, while these are repeatable tuning on vessels already owned. Levels cost base * (level + 1), so the third point in something is not the price of the first. Upgrades are read live rather than baked in at build time, so researching one improves the ships already flying. The shield is personal, not a bubble: it absorbs a hit that would destroy the vessel - ships have no health, contact kills - and is then down until it cycles. Its ring is a NeonPiece child toggled with `visible` per #10, not a redraw of the hull. The build menu now holds six entries across three rows, which the #21 repacking already handles. Enemies still have no weapon, so "blocks shots" has nothing to block yet; that is filed separately rather than widened into this ticket. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
19ac758da1
commit
1cbae8ff70
13 changed files with 876 additions and 5 deletions
|
|
@ -16,6 +16,7 @@ func _ready() -> void:
|
|||
GameState.add_building(GameState.BUILDING_MOTHERSHIP, Vector2(-330.0, 0.0))
|
||||
GameState.add_building(GameState.BUILDING_SHIP_CRAFTER, Vector2(140.0, 0.0))
|
||||
GameState.add_building(GameState.BUILDING_TRANSPORT_HUB, Vector2(480.0, 0.0))
|
||||
GameState.add_building(GameState.BUILDING_SHIP_LAB, Vector2(820.0, 0.0))
|
||||
|
||||
var main: Node = load("res://Main.tscn").instantiate()
|
||||
add_child(main)
|
||||
|
|
@ -23,6 +24,6 @@ func _ready() -> void:
|
|||
main.get_node("EnemySpawner").set_process(false)
|
||||
# Park the fleet below the pair so the camera frames both, and zoom out
|
||||
# far enough to see them whole.
|
||||
main.get_node("Fleet").move_to(Vector2(0.0, 210.0))
|
||||
main.get_node("Fleet").move_to(Vector2(240.0, 260.0))
|
||||
var cam: Camera2D = main.get_node("Camera2D")
|
||||
cam.zoom = Vector2(1.0, 1.0)
|
||||
cam.zoom = Vector2(0.78, 0.78)
|
||||
|
|
|
|||
25
tests/_lab_menu_preview.gd
Normal file
25
tests/_lab_menu_preview.gd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
extends Node2D
|
||||
|
||||
# Preview, not a test. The ship lab's upgrade screen (#5), so its layout can
|
||||
# be checked on a real viewport - headless draws no pixels.
|
||||
#
|
||||
# bash tests/screenshot.sh res://tests/_lab_menu_preview.tscn /tmp/lab.png 20 720x1280
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.buildings.clear()
|
||||
GameState.extractors.clear()
|
||||
GameState.transporters.clear()
|
||||
GameState.reset_progression()
|
||||
GameState.rocks = 240
|
||||
GameState.unlocked = ["shipyards", "vessel_science"]
|
||||
var main: Node = load("res://Main.tscn").instantiate()
|
||||
add_child(main)
|
||||
main.get_node("BuildingField").place(GameState.BUILDING_SHIP_LAB, Vector2(400.0, 0.0))
|
||||
# A level already bought, so the list shows both a researched and an
|
||||
# unresearched line rather than a uniform page of zeroes.
|
||||
GameState.vessel_levels["int_damage"] = 1
|
||||
var bc: Node = main.get_node("BuildController")
|
||||
main.get_node("UI/LabMenu").visible = true
|
||||
bc.lab_vessel = GameState.VESSEL_INTERCEPTOR
|
||||
bc._refresh_lab()
|
||||
1
tests/_lab_menu_preview.gd.uid
Normal file
1
tests/_lab_menu_preview.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dlueabpa84uyf
|
||||
6
tests/_lab_menu_preview.tscn
Normal file
6
tests/_lab_menu_preview.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/_lab_menu_preview.gd" id="1"]
|
||||
|
||||
[node name="LabMenuPreview" type="Node2D"]
|
||||
script = ExtResource("1")
|
||||
181
tests/test_shield_vessel.gd
Normal file
181
tests/test_shield_vessel.gd
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
extends SceneTree
|
||||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_shield_vessel.gd
|
||||
# Forgejo #5: the shield vessel's shield absorbs a hit that would destroy any
|
||||
# other ship, and is then down until it cycles back up.
|
||||
#
|
||||
# The shield is PERSONAL - it protects the vessel carrying it and nothing
|
||||
# else. Ships have no health in this game: contact with an enemy or an
|
||||
# asteroid destroys them outright, so "absorbs a hit" means surviving the
|
||||
# collision that would otherwise have killed it.
|
||||
#
|
||||
# Verifies:
|
||||
# 1. an ordinary interceptor still dies to a rock (so the shield result
|
||||
# below means something)
|
||||
# 2. a shield vessel survives the same rock, and the rock is destroyed
|
||||
# 3. its shield is then DOWN - a second rock while it is cycling kills it,
|
||||
# or the shield would be permanent invulnerability
|
||||
# 4. the shield comes back on its own after the recharge time
|
||||
# 5. researched capacity lets it take more than one hit
|
||||
# 6. the recharge upgrade actually shortens the wait
|
||||
|
||||
var game_state: Node
|
||||
var scene: Node
|
||||
var fleet: Node
|
||||
var interceptor: Node
|
||||
var shield_ship: Node
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
game_state = root.get_node("GameState")
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
game_state.transporters.clear()
|
||||
game_state.vessels_owed.clear()
|
||||
game_state.reset_progression()
|
||||
game_state.rocks = 2000
|
||||
scene = load("res://Main.tscn").instantiate()
|
||||
root.add_child(scene)
|
||||
fleet = scene.get_node("Fleet")
|
||||
|
||||
|
||||
func _rock_onto(ship: Node) -> void:
|
||||
var rock: Area2D = load("res://Asteroid.tscn").instantiate()
|
||||
rock.velocity = Vector2.ZERO
|
||||
rock.global_position = ship.global_position
|
||||
scene.add_child(rock)
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
match stage:
|
||||
0:
|
||||
scene.get_node("AsteroidField").set_process(false)
|
||||
scene.get_node("EnemySpawner").set_process(false)
|
||||
for a in get_nodes_in_group("asteroids"):
|
||||
if is_instance_valid(a):
|
||||
a.queue_free()
|
||||
fleet.spawn_ships(1, Vector2.ZERO)
|
||||
interceptor = fleet.ships[0]
|
||||
# Well clear of the interceptor, or one rock hits both.
|
||||
fleet.add_ship(GameState.VESSEL_SHIELD)
|
||||
shield_ship = fleet.ships[1]
|
||||
shield_ship.position = Vector2(2000.0, 0.0)
|
||||
elapsed = 0.0
|
||||
stage = 1
|
||||
return false
|
||||
1:
|
||||
if elapsed < 0.2:
|
||||
return false
|
||||
if not shield_ship.has_shield():
|
||||
print("TEST_SHIELD_VESSEL: FAIL (a fresh shield vessel has no shield)")
|
||||
quit(1)
|
||||
return true
|
||||
# --- 1. the control: an interceptor dies --------------------
|
||||
_rock_onto(interceptor)
|
||||
elapsed = 0.0
|
||||
stage = 2
|
||||
return false
|
||||
2:
|
||||
if elapsed < 0.4:
|
||||
return false
|
||||
if is_instance_valid(interceptor):
|
||||
print("TEST_SHIELD_VESSEL: FAIL (an ordinary interceptor survived a rock - the test proves nothing)")
|
||||
quit(1)
|
||||
return true
|
||||
print("control: interceptor destroyed by a rock")
|
||||
|
||||
# --- 2. the shield vessel survives it -----------------------
|
||||
_rock_onto(shield_ship)
|
||||
elapsed = 0.0
|
||||
stage = 3
|
||||
return false
|
||||
3:
|
||||
if elapsed < 0.4:
|
||||
return false
|
||||
if not is_instance_valid(shield_ship):
|
||||
print("TEST_SHIELD_VESSEL: FAIL (the shield did not absorb the hit)")
|
||||
quit(1)
|
||||
return true
|
||||
if shield_ship.has_shield():
|
||||
print("TEST_SHIELD_VESSEL: FAIL (shield still up after taking a hit - it never goes down)")
|
||||
quit(1)
|
||||
return true
|
||||
print("shield vessel survived, shield now down")
|
||||
|
||||
# --- 3. defenceless while it cycles -------------------------
|
||||
_rock_onto(shield_ship)
|
||||
elapsed = 0.0
|
||||
stage = 4
|
||||
return false
|
||||
4:
|
||||
if elapsed < 0.4:
|
||||
return false
|
||||
if is_instance_valid(shield_ship):
|
||||
print("TEST_SHIELD_VESSEL: FAIL (survived a second hit with the shield down - it is just invulnerable)")
|
||||
quit(1)
|
||||
return true
|
||||
print("second hit while cycling destroyed it, as it should")
|
||||
|
||||
# --- 4 + 5. recharge, and researched capacity ---------------
|
||||
game_state.vessel_levels["shd_hits"] = 1
|
||||
fleet.add_ship(GameState.VESSEL_SHIELD)
|
||||
shield_ship = fleet.ships[fleet.ships.size() - 1]
|
||||
shield_ship.position = Vector2(-2000.0, 0.0)
|
||||
elapsed = 0.0
|
||||
stage = 5
|
||||
return false
|
||||
5:
|
||||
if elapsed < 0.2:
|
||||
return false
|
||||
if shield_ship.shield_charges != game_state.shield_max_charges():
|
||||
print("TEST_SHIELD_VESSEL: FAIL (researched capacity %d, vessel has %d)" % [
|
||||
game_state.shield_max_charges(), shield_ship.shield_charges
|
||||
])
|
||||
quit(1)
|
||||
return true
|
||||
print("with Layered Emitters researched: %d charges" % shield_ship.shield_charges)
|
||||
_rock_onto(shield_ship)
|
||||
elapsed = 0.0
|
||||
stage = 6
|
||||
return false
|
||||
6:
|
||||
if elapsed < 0.4:
|
||||
return false
|
||||
if not is_instance_valid(shield_ship) or not shield_ship.has_shield():
|
||||
print("TEST_SHIELD_VESSEL: FAIL (a two-charge shield did not survive one hit with a charge left)")
|
||||
quit(1)
|
||||
return true
|
||||
print("two-charge shield took a hit and is still up (%d left)" % shield_ship.shield_charges)
|
||||
|
||||
# --- 6. the recharge upgrade shortens the wait --------------
|
||||
var slow: float = game_state.shield_recharge_time()
|
||||
game_state.vessel_levels["shd_recharge"] = 2
|
||||
var fast: float = game_state.shield_recharge_time()
|
||||
print("recharge %.1fs -> %.1fs with Fast Cycling" % [slow, fast])
|
||||
if fast >= slow:
|
||||
print("TEST_SHIELD_VESSEL: FAIL (the recharge upgrade did not shorten the wait)")
|
||||
quit(1)
|
||||
return true
|
||||
|
||||
# --- 4. it really does come back ----------------------------
|
||||
shield_ship.shield_charges = 0
|
||||
shield_ship.shield_recharge_left = 0.15
|
||||
elapsed = 0.0
|
||||
stage = 7
|
||||
return false
|
||||
7:
|
||||
if elapsed < 0.6:
|
||||
return false
|
||||
if not shield_ship.has_shield():
|
||||
print("TEST_SHIELD_VESSEL: FAIL (the shield never cycled back up)")
|
||||
quit(1)
|
||||
return true
|
||||
print("shield cycled back up on its own")
|
||||
print("TEST_SHIELD_VESSEL: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
return false
|
||||
1
tests/test_shield_vessel.gd.uid
Normal file
1
tests/test_shield_vessel.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmhp0nqvetr56
|
||||
177
tests/test_ship_lab.gd
Normal file
177
tests/test_ship_lab.gd
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
extends SceneTree
|
||||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_ship_lab.gd
|
||||
# Forgejo #5: the ship lab researches upgrades per vessel type and unlocks
|
||||
# new vessel types. The shield vessel is the first of those.
|
||||
#
|
||||
# Verifies:
|
||||
# 1. the lab is gated behind its own research node, like every structure
|
||||
# 2. upgrades cannot be bought without a lab built - it is a place you go,
|
||||
# not a menu that exists once researched
|
||||
# 3. buying raises the level, charges the escalating price, and stops at
|
||||
# max
|
||||
# 4. an upgrade improves the ships ALREADY FLYING, not just the next one
|
||||
# built
|
||||
# 5. the shield vessel is unlocked at the lab, and only then can the
|
||||
# crafter build one
|
||||
# 6. a shield vessel is what comes back from production - a typed order
|
||||
# must not decay into an interceptor
|
||||
# 7. upgrades are per vessel type: an interceptor upgrade does not tune
|
||||
# the transporter
|
||||
|
||||
var game_state: Node
|
||||
var scene: Node
|
||||
var fleet: Node
|
||||
var field: Node
|
||||
var controller: Node
|
||||
var crafter_id: int = 0
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
game_state = root.get_node("GameState")
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
game_state.transporters.clear()
|
||||
game_state.vessels_owed.clear()
|
||||
game_state.reset_progression()
|
||||
game_state.rocks = 1200
|
||||
game_state.fleet_cargo = 0
|
||||
scene = load("res://Main.tscn").instantiate()
|
||||
root.add_child(scene)
|
||||
fleet = scene.get_node("Fleet")
|
||||
field = scene.get_node("BuildingField")
|
||||
controller = scene.get_node("BuildController")
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
match stage:
|
||||
0:
|
||||
scene.get_node("AsteroidField").set_process(false)
|
||||
scene.get_node("EnemySpawner").set_process(false)
|
||||
for a in get_nodes_in_group("asteroids"):
|
||||
if is_instance_valid(a):
|
||||
a.queue_free()
|
||||
|
||||
# --- 1. gated behind research -------------------------------
|
||||
if game_state.is_building_unlocked(GameState.BUILDING_SHIP_LAB):
|
||||
print("TEST_SHIP_LAB: FAIL (lab buildable with no research)")
|
||||
quit(1)
|
||||
return true
|
||||
var gate: String = game_state.research_for_building(GameState.BUILDING_SHIP_LAB)
|
||||
if gate == "":
|
||||
print("TEST_SHIP_LAB: FAIL (no research node gates the lab)")
|
||||
quit(1)
|
||||
return true
|
||||
print("lab gated behind '%s'" % gate)
|
||||
|
||||
# --- 2. no lab, no upgrades ---------------------------------
|
||||
if game_state.can_buy_upgrade("int_damage"):
|
||||
print("TEST_SHIP_LAB: FAIL (upgrades purchasable with no lab built)")
|
||||
quit(1)
|
||||
return true
|
||||
if game_state.buy_upgrade("int_damage"):
|
||||
print("TEST_SHIP_LAB: FAIL (bought an upgrade with no lab built)")
|
||||
quit(1)
|
||||
return true
|
||||
print("no lab -> no upgrades")
|
||||
|
||||
game_state.unlocked = ["shipyards", "vessel_science", "coordination", "wing", "squadron"]
|
||||
field.place(GameState.BUILDING_SHIP_LAB, Vector2(-700.0, 0.0))
|
||||
field.place(GameState.BUILDING_SHIP_CRAFTER, Vector2(700.0, 0.0))
|
||||
crafter_id = int(game_state.buildings[-1].id)
|
||||
elapsed = 0.0
|
||||
stage = 1
|
||||
return false
|
||||
1:
|
||||
if elapsed < 0.3:
|
||||
return false
|
||||
# --- 3. buying raises the level and charges ------------------
|
||||
var before_rocks: int = game_state.rocks
|
||||
var first_cost: int = game_state.upgrade_cost("int_damage")
|
||||
if not game_state.buy_upgrade("int_damage"):
|
||||
print("TEST_SHIP_LAB: FAIL (could not buy an upgrade with a lab built)")
|
||||
quit(1)
|
||||
return true
|
||||
if game_state.upgrade_level("int_damage") != 1:
|
||||
print("TEST_SHIP_LAB: FAIL (level did not rise)")
|
||||
quit(1)
|
||||
return true
|
||||
if game_state.rocks != before_rocks - first_cost:
|
||||
print("TEST_SHIP_LAB: FAIL (wrong price charged)")
|
||||
quit(1)
|
||||
return true
|
||||
var second_cost: int = game_state.upgrade_cost("int_damage")
|
||||
if second_cost <= first_cost:
|
||||
print("TEST_SHIP_LAB: FAIL (level 2 costs %d, no more than level 1 at %d)" % [second_cost, first_cost])
|
||||
quit(1)
|
||||
return true
|
||||
print("bought level 1 for %d, level 2 now costs %d" % [first_cost, second_cost])
|
||||
|
||||
# --- 4. it reaches ships already flying ----------------------
|
||||
var flying: Node = fleet.ships[0]
|
||||
if flying.projectile_damage != GameState.SHIP_BASE_DAMAGE + 1:
|
||||
print("TEST_SHIP_LAB: FAIL (a ship already flying still does %d damage)" % flying.projectile_damage)
|
||||
quit(1)
|
||||
return true
|
||||
print("ship already flying now does %d damage" % flying.projectile_damage)
|
||||
|
||||
# --- 7. per vessel type --------------------------------------
|
||||
var trn_speed_before: float = game_state.transporter_speed()
|
||||
game_state.buy_upgrade("int_speed")
|
||||
if game_state.transporter_speed() != trn_speed_before:
|
||||
print("TEST_SHIP_LAB: FAIL (an interceptor upgrade changed the transporter)")
|
||||
quit(1)
|
||||
return true
|
||||
print("interceptor upgrades leave the transporter alone")
|
||||
|
||||
# --- 5. the shield vessel is unlocked at the lab -------------
|
||||
if game_state.shield_vessel_unlocked():
|
||||
print("TEST_SHIP_LAB: FAIL (shield vessel available before it was unlocked)")
|
||||
quit(1)
|
||||
return true
|
||||
if game_state.queue_order(crafter_id, GameState.VESSEL_SHIELD):
|
||||
print("TEST_SHIP_LAB: FAIL (crafter took a shield order before the type was unlocked)")
|
||||
quit(1)
|
||||
return true
|
||||
if not game_state.unlock_shield_vessel():
|
||||
print("TEST_SHIP_LAB: FAIL (could not unlock the shield vessel at the lab)")
|
||||
quit(1)
|
||||
return true
|
||||
print("shield vessel unlocked at the lab")
|
||||
|
||||
# --- 6. a typed order comes back as that type ----------------
|
||||
fleet.spawn_ships(1, Vector2.ZERO)
|
||||
if not game_state.queue_order(crafter_id, GameState.VESSEL_SHIELD):
|
||||
print("TEST_SHIP_LAB: FAIL (crafter refused a shield order after unlocking)")
|
||||
quit(1)
|
||||
return true
|
||||
game_state.deposit_to_building(crafter_id, GameState.SHIELD_COST)
|
||||
elapsed = 0.0
|
||||
stage = 2
|
||||
return false
|
||||
2:
|
||||
if elapsed < 0.6:
|
||||
return false
|
||||
var shield_ship: Node = null
|
||||
for ship in fleet.ships:
|
||||
if is_instance_valid(ship) and ship.vessel_type == GameState.VESSEL_SHIELD:
|
||||
shield_ship = ship
|
||||
if shield_ship == null:
|
||||
print("TEST_SHIP_LAB: FAIL (the shield order produced no shield vessel: %d ships, owed %s)" % [
|
||||
fleet.ships.size(), game_state.vessels_owed
|
||||
])
|
||||
quit(1)
|
||||
return true
|
||||
if not shield_ship.has_shield():
|
||||
print("TEST_SHIP_LAB: FAIL (the shield vessel arrived with no shield up)")
|
||||
quit(1)
|
||||
return true
|
||||
print("shield vessel built, shield up with %d charge(s)" % shield_ship.shield_charges)
|
||||
print("TEST_SHIP_LAB: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
return false
|
||||
1
tests/test_ship_lab.gd.uid
Normal file
1
tests/test_ship_lab.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cwwl0p787wqdh
|
||||
Loading…
Reference in a new issue