Guide the fleet to the nearest unconquered scan target
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
This commit is contained in:
parent
fd792e8b63
commit
10d19a369b
9 changed files with 311 additions and 38 deletions
|
|
@ -59,12 +59,29 @@ func _run() -> void:
|
|||
or not state.is_building_unlocked(GameState.BUILDING_PLANET_SCANNER):
|
||||
return _fail("Deep-Space Scanning did not unlock its building")
|
||||
state.add_building(GameState.BUILDING_PLANET_SCANNER, Vector2.ZERO)
|
||||
var explored_before_scan: Dictionary = state.explored_chunks.duplicate()
|
||||
var rocky: Dictionary = state.scan_for_planet(PlanetDefinitions.ROCKY_ID,
|
||||
Vector2.ZERO)
|
||||
if rocky.is_empty() or String(rocky.definition_id) != PlanetDefinitions.ROCKY_ID:
|
||||
return _fail("the scanner did not find a real rocky planet")
|
||||
if explored_before_scan.has(Vector2i(rocky.chunk)):
|
||||
return _fail("the scanner test's first target was already explored")
|
||||
if not state.explored_chunks.has(Vector2i(rocky.chunk)):
|
||||
return _fail("a scan result was not revealed on the persistent map")
|
||||
if String(state.active_scanner_target().planet_id) != String(rocky.planet_id):
|
||||
return _fail("the revealed planet was not retained as navigation target")
|
||||
if not _is_nearest_unconquered(state, rocky, PlanetDefinitions.ROCKY_ID):
|
||||
return _fail("the scanner did not select the physically closest rocky planet")
|
||||
# A conquered nearest match must be skipped on the next scan.
|
||||
state.planet_capture[String(rocky.planet_id)] = {
|
||||
"captured": [], "conquered": true,
|
||||
}
|
||||
var next_rocky: Dictionary = state.scan_for_planet(PlanetDefinitions.ROCKY_ID,
|
||||
Vector2.ZERO)
|
||||
if next_rocky.is_empty() or String(next_rocky.planet_id) == String(rocky.planet_id) \
|
||||
or state.is_planet_conquered(String(next_rocky.planet_id)):
|
||||
return _fail("scanner reused the nearest conquered rocky planet")
|
||||
print("scanner found the nearest unvisited world and skipped it after conquest")
|
||||
if PlanetDefinitions.BOSS_ID in state.scanner_available_planet_types():
|
||||
return _fail("boss signature is available before the four-world survey")
|
||||
|
||||
|
|
@ -83,6 +100,13 @@ func _run() -> void:
|
|||
Vector2.ZERO)
|
||||
if boss.is_empty() or Vector2i(boss.chunk) != WorldGen.OCTOPUS_BIOME_CENTER:
|
||||
return _fail("boss scan did not resolve the unique hostile region")
|
||||
var map_content: Node2D = load("res://world/WorldMapContent.gd").new()
|
||||
var marker: Dictionary = map_content.scanner_target_marker()
|
||||
if marker.is_empty() or String(marker.planet_id) != String(boss.planet_id) \
|
||||
or Vector2(marker.position).distance_to(
|
||||
Vector2(boss.world_position) * map_content.WORLD_TO_LOCAL) > 0.01:
|
||||
return _fail("the active scan has no matching destination point on the map")
|
||||
map_content.free()
|
||||
print("researched scanner reveals generated destinations; the fifth option waits for 4/4")
|
||||
|
||||
# #192: the scanner is taught immediately before the widened survey.
|
||||
|
|
@ -104,10 +128,27 @@ func _run() -> void:
|
|||
root.add_child(host)
|
||||
var fake_fleet := FakeFleet.new()
|
||||
fake_fleet.name = "Fleet"
|
||||
fake_fleet.position = WorldGen.chunk_origin(WorldGen.OCTOPUS_BIOME_CENTER) \
|
||||
+ Vector2(WorldGen.CHUNK_SIZE * 0.5, WorldGen.CHUNK_SIZE * 0.5)
|
||||
fake_fleet.position = Vector2.ZERO
|
||||
fake_fleet.add_to_group("player_fleet")
|
||||
host.add_child(fake_fleet)
|
||||
menu.close_menu()
|
||||
var guidance: Control = load("res://ui/ScannerGuidance.tscn").instantiate()
|
||||
root.add_child(guidance)
|
||||
guidance._process(0.0)
|
||||
if not guidance.visible or not guidance.get_node("TargetLabel").text.contains(
|
||||
String(boss.name).to_upper()):
|
||||
return _fail("the flight HUD did not point toward the scanned destination")
|
||||
var indicator: Control = guidance.get_node("Indicator")
|
||||
var indicator_center: Vector2 = indicator.position + indicator.size * 0.5
|
||||
var viewport_size: Vector2 = guidance.get_viewport_rect().size
|
||||
if indicator_center.x < 20.0 or indicator_center.y < 20.0 \
|
||||
or indicator_center.x > viewport_size.x - 20.0 \
|
||||
or indicator_center.y > viewport_size.y - 20.0:
|
||||
return _fail("scanner direction indicator was placed outside the viewport")
|
||||
guidance.queue_free()
|
||||
|
||||
fake_fleet.position = WorldGen.chunk_origin(WorldGen.OCTOPUS_BIOME_CENTER) \
|
||||
+ Vector2(WorldGen.CHUNK_SIZE * 0.5, WorldGen.CHUNK_SIZE * 0.5)
|
||||
var field: Node2D = load("res://world/OctopusField.gd").new()
|
||||
field.name = "OctopusField"
|
||||
host.add_child(field)
|
||||
|
|
@ -130,3 +171,24 @@ func _run() -> void:
|
|||
func _fail(message: String) -> void:
|
||||
print("FAIL: %s" % message)
|
||||
quit(1)
|
||||
|
||||
|
||||
func _is_nearest_unconquered(state: Node, result: Dictionary,
|
||||
definition_id: String) -> bool:
|
||||
var origin := Vector2.ZERO
|
||||
var result_distance: float = origin.distance_to(Vector2(result.world_position))
|
||||
var radius: int = int(result.distance_chunks) + 2
|
||||
for x in range(-radius, radius + 1):
|
||||
for y in range(-radius, radius + 1):
|
||||
var chunk := Vector2i(x, y)
|
||||
if not WorldGen.has_planet_at_chunk(chunk):
|
||||
continue
|
||||
var data: Dictionary = WorldGen.planet_data_at_chunk(chunk)
|
||||
if String(data.definition_id) != definition_id \
|
||||
or state.is_planet_conquered(String(data.planet_id)):
|
||||
continue
|
||||
var world_position: Vector2 = WorldGen.chunk_origin(chunk) \
|
||||
+ Vector2(data.local_pos)
|
||||
if origin.distance_to(world_position) < result_distance - 0.01:
|
||||
return false
|
||||
return true
|
||||
|
|
|
|||
Loading…
Reference in a new issue