Initial implementation of two rail types per tile
This commit is contained in:
96
src/rail.cpp
96
src/rail.cpp
@@ -179,6 +179,102 @@ RailType GetTileRailType(TileIndex tile)
|
||||
return INVALID_RAILTYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rail type of tile and track piece, or INVALID_RAILTYPE if this is no rail tile and return_invalid is true.
|
||||
*/
|
||||
RailType GenericGetRailTypeByTrack(TileIndex t, Track track, bool return_invalid)
|
||||
{
|
||||
if (IsPlainRailTile(t)) {
|
||||
TrackBits bits = GetTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (TrackToTrackBits(track) & TRACK_BIT_RT_1) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else if (IsRailTunnelBridgeTile(t)) {
|
||||
TrackBits bits = GetTunnelBridgeTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (TrackToTrackBits(track) & GetAcrossBridgePossibleTrackBits(t)) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else {
|
||||
return return_invalid ? GetTileRailType(t) : GetRailType(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rail type of tile and track piece, or INVALID_RAILTYPE if this is no rail tile and return_invalid is true.
|
||||
*/
|
||||
RailType GenericGetRailTypeByTrackBit(TileIndex t, TrackBits tb, bool return_invalid)
|
||||
{
|
||||
if (IsPlainRailTile(t)) {
|
||||
TrackBits bits = GetTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (tb & TRACK_BIT_RT_1) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else if (IsRailTunnelBridgeTile(t)) {
|
||||
TrackBits bits = GetTunnelBridgeTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (tb & GetAcrossBridgePossibleTrackBits(t)) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else {
|
||||
return return_invalid ? GetTileRailType(t) : GetRailType(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rail type of tile and entrance direction, or INVALID_RAILTYPE if this is no rail tile and return_invalid is true.
|
||||
*/
|
||||
RailType GenericGetRailTypeByEntryDir(TileIndex t, DiagDirection enterdir, bool return_invalid)
|
||||
{
|
||||
if (IsPlainRailTile(t)) {
|
||||
TrackBits bits = GetTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (bits & DiagdirReachesTracks(enterdir) & TRACK_BIT_RT_1) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else if (IsRailTunnelBridgeTile(t)) {
|
||||
TrackBits bits = GetTunnelBridgeTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return (bits & DiagdirReachesTracks(enterdir) & GetAcrossBridgePossibleTrackBits(t)) ? GetRailType(t) : GetSecondaryRailType(t);
|
||||
} else {
|
||||
return GetRailType(t);
|
||||
}
|
||||
} else {
|
||||
return return_invalid ? GetTileRailType(t) : GetRailType(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the secondary rail type of tile, or INVALID_RAILTYPE if this tile has no secondary rail type
|
||||
*/
|
||||
RailType GetTileSecondaryRailTypeIfValid(TileIndex t)
|
||||
{
|
||||
if (IsPlainRailTile(t)) {
|
||||
TrackBits bits = GetTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return GetSecondaryRailType(t);
|
||||
} else {
|
||||
return INVALID_RAILTYPE;
|
||||
}
|
||||
} else if (IsRailTunnelBridgeTile(t)) {
|
||||
TrackBits bits = GetTunnelBridgeTrackBits(t);
|
||||
if (bits == TRACK_BIT_HORZ || bits == TRACK_BIT_VERT) {
|
||||
return GetSecondaryRailType(t);
|
||||
} else {
|
||||
return INVALID_RAILTYPE;
|
||||
}
|
||||
} else {
|
||||
return INVALID_RAILTYPE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds out if a company has a certain railtype available
|
||||
* @param company the company in question
|
||||
|
Reference in New Issue
Block a user