diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 1de9d01558..439239b65d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4927,7 +4927,7 @@ static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, Byte break; case 0x12: // General flags - rs->flags = (uint16_t)buf.ReadDWord(); // Future-proofing, size this as 4 bytes, but we only need two byte's worth of flags at present + rs->flags = static_cast(buf.ReadDWord()); // Future-proofing, size this as 4 bytes, but we only need two byte's worth of flags at present break; case 0x15: // Cost multipliers diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 58ae873c63..c67144a15f 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -295,7 +295,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, PaletteID pal = dts->ground.pal; RoadStopDrawMode draw_mode; - if (HasBit(spec->flags, RSF_DRAW_MODE_REGISTER)) { + if (spec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) { draw_mode = static_cast(GetRegister(0x100)); } else { draw_mode = spec->draw_mode; @@ -362,7 +362,7 @@ void AnimateRoadStopTile(TileIndex tile) const RoadStopSpec *ss = GetRoadStopSpec(tile); if (ss == nullptr) return; - RoadStopAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, RSF_CB141_RANDOM_BITS)); + RoadStopAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, ss->flags.Test(RoadStopSpecFlag::Cb141RandomBits)); } void TriggerRoadStopAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type) @@ -517,8 +517,8 @@ bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadT // The roadstopspec is nullptr, must be the default station, always return true. if (roadstopspec == nullptr) return true; - if (HasBit(roadstopspec->flags, RSF_BUILD_MENU_ROAD_ONLY) && !RoadTypeIsRoad(roadtype)) return false; - if (HasBit(roadstopspec->flags, RSF_BUILD_MENU_TRAM_ONLY) && !RoadTypeIsTram(roadtype)) return false; + if (roadstopspec->flags.Test(RoadStopSpecFlag::RoadOnly) && !RoadTypeIsRoad(roadtype)) return false; + if (roadstopspec->flags.Test(RoadStopSpecFlag::TramOnly) && !RoadTypeIsTram(roadtype)) return false; if (roadstopspec->stop_type == ROADSTOPTYPE_ALL) return true; diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index d01f3d04ab..e5314cb2c2 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -67,15 +67,16 @@ enum RoadStopDrawMode : uint8_t { }; DECLARE_ENUM_AS_BIT_SET(RoadStopDrawMode) -enum RoadStopSpecFlags : uint8_t { - RSF_CB141_RANDOM_BITS = 0, ///< Callback 141 needs random bits. - RSF_NO_CATENARY = 2, ///< Do not show catenary. - RSF_DRIVE_THROUGH_ONLY = 3, ///< Stop is drive-through only. - RSF_NO_AUTO_ROAD_CONNECTION = 4, ///< No auto road connection. - RSF_BUILD_MENU_ROAD_ONLY = 5, ///< Only show in the road build menu (not tram). - RSF_BUILD_MENU_TRAM_ONLY = 6, ///< Only show in the tram build menu (not road). - RSF_DRAW_MODE_REGISTER = 8, ///< Read draw mode from register 0x100. +enum class RoadStopSpecFlag : uint8_t { + Cb141RandomBits = 0, ///< Callback 141 needs random bits. + NoCatenary = 2, ///< Do not show catenary. + DriveThroughOnly = 3, ///< Stop is drive-through only. + NoAutoRoadConnection = 4, ///< No auto road connection. + RoadOnly = 5, ///< Only show in the road build menu (not tram). + TramOnly = 6, ///< Only show in the tram build menu (not road). + DrawModeRegister = 8, ///< Read draw mode from register 0x100. }; +using RoadStopSpecFlags = EnumBitSet; enum RoadStopView : uint8_t { RSV_BAY_NE = 0, ///< Bay road stop, facing Northeast @@ -146,7 +147,7 @@ struct RoadStopSpec : NewGRFSpecBase { RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL; RoadStopDrawMode draw_mode = ROADSTOP_DRAW_MODE_ROAD | ROADSTOP_DRAW_MODE_OVERLAY; RoadStopCallbackMasks callback_mask{}; - uint16_t flags = 0; + RoadStopSpecFlags flags{}; CargoTypes cargo_triggers = 0; ///< Bitmask of cargo types which cause trigger re-randomizing diff --git a/src/road_gui.cpp b/src/road_gui.cpp index d250ad1921..0d7cc3531a 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -83,8 +83,8 @@ static bool IsRoadStopEverAvailable(const RoadStopSpec *spec, StationType type) { if (spec == nullptr) return true; - if (HasBit(spec->flags, RSF_BUILD_MENU_ROAD_ONLY) && !RoadTypeIsRoad(_cur_roadtype)) return false; - if (HasBit(spec->flags, RSF_BUILD_MENU_TRAM_ONLY) && !RoadTypeIsTram(_cur_roadtype)) return false; + if (spec->flags.Test(RoadStopSpecFlag::RoadOnly) && !RoadTypeIsRoad(_cur_roadtype)) return false; + if (spec->flags.Test(RoadStopSpecFlag::TramOnly) && !RoadTypeIsTram(_cur_roadtype)) return false; switch (spec->stop_type) { case ROADSTOPTYPE_ALL: return true; @@ -202,7 +202,7 @@ void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t wid bool connect_to_road = true; if ((uint)spec_class < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) { const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index); - if (roadstopspec != nullptr && HasBit(roadstopspec->flags, RSF_NO_AUTO_ROAD_CONNECTION)) connect_to_road = false; + if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false; } if (connect_to_road) { @@ -1244,7 +1244,7 @@ public: StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui.orientation); } else { DiagDirection orientation = _roadstop_gui.orientation; - if (orientation < DIAGDIR_END && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) orientation = DIAGDIR_END; + if (orientation < DIAGDIR_END && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DIAGDIR_END; DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, (uint8_t)orientation); } } @@ -1291,13 +1291,13 @@ private: /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */ if (RoadTypeIsRoad(_cur_roadtype)) { this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation); - this->GetWidget(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) ? 1 : 0); + this->GetWidget(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0); this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation); } if (_roadstop_gui.orientation >= DIAGDIR_END) return; - if (spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) { + if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) { this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation); _roadstop_gui.orientation = DIAGDIR_END; this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation); @@ -1452,7 +1452,7 @@ public: case WID_BROS_STATION_Y: if (widget < WID_BROS_STATION_X) { const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type); - if (spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) return; + if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return; } this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation); _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 623898e48b..350264c849 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1979,7 +1979,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8_t width, if (roadstopspec != nullptr) { if (stop_type == RoadStopType::Truck && roadstopspec->stop_type != ROADSTOPTYPE_FREIGHT && roadstopspec->stop_type != ROADSTOPTYPE_ALL) return CMD_ERROR; if (stop_type == RoadStopType::Bus && roadstopspec->stop_type != ROADSTOPTYPE_PASSENGER && roadstopspec->stop_type != ROADSTOPTYPE_ALL) return CMD_ERROR; - if (!is_drive_through && HasBit(roadstopspec->flags, RSF_DRIVE_THROUGH_ONLY)) return CMD_ERROR; + if (!is_drive_through && roadstopspec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return CMD_ERROR; } /* Check if the requested road stop is too big */ @@ -3342,7 +3342,7 @@ draw_default_foundation: RoadStopResolverObject object(stopspec, st, ti->tile, INVALID_ROADTYPE, type, view); const SpriteGroup *group = object.Resolve(); if (group != nullptr && group->type == SGT_TILELAYOUT) { - if (HasBit(stopspec->flags, RSF_DRAW_MODE_REGISTER)) { + if (stopspec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) { stop_draw_mode = static_cast(GetRegister(0x100)); } if (type == StationType::RoadWaypoint && (stop_draw_mode & ROADSTOP_DRAW_MODE_WAYP_GROUND)) { @@ -3378,7 +3378,7 @@ draw_default_foundation: } } - if (stopspec == nullptr || !HasBit(stopspec->flags, RSF_NO_CATENARY)) { + if (stopspec == nullptr || !stopspec->flags.Test(RoadStopSpecFlag::NoCatenary)) { /* Draw road, tram catenary */ DrawRoadCatenary(ti); }