mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-10 06:52:05 +01:00
Codechange: Use enum class for RailTileType
This commit is contained in:
committed by
Peter Nelson
parent
e8ba7d0a08
commit
0f5a4290df
@@ -89,7 +89,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, DiagDirections *override
|
||||
case MP_RAILWAY:
|
||||
if (!HasRailCatenary(GetRailType(t))) return TRACK_BIT_NONE;
|
||||
switch (GetRailTileType(t)) {
|
||||
case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS:
|
||||
case RailTileType::Normal: case RailTileType::Signals:
|
||||
return GetTrackBits(t);
|
||||
default:
|
||||
return TRACK_BIT_NONE;
|
||||
|
||||
@@ -1636,7 +1636,7 @@ CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_
|
||||
switch (tt) {
|
||||
case MP_RAILWAY:
|
||||
switch (GetRailTileType(tile)) {
|
||||
case RAIL_TILE_DEPOT:
|
||||
case RailTileType::Depot:
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* notify YAPF about the track layout change */
|
||||
YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
|
||||
@@ -1649,7 +1649,7 @@ CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_
|
||||
cost.AddCost(RailConvertCost(type, totype));
|
||||
break;
|
||||
|
||||
default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
|
||||
default: // RailTileType::Normal, RailTileType::Signals
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* notify YAPF about the track layout change */
|
||||
TrackBits tracks = GetTrackBits(tile);
|
||||
@@ -1806,8 +1806,8 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags)
|
||||
}
|
||||
|
||||
switch (GetRailTileType(tile)) {
|
||||
case RAIL_TILE_SIGNALS:
|
||||
case RAIL_TILE_NORMAL: {
|
||||
case RailTileType::Signals:
|
||||
case RailTileType::Normal: {
|
||||
Slope tileh = GetTileSlope(tile);
|
||||
/* Is there flat water on the lower halftile that gets cleared expensively? */
|
||||
bool water_ground = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh));
|
||||
@@ -1836,7 +1836,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags)
|
||||
return cost;
|
||||
}
|
||||
|
||||
case RAIL_TILE_DEPOT:
|
||||
case RailTileType::Depot:
|
||||
return RemoveTrainDepot(tile, flags);
|
||||
|
||||
default:
|
||||
@@ -2725,11 +2725,11 @@ static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode,
|
||||
|
||||
switch (GetRailTileType(tile)) {
|
||||
default: NOT_REACHED();
|
||||
case RAIL_TILE_NORMAL:
|
||||
case RailTileType::Normal:
|
||||
trackbits = GetTrackBits(tile);
|
||||
break;
|
||||
|
||||
case RAIL_TILE_SIGNALS: {
|
||||
case RailTileType::Signals: {
|
||||
trackbits = GetTrackBits(tile);
|
||||
uint8_t a = GetPresentSignals(tile);
|
||||
uint b = GetSignalStates(tile);
|
||||
@@ -2752,7 +2752,7 @@ static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode,
|
||||
break;
|
||||
}
|
||||
|
||||
case RAIL_TILE_DEPOT: {
|
||||
case RailTileType::Depot: {
|
||||
DiagDirection dir = GetRailDepotDirection(tile);
|
||||
|
||||
if (side != INVALID_DIAGDIR && side != dir) break;
|
||||
@@ -2780,11 +2780,11 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc &td)
|
||||
td.railtype = rti->strings.name;
|
||||
td.owner[0] = GetTileOwner(tile);
|
||||
switch (GetRailTileType(tile)) {
|
||||
case RAIL_TILE_NORMAL:
|
||||
case RailTileType::Normal:
|
||||
td.str = STR_LAI_RAIL_DESCRIPTION_TRACK;
|
||||
break;
|
||||
|
||||
case RAIL_TILE_SIGNALS: {
|
||||
case RailTileType::Signals: {
|
||||
static const StringID signal_type[6][6] = {
|
||||
{
|
||||
STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_SIGNALS,
|
||||
@@ -2849,7 +2849,7 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc &td)
|
||||
break;
|
||||
}
|
||||
|
||||
case RAIL_TILE_DEPOT:
|
||||
case RailTileType::Depot:
|
||||
td.str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
|
||||
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) {
|
||||
if (td.rail_speed > 0) {
|
||||
|
||||
@@ -119,8 +119,8 @@ static void GenericPlaceRail(TileIndex tile, Track track)
|
||||
*/
|
||||
static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track)
|
||||
{
|
||||
if (GetRailTileType(tile) == RAIL_TILE_DEPOT) return;
|
||||
if (GetRailTileType(tile) == RAIL_TILE_SIGNALS && !_settings_client.gui.auto_remove_signals) return;
|
||||
if (GetRailTileType(tile) == RailTileType::Depot) return;
|
||||
if (GetRailTileType(tile) == RailTileType::Signals && !_settings_client.gui.auto_remove_signals) return;
|
||||
if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return;
|
||||
|
||||
Command<CMD_BUILD_SINGLE_RAIL>::Post(tile, _cur_railtype, track, _settings_client.gui.auto_remove_signals);
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
|
||||
|
||||
/** Different types of Rail-related tiles */
|
||||
enum RailTileType : uint8_t {
|
||||
RAIL_TILE_NORMAL = 0, ///< Normal rail tile without signals
|
||||
RAIL_TILE_SIGNALS = 1, ///< Normal rail tile with signals
|
||||
RAIL_TILE_DEPOT = 3, ///< Depot (one entrance)
|
||||
enum class RailTileType : uint8_t {
|
||||
Normal = 0, ///< Normal rail tile without signals
|
||||
Signals = 1, ///< Normal rail tile with signals
|
||||
Depot = 3, ///< Depot (one entrance)
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -36,12 +36,12 @@ enum RailTileType : uint8_t {
|
||||
debug_inline static RailTileType GetRailTileType(Tile t)
|
||||
{
|
||||
assert(IsTileType(t, MP_RAILWAY));
|
||||
return (RailTileType)GB(t.m5(), 6, 2);
|
||||
return static_cast<RailTileType>(GB(t.m5(), 6, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this is plain rails, with or without signals. Iow, if this
|
||||
* tiles RailTileType is RAIL_TILE_NORMAL or RAIL_TILE_SIGNALS.
|
||||
* tiles RailTileType is RailTileType::Normal or RailTileType::Signals.
|
||||
* @param t the tile to get the information from
|
||||
* @pre IsTileType(t, MP_RAILWAY)
|
||||
* @return true if and only if the tile is normal rail (with or without signals)
|
||||
@@ -49,7 +49,7 @@ debug_inline static RailTileType GetRailTileType(Tile t)
|
||||
debug_inline static bool IsPlainRail(Tile t)
|
||||
{
|
||||
RailTileType rtt = GetRailTileType(t);
|
||||
return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS;
|
||||
return rtt == RailTileType::Normal || rtt == RailTileType::Signals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ debug_inline static bool IsPlainRailTile(Tile t)
|
||||
*/
|
||||
inline bool HasSignals(Tile t)
|
||||
{
|
||||
return GetRailTileType(t) == RAIL_TILE_SIGNALS;
|
||||
return GetRailTileType(t) == RailTileType::Signals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ inline bool HasSignals(Tile t)
|
||||
inline void SetHasSignals(Tile tile, bool signals)
|
||||
{
|
||||
assert(IsPlainRailTile(tile));
|
||||
AssignBit(tile.m5(), 6, signals);
|
||||
SB(tile.m5(), 6, 2, to_underlying(signals ? RailTileType::Signals : RailTileType::Normal));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ inline void SetHasSignals(Tile tile, bool signals)
|
||||
*/
|
||||
debug_inline static bool IsRailDepot(Tile t)
|
||||
{
|
||||
return GetRailTileType(t) == RAIL_TILE_DEPOT;
|
||||
return GetRailTileType(t) == RailTileType::Depot;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,14 +291,14 @@ inline bool IsPbsSignal(SignalType s)
|
||||
|
||||
inline SignalType GetSignalType(Tile t, Track track)
|
||||
{
|
||||
assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
|
||||
assert(GetRailTileType(t) == RailTileType::Signals);
|
||||
uint8_t pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
|
||||
return (SignalType)GB(t.m2(), pos, 3);
|
||||
}
|
||||
|
||||
inline void SetSignalType(Tile t, Track track, SignalType s)
|
||||
{
|
||||
assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
|
||||
assert(GetRailTileType(t) == RailTileType::Signals);
|
||||
uint8_t pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
|
||||
SB(t.m2(), pos, 3, s);
|
||||
if (track == INVALID_TRACK) SB(t.m2(), 4, 3, s);
|
||||
@@ -412,7 +412,7 @@ inline bool IsSignalPresent(Tile t, uint8_t signalbit)
|
||||
inline bool HasSignalOnTrack(Tile tile, Track track)
|
||||
{
|
||||
assert(IsValidTrack(track));
|
||||
return GetRailTileType(tile) == RAIL_TILE_SIGNALS && (GetPresentSignals(tile) & SignalOnTrack(track)) != 0;
|
||||
return GetRailTileType(tile) == RailTileType::Signals && (GetPresentSignals(tile) & SignalOnTrack(track)) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +425,7 @@ inline bool HasSignalOnTrack(Tile tile, Track track)
|
||||
inline bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
|
||||
{
|
||||
assert (IsValidTrackdir(trackdir));
|
||||
return GetRailTileType(tile) == RAIL_TILE_SIGNALS && GetPresentSignals(tile) & SignalAlongTrackdir(trackdir);
|
||||
return GetRailTileType(tile) == RailTileType::Signals && GetPresentSignals(tile) & SignalAlongTrackdir(trackdir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,7 +523,7 @@ inline void MakeRailNormal(Tile t, Owner o, TrackBits b, RailType r)
|
||||
t.m2() = 0;
|
||||
t.m3() = 0;
|
||||
t.m4() = 0;
|
||||
t.m5() = RAIL_TILE_NORMAL << 6 | b;
|
||||
t.m5() = to_underlying(RailTileType::Normal) << 6 | b;
|
||||
SB(t.m6(), 2, 6, 0);
|
||||
t.m7() = 0;
|
||||
t.m8() = r;
|
||||
@@ -556,7 +556,7 @@ inline void MakeRailDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirectio
|
||||
tile.m2() = depot_id.base();
|
||||
tile.m3() = 0;
|
||||
tile.m4() = 0;
|
||||
tile.m5() = RAIL_TILE_DEPOT << 6 | dir;
|
||||
tile.m5() = to_underlying(RailTileType::Depot) << 6 | dir;
|
||||
SB(tile.m6(), 2, 6, 0);
|
||||
tile.m7() = 0;
|
||||
tile.m8() = rail_type;
|
||||
|
||||
@@ -45,7 +45,7 @@ RoadType RoadTypeInfo::Index() const
|
||||
static bool IsPossibleCrossing(const TileIndex tile, Axis ax)
|
||||
{
|
||||
return (IsTileType(tile, MP_RAILWAY) &&
|
||||
GetRailTileType(tile) == RAIL_TILE_NORMAL &&
|
||||
GetRailTileType(tile) == RailTileType::Normal &&
|
||||
GetTrackBits(tile) == (ax == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) &&
|
||||
std::get<0>(GetFoundationSlope(tile)) == SLOPE_FLAT);
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces,
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
|
||||
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
|
||||
if (GetRailTileType(tile) != RailTileType::Normal) goto do_clear;
|
||||
|
||||
if (RoadNoLevelCrossing(rt)) {
|
||||
return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
|
||||
|
||||
@@ -67,7 +67,7 @@ static void FixTTDMapArray()
|
||||
|
||||
case MP_RAILWAY:
|
||||
/* We save presignals different from TTDPatch, convert them */
|
||||
if (GB(tile.m5(), 6, 2) == 1) { // RAIL_TILE_SIGNALS
|
||||
if (GB(tile.m5(), 6, 2) == 1) { // RailTileType::Signals
|
||||
/* This byte is always zero in TTD for this type of tile */
|
||||
if (tile.m4()) { // Convert the presignals to our own format
|
||||
tile.m4() = (tile.m4() >> 1) & 7;
|
||||
@@ -226,16 +226,16 @@ static bool FixTTOMapArray()
|
||||
|
||||
case MP_RAILWAY:
|
||||
switch (GB(tile.m5(), 6, 2)) {
|
||||
case 0: // RAIL_TILE_NORMAL
|
||||
case 0: // RailTileType::Normal
|
||||
break;
|
||||
case 1: // RAIL_TILE_SIGNALS
|
||||
case 1: // RailTileType::Signals
|
||||
tile.m4() = (~tile.m5() & 1) << 2; // signal variant (present only in OTTD)
|
||||
SB(tile.m2(), 6, 2, GB(tile.m5(), 3, 2)); // signal status
|
||||
tile.m3() |= 0xC0; // both signals are present
|
||||
tile.m5() = HasBit(tile.m5(), 5) ? 2 : 1; // track direction (only X or Y)
|
||||
tile.m5() |= 0x40; // RAIL_TILE_SIGNALS
|
||||
tile.m5() |= 0x40; // RailTileType::Signals
|
||||
break;
|
||||
case 3: // RAIL_TILE_DEPOT
|
||||
case 3: // RailTileType::Depot
|
||||
tile.m2() = 0;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -100,11 +100,11 @@ void MoveWaypointsToBaseStations()
|
||||
TileIndex t = wp.xy;
|
||||
/* Sometimes waypoint (sign) locations became disconnected from their actual location in
|
||||
* the map array. If this is the case, try to locate the actual location in the map array */
|
||||
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != 2 /* RAIL_TILE_WAYPOINT */ || Tile(t).m2() != wp.index) {
|
||||
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != RailTileType{2} /* RAIL_TILE_WAYPOINT */ || Tile(t).m2() != wp.index) {
|
||||
Debug(sl, 0, "Found waypoint tile {} with invalid position", t);
|
||||
t = INVALID_TILE;
|
||||
for (auto tile : Map::Iterate()) {
|
||||
if (IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == 2 /* RAIL_TILE_WAYPOINT */ && tile.m2() == wp.index) {
|
||||
if (IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RailTileType{2} /* RAIL_TILE_WAYPOINT */ && tile.m2() == wp.index) {
|
||||
t = TileIndex(tile);
|
||||
Debug(sl, 0, "Found actual waypoint position at {}", TileIndex(tile));
|
||||
break;
|
||||
|
||||
@@ -3086,7 +3086,7 @@ static inline void AffectSpeedByZChange(Train *v, int old_z)
|
||||
static bool TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
|
||||
{
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
GetRailTileType(tile) == RAIL_TILE_SIGNALS) {
|
||||
GetRailTileType(tile) == RailTileType::Signals) {
|
||||
TrackdirBits tracks = TrackBitsToTrackdirBits(GetTrackBits(tile)) & DiagdirReachesTrackdirs(dir);
|
||||
Trackdir trackdir = FindFirstTrackdir(tracks);
|
||||
if (UpdateSignalsOnSegment(tile, TrackdirToExitdir(trackdir), GetTileOwner(tile)) == SIGSEG_PBS && HasSignalOnTrackdir(tile, trackdir)) {
|
||||
|
||||
@@ -104,7 +104,7 @@ Axis GetAxisForNewRailWaypoint(TileIndex tile)
|
||||
if (IsRailWaypointTile(tile)) return GetRailStationAxis(tile);
|
||||
|
||||
/* Non-plain rail type, no valid axis for waypoints. */
|
||||
if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RAIL_TILE_NORMAL) return INVALID_AXIS;
|
||||
if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RailTileType::Normal) return INVALID_AXIS;
|
||||
|
||||
switch (GetTrackBits(tile)) {
|
||||
case TRACK_BIT_X: return AXIS_X;
|
||||
|
||||
Reference in New Issue
Block a user