diff options
author | Patric Stout <truebrain@openttd.org> | 2021-02-25 22:46:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 22:46:46 +0100 |
commit | d4583fa64c067c00d3a7592642b3c269d02a8bef (patch) | |
tree | 942865605eb6ae2385ce5e4b5d7a010064586dbb /src/pathfinder/pathfinder_func.h | |
parent | 9209807d662a619ee8c3edcae0d5b5fcf6db6d1d (diff) | |
download | openttd-d4583fa64c067c00d3a7592642b3c269d02a8bef.tar.xz |
Fix #8123: trams on half-tiles couldn't find depots (#8738)
Basically, follow_track.hpp contains a fix for half-tiles, but
this wasn't duplicated for when trying to find a depot and in
a few other places. This makes sure all places act the same.
Diffstat (limited to 'src/pathfinder/pathfinder_func.h')
-rw-r--r-- | src/pathfinder/pathfinder_func.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pathfinder/pathfinder_func.h b/src/pathfinder/pathfinder_func.h index 03edf6995..f11b8088a 100644 --- a/src/pathfinder/pathfinder_func.h +++ b/src/pathfinder/pathfinder_func.h @@ -10,6 +10,7 @@ #ifndef PATHFINDER_FUNC_H #define PATHFINDER_FUNC_H +#include "../tile_cmd.h" #include "../waypoint_base.h" /** @@ -46,4 +47,40 @@ static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile return TileXY(x, y); } +/** + * Wrapper around GetTileTrackStatus() and TrackStatusToTrackdirBits(), as for + * single tram bits GetTileTrackStatus() returns 0. The reason for this is + * that there are no half-tile TrackBits in OpenTTD. + * This tile, however, is a valid tile for trams, one on which they can + * reverse safely. To "fix" this, pretend that if we are on a half-tile, we + * are in fact on a straight tram track tile. CFollowTrackT will make sure + * the pathfinders cannot exit on the wrong side and allows reversing on such + * tiles. + */ +static inline TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt) +{ + TrackdirBits bits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, rtt)); + + if (rtt == RTT_TRAM && bits == TRACKDIR_BIT_NONE) { + if (IsNormalRoadTile(tile)) { + RoadBits rb = GetRoadBits(tile, RTT_TRAM); + switch (rb) { + case ROAD_NE: + case ROAD_SW: + bits = TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW; + break; + + case ROAD_NW: + case ROAD_SE: + bits = TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_Y_SE; + break; + + default: break; + } + } + } + + return bits; +} + #endif /* PATHFINDER_FUNC_H */ |