1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-15 08:22:34 +01:00

Change: Separate ships travelling in opposite direction (#14493)

This commit is contained in:
Kuhnovic
2025-08-08 09:52:01 +02:00
committed by GitHub
parent c8a07fe90b
commit 40457fc0dd

View File

@@ -355,6 +355,23 @@ public:
return 0;
}
/**
* Whether the provided direction is a preferred direction for a given tile. This is used to separate ships travelling in opposite directions.
* @param tile Tile of current node.
* @param td Trackdir of current node.
* @returns true if a preferred direction, false otherwise.
*/
inline static bool IsPreferredShipDirection(TileIndex tile, Trackdir td)
{
const bool odd_x = TileX(tile) & 1;
const bool odd_y = TileY(tile) & 1;
if (td == TRACKDIR_X_NE) return odd_y;
if (td == TRACKDIR_X_SW) return !odd_y;
if (td == TRACKDIR_Y_NW) return odd_x;
if (td == TRACKDIR_Y_SE) return !odd_x;
return (odd_x ^ odd_y) ^ HasBit(TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_LOWER_E, td);
}
/**
* Called by YAPF to calculate the cost from the origin to the given node.
* Calculates only the cost of given node, adds it to the parent node cost
@@ -376,6 +393,9 @@ public:
c += count * 3 * YAPF_TILE_LENGTH;
}
/* Encourage separation between ships traveling in different directions. */
if (!IsPreferredShipDirection(n.GetTile(), n.GetTrackdir())) c += YAPF_TILE_LENGTH;
/* Skipped tile cost for aqueducts. */
c += YAPF_TILE_LENGTH * tf->tiles_skipped;