Highlight tunnel connections in green when selected
This commit is contained in:
@@ -113,3 +113,43 @@ TunnelCompletion resolveTunnelCompletion(const TunnelLookup& lookup, QPoint hove
|
||||
}
|
||||
return TunnelCompletion{BuildingType::TunnelEntry, exitPartner};
|
||||
}
|
||||
|
||||
std::optional<QPoint> findTunnelPartner(const TunnelLookup& lookup, QPoint tile,
|
||||
BuildingType type, Rotation rotation,
|
||||
int maxDistance)
|
||||
{
|
||||
if (type == BuildingType::TunnelEntry)
|
||||
{
|
||||
// An entry pairs with the first same-direction tunnel ahead, if it is an exit.
|
||||
const std::optional<QPoint> ahead =
|
||||
firstTunnelFacing(lookup, tile, rotation, rotation, maxDistance);
|
||||
if (ahead.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*ahead);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelExit)
|
||||
{
|
||||
return ahead;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (type == BuildingType::TunnelExit)
|
||||
{
|
||||
// An exit is claimed by the first same-direction tunnel behind it, if it is an
|
||||
// entry (its forward search reaches this exit as its first same-direction tunnel).
|
||||
const std::optional<QPoint> behind =
|
||||
firstTunnelFacing(lookup, tile, oppositeRotation(rotation), rotation, maxDistance);
|
||||
if (behind.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*behind);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelEntry)
|
||||
{
|
||||
return behind;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -52,3 +52,15 @@ struct TunnelCompletion
|
||||
TunnelCompletion resolveTunnelCompletion(const TunnelLookup& lookup, QPoint hoverTile,
|
||||
Rotation rotation, int maxDistance,
|
||||
QVector2D cursorWorldPos);
|
||||
|
||||
// Finds the matching end of an existing tunnel building at `tile` of the given `type`
|
||||
// (TunnelEntry or TunnelExit) facing `rotation`, applying the pairing scan of
|
||||
// REQ-BLD-TUNNEL-PAIR over `lookup`:
|
||||
// - for an entry, the first same-direction tunnel along its facing direction, if it
|
||||
// is an exit;
|
||||
// - for an exit, the first same-direction tunnel opposite its facing direction, if it
|
||||
// is an entry.
|
||||
// Returns the partner tile, or std::nullopt when the tunnel is unpaired.
|
||||
std::optional<QPoint> findTunnelPartner(const TunnelLookup& lookup, QPoint tile,
|
||||
BuildingType type, Rotation rotation,
|
||||
int maxDistance);
|
||||
|
||||
Reference in New Issue
Block a user