Fix assertion failure which could occur when using reverse behind signal

This commit is contained in:
Jonathan G Rennison
2020-09-04 17:41:27 +01:00
parent 00a31a4885
commit 5196caddde
2 changed files with 30 additions and 9 deletions

View File

@@ -67,6 +67,11 @@ public:
n.m_estimate = n.m_cost;
return true;
}
inline int TeleportCost(TileIndex cur_tile, TileIndex prev_tile)
{
return 0;
}
};
template <class Types>
@@ -105,6 +110,11 @@ public:
n.m_estimate = n.m_cost;
return true;
}
inline int TeleportCost(TileIndex cur_tile, TileIndex prev_tile)
{
return 0;
}
};
template <class Types>
@@ -201,6 +211,22 @@ public:
assert(n.m_estimate >= n.m_parent->m_estimate);
return true;
}
inline int TeleportCost(TileIndex cur_tile, TileIndex prev_tile)
{
auto calculate_distance_cost = [&](TileIndex t, int d_adjust) -> int {
int x1 = 2 * TileX(t);
int y1 = 2 * TileY(t);
int x2 = 2 * TileX(m_destTile);
int y2 = 2 * TileY(m_destTile);
int dx = abs(x1 - x2) + d_adjust;
int dy = abs(y1 - y2);
int dmin = min(dx, dy) + d_adjust; // up to 2x track exit dir tile offsets in opposite directions
int dxy = abs(dx - dy) + d_adjust; // "
return dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
};
return max<int>(0, calculate_distance_cost(prev_tile, 8) - calculate_distance_cost(cur_tile, 0));
}
};
#endif /* YAPF_DESTRAIL_HPP */