mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
Fix crash when checking for train reverse on custom bridge heads with YAPF
This commit is contained in:
parent
796a878b90
commit
b048f824dc
@ -680,30 +680,32 @@ bool YapfTrainCheckReverse(const Train *v)
|
|||||||
/* front in tunnel / on bridge */
|
/* front in tunnel / on bridge */
|
||||||
DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile);
|
DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile);
|
||||||
|
|
||||||
if (TrackdirToExitdir(td) == dir_into_wormhole) tile = GetOtherTunnelBridgeEnd(tile);
|
|
||||||
/* Now 'tile' is the tunnel entry/bridge ramp the train will reach when driving forward */
|
|
||||||
|
|
||||||
/* Current position of the train in the wormhole */
|
/* Current position of the train in the wormhole */
|
||||||
TileIndex cur_tile = TileVirtXY(v->x_pos, v->y_pos);
|
TileIndex cur_tile = TileVirtXY(v->x_pos, v->y_pos);
|
||||||
|
|
||||||
/* Add distance to drive in the wormhole as penalty for the forward path, i.e. bonus for the reverse path
|
/* Add distance to drive in the wormhole as penalty for the forward path, i.e. bonus for the reverse path
|
||||||
* Note: Negative penalties are ok for the start tile. */
|
* Note: Negative penalties are ok for the start tile. */
|
||||||
|
if (TrackdirToExitdir(td) == dir_into_wormhole) {
|
||||||
|
reverse_penalty += DistanceManhattan(cur_tile, tile) * YAPF_TILE_LENGTH;
|
||||||
|
} else {
|
||||||
reverse_penalty -= DistanceManhattan(cur_tile, tile) * YAPF_TILE_LENGTH;
|
reverse_penalty -= DistanceManhattan(cur_tile, tile) * YAPF_TILE_LENGTH;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (last_veh->track & TRACK_BIT_WORMHOLE) {
|
if (last_veh->track & TRACK_BIT_WORMHOLE) {
|
||||||
/* back in tunnel / on bridge */
|
/* back in tunnel / on bridge */
|
||||||
DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile_rev);
|
DiagDirection dir_into_wormhole = GetTunnelBridgeDirection(tile_rev);
|
||||||
|
|
||||||
if (TrackdirToExitdir(td_rev) == dir_into_wormhole) tile_rev = GetOtherTunnelBridgeEnd(tile_rev);
|
|
||||||
/* Now 'tile_rev' is the tunnel entry/bridge ramp the train will reach when reversing */
|
|
||||||
|
|
||||||
/* Current position of the last wagon in the wormhole */
|
/* Current position of the last wagon in the wormhole */
|
||||||
TileIndex cur_tile = TileVirtXY(last_veh->x_pos, last_veh->y_pos);
|
TileIndex cur_tile = TileVirtXY(last_veh->x_pos, last_veh->y_pos);
|
||||||
|
|
||||||
/* Add distance to drive in the wormhole as penalty for the revere path. */
|
/* Add distance to drive in the wormhole as penalty for the revere path. */
|
||||||
|
if (TrackdirToExitdir(td_rev) == dir_into_wormhole) {
|
||||||
|
reverse_penalty -= DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
|
||||||
|
} else {
|
||||||
reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
|
reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef bool (*PfnCheckReverseTrain)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int);
|
typedef bool (*PfnCheckReverseTrain)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int);
|
||||||
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
|
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
|
||||||
|
Loading…
Reference in New Issue
Block a user