From fb70a7fe7e4c83caffdb3e9604a09a964c98348d Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 6 Feb 2025 20:08:52 +0000 Subject: [PATCH] Codechange: Use EnumBitSet for IndustryTileSpecialFlags. --- src/industry_cmd.cpp | 2 +- src/industrytype.h | 9 ++++----- src/newgrf.cpp | 4 ++-- src/newgrf_industrytiles.cpp | 2 +- src/table/build_industry.h | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index f1f8e9b4e1..2df20b0a81 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -421,7 +421,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca auto accepts_cargo = itspec->accepts_cargo; auto cargo_acceptance = itspec->acceptance; - if (itspec->special_flags & INDTILE_SPECIAL_ACCEPTS_ALL_CARGO) { + if (itspec->special_flags.Test(IndustryTileSpecialFlag::AcceptsAllCargo)) { /* Copy all accepted cargoes from industry itself */ for (const auto &a : ind->accepted) { auto pos = std::ranges::find(accepts_cargo, a.cargo); diff --git a/src/industrytype.h b/src/industrytype.h index 4f37b0cdb4..a7a39afc2f 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -81,12 +81,11 @@ enum class IndustryBehaviour : uint8_t { using IndustryBehaviours = EnumBitSet; /** Flags for miscellaneous industry tile specialities */ -enum IndustryTileSpecialFlags : uint8_t { - INDTILE_SPECIAL_NONE = 0, - INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS = 1 << 0, ///< Callback 0x26 needs random bits - INDTILE_SPECIAL_ACCEPTS_ALL_CARGO = 1 << 1, ///< Tile always accepts all cargoes the associated industry accepts +enum class IndustryTileSpecialFlag : uint8_t { + NextFrameRandomBits = 0, ///< Callback 0x26 needs random bits + AcceptsAllCargo = 1, ///< Tile always accepts all cargoes the associated industry accepts }; -DECLARE_ENUM_AS_BIT_SET(IndustryTileSpecialFlags) +using IndustryTileSpecialFlags = EnumBitSet; /** Definition of one tile in an industry tile layout */ struct IndustryTileLayoutTile { diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 8dc422fc52..3c857f99c3 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3431,7 +3431,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint first, uint last, int prop, break; case 0x12: // Special flags - tsp->special_flags = (IndustryTileSpecialFlags)buf.ReadByte(); + tsp->special_flags = IndustryTileSpecialFlags{buf.ReadByte()}; break; case 0x13: { // variable length cargo acceptance @@ -3444,7 +3444,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint first, uint last, int prop, for (uint i = 0; i < std::size(tsp->acceptance); i++) { if (i < num_cargoes) { tsp->accepts_cargo[i] = GetCargoTranslation(buf.ReadByte(), _cur.grffile); - /* Tile acceptance can be negative to counteract the INDTILE_SPECIAL_ACCEPTS_ALL_CARGO flag */ + /* Tile acceptance can be negative to counteract the IndustryTileSpecialFlag::AcceptsAllCargo flag */ tsp->acceptance[i] = (int8_t)buf.ReadByte(); } else { tsp->accepts_cargo[i] = INVALID_CARGO; diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 59cc3fcc80..41b9c4b506 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -270,7 +270,7 @@ void AnimateNewIndustryTile(TileIndex tile) const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile)); if (itspec == nullptr) return; - IndustryAnimationBase::AnimateTile(itspec, Industry::GetByTile(tile), tile, (itspec->special_flags & INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS) != 0); + IndustryAnimationBase::AnimateTile(itspec, Industry::GetByTile(tile), tile, itspec->special_flags.Test(IndustryTileSpecialFlag::NextFrameRandomBits)); } bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32_t random) diff --git a/src/table/build_industry.h b/src/table/build_industry.h index 16ce9881bc..325afdcc01 100644 --- a/src/table/build_industry.h +++ b/src/table/build_industry.h @@ -1533,7 +1533,7 @@ static const IndustrySpec _origin_industry_specs[NEW_INDUSTRYOFFSET] = { */ #define MT(ca1, c1, ca2, c2, ca3, c3, sl, a1, a2, a3) { \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ - {ca1, ca2, ca3}, sl, a1, a2, a3, IndustryTileCallbackMasks{}, {0, ANIM_STATUS_NO_ANIMATION, 2, 0}, INDTILE_SPECIAL_NONE, true, GRFFileProps(INVALID_INDUSTRYTILE), {c1, c2, c3} \ + {ca1, ca2, ca3}, sl, a1, a2, a3, IndustryTileCallbackMasks{}, {0, ANIM_STATUS_NO_ANIMATION, 2, 0}, IndustryTileSpecialFlags{}, true, GRFFileProps(INVALID_INDUSTRYTILE), {c1, c2, c3} \ } static const IndustryTileSpec _origin_industry_tile_specs[NEW_INDUSTRYTILEOFFSET] = { /* Coal Mine */