1
0
Fork 0

Codechange: Use EnumBitSet for RoadStopSpecFlags.

pull/13469/head
Peter Nelson 2025-02-04 02:01:37 +00:00 committed by Peter Nelson
parent 1a6e7f2162
commit 17f6da413d
5 changed files with 25 additions and 24 deletions

View File

@ -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<RoadStopSpecFlags>(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

View File

@ -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<RoadStopDrawMode>(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;

View File

@ -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<RoadStopSpecFlag, uint8_t>;
enum RoadStopView : uint8_t {
RSV_BAY_NE = 0, ///< Bay road stop, facing Northeast
@ -146,7 +147,7 @@ struct RoadStopSpec : NewGRFSpecBase<RoadStopClassID> {
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

View File

@ -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<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) ? 1 : 0);
this->GetWidget<NWidgetStacked>(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);

View File

@ -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<RoadStopDrawMode>(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);
}