Fix assertion failure which could occur when using reverse behind signal
This commit is contained in:
@@ -478,15 +478,6 @@ public:
|
||||
/* Skip the first transition cost calculation. */
|
||||
goto no_entry_cost;
|
||||
} else if (n.flags_u.flags_s.m_teleport) {
|
||||
int x1 = 2 * TileX(prev.tile);
|
||||
int y1 = 2 * TileY(prev.tile);
|
||||
int x2 = 2 * TileX(cur.tile);
|
||||
int y2 = 2 * TileY(cur.tile);
|
||||
int dx = abs(x1 - x2) + 4; // up to 2x track exit dir tile offsets in opposite directions
|
||||
int dy = abs(y1 - y2) + 4; // "
|
||||
int dmin = min(dx, dy);
|
||||
int dxy = abs(dx - dy);
|
||||
segment_entry_cost += dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
|
||||
goto no_entry_cost;
|
||||
}
|
||||
|
||||
@@ -765,6 +756,10 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||
}
|
||||
}
|
||||
|
||||
if (has_parent && n.flags_u.flags_s.m_teleport) {
|
||||
extra_cost += Yapf().TeleportCost(n.GetLastTile(), n.m_parent->GetLastTile());
|
||||
}
|
||||
|
||||
/* total node cost */
|
||||
n.m_cost = parent_cost + segment_entry_cost + segment_cost + extra_cost;
|
||||
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user