From d4583fa64c067c00d3a7592642b3c269d02a8bef Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 25 Feb 2021 22:46:46 +0100 Subject: 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. --- src/pathfinder/pathfinder_func.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/pathfinder/pathfinder_func.h') 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 */ -- cgit v1.2.3-70-g09d2