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.
This commit is contained in:
Patric Stout
2021-02-25 22:46:46 +01:00
committed by GitHub
parent 9209807d66
commit d4583fa64c
3 changed files with 45 additions and 22 deletions

View File

@@ -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 */