1
0
Fork 0

Codechange: Use EnumBitSet for StationSpecFlags.

pull/13469/head
Peter Nelson 2025-02-04 01:54:01 +00:00 committed by Peter Nelson
parent 1f7760dc7a
commit 1a6e7f2162
4 changed files with 17 additions and 16 deletions

View File

@ -2131,7 +2131,7 @@ static ChangeInfoResult StationChangeInfo(uint first, uint last, int prop, ByteR
break; break;
case 0x13: // General flags case 0x13: // General flags
statspec->flags = buf.ReadByte(); statspec->flags = StationSpecFlags{buf.ReadByte()};
break; break;
case 0x14: { // Overhead wire placement case 0x14: { // Overhead wire placement

View File

@ -532,7 +532,7 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [
} }
} }
if (HasBit(this->station_scope.statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h); if (this->station_scope.statspec->flags.Test(StationSpecFlag::DivByStationSize)) cargo /= (st->train_station.w + st->train_station.h);
cargo = std::min(0xfffu, cargo); cargo = std::min(0xfffu, cargo);
if (cargo > this->station_scope.statspec->cargo_threshold) { if (cargo > this->station_scope.statspec->cargo_threshold) {
@ -608,7 +608,7 @@ StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseSt
* @param statspec Station spec * @param statspec Station spec
* @param st Station (nullptr in GUI) * @param st Station (nullptr in GUI)
* @param tile Station tile being drawn (INVALID_TILE in GUI) * @param tile Station tile being drawn (INVALID_TILE in GUI)
* @param var10 Value to put in variable 10; normally 0; 1 when resolving the groundsprite and SSF_SEPARATE_GROUND is set. * @param var10 Value to put in variable 10; normally 0; 1 when resolving the groundsprite and StationSpecFlag::SeparateGround is set.
* @return First sprite of the Action 1 spriteset to use, minus an offset of 0x42D to accommodate for weird NewGRF specs. * @return First sprite of the Action 1 spriteset to use, minus an offset of 0x42D to accommodate for weird NewGRF specs.
*/ */
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10) SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
@ -808,7 +808,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
if (layout != nullptr) { if (layout != nullptr) {
/* Sprite layout which needs preprocessing */ /* Sprite layout which needs preprocessing */
bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND); bool separate_ground = statspec->flags.Test(StationSpecFlag::SeparateGround);
uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground); uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
for (uint8_t var10 : SetBitIterator(var10_values)) { for (uint8_t var10 : SetBitIterator(var10_values)) {
uint32_t var10_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, var10); uint32_t var10_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, var10);
@ -875,7 +875,7 @@ void AnimateStationTile(TileIndex tile)
const StationSpec *ss = GetStationSpec(tile); const StationSpec *ss = GetStationSpec(tile);
if (ss == nullptr) return; if (ss == nullptr) return;
StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, SSF_CB141_RANDOM_BITS)); StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, ss->flags.Test(StationSpecFlag::Cb141RandomBits));
} }
void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type) void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type)

View File

@ -93,13 +93,14 @@ enum StationClassID : uint16_t {
/** Allow incrementing of StationClassID variables */ /** Allow incrementing of StationClassID variables */
DECLARE_INCREMENT_DECREMENT_OPERATORS(StationClassID) DECLARE_INCREMENT_DECREMENT_OPERATORS(StationClassID)
enum StationSpecFlags : uint8_t { enum class StationSpecFlag : uint8_t {
SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites. SeparateGround = 0, ///< Use different sprite set for ground sprites.
SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size. DivByStationSize = 1, ///< Divide cargo amount by station size.
SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits. Cb141RandomBits = 2, ///< Callback 141 needs random bits.
SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations. CustomFoundations = 3, ///< Draw custom foundations.
SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple. ExtendedFoundations = 4, ///< Extended foundation block instead of simple.
}; };
using StationSpecFlags = EnumBitSet<StationSpecFlag, uint8_t>;
/** Randomisation triggers for stations */ /** Randomisation triggers for stations */
enum StationRandomTrigger : uint8_t { enum StationRandomTrigger : uint8_t {
@ -158,7 +159,7 @@ struct StationSpec : NewGRFSpecBase<StationClassID> {
StationCallbackMasks callback_mask; ///< Bitmask of station callbacks that have to be called StationCallbackMasks callback_mask; ///< Bitmask of station callbacks that have to be called
uint8_t flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size StationSpecFlags flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
enum class TileFlag : uint8_t { enum class TileFlag : uint8_t {
Pylons = 0, ///< Tile should contain catenary pylons. Pylons = 0, ///< Tile should contain catenary pylons.

View File

@ -3173,7 +3173,7 @@ static void DrawTile_Station(TileInfo *ti)
/* don't show foundation for docks */ /* don't show foundation for docks */
if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) { if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) {
if (statspec != nullptr && HasBit(statspec->flags, SSF_CUSTOM_FOUNDATIONS)) { if (statspec != nullptr && statspec->flags.Test(StationSpecFlag::CustomFoundations)) {
/* Station has custom foundations. /* Station has custom foundations.
* Check whether the foundation continues beyond the tile's upper sides. */ * Check whether the foundation continues beyond the tile's upper sides. */
uint edge_info = 0; uint edge_info = 0;
@ -3183,7 +3183,7 @@ static void DrawTile_Station(TileInfo *ti)
SpriteID image = GetCustomStationFoundationRelocation(statspec, st, ti->tile, tile_layout, edge_info); SpriteID image = GetCustomStationFoundationRelocation(statspec, st, ti->tile, tile_layout, edge_info);
if (image == 0) goto draw_default_foundation; if (image == 0) goto draw_default_foundation;
if (HasBit(statspec->flags, SSF_EXTENDED_FOUNDATIONS)) { if (statspec->flags.Test(StationSpecFlag::ExtendedFoundations)) {
/* Station provides extended foundations. */ /* Station provides extended foundations. */
static const uint8_t foundation_parts[] = { static const uint8_t foundation_parts[] = {
@ -3277,7 +3277,7 @@ draw_default_foundation:
} else { } else {
if (layout != nullptr) { if (layout != nullptr) {
/* Sprite layout which needs preprocessing */ /* Sprite layout which needs preprocessing */
bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND); bool separate_ground = statspec->flags.Test(StationSpecFlag::SeparateGround);
uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground); uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
for (uint8_t var10 : SetBitIterator(var10_values)) { for (uint8_t var10 : SetBitIterator(var10_values)) {
uint32_t var10_relocation = GetCustomStationRelocation(statspec, st, ti->tile, var10); uint32_t var10_relocation = GetCustomStationRelocation(statspec, st, ti->tile, var10);
@ -3289,7 +3289,7 @@ draw_default_foundation:
} else if (statspec != nullptr) { } else if (statspec != nullptr) {
/* Simple sprite layout */ /* Simple sprite layout */
ground_relocation = relocation = GetCustomStationRelocation(statspec, st, ti->tile, 0); ground_relocation = relocation = GetCustomStationRelocation(statspec, st, ti->tile, 0);
if (HasBit(statspec->flags, SSF_SEPARATE_GROUND)) { if (statspec->flags.Test(StationSpecFlag::SeparateGround)) {
ground_relocation = GetCustomStationRelocation(statspec, st, ti->tile, 1); ground_relocation = GetCustomStationRelocation(statspec, st, ti->tile, 1);
} }
ground_relocation += rti->fallback_railtype; ground_relocation += rti->fallback_railtype;