Highlight selected tunnels' connection in green (REQ-BLD-TUNNEL-SELECT-HIGHLIGHT)

While a Tunnel Entry or Exit (building or construction site) is selected,
mark its connection green in the game world — the entry tile, exit tile,
and tiles between — reusing the tunnel_preview color from the placement
preview. Unpaired tunnels show no green.

- Add core findTunnelPartner(): the matching end of an existing tunnel
  tile, reusing firstTunnelFacing so the pairing scan stays single-sourced;
  unit-tested in TunnelCompletionTest.
- GameWorldView: extract the built+site tunnel index into
  collectTunnelTiles() (shared with updateTunnelGhost) and add
  drawSelectedTunnelConnections(), called from drawOverlays. Tiles are
  deduped via a set so a connection selected from both ends fills once.
- Also commits the REQ-BLD-TUNNEL-SELECT-HIGHLIGHT requirement text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y7N59FsLA5e2kuVdqe4Uhc
This commit is contained in:
2026-07-21 19:32:51 +02:00
parent 9a21506b5c
commit 3ac3d8a6e6
6 changed files with 220 additions and 12 deletions

View File

@@ -169,3 +169,80 @@ TEST_CASE("A candidate beyond the max distance is not matched")
REQUIRE(result.resolvedType == BuildingType::TunnelEntry);
REQUIRE(!result.partnerTile.has_value());
}
// ---------------------------------------------------------------------------
// findTunnelPartner: the matching end of an existing selected tunnel
// (REQ-BLD-TUNNEL-SELECT-HIGHLIGHT)
// ---------------------------------------------------------------------------
TEST_CASE("findTunnelPartner: a selected entry finds its exit ahead")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(2, 5), BuildingType::TunnelEntry, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(6, 5));
}
TEST_CASE("findTunnelPartner: a selected exit finds its entry behind")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(6, 5), BuildingType::TunnelExit, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(2, 5));
}
TEST_CASE("findTunnelPartner: an unpaired tunnel has no partner")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 10).has_value());
}
TEST_CASE("findTunnelPartner: a same-direction tunnel between blocks the pairing")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East}; // selected
tunnels[{4, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East}; // blocker
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
// The scan from the selected entry stops at the same-direction entry, which is not
// an exit, so the exit beyond it is not paired.
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 10).has_value());
}
TEST_CASE("findTunnelPartner: a differently-facing tunnel is skipped")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{4, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::North}; // skipped
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East}; // match
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(2, 5), BuildingType::TunnelEntry, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(6, 5));
}
TEST_CASE("findTunnelPartner: a partner beyond the max distance is not matched")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East}; // distance 4
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 3).has_value());
}