Add planet conquest state and gate extractor placement (#41)
Planets now need every capture point held before an extractor can go up there: GameState tracks per-planet capture progress keyed by the same stable planet_id as extractors, and BuildController's four extractor placement checks (menu enable, status text, info popup, confirm) all re-check conquest, not just proximity/duplication. Part of the #40 conquest-mechanic breakdown.
This commit is contained in:
parent
7da4531f25
commit
a1ad6cc844
5 changed files with 238 additions and 4 deletions
|
|
@ -42,6 +42,12 @@ func _initialize() -> void:
|
|||
game_state.rocks = 200
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
game_state.planet_capture.clear()
|
||||
# This test is about the planet-proximity/duplicate rules, not conquest
|
||||
# (see test_planet_conquest_gate), so pre-conquer the target planet.
|
||||
var target_planet_id: String = "chunk:%d:%d" % [target_chunk.x, target_chunk.y]
|
||||
game_state.register_capture_points(target_planet_id, 1)
|
||||
game_state.mark_point_captured(target_planet_id, 0)
|
||||
# Extractors are gated behind research (see test_skill_tree). This test
|
||||
# is about the planet-proximity rule, so grant the research up front.
|
||||
game_state.reset_progression()
|
||||
|
|
|
|||
157
tests/test_planet_conquest_gate.gd
Normal file
157
tests/test_planet_conquest_gate.gd
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
extends SceneTree
|
||||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_planet_conquest_gate.gd
|
||||
# Verifies:
|
||||
# 1. GameState starts every planet unconquered, and register_capture_points
|
||||
# is idempotent (a second call with the same total doesn't wipe progress)
|
||||
# 2. mark_point_captured only conquers once every point is captured, and
|
||||
# the planet_conquered signal fires exactly once
|
||||
# 3. over an unconquered planet, the extractor build option is disabled,
|
||||
# the info popup explains why, and confirming spends nothing and builds
|
||||
# nothing
|
||||
# 4. once conquered, the same build flow works and charges the cost
|
||||
|
||||
var main_scene: Node
|
||||
var fleet: Node
|
||||
var game_state: Node
|
||||
var controller: Node
|
||||
var button: IconButton
|
||||
var popup: Control
|
||||
var target_chunk: Vector2i
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
var conquered_signal_count: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
var found: bool = false
|
||||
for x in range(-15, 15):
|
||||
for y in range(-15, 15):
|
||||
var chunk: Vector2i = Vector2i(x, y)
|
||||
if WorldGen.has_planet_at_chunk(chunk):
|
||||
target_chunk = chunk
|
||||
found = true
|
||||
break
|
||||
if found:
|
||||
break
|
||||
if not found:
|
||||
return _fail("no planet chunk to test with")
|
||||
|
||||
game_state = root.get_node("GameState")
|
||||
game_state.rocks = 200
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
game_state.planet_capture.clear()
|
||||
game_state.reset_progression()
|
||||
for node in GameState.SKILL_TREE:
|
||||
game_state.unlocked.append(node.id)
|
||||
|
||||
var target_planet_id: String = "chunk:%d:%d" % [target_chunk.x, target_chunk.y]
|
||||
|
||||
# Unit-level checks on GameState itself, before any scene involvement.
|
||||
if game_state.is_planet_conquered(target_planet_id):
|
||||
return _fail("a fresh planet reported conquered")
|
||||
game_state.register_capture_points(target_planet_id, 3)
|
||||
game_state.mark_point_captured(target_planet_id, 0)
|
||||
game_state.register_capture_points(target_planet_id, 3) # idempotent re-registration
|
||||
if game_state.captured_point_count(target_planet_id) != 1:
|
||||
return _fail("re-registering wiped already-captured progress")
|
||||
game_state.planet_conquered.connect(func(_id): conquered_signal_count += 1)
|
||||
game_state.mark_point_captured(target_planet_id, 1)
|
||||
if game_state.is_planet_conquered(target_planet_id):
|
||||
return _fail("conquered with points still missing")
|
||||
game_state.mark_point_captured(target_planet_id, 2)
|
||||
if not game_state.is_planet_conquered(target_planet_id):
|
||||
return _fail("all points captured but planet not marked conquered")
|
||||
# Marking an already-captured point again must not double-fire the signal.
|
||||
game_state.mark_point_captured(target_planet_id, 2)
|
||||
if conquered_signal_count != 1:
|
||||
return _fail("planet_conquered fired %d times, expected exactly 1" % conquered_signal_count)
|
||||
|
||||
# Reset conquest for the scene-level gate check below - this run tests
|
||||
# the unconquered path first, then conquers it.
|
||||
game_state.planet_capture.clear()
|
||||
|
||||
main_scene = load("res://Main.tscn").instantiate()
|
||||
root.add_child(main_scene)
|
||||
fleet = main_scene.get_node("Fleet")
|
||||
controller = main_scene.get_node("BuildController")
|
||||
button = main_scene.get_node("UI/BuildMenu/ExtractorButton")
|
||||
popup = main_scene.get_node("UI/BuildMenu/InfoPopup")
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
match stage:
|
||||
0:
|
||||
main_scene.get_node("AsteroidField").set_process(false)
|
||||
main_scene.get_node("EnemySpawner").set_process(false)
|
||||
var near: Vector2 = WorldGen.chunk_origin(target_chunk) + Vector2.ONE * WorldGen.CHUNK_SIZE * 0.5
|
||||
for ship in fleet.ships:
|
||||
ship.position = near
|
||||
fleet.move_to(near)
|
||||
elapsed = 0.0
|
||||
stage = 1
|
||||
return false
|
||||
1:
|
||||
var planet_field: Node = main_scene.get_node("PlanetField")
|
||||
if elapsed < planet_field.check_interval + 0.2:
|
||||
return false
|
||||
if not planet_field.populated_chunks.has(target_chunk):
|
||||
return _fail("planet never spawned")
|
||||
var planet: Node2D = planet_field.populated_chunks[target_chunk][0]
|
||||
for ship in fleet.ships:
|
||||
ship.position = planet.position
|
||||
fleet.move_to(planet.position)
|
||||
elapsed = 0.0
|
||||
stage = 2
|
||||
return false
|
||||
2:
|
||||
if elapsed < 0.3:
|
||||
return false
|
||||
var planet_field: Node = main_scene.get_node("PlanetField")
|
||||
var planet: Node2D = planet_field.populated_chunks[target_chunk][0]
|
||||
|
||||
controller._on_build_pressed()
|
||||
if button.enabled:
|
||||
return _fail("extractor option enabled over an unconquered planet")
|
||||
controller._show_building_info(GameState.BUILDING_EXTRACTOR)
|
||||
var explains_capture: bool = popup.visible \
|
||||
and "captur" in popup.get_node("Panel/MessageLabel").text.to_lower()
|
||||
var offered: bool = popup.get_node("Panel/BuildButton").visible
|
||||
if not explains_capture or offered:
|
||||
return _fail("unconquered popup did not explain itself, or offered a build")
|
||||
var rocks_before: int = game_state.rocks
|
||||
controller._confirm_build() # must do nothing even if somehow pressed
|
||||
if game_state.rocks != rocks_before or not game_state.extractors.is_empty():
|
||||
return _fail("build proceeded over an unconquered planet")
|
||||
popup.visible = false
|
||||
|
||||
# Now conquer it and confirm the same flow succeeds.
|
||||
game_state.register_capture_points(planet.planet_id, 2)
|
||||
game_state.mark_point_captured(planet.planet_id, 0)
|
||||
game_state.mark_point_captured(planet.planet_id, 1)
|
||||
|
||||
controller._on_build_pressed()
|
||||
if not button.enabled:
|
||||
return _fail("extractor option stayed disabled after conquest")
|
||||
controller._show_building_info(GameState.BUILDING_EXTRACTOR)
|
||||
if not popup.get_node("Panel/BuildButton").visible:
|
||||
return _fail("conquered planet did not offer a build")
|
||||
controller._confirm_build()
|
||||
var built: bool = game_state.has_extractor_at(planet.planet_id)
|
||||
var charged: bool = game_state.rocks == rocks_before - GameState.EXTRACTOR_COST
|
||||
if not built or not charged:
|
||||
return _fail("conquered planet did not build/charge correctly")
|
||||
|
||||
print("TEST_PLANET_CONQUEST_GATE: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _fail(message: String) -> bool:
|
||||
print("TEST_PLANET_CONQUEST_GATE: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
return true
|
||||
1
tests/test_planet_conquest_gate.gd.uid
Normal file
1
tests/test_planet_conquest_gate.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://k4l7u3r84jch
|
||||
Loading…
Reference in a new issue