diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 9e234b6698..d82daa5f7c 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -2627,11 +2627,11 @@ static void ConDumpRoadTypes() (uint)rt, RoadTypeIsTram(rt) ? "Tram" : "Road", FormatLabel(rti->label), - HasBit(rti->flags, ROTF_CATENARY) ? 'c' : '-', - HasBit(rti->flags, ROTF_NO_LEVEL_CROSSING) ? 'l' : '-', - HasBit(rti->flags, ROTF_NO_HOUSES) ? 'X' : '-', - HasBit(rti->flags, ROTF_HIDDEN) ? 'h' : '-', - HasBit(rti->flags, ROTF_TOWN_BUILD) ? 'T' : '-', + rti->flags.Test(RoadTypeFlag::Catenary) ? 'c' : '-', + rti->flags.Test(RoadTypeFlag::NoLevelCrossing) ? 'l' : '-', + rti->flags.Test(RoadTypeFlag::NoHouses) ? 'X' : '-', + rti->flags.Test(RoadTypeFlag::Hidden) ? 'h' : '-', + rti->flags.Test(RoadTypeFlag::TownBuild) ? 'T' : '-', std::byteswap(grfid), GetStringPtr(rti->strings.name) ); @@ -2664,12 +2664,12 @@ static void ConDumpRailTypes() IConsolePrint(CC_DEFAULT, " {:02d} {}, Flags: {}{}{}{}{}{}, GRF: {:08X}, {}", (uint)rt, FormatLabel(rti->label), - HasBit(rti->flags, RTF_CATENARY) ? 'c' : '-', - HasBit(rti->flags, RTF_NO_LEVEL_CROSSING) ? 'l' : '-', - HasBit(rti->flags, RTF_HIDDEN) ? 'h' : '-', - HasBit(rti->flags, RTF_NO_SPRITE_COMBINE) ? 's' : '-', - HasBit(rti->flags, RTF_ALLOW_90DEG) ? 'a' : '-', - HasBit(rti->flags, RTF_DISALLOW_90DEG) ? 'd' : '-', + rti->flags.Test(RailTypeFlag::Catenary) ? 'c' : '-', + rti->flags.Test(RailTypeFlag::NoLevelCrossing) ? 'l' : '-', + rti->flags.Test(RailTypeFlag::Hidden) ? 'h' : '-', + rti->flags.Test(RailTypeFlag::NoSpriteCombine) ? 's' : '-', + rti->flags.Test(RailTypeFlag::Allow90Deg) ? 'a' : '-', + rti->flags.Test(RailTypeFlag::Disallow90Deg) ? 'd' : '-', std::byteswap(grfid), GetStringPtr(rti->strings.name) ); diff --git a/src/elrail_func.h b/src/elrail_func.h index f45ee53904..ec42c4cc61 100644 --- a/src/elrail_func.h +++ b/src/elrail_func.h @@ -20,7 +20,7 @@ */ inline bool HasRailCatenary(RailType rt) { - return HasBit(GetRailTypeInfo(rt)->flags, RTF_CATENARY); + return GetRailTypeInfo(rt)->flags.Test(RailTypeFlag::Catenary); } /** diff --git a/src/newgrf.cpp b/src/newgrf.cpp index e9f04c95d6..fc3597d2bc 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4340,7 +4340,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint first, uint last, int prop, Byte } case 0x10: // Rail Type flags - rti->flags = (RailTypeFlags)buf.ReadByte(); + rti->flags = static_cast(buf.ReadByte()); break; case 0x11: // Curve speed advantage @@ -4557,7 +4557,7 @@ static ChangeInfoResult RoadTypeChangeInfo(uint first, uint last, int prop, Byte } case 0x10: // Road Type flags - rti->flags = (RoadTypeFlags)buf.ReadByte(); + rti->flags = static_cast(buf.ReadByte()); break; case 0x13: // Construction cost factor diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index fe07dc16e4..46dc748b33 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -565,7 +565,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec case VEH_TRAIN: { RailType rt = GetTileRailType(v->tile); const RailTypeInfo *rti = GetRailTypeInfo(rt); - return ((rti->flags & RTFB_CATENARY) ? 0x200 : 0) | + return (rti->flags.Test(RailTypeFlag::Catenary) ? 0x200 : 0) | (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) | GetReverseRailTypeTranslation(rt, object->ro.grffile); } @@ -573,7 +573,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec case VEH_ROAD: { RoadType rt = GetRoadType(v->tile, GetRoadTramType(RoadVehicle::From(v)->roadtype)); const RoadTypeInfo *rti = GetRoadTypeInfo(rt); - return ((rti->flags & ROTFB_CATENARY) ? 0x200 : 0) | + return (rti->flags.Test(RoadTypeFlag::Catenary) ? 0x200 : 0) | 0x100 | GetReverseRoadTypeTranslation(rt, object->ro.grffile); } diff --git a/src/rail.h b/src/rail.h index 59750119aa..cff9922647 100644 --- a/src/rail.h +++ b/src/rail.h @@ -14,6 +14,7 @@ #include "track_type.h" #include "gfx_type.h" #include "core/bitmath_func.hpp" +#include "core/enum_type.hpp" #include "economy_func.h" #include "slope_type.h" #include "strings_type.h" @@ -22,26 +23,15 @@ #include "settings_type.h" /** Railtype flag bit numbers. */ -enum RailTypeFlag : uint8_t { - RTF_CATENARY = 0, ///< Bit number for drawing a catenary. - RTF_NO_LEVEL_CROSSING = 1, ///< Bit number for disallowing level crossings. - RTF_HIDDEN = 2, ///< Bit number for hiding from selection. - RTF_NO_SPRITE_COMBINE = 3, ///< Bit number for using non-combined junctions. - RTF_ALLOW_90DEG = 4, ///< Bit number for always allowed 90 degree turns, regardless of setting. - RTF_DISALLOW_90DEG = 5, ///< Bit number for never allowed 90 degree turns, regardless of setting. +enum class RailTypeFlag : uint8_t { + Catenary = 0, ///< Bit number for drawing a catenary. + NoLevelCrossing = 1, ///< Bit number for disallowing level crossings. + Hidden = 2, ///< Bit number for hiding from selection. + NoSpriteCombine = 3, ///< Bit number for using non-combined junctions. + Allow90Deg = 4, ///< Bit number for always allowed 90 degree turns, regardless of setting. + Disallow90Deg = 5, ///< Bit number for never allowed 90 degree turns, regardless of setting. }; - -/** Railtype flags. */ -enum RailTypeFlags : uint8_t { - RTFB_NONE = 0, ///< All flags cleared. - RTFB_CATENARY = 1 << RTF_CATENARY, ///< Value for drawing a catenary. - RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING, ///< Value for disallowing level crossings. - RTFB_HIDDEN = 1 << RTF_HIDDEN, ///< Value for hiding from selection. - RTFB_NO_SPRITE_COMBINE = 1 << RTF_NO_SPRITE_COMBINE, ///< Value for using non-combined junctions. - RTFB_ALLOW_90DEG = 1 << RTF_ALLOW_90DEG, ///< Value for always allowed 90 degree turns, regardless of setting. - RTFB_DISALLOW_90DEG = 1 << RTF_DISALLOW_90DEG, ///< Value for never allowed 90 degree turns, regardless of setting. -}; -DECLARE_ENUM_AS_BIT_SET(RailTypeFlags) +using RailTypeFlags = EnumBitSet; struct SpriteGroup; @@ -344,7 +334,7 @@ inline bool HasPowerOnRail(RailType enginetype, RailType tiletype) */ inline bool RailNoLevelCrossings(RailType rt) { - return HasBit(GetRailTypeInfo(rt)->flags, RTF_NO_LEVEL_CROSSING); + return GetRailTypeInfo(rt)->flags.Test(RailTypeFlag::NoLevelCrossing); } /** @@ -361,8 +351,8 @@ inline bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def = _sett const RailTypeInfo *rti1 = GetRailTypeInfo(rt1); const RailTypeInfo *rti2 = GetRailTypeInfo(rt2); - bool rt1_90deg = HasBit(rti1->flags, RTF_DISALLOW_90DEG) || (!HasBit(rti1->flags, RTF_ALLOW_90DEG) && def); - bool rt2_90deg = HasBit(rti2->flags, RTF_DISALLOW_90DEG) || (!HasBit(rti2->flags, RTF_ALLOW_90DEG) && def); + bool rt1_90deg = rti1->flags.Test(RailTypeFlag::Disallow90Deg) || (!rti1->flags.Test(RailTypeFlag::Allow90Deg) && def); + bool rt2_90deg = rti2->flags.Test(RailTypeFlag::Disallow90Deg) || (!rti2->flags.Test(RailTypeFlag::Allow90Deg) && def); return rt1_90deg || rt2_90deg; } diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index dabc8015f5..bd7aecc937 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -132,7 +132,7 @@ void InitRailTypes() for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { RailTypeInfo *rti = &_railtypes[rt]; ResolveRailTypeGUISprites(rti); - if (HasBit(rti->flags, RTF_HIDDEN)) SetBit(_railtypes_hidden_mask, rt); + if (rti->flags.Test(RailTypeFlag::Hidden)) SetBit(_railtypes_hidden_mask, rt); } _sorted_railtypes.clear(); @@ -2109,7 +2109,7 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailTypeIn DrawGroundSprite(image, PAL_NONE); } - bool no_combine = ti->tileh == SLOPE_FLAT && HasBit(rti->flags, RTF_NO_SPRITE_COMBINE); + bool no_combine = ti->tileh == SLOPE_FLAT && rti->flags.Test(RailTypeFlag::NoSpriteCombine); SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY); SpriteID ground = GetCustomRailSprite(rti, ti->tile, no_combine ? RTSG_GROUND_COMPLETE : RTSG_GROUND); TrackBits pbs = _settings_client.gui.show_track_reservation ? GetRailReservationTrackBits(ti->tile) : TRACK_BIT_NONE; diff --git a/src/road.cpp b/src/road.cpp index 0ac5556c93..3f546f5d33 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -122,7 +122,7 @@ bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype) * The GS under deity mode, as well as anybody in the editor builds roads that are * owned by towns. So if a town may build it, it should be buildable by them too. */ - return (rti->flags & ROTFB_HIDDEN) == 0 || (rti->flags & ROTFB_TOWN_BUILD) != 0; + return !rti->flags.Test( RoadTypeFlag::Hidden) || rti->flags.Test( RoadTypeFlag::TownBuild); } else { const Company *c = Company::GetIfValid(company); if (c == nullptr) return false; diff --git a/src/road.h b/src/road.h index 05e14a4855..bb301d2137 100644 --- a/src/road.h +++ b/src/road.h @@ -33,25 +33,15 @@ DECLARE_ENUM_AS_BIT_SET(RoadTramTypes) static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM }; -/** Roadtype flag bit numbers. Starts with RO instead of R because R is used for rails */ -enum RoadTypeFlag { - ROTF_CATENARY = 0, ///< Bit number for adding catenary - ROTF_NO_LEVEL_CROSSING, ///< Bit number for disabling level crossing - ROTF_NO_HOUSES, ///< Bit number for setting this roadtype as not house friendly - ROTF_HIDDEN, ///< Bit number for hidden from construction. - ROTF_TOWN_BUILD, ///< Bit number for allowing towns to build this roadtype. +/** Roadtype flag bit numbers. */ +enum class RoadTypeFlag : uint8_t { + Catenary = 0, ///< Bit number for adding catenary + NoLevelCrossing = 1, ///< Bit number for disabling level crossing + NoHouses = 2, ///< Bit number for setting this roadtype as not house friendly + Hidden = 3, ///< Bit number for hidden from construction. + TownBuild = 4, ///< Bit number for allowing towns to build this roadtype. }; - -/** Roadtype flags. Starts with RO instead of R because R is used for rails */ -enum RoadTypeFlags : uint8_t { - ROTFB_NONE = 0, ///< All flags cleared. - ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary. - ROTFB_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING, ///< Value for disabling a level crossing. - ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ///< Value for for setting this roadtype as not house friendly. - ROTFB_HIDDEN = 1 << ROTF_HIDDEN, ///< Value for hidden from construction. - ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD, ///< Value for allowing towns to build this roadtype. -}; -DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags) +using RoadTypeFlags = EnumBitSet; struct SpriteGroup; @@ -295,7 +285,7 @@ inline Money RoadConvertCost(RoadType from, RoadType to) inline bool RoadNoLevelCrossing(RoadType roadtype) { assert(roadtype < ROADTYPE_END); - return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_NO_LEVEL_CROSSING); + return GetRoadTypeInfo(roadtype)->flags.Test(RoadTypeFlag::NoLevelCrossing); } RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 27b1283840..977f6dfe05 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -116,7 +116,7 @@ void InitRoadTypes() for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) { RoadTypeInfo *rti = &_roadtypes[rt]; ResolveRoadTypeGUISprites(rti); - if (HasBit(rti->flags, ROTF_HIDDEN)) SetBit(_roadtypes_hidden_mask, rt); + if (rti->flags.Test(RoadTypeFlag::Hidden)) SetBit(_roadtypes_hidden_mask, rt); } _sorted_roadtypes.clear(); @@ -141,7 +141,7 @@ RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt) *rti = _original_roadtypes[(rtt == RTT_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD]; rti->label = label; rti->alternate_labels.clear(); - rti->flags = ROTFB_NONE; + rti->flags = {}; rti->introduction_date = CalendarTime::INVALID_DATE; /* Make us compatible with ourself. */ @@ -1830,7 +1830,7 @@ static void DrawTile_Road(TileInfo *ti) int relocation = GetCustomRoadSprite(rti, ti->tile, ROTSG_DEPOT); bool default_gfx = relocation == 0; if (default_gfx) { - if (HasBit(rti->flags, ROTF_CATENARY)) { + if (rti->flags.Test(RoadTypeFlag::Catenary)) { if (_loaded_newgrf_features.tram == TRAMWAY_REPLACE_DEPOT_WITH_TRACK && road_rt == INVALID_ROADTYPE && !rti->UsesOverlay()) { /* Sprites with track only work for default tram */ relocation = SPR_TRAMWAY_DEPOT_WITH_TRACK - SPR_ROAD_DEPOT; @@ -1880,7 +1880,7 @@ void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt) int relocation = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_DEPOT); bool default_gfx = relocation == 0; if (default_gfx) { - if (HasBit(rti->flags, ROTF_CATENARY)) { + if (rti->flags.Test(RoadTypeFlag::Catenary)) { if (_loaded_newgrf_features.tram == TRAMWAY_REPLACE_DEPOT_WITH_TRACK && RoadTypeIsTram(rt) && !rti->UsesOverlay()) { /* Sprites with track only work for default tram */ relocation = SPR_TRAMWAY_DEPOT_WITH_TRACK - SPR_ROAD_DEPOT; diff --git a/src/road_func.h b/src/road_func.h index ed3e3db6d0..8f7727af56 100644 --- a/src/road_func.h +++ b/src/road_func.h @@ -135,7 +135,7 @@ inline Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total inline bool HasRoadCatenary(RoadType roadtype) { assert(roadtype < ROADTYPE_END); - return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY); + return GetRoadTypeInfo(roadtype)->flags.Test(RoadTypeFlag::Catenary); } /** diff --git a/src/table/railtypes.h b/src/table/railtypes.h index 69fd27bb4b..4ed5b33921 100644 --- a/src/table/railtypes.h +++ b/src/table/railtypes.h @@ -75,7 +75,7 @@ static const RailTypeInfo _original_railtypes[] = { 0, /* flags */ - RTFB_NONE, + {}, /* cost multiplier */ 8, @@ -176,7 +176,7 @@ static const RailTypeInfo _original_railtypes[] = { 0, /* flags */ - RTFB_CATENARY, + {RailTypeFlag::Catenary}, /* cost multiplier */ 12, @@ -273,7 +273,7 @@ static const RailTypeInfo _original_railtypes[] = { 1, /* flags */ - RTFB_NONE, + {}, /* cost multiplier */ 16, @@ -370,7 +370,7 @@ static const RailTypeInfo _original_railtypes[] = { 2, /* flags */ - RTFB_NONE, + {}, /* cost multiplier */ 24, diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h index fc20705bc6..57c1156cfa 100644 --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -61,7 +61,7 @@ static const RoadTypeInfo _original_roadtypes[] = { ROADTYPES_ROAD, /* flags */ - ROTFB_TOWN_BUILD, + {RoadTypeFlag::TownBuild}, /* cost multiplier */ 8, @@ -141,7 +141,7 @@ static const RoadTypeInfo _original_roadtypes[] = { ROADTYPES_TRAM, /* flags */ - ROTFB_CATENARY | ROTFB_NO_HOUSES, + {RoadTypeFlag::Catenary, RoadTypeFlag::NoHouses}, /* cost multiplier */ 16, diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index b4d8341233..962c7fc3d9 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -972,7 +972,7 @@ RoadType GetTownRoadType() if (rti->label == 0) continue; /* Can town build this road. */ - if (!HasBit(rti->flags, ROTF_TOWN_BUILD)) continue; + if (!rti->flags.Test(RoadTypeFlag::TownBuild)) continue; /* Not yet introduced at this date. */ if (IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base()) && rti->introduction_date > TimerGameCalendar::date) continue; @@ -999,7 +999,7 @@ static TimerGameCalendar::Date GetTownRoadTypeFirstIntroductionDate() if (RoadTypeIsTram(rt)) continue; const RoadTypeInfo *rti = GetRoadTypeInfo(rt); if (rti->label == 0) continue; // Unused road type. - if (!HasBit(rti->flags, ROTF_TOWN_BUILD)) continue; // Town can't build this road type. + if (!rti->flags.Test(RoadTypeFlag::TownBuild)) continue; // Town can't build this road type. if (best != nullptr && rti->introduction_date >= best->introduction_date) continue; best = rti; @@ -1496,8 +1496,8 @@ static inline bool RoadTypesAllowHouseHere(TileIndex t) RoadType road_rt = GetRoadTypeRoad(cur_tile); RoadType tram_rt = GetRoadTypeTram(cur_tile); - if (road_rt != INVALID_ROADTYPE && !HasBit(GetRoadTypeInfo(road_rt)->flags, ROTF_NO_HOUSES)) return true; - if (tram_rt != INVALID_ROADTYPE && !HasBit(GetRoadTypeInfo(tram_rt)->flags, ROTF_NO_HOUSES)) return true; + if (road_rt != INVALID_ROADTYPE && !GetRoadTypeInfo(road_rt)->flags.Test(RoadTypeFlag::NoHouses)) return true; + if (tram_rt != INVALID_ROADTYPE && !GetRoadTypeInfo(tram_rt)->flags.Test(RoadTypeFlag::NoHouses)) return true; } /* If no road was found surrounding the tile we can allow building the house since there is @@ -1516,7 +1516,7 @@ static bool TownCanGrowRoad(TileIndex tile) /* Allow extending on roadtypes which can be built by town, or if the road type matches the type the town will build. */ RoadType rt = GetRoadTypeRoad(tile); - return HasBit(GetRoadTypeInfo(rt)->flags, ROTF_TOWN_BUILD) || GetTownRoadType() == rt; + return GetRoadTypeInfo(rt)->flags.Test(RoadTypeFlag::TownBuild) || GetTownRoadType() == rt; } /**