diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 3da937bb86..68d626e059 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -63,7 +63,7 @@ static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle */ bool IsArticulatedEngine(EngineID engine_type) { - return HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE); + return EngInfo(engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine); } /** @@ -74,7 +74,7 @@ bool IsArticulatedEngine(EngineID engine_type) */ uint CountArticulatedParts(EngineID engine_type, bool purchase_window) { - if (!HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return 0; + if (!EngInfo(engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) return 0; /* If we can't allocate a vehicle now, we can't allocate it in the command * either, so it doesn't matter how many articulated parts there are. */ @@ -146,7 +146,7 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine) if (!e->IsGroundVehicle()) return capacity; - if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity; + if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return capacity; for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); @@ -176,7 +176,7 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine) if (!e->IsGroundVehicle()) return cargoes; - if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargoes; + if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return cargoes; for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); @@ -202,7 +202,7 @@ bool IsArticulatedVehicleRefittable(EngineID engine) const Engine *e = Engine::Get(engine); if (!e->IsGroundVehicle()) return false; - if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return false; + if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return false; for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); @@ -229,7 +229,7 @@ void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES; if (!e->IsGroundVehicle()) return; - if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return; + if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return; for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); @@ -338,7 +338,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v) void AddArticulatedParts(Vehicle *first) { VehicleType type = first->type; - if (!HasBit(EngInfo(first->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return; + if (!EngInfo(first->engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) return; Vehicle *v = first; for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { diff --git a/src/cargotype.h b/src/cargotype.h index 714b8fe22c..a7732c77f9 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -13,6 +13,7 @@ #include "economy_type.h" #include "cargo_type.h" #include "gfx_type.h" +#include "newgrf_callbacks.h" #include "strings_type.h" #include "landscape_type.h" #include "core/bitmath_func.hpp" @@ -88,7 +89,7 @@ struct CargoSpec { TownAcceptanceEffect town_acceptance_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies. TownProductionEffect town_production_effect = INVALID_TPE; ///< The effect on town cargo production. uint16_t town_production_multiplier = TOWN_PRODUCTION_DIVISOR; ///< Town production multipler, if commanded by TownProductionEffect. - uint8_t callback_mask; ///< Bitmask of cargo callbacks that have to be called + CargoCallbackMasks callback_mask; ///< Bitmask of cargo callbacks that have to be called StringID name; ///< Name of this type of cargo. StringID name_single; ///< Name of a single entity of this type of cargo. diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index d82daa5f7c..548d6abe1e 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -2712,7 +2712,7 @@ static void ConDumpCargoTypes() spec->Index(), spec->bitnum, FormatLabel(spec->label.base()), - spec->callback_mask, + spec->callback_mask.base(), (spec->classes & CC_PASSENGERS) != 0 ? 'p' : '-', (spec->classes & CC_MAIL) != 0 ? 'm' : '-', (spec->classes & CC_EXPRESS) != 0 ? 'x' : '-', diff --git a/src/economy.cpp b/src/economy.cpp index 53b953ca78..67ab8b3368 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -988,7 +988,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16_t transit_per } /* Use callback to calculate cargo profit, if available */ - if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { + if (cs->callback_mask.Test(CargoCallbackMask::ProfitCalc)) { uint32_t var18 = ClampTo(dist) | (ClampTo(num_pieces) << 16) | (ClampTo(transit_periods) << 24); uint16_t callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs); if (callback != CALLBACK_FAILED) { @@ -1161,12 +1161,12 @@ static Money DeliverGoods(int num_pieces, CargoType cargo_type, StationID dest, static void TriggerIndustryProduction(Industry *i) { const IndustrySpec *indspec = GetIndustrySpec(i->type); - uint16_t callback = indspec->callback_mask; + IndustryCallbackMasks cbm = indspec->callback_mask; i->was_cargo_delivered = true; - if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { - if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) { + if (cbm.Test(IndustryCallbackMask::ProductionCargoArrival) || cbm.Test(IndustryCallbackMask::Production256Ticks)) { + if (cbm.Test(IndustryCallbackMask::ProductionCargoArrival)) { IndustryProductionCallback(i, 0); } else { SetWindowDirty(WC_INDUSTRY_VIEW, i->index); @@ -1331,7 +1331,7 @@ static uint GetLoadAmount(Vehicle *v) if (e->GetGRF() != nullptr && e->GetGRF()->grf_version >= 8) { /* Use callback 36 */ cb_load_amount = GetVehicleProperty(v, PROP_VEHICLE_LOAD_AMOUNT, CALLBACK_FAILED); - } else if (HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) { + } else if (e->info.callback_mask.Test(VehicleCallbackMask::LoadAmount)) { /* Use callback 12 */ cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); } diff --git a/src/engine.cpp b/src/engine.cpp index 994aba591a..66de7b2173 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -214,7 +214,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const } /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */ - if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && + if (this->info.callback_mask.Test(VehicleCallbackMask::RefitCapacity) && (new_multipliers || default_cargo != cargo_type || (v != nullptr && v->cargo_subtype != 0))) { uint16_t callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v); if (callback != CALLBACK_FAILED) return callback; @@ -1306,7 +1306,7 @@ bool IsEngineRefittable(EngineID engine) /* Are there suffixes? * Note: This does not mean the suffixes are actually available for every consist at any time. */ - if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true; + if (ei->callback_mask.Test(VehicleCallbackMask::CargoSuffix)) return true; /* Is there any cargo except the default cargo? */ CargoType default_cargo = e->GetDefaultCargoType(); diff --git a/src/engine_type.h b/src/engine_type.h index 51427541e6..17e66daeb6 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -11,6 +11,7 @@ #define ENGINE_TYPE_H #include "economy_type.h" +#include "newgrf_callbacks.h" #include "rail_type.h" #include "road_type.h" #include "cargo_type.h" @@ -156,7 +157,7 @@ struct EngineInfo { CargoTypes refit_mask; uint8_t refit_cost; uint8_t misc_flags; ///< Miscellaneous flags. @see EngineMiscFlags - uint16_t callback_mask; ///< Bitmask of vehicle callbacks that have to be called + VehicleCallbackMasks callback_mask; ///< Bitmask of vehicle callbacks that have to be called int8_t retire_early; ///< Number of years early to retire vehicle ExtraEngineFlags extra_flags; StringID string_id; ///< Default name of engine diff --git a/src/house.h b/src/house.h index 0b47e6570e..0c5f4c49b3 100644 --- a/src/house.h +++ b/src/house.h @@ -14,6 +14,7 @@ #include "timer/timer_game_calendar.h" #include "house_type.h" #include "newgrf_animation_type.h" +#include "newgrf_callbacks.h" #include "newgrf_commons.h" /** @@ -107,7 +108,7 @@ struct HouseSpec { /* NewHouses properties */ GRFFileProps grf_prop; ///< Properties related the the grf file - uint16_t callback_mask; ///< Bitmask of house callbacks that have to be called + HouseCallbackMasks callback_mask; ///< Bitmask of house callbacks that have to be called Colours random_colour[4]; ///< 4 "random" colours uint8_t probability; ///< Relative probability of appearing (16 is the standard value) HouseExtraFlags extra_flags; ///< some more flags diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 9a136933c2..f5c7ea50fd 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -403,7 +403,7 @@ static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh) */ if (gfx >= NEW_INDUSTRYTILEOFFSET) { const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); - if (indts->grf_prop.spritegroup[0] != nullptr && HasBit(indts->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) { + if (indts->grf_prop.spritegroup[0] != nullptr && indts->callback_mask.Test(IndustryTileCallbackMask::DrawFoundations)) { uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, Industry::GetByTile(tile), tile); if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(indts->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE; } @@ -435,7 +435,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca } } - if (HasBit(itspec->callback_mask, CBM_INDT_ACCEPT_CARGO)) { + if (itspec->callback_mask.Test(IndustryTileCallbackMask::AcceptCargo)) { /* Try callback for accepts list, if success override all existing accepts */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { @@ -444,7 +444,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca } } - if (HasBit(itspec->callback_mask, CBM_INDT_CARGO_ACCEPTANCE)) { + if (itspec->callback_mask.Test(IndustryTileCallbackMask::CargoAcceptance)) { /* Try callback for acceptance list, if success override all existing acceptance */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { @@ -1182,7 +1182,7 @@ static void ProduceIndustryGoods(Industry *i) i->counter--; /* If using an industry callback, scale the callback interval by cargo scale percentage. */ - if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) { + if (indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) { if (i->counter % ScaleByInverseCargoScale(Ticks::INDUSTRY_PRODUCE_TICKS, false) == 0) { IndustryProductionCallback(i, 1); ProduceIndustryGoodsHelper(i, false); @@ -1195,13 +1195,13 @@ static void ProduceIndustryGoods(Industry *i) */ if ((i->counter % Ticks::INDUSTRY_PRODUCE_TICKS) == 0) { /* Handle non-callback cargo production. */ - if (!HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) ProduceIndustryGoodsHelper(i, true); + if (!indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) ProduceIndustryGoodsHelper(i, true); IndustryBehaviour indbehav = indsp->behaviour; if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) { uint16_t cb_res = CALLBACK_FAILED; - if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) { + if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) { cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->location.tile); } @@ -1216,7 +1216,7 @@ static void ProduceIndustryGoods(Industry *i) } if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) { uint16_t cb_res = CALLBACK_FAILED; - if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) { + if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) { cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 1, i, i->type, i->location.tile); } @@ -1545,7 +1545,7 @@ static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileL if (gfx != GFX_WATERTILE_SPECIALCHECK) { const IndustryTileSpec *its = GetIndustryTileSpec(gfx); - if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { + if (its->callback_mask.Test(IndustryTileCallbackMask::ShapeCheck)) { custom_shape = true; CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type); if (ret.Failed()) return ret; @@ -1822,7 +1822,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, /* Call callbacks after the regular fields got initialised. */ - if (HasBit(indspec->callback_mask, CBM_IND_PROD_CHANGE_BUILD)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::ProdChangeBuild)) { uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROD_CHANGE_BUILD, 0, Random(), i, type, INVALID_TILE); if (res != CALLBACK_FAILED) { if (res < PRODLEVEL_MINIMUM || res > PRODLEVEL_MAXIMUM) { @@ -1835,7 +1835,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, } if (_generating_world) { - if (HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) { IndustryProductionCallback(i, 1); for (auto &p : i->produced) { p.history[LAST_MONTH].production = p.waiting * 8; @@ -1848,7 +1848,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, } } - if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::DecideColour)) { uint16_t res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE); if (res != CALLBACK_FAILED) { if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_DECIDE_COLOUR, res); @@ -1856,7 +1856,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, } } - if (HasBit(indspec->callback_mask, CBM_IND_INPUT_CARGO_TYPES)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::InputCargoTypes)) { /* Clear all input cargo types */ i->accepted.clear(); /* Query actual types */ @@ -1894,7 +1894,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, } } - if (HasBit(indspec->callback_mask, CBM_IND_OUTPUT_CARGO_TYPES)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::OutputCargoTypes)) { /* Clear all output cargo types */ i->produced.clear(); /* Query actual types */ @@ -2007,7 +2007,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do if (ret.Failed()) return ret; /* 3. NewGRF-defined checks on industry level. */ - if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) { + if (GetIndustrySpec(type)->callback_mask.Test(IndustryCallbackMask::Location)) { ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type); } else { ret = _check_new_industry_procs[indspec->check_proc](tile); @@ -2806,7 +2806,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) uint8_t mul = 0; int8_t increment = 0; - bool callback_enabled = HasBit(indspec->callback_mask, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE); + bool callback_enabled = indspec->callback_mask.Test(monthly ? IndustryCallbackMask::MonthlyProdChange : IndustryCallbackMask::ProductionChange); if (callback_enabled) { uint16_t res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->location.tile); if (res != CALLBACK_FAILED) { // failed callback means "do nothing" @@ -3150,8 +3150,12 @@ Money IndustrySpec::GetRemovalCost() const bool IndustrySpec::UsesOriginalEconomy() const { return _settings_game.economy.type == ET_ORIGINAL || - HasBit(this->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || // production callbacks - HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE) || HasBit(this->callback_mask, CBM_IND_PROD_CHANGE_BUILD); // production change callbacks + this->callback_mask.Any({ + IndustryCallbackMask::Production256Ticks, + IndustryCallbackMask::ProductionCargoArrival, // production callbacks + IndustryCallbackMask::MonthlyProdChange, + IndustryCallbackMask::ProductionChange, + IndustryCallbackMask::ProdChangeBuild}); // production change callbacks } static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new) @@ -3170,7 +3174,7 @@ static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, i const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); /* Call callback 3C 'disable autosloping for industry tiles'. */ - if (HasBit(itspec->callback_mask, CBM_INDT_AUTOSLOPE)) { + if (itspec->callback_mask.Test(IndustryTileCallbackMask::Autoslope)) { /* If the callback fails, allow autoslope. */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_AUTOSLOPE, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res == CALLBACK_FAILED || !ConvertBooleanCallback(itspec->grf_prop.grffile, CBID_INDTILE_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 0416cc3efc..0c8595571b 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -95,7 +95,7 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, suffix.text.clear(); suffix.display = CSD_CARGO_AMOUNT; - if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::CargoSuffix)) { TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE; uint16_t callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast(ind), ind_type, t); if (callback == CALLBACK_FAILED) return; @@ -584,7 +584,7 @@ public: ir.top = DrawStringMultiLine(ir, cargostring); /* Get the additional purchase info text, if it has not already been queried. */ - if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) { + if (indsp->callback_mask.Test(IndustryCallbackMask::FundMoreText)) { uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE); if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { if (callback_res > 0x400) { @@ -887,7 +887,7 @@ public: } const int label_indent = WidgetDimensions::scaled.hsep_normal + this->cargo_icon_size.width; - bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS); + bool stockpiling = ind->callback_mask.Any({IndustryCallbackMask::ProductionCargoArrival, IndustryCallbackMask::Production256Ticks}); for (const auto &a : i->accepted) { if (!IsValidCargoType(a.cargo)) continue; @@ -977,7 +977,7 @@ public: } /* Get the extra message for the GUI */ - if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) { + if (ind->callback_mask.Test(IndustryCallbackMask::WindowMoreText)) { uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile); if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { if (callback_res > 0x400) { diff --git a/src/industrytype.h b/src/industrytype.h index e498dd99f5..f27dc1e1f0 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -16,6 +16,7 @@ #include "landscape_type.h" #include "cargo_type.h" #include "newgrf_animation_type.h" +#include "newgrf_callbacks.h" #include "newgrf_commons.h" /** Available types of industry lifetimes. */ @@ -127,7 +128,7 @@ struct IndustrySpec { uint8_t appear_ingame[NUM_LANDSCAPE]; ///< Probability of appearance in game uint8_t appear_creation[NUM_LANDSCAPE]; ///< Probability of appearance during map creation /* Newgrf data */ - uint16_t callback_mask; ///< Bitmask of industry callbacks that have to be called + IndustryCallbackMasks callback_mask; ///< Bitmask of industry callbacks that have to be called bool enabled; ///< entity still available (by default true).newgrf can disable it, though GRFFileProps grf_prop; ///< properties related to the grf file std::vector random_sounds; ///< Random sounds; @@ -158,7 +159,7 @@ struct IndustryTileSpec { */ bool anim_state; /* Newgrf data */ - uint8_t callback_mask; ///< Bitmask of industry tile callbacks that have to be called + IndustryTileCallbackMasks callback_mask; ///< Bitmask of industry tile callbacks that have to be called AnimationInfo animation; ///< Information about the animation (is it looping, how many loops etc) IndustryTileSpecialFlags special_flags; ///< Bitmask of extra flags used by the tile bool enabled; ///< entity still available (by default true).newgrf can disable it, though diff --git a/src/newgrf.cpp b/src/newgrf.cpp index f847209db3..4fb54e19b0 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1241,9 +1241,12 @@ static ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, B break; } - case 0x1E: // Callback - SB(ei->callback_mask, 0, 8, buf.ReadByte()); + case 0x1E: { // Callback + auto mask = ei->callback_mask.base(); + SB(mask, 0, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case PROP_TRAIN_TRACTIVE_EFFORT: // 0x1F Tractive effort coefficient rvi->tractive_effort = buf.ReadByte(); @@ -1340,9 +1343,12 @@ static ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, B ei->extra_flags = static_cast(buf.ReadDWord()); break; - case 0x31: // Callback additional mask - SB(ei->callback_mask, 8, 8, buf.ReadByte()); + case 0x31: { // Callback additional mask + auto mask = ei->callback_mask.base(); + SB(mask, 8, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x32: // Cargo classes required for a refit. _gted[e->index].cargo_allowed_required = buf.ReadWord(); @@ -1461,9 +1467,12 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B break; } - case 0x17: // Callback mask - SB(ei->callback_mask, 0, 8, buf.ReadByte()); + case 0x17: { // Callback mask + auto mask = ei->callback_mask.base(); + SB(mask, 0, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case PROP_ROADVEH_TRACTIVE_EFFORT: // Tractive effort coefficient in 1/256. rvi->tractive_effort = buf.ReadByte(); @@ -1545,9 +1554,12 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B ei->extra_flags = static_cast(buf.ReadDWord()); break; - case 0x28: // Callback additional mask - SB(ei->callback_mask, 8, 8, buf.ReadByte()); + case 0x28: { // Callback additional mask + auto mask = ei->callback_mask.base(); + SB(mask, 8, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x29: // Cargo classes required for a refit. _gted[e->index].cargo_allowed_required = buf.ReadWord(); @@ -1648,9 +1660,12 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B break; } - case 0x12: // Callback mask - SB(ei->callback_mask, 0, 8, buf.ReadByte()); + case 0x12: { // Callback mask + auto mask = ei->callback_mask.base(); + SB(mask, 0, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x13: // Refit cost ei->refit_cost = buf.ReadByte(); @@ -1728,9 +1743,12 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B ei->extra_flags = static_cast(buf.ReadDWord()); break; - case 0x22: // Callback additional mask - SB(ei->callback_mask, 8, 8, buf.ReadByte()); + case 0x22: { // Callback additional mask + auto mask = ei->callback_mask.base(); + SB(mask, 8, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x23: // Speed (1 unit is 0.5 km-ish/h) svi->max_speed = buf.ReadWord(); @@ -1839,9 +1857,12 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro break; } - case 0x14: // Callback mask - SB(ei->callback_mask, 0, 8, buf.ReadByte()); + case 0x14: { // Callback mask + auto mask = ei->callback_mask.base(); + SB(mask, 0, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x15: // Refit cost ei->refit_cost = buf.ReadByte(); @@ -1905,9 +1926,12 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro ei->extra_flags = static_cast(buf.ReadDWord()); break; - case 0x22: // Callback additional mask - SB(ei->callback_mask, 8, 8, buf.ReadByte()); + case 0x22: { // Callback additional mask + auto mask = ei->callback_mask.base(); + SB(mask, 8, 8, buf.ReadByte()); + ei->callback_mask = VehicleCallbackMasks{mask}; break; + } case 0x23: // Cargo classes required for a refit. _gted[e->index].cargo_allowed_required = buf.ReadWord(); @@ -2034,7 +2058,7 @@ static ChangeInfoResult StationChangeInfo(uint first, uint last, int prop, ByteR } case 0x0B: // Callback mask - statspec->callback_mask = buf.ReadByte(); + statspec->callback_mask = static_cast(buf.ReadByte()); break; case 0x0C: // Disallowed number of platforms @@ -2224,7 +2248,7 @@ static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteRea switch (prop) { case 0x08: - cp->callback_mask = buf.ReadByte(); + cp->callback_mask = static_cast(buf.ReadByte()); break; case 0x09: @@ -2550,9 +2574,12 @@ static ChangeInfoResult TownHouseChangeInfo(uint first, uint last, int prop, Byt housespec->building_availability = (HouseZones)buf.ReadWord(); break; - case 0x14: // House callback mask - housespec->callback_mask |= buf.ReadByte(); + case 0x14: { // House callback mask + auto mask = housespec->callback_mask.base(); + SB(mask, 0, 8, buf.ReadByte()); + housespec->callback_mask = HouseCallbackMasks{mask}; break; + } case 0x15: { // House override byte uint8_t override = buf.ReadByte(); @@ -2597,9 +2624,12 @@ static ChangeInfoResult TownHouseChangeInfo(uint first, uint last, int prop, Byt housespec->class_id = AllocateHouseClassID(buf.ReadByte(), _cur.grffile->grfid); break; - case 0x1D: // Callback mask part 2 - housespec->callback_mask |= (buf.ReadByte() << 8); + case 0x1D: { // Callback mask part 2 + auto mask = housespec->callback_mask.base(); + SB(mask, 8, 8, buf.ReadByte()); + housespec->callback_mask = HouseCallbackMasks{mask}; break; + } case 0x1E: { // Accepted cargo types uint32_t cargotypes = buf.ReadDWord(); @@ -3167,7 +3197,7 @@ static ChangeInfoResult CargoChangeInfo(uint first, uint last, int prop, ByteRea break; case 0x1A: // Bitmask of callbacks to use - cs->callback_mask = buf.ReadByte(); + cs->callback_mask = static_cast(buf.ReadByte()); break; case 0x1D: // Vehicle capacity muliplier @@ -3384,7 +3414,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint first, uint last, int prop, break; case 0x0E: // Callback mask - tsp->callback_mask = buf.ReadByte(); + tsp->callback_mask = static_cast(buf.ReadByte()); break; case 0x0F: // Animation information @@ -3828,8 +3858,9 @@ static ChangeInfoResult IndustriesChangeInfo(uint first, uint last, int prop, By case 0x21: // Callback mask case 0x22: { // Callback additional mask - uint8_t aflag = buf.ReadByte(); - SB(indsp->callback_mask, (prop - 0x21) * 8, 8, aflag); + auto mask = indsp->callback_mask.base(); + SB(mask, (prop - 0x21) * 8, 8, buf.ReadByte()); + indsp->callback_mask = IndustryCallbackMasks{mask}; break; } @@ -4231,7 +4262,7 @@ static ChangeInfoResult ObjectChangeInfo(uint first, uint last, int prop, ByteRe break; case 0x15: // Callback mask - spec->callback_mask = buf.ReadWord(); + spec->callback_mask = static_cast(buf.ReadWord()); break; case 0x16: // Building height @@ -4761,7 +4792,7 @@ static ChangeInfoResult AirportTilesChangeInfo(uint first, uint last, int prop, } case 0x0E: // Callback mask - tsp->callback_mask = buf.ReadByte(); + tsp->callback_mask = static_cast(buf.ReadByte()); break; case 0x0F: // Animation information @@ -4892,7 +4923,7 @@ static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, Byte break; case 0x11: // Callback mask - rs->callback_mask = buf.ReadByte(); + rs->callback_mask = static_cast(buf.ReadByte()); break; case 0x12: // General flags @@ -9124,7 +9155,7 @@ static void CalculateRefitMasks() /* Custom refit mask callback. */ const GRFFile *file = _gted[e->index].defaultcargo_grf; if (file == nullptr) file = e->GetGRF(); - if (file != nullptr && HasBit(e->info.callback_mask, CBM_VEHICLE_CUSTOM_REFIT)) { + if (file != nullptr && e->info.callback_mask.Test(VehicleCallbackMask::CustomRefit)) { for (const CargoSpec *cs : CargoSpec::Iterate()) { uint8_t local_slot = file->cargo_map[cs->Index()]; uint16_t callback = GetVehicleCallback(CBID_VEHICLE_CUSTOM_REFIT, cs->classes, local_slot, engine, nullptr); diff --git a/src/newgrf.h b/src/newgrf.h index f99af841e0..b5160503eb 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -14,6 +14,7 @@ #include "rail_type.h" #include "road_type.h" #include "fileio_type.h" +#include "newgrf_callbacks.h" #include "newgrf_text_type.h" #include "core/bitmath_func.hpp" #include "core/alloc_type.hpp" @@ -38,7 +39,7 @@ enum CanalFeature : uint8_t { /** Canal properties local to the NewGRF */ struct CanalProperties { - uint8_t callback_mask; ///< Bitmask of canal callbacks that have to be called. + CanalCallbackMasks callback_mask; ///< Bitmask of canal callbacks that have to be called. uint8_t flags; ///< Flags controlling display. }; diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp index cfd7e25b41..ac98b84e29 100644 --- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -259,7 +259,7 @@ bool DrawNewAirportTile(TileInfo *ti, Station *st, const AirportTileSpec *airts) { if (ti->tileh != SLOPE_FLAT) { bool draw_old_one = true; - if (HasBit(airts->callback_mask, CBM_AIRT_DRAW_FOUNDATIONS)) { + if (airts->callback_mask.Test(AirportTileCallbackMask::DrawFoundations)) { /* Called to determine the type (if any) of foundation to draw */ uint32_t callback_res = GetAirportTileCallback(CBID_AIRPTILE_DRAW_FOUNDATIONS, 0, 0, airts, st, ti->tile); if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(airts->grf_prop.grffile, CBID_AIRPTILE_DRAW_FOUNDATIONS, callback_res); @@ -281,11 +281,11 @@ bool DrawNewAirportTile(TileInfo *ti, Station *st, const AirportTileSpec *airts) /** Helper class for animation control. */ struct AirportTileAnimationBase : public AnimationBase > { - static const CallbackID cb_animation_speed = CBID_AIRPTILE_ANIMATION_SPEED; - static const CallbackID cb_animation_next_frame = CBID_AIRPTILE_ANIM_NEXT_FRAME; + static constexpr CallbackID cb_animation_speed = CBID_AIRPTILE_ANIMATION_SPEED; + static constexpr CallbackID cb_animation_next_frame = CBID_AIRPTILE_ANIM_NEXT_FRAME; - static const AirportTileCallbackMask cbm_animation_speed = CBM_AIRT_ANIM_SPEED; - static const AirportTileCallbackMask cbm_animation_next_frame = CBM_AIRT_ANIM_NEXT_FRAME; + static constexpr AirportTileCallbackMask cbm_animation_speed = AirportTileCallbackMask::AnimationSpeed; + static constexpr AirportTileCallbackMask cbm_animation_next_frame = AirportTileCallbackMask::AnimationNextFrame; }; void AnimateAirportTile(TileIndex tile) diff --git a/src/newgrf_airporttiles.h b/src/newgrf_airporttiles.h index 1e4e96c895..592e367bc3 100644 --- a/src/newgrf_airporttiles.h +++ b/src/newgrf_airporttiles.h @@ -13,6 +13,7 @@ #include "airport.h" #include "station_map.h" #include "newgrf_animation_type.h" +#include "newgrf_callbacks.h" #include "newgrf_commons.h" #include "newgrf_spritegroup.h" #include "station_base.h" @@ -68,7 +69,7 @@ struct AirportTileResolverObject : public ResolverObject { struct AirportTileSpec { AnimationInfo animation; ///< Information about the animation. StringID name; ///< Tile Subname string, land information on this tile will give you "AirportName (TileSubname)" - uint8_t callback_mask; ///< Bitmask telling which grf callback is set + AirportTileCallbackMasks callback_mask; ///< Bitmask telling which grf callback is set uint8_t animation_special_flags; ///< Extra flags to influence the animation bool enabled; ///< entity still available (by default true). newgrf can disable it, though GRFFileProps grf_prop; ///< properties related the the grf file diff --git a/src/newgrf_animation_base.h b/src/newgrf_animation_base.h index 3352f7705a..c1c266f93d 100644 --- a/src/newgrf_animation_base.h +++ b/src/newgrf_animation_base.h @@ -55,7 +55,7 @@ struct AnimationBase { /* Acquire the animation speed from the NewGRF. */ uint8_t animation_speed = spec->animation.speed; - if (HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) { + if (spec->callback_mask.Test(Tbase::cbm_animation_speed)) { uint16_t callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data); if (callback != CALLBACK_FAILED) { if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8) ErrorUnknownCallbackResult(spec->grf_prop.grfid, Tbase::cb_animation_speed, callback); @@ -74,7 +74,7 @@ struct AnimationBase { bool frame_set_by_callback = false; - if (HasBit(spec->callback_mask, Tbase::cbm_animation_next_frame)) { + if (spec->callback_mask.Test(Tbase::cbm_animation_next_frame)) { uint16_t callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile, extra_data); if (callback != CALLBACK_FAILED) { diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h index 792692b34a..1753713d06 100644 --- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -10,6 +10,8 @@ #ifndef NEWGRF_CALLBACKS_H #define NEWGRF_CALLBACKS_H +#include "core/enum_type.hpp" + /** * List of implemented NewGRF callbacks. * Most of these callbacks are only triggered when the corresponding @@ -297,129 +299,139 @@ enum CallbackID : uint16_t { * Callback masks for vehicles, indicates which callbacks are used by a vehicle. * Some callbacks are always used and don't have a mask. */ -enum VehicleCallbackMask : uint8_t { - CBM_VEHICLE_VISUAL_EFFECT = 0, ///< Visual effects and wagon power (trains, road vehicles and ships) - CBM_VEHICLE_LENGTH = 1, ///< Vehicle length (trains and road vehicles) - CBM_VEHICLE_LOAD_AMOUNT = 2, ///< Load amount - CBM_VEHICLE_REFIT_CAPACITY = 3, ///< Cargo capacity after refit - CBM_VEHICLE_ARTIC_ENGINE = 4, ///< Add articulated engines (trains and road vehicles) - CBM_VEHICLE_CARGO_SUFFIX = 5, ///< Show suffix after cargo name - CBM_VEHICLE_COLOUR_REMAP = 6, ///< Change colour mapping of vehicle - CBM_VEHICLE_SOUND_EFFECT = 7, ///< Vehicle uses custom sound effects - CBM_VEHICLE_NAME = 8, ///< Engine name - CBM_VEHICLE_CUSTOM_REFIT = 9, ///< Custom refit mask +enum class VehicleCallbackMask : uint8_t { + VisualEffect = 0, ///< Visual effects and wagon power (trains, road vehicles and ships) + Length = 1, ///< Vehicle length (trains and road vehicles) + LoadAmount = 2, ///< Load amount + RefitCapacity = 3, ///< Cargo capacity after refit + ArticEngine = 4, ///< Add articulated engines (trains and road vehicles) + CargoSuffix = 5, ///< Show suffix after cargo name + ColourRemap = 6, ///< Change colour mapping of vehicle + SoundEffect = 7, ///< Vehicle uses custom sound effects + Name = 8, ///< Engine name + CustomRefit = 9, ///< Custom refit mask }; +using VehicleCallbackMasks = EnumBitSet; /** * Callback masks for stations. */ -enum StationCallbackMask : uint8_t { - CBM_STATION_AVAIL = 0, ///< Availability of station in construction window - CBM_STATION_DRAW_TILE_LAYOUT = 1, ///< Use callback to select a tile layout to use when drawing. - CBM_STATION_ANIMATION_NEXT_FRAME = 2, ///< Use a custom next frame callback - CBM_STATION_ANIMATION_SPEED = 3, ///< Customize the animation speed of the station - CBM_STATION_SLOPE_CHECK = 4, ///< Check slope of new station tiles +enum class StationCallbackMask : uint8_t { + Avail = 0, ///< Availability of station in construction window + DrawTileLayout = 1, ///< Use callback to select a tile layout to use when drawing. + AnimationNextFrame = 2, ///< Use a custom next frame callback + AnimationSpeed = 3, ///< Customize the animation speed of the station + SlopeCheck = 4, ///< Check slope of new station tiles }; +using StationCallbackMasks = EnumBitSet; /** * Callback masks for road stops. */ -enum RoadStopCallbackMask : uint8_t { - CBM_ROAD_STOP_AVAIL = 0, ///< Availability of road stop in construction window - CBM_ROAD_STOP_ANIMATION_NEXT_FRAME = 1, ///< Use a custom next frame callback - CBM_ROAD_STOP_ANIMATION_SPEED = 2, ///< Customize the animation speed of the road stop +enum class RoadStopCallbackMask : uint8_t { + Avail = 0, ///< Availability of road stop in construction window + AnimationNextFrame = 1, ///< Use a custom next frame callback + AnimationSpeed = 2, ///< Customize the animation speed of the road stop }; +using RoadStopCallbackMasks = EnumBitSet; /** * Callback masks for houses. */ -enum HouseCallbackMask : uint8_t { - CBM_HOUSE_ALLOW_CONSTRUCTION = 0, ///< decide whether the house can be built on a given tile - CBM_HOUSE_ANIMATION_NEXT_FRAME = 1, ///< decides next animation frame - CBM_HOUSE_ANIMATION_START_STOP = 2, ///< periodically start/stop the animation - CBM_HOUSE_CONSTRUCTION_STATE_CHANGE = 3, ///< change animation when construction state changes - CBM_HOUSE_COLOUR = 4, ///< decide the colour of the building - CBM_HOUSE_CARGO_ACCEPTANCE = 5, ///< decides amount of cargo acceptance - CBM_HOUSE_ANIMATION_SPEED = 6, ///< decides animation speed - CBM_HOUSE_DESTRUCTION = 7, ///< trigger destruction of building - CBM_HOUSE_ACCEPT_CARGO = 8, ///< decides accepted types - CBM_HOUSE_PRODUCE_CARGO = 9, ///< custom cargo production - CBM_HOUSE_DENY_DESTRUCTION = 10, ///< conditional protection - CBM_HOUSE_DRAW_FOUNDATIONS = 11, ///< decides if default foundations need to be drawn - CBM_HOUSE_AUTOSLOPE = 12, ///< decides allowance of autosloping +enum class HouseCallbackMask : uint8_t { + AllowConstruction = 0, ///< decide whether the house can be built on a given tile + AnimationNextFrame = 1, ///< decides next animation frame + AnimationStartStop = 2, ///< periodically start/stop the animation + ConstructionStateChange = 3, ///< change animation when construction state changes + Colour = 4, ///< decide the colour of the building + CargoAcceptance = 5, ///< decides amount of cargo acceptance + AnimationSpeed = 6, ///< decides animation speed + Destruction = 7, ///< trigger destruction of building + AcceptCargo = 8, ///< decides accepted types + ProduceCargo = 9, ///< custom cargo production + DenyDestruction = 10, ///< conditional protection + DrawFoundations = 11, ///< decides if default foundations need to be drawn + Autoslope = 12, ///< decides allowance of autosloping }; +using HouseCallbackMasks = EnumBitSet; /** * Callback masks for canals. */ -enum CanalCallbackMask : uint8_t { - CBM_CANAL_SPRITE_OFFSET = 0, ///< Enable add sprite offset callback +enum class CanalCallbackMask : uint8_t { + SpriteOffset = 0, ///< Enable add sprite offset callback }; +using CanalCallbackMasks = EnumBitSet; /** * Callback masks for cargoes. */ -enum CargoCallbackMask : uint8_t { - CBM_CARGO_PROFIT_CALC = 0, ///< custom profit calculation - CBM_CARGO_STATION_RATING_CALC = 1, ///< custom station rating for this cargo type +enum class CargoCallbackMask : uint8_t { + ProfitCalc = 0, ///< custom profit calculation + StationRatingCalc = 1, ///< custom station rating for this cargo type }; +using CargoCallbackMasks = EnumBitSet; /** * Callback masks for Industries */ -enum IndustryCallbackMask : uint8_t { - CBM_IND_PROBABILITY = 0, ///< industry availability/probability callback - CBM_IND_PRODUCTION_CARGO_ARRIVAL = 1, ///< call production callback when cargo arrives at the industry - CBM_IND_PRODUCTION_256_TICKS = 2, ///< call production callback every 256 ticks - CBM_IND_LOCATION = 3, ///< check industry construction on given area - CBM_IND_PRODUCTION_CHANGE = 4, ///< controls random production change - CBM_IND_MONTHLYPROD_CHANGE = 5, ///< controls monthly random production change - CBM_IND_CARGO_SUFFIX = 6, ///< cargo sub-type display - CBM_IND_FUND_MORE_TEXT = 7, ///< additional text in fund window - CBM_IND_WINDOW_MORE_TEXT = 8, ///< additional text in industry window - CBM_IND_SPECIAL_EFFECT = 9, ///< control special effects - CBM_IND_REFUSE_CARGO = 10, ///< option out of accepting cargo - CBM_IND_DECIDE_COLOUR = 11, ///< give a custom colour to newly build industries - CBM_IND_INPUT_CARGO_TYPES = 12, ///< customize the cargoes the industry requires - CBM_IND_OUTPUT_CARGO_TYPES = 13, ///< customize the cargoes the industry produces - CBM_IND_PROD_CHANGE_BUILD = 14, ///< initialise production level on construction +enum class IndustryCallbackMask : uint8_t { + Probability = 0, ///< industry availability/probability callback + ProductionCargoArrival = 1, ///< call production callback when cargo arrives at the industry + Production256Ticks = 2, ///< call production callback every 256 ticks + Location = 3, ///< check industry construction on given area + ProductionChange = 4, ///< controls random production change + MonthlyProdChange = 5, ///< controls monthly random production change + CargoSuffix = 6, ///< cargo sub-type display + FundMoreText = 7, ///< additional text in fund window + WindowMoreText = 8, ///< additional text in industry window + SpecialEffect = 9, ///< control special effects + RefuseCargo = 10, ///< option out of accepting cargo + DecideColour = 11, ///< give a custom colour to newly build industries + InputCargoTypes = 12, ///< customize the cargoes the industry requires + OutputCargoTypes = 13, ///< customize the cargoes the industry produces + ProdChangeBuild = 14, ///< initialise production level on construction }; +using IndustryCallbackMasks = EnumBitSet; /** * Callback masks for industry tiles */ -enum IndustryTileCallbackMask : uint8_t { - CBM_INDT_ANIM_NEXT_FRAME = 0, ///< decides next animation frame - CBM_INDT_ANIM_SPEED = 1, ///< decides animation speed - CBM_INDT_CARGO_ACCEPTANCE = 2, ///< decides amount of cargo acceptance - CBM_INDT_ACCEPT_CARGO = 3, ///< decides accepted types - CBM_INDT_SHAPE_CHECK = 4, ///< decides slope suitability - CBM_INDT_DRAW_FOUNDATIONS = 5, ///< decides if default foundations need to be drawn - CBM_INDT_AUTOSLOPE = 6, ///< decides allowance of autosloping +enum class IndustryTileCallbackMask : uint8_t { + AnimationNextFrame = 0, ///< decides next animation frame + AnimationSpeed = 1, ///< decides animation speed + CargoAcceptance = 2, ///< decides amount of cargo acceptance + AcceptCargo = 3, ///< decides accepted types + ShapeCheck = 4, ///< decides slope suitability + DrawFoundations = 5, ///< decides if default foundations need to be drawn + Autoslope = 6, ///< decides allowance of autosloping }; +using IndustryTileCallbackMasks = EnumBitSet; /** * Callback masks for objects */ -enum ObjectCallbackMask : uint8_t { - CBM_OBJ_SLOPE_CHECK = 0, ///< decides slope suitability - CBM_OBJ_ANIMATION_NEXT_FRAME = 1, ///< decides next animation frame - CBM_OBJ_ANIMATION_SPEED = 2, ///< decides animation speed - CBM_OBJ_COLOUR = 3, ///< decide the colour of the building - CBM_OBJ_FUND_MORE_TEXT = 4, ///< additional text in fund window - CBM_OBJ_AUTOSLOPE = 5, ///< decides allowance of autosloping +enum class ObjectCallbackMask : uint8_t { + SlopeCheck = 0, ///< decides slope suitability + AnimationNextFrame = 1, ///< decides next animation frame + AnimationSpeed = 2, ///< decides animation speed + Colour = 3, ///< decide the colour of the building + FundMoreText = 4, ///< additional text in fund window + Autoslope = 5, ///< decides allowance of autosloping }; +using ObjectCallbackMasks = EnumBitSet; /** * Callback masks for airport tiles */ -enum AirportTileCallbackMask : uint8_t { - CBM_AIRT_ANIM_NEXT_FRAME = 0, ///< decides next animation frame - CBM_AIRT_ANIM_SPEED = 1, ///< decides animation speed - CBM_AIRT_SHAPE_CHECK = 4, ///< decides slope suitability - CBM_AIRT_DRAW_FOUNDATIONS = 5, ///< decides if default foundations need to be drawn - CBM_AIRT_AUTOSLOPE = 6, ///< decides allowance of autosloping +enum class AirportTileCallbackMask : uint8_t { + AnimationNextFrame = 0, ///< decides next animation frame + AnimationSpeed = 1, ///< decides animation speed + ShapeCheck = 4, ///< decides slope suitability + DrawFoundations = 5, ///< decides if default foundations need to be drawn + Autoslope = 6, ///< decides allowance of autosloping }; +using AirportTileCallbackMasks = EnumBitSet; /** * Different values for Callback result evaluations diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp index 0bb7260533..48315fc4bf 100644 --- a/src/newgrf_canal.cpp +++ b/src/newgrf_canal.cpp @@ -170,7 +170,7 @@ static uint16_t GetCanalCallback(CallbackID callback, uint32_t param1, uint32_t */ uint GetCanalSpriteOffset(CanalFeature feature, TileIndex tile, uint cur_offset) { - if (HasBit(_water_feature[feature].callback_mask, CBM_CANAL_SPRITE_OFFSET)) { + if (_water_feature[feature].callback_mask.Test(CanalCallbackMask::SpriteOffset)) { uint16_t cb = GetCanalCallback(CBID_CANALS_SPRITE_OFFSET, cur_offset, 0, feature, tile); if (cb != CALLBACK_FAILED) return cur_offset + cb; } diff --git a/src/newgrf_canal.h b/src/newgrf_canal.h index 28d4c8403d..547d8a6b8b 100644 --- a/src/newgrf_canal.h +++ b/src/newgrf_canal.h @@ -11,6 +11,7 @@ #define NEWGRF_CANAL_H #include "newgrf.h" +#include "newgrf_callbacks.h" #include "tile_type.h" /** Flags controlling the display of canals. */ @@ -22,7 +23,7 @@ enum CanalFeatureFlag : uint8_t { struct WaterFeature { const SpriteGroup *group = nullptr; ///< Sprite group to start resolving. const GRFFile *grffile = nullptr; ///< NewGRF where 'group' belongs to. - uint8_t callback_mask = 0; ///< Bitmask of canal callbacks that have to be called. + CanalCallbackMasks callback_mask = {}; ///< Bitmask of canal callbacks that have to be called. uint8_t flags = 0; ///< Flags controlling display. }; diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index c07e8111f0..a126193fbc 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -102,11 +102,20 @@ struct NICallback { std::string_view name; ///< The human readable name of the callback NIOffsetProc *offset_proc; ///< Callback proc to get the actual variable address in memory uint8_t read_size; ///< The number of bytes (i.e. byte, word, dword etc) to read - uint8_t cb_bit; ///< The bit that needs to be set for this callback to be enabled + std::variant< + std::monostate, + VehicleCallbackMask, + StationCallbackMask, + RoadStopCallbackMask, + HouseCallbackMask, + CanalCallbackMask, + CargoCallbackMask, + IndustryCallbackMask, + IndustryTileCallbackMask, + ObjectCallbackMask, + AirportTileCallbackMask> cb_bit; ///< The bit that needs to be set for this callback to be enabled uint16_t cb_id; ///< The number of the callback }; -/** Mask to show no bit needs to be enabled for the callback. */ -static const int CBM_NO_BIT = UINT8_MAX; /** Representation on the NewGRF variables. */ struct NIVariable { @@ -508,7 +517,7 @@ struct NewGRFInspectWindow : Window { if (!nif->callbacks.empty()) { this->DrawString(r, i++, "Callbacks:"); for (const NICallback &nic : nif->callbacks) { - if (nic.cb_bit != CBM_NO_BIT) { + if (!std::holds_alternative(nic.cb_bit)) { const void *ptr = nic.offset_proc(base_spec); uint value; switch (nic.read_size) { @@ -518,7 +527,23 @@ struct NewGRFInspectWindow : Window { default: NOT_REACHED(); } - if (!HasBit(value, nic.cb_bit)) continue; + struct visitor { + uint value; + + bool operator()(const std::monostate &) { return false; } + bool operator()(const VehicleCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const StationCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const RoadStopCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const HouseCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const CanalCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const CargoCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const IndustryCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const IndustryTileCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const ObjectCallbackMask &bit) { return static_cast(this->value).Test(bit); } + bool operator()(const AirportTileCallbackMask &bit) { return static_cast(this->value).Test(bit); } + }; + + if (!std::visit(visitor{value}, nic.cb_bit)) continue; this->DrawString(r, i++, fmt::format(" {:03x}: {}", nic.cb_id, nic.name)); } else { this->DrawString(r, i++, fmt::format(" {:03x}: {} (unmasked)", nic.cb_id, nic.name)); diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index a917a33a1a..812a162182 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -529,7 +529,7 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou const HouseSpec *hs = HouseSpec::Get(house_id); PaletteID palette = GENERAL_SPRITE_COLOUR(hs->random_colour[TileHash2Bit(ti->x, ti->y)]); - if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) { + if (hs->callback_mask.Test(HouseCallbackMask::Colour)) { uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile); if (callback != CALLBACK_FAILED) { /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ @@ -556,7 +556,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id) if (ti->tileh != SLOPE_FLAT) { bool draw_old_one = true; - if (HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) { + if (hs->callback_mask.Test(HouseCallbackMask::DrawFoundations)) { /* Called to determine the type (if any) of foundation to draw for the house tile */ uint32_t callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile); if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res); @@ -584,11 +584,11 @@ uint16_t GetSimpleHouseCallback(CallbackID callback, uint32_t param1, uint32_t p /** Helper class for animation control. */ struct HouseAnimationBase : public AnimationBase > { - static const CallbackID cb_animation_speed = CBID_HOUSE_ANIMATION_SPEED; - static const CallbackID cb_animation_next_frame = CBID_HOUSE_ANIMATION_NEXT_FRAME; + static constexpr CallbackID cb_animation_speed = CBID_HOUSE_ANIMATION_SPEED; + static constexpr CallbackID cb_animation_next_frame = CBID_HOUSE_ANIMATION_NEXT_FRAME; - static const HouseCallbackMask cbm_animation_speed = CBM_HOUSE_ANIMATION_SPEED; - static const HouseCallbackMask cbm_animation_next_frame = CBM_HOUSE_ANIMATION_NEXT_FRAME; + static constexpr HouseCallbackMask cbm_animation_speed = HouseCallbackMask::AnimationSpeed; + static constexpr HouseCallbackMask cbm_animation_next_frame = HouseCallbackMask::AnimationNextFrame; }; void AnimateNewHouseTile(TileIndex tile) @@ -603,7 +603,7 @@ void AnimateNewHouseConstruction(TileIndex tile) { const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); - if (HasBit(hs->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) { + if (hs->callback_mask.Test(HouseCallbackMask::ConstructionStateChange)) { HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, hs, Town::GetByTile(tile), tile, 0, 0); } } @@ -618,7 +618,7 @@ bool CanDeleteHouse(TileIndex tile) return true; } - if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) { + if (hs->callback_mask.Test(HouseCallbackMask::DenyDestruction)) { uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile); return (callback_res == CALLBACK_FAILED || !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DENY_DESTRUCTION, callback_res)); } else { @@ -630,7 +630,7 @@ static void AnimationControl(TileIndex tile, uint16_t random_bits) { const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); - if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { + if (hs->callback_mask.Test(HouseCallbackMask::AnimationStartStop)) { uint32_t param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random(); HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_START_STOP, hs, Town::GetByTile(tile), tile, param, 0); } @@ -648,7 +648,7 @@ bool NewHouseTileLoop(TileIndex tile) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP); if (hs->building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP); - if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { + if (hs->callback_mask.Test(HouseCallbackMask::AnimationStartStop)) { /* If this house is marked as having a synchronised callback, all the * tiles will have the callback called at once, rather than when the * tile loop reaches them. This should only be enabled for the northern @@ -666,7 +666,7 @@ bool NewHouseTileLoop(TileIndex tile) } /* Check callback 21, which determines if a house should be destroyed. */ - if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) { + if (hs->callback_mask.Test(HouseCallbackMask::Destruction)) { uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile); if (callback_res != CALLBACK_FAILED && Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DESTRUCTION, callback_res)) { ClearTownHouse(Town::GetByTile(tile), tile); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index c3ac5d5d74..55992c157b 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -214,8 +214,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_ case 0x40: case 0x41: case 0x42: { // waiting cargo, but only if those two callback flags are set - uint16_t callback = indspec->callback_mask; - if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { + IndustryCallbackMasks callback = indspec->callback_mask; + if (callback.Any({IndustryCallbackMask::ProductionCargoArrival, IndustryCallbackMask::Production256Ticks})) { if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) { if (this->industry->prod_level == 0) return 0; return ClampTo(this->industry->GetAccepted(variable - 0x40).waiting / this->industry->prod_level); @@ -572,7 +572,7 @@ uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityC { const IndustrySpec *indspec = GetIndustrySpec(type); - if (HasBit(indspec->callback_mask, CBM_IND_PROBABILITY)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::Probability)) { uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, nullptr, type, INVALID_TILE); if (res != CALLBACK_FAILED) { if (indspec->grf_prop.grffile->grf_version < 8) { @@ -686,7 +686,7 @@ bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoType cargo_type) assert(ind->IsCargoAccepted(cargo_type)); const IndustrySpec *indspec = GetIndustrySpec(ind->type); - if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) { + if (indspec->callback_mask.Test(IndustryCallbackMask::RefuseCargo)) { uint16_t res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, indspec->grf_prop.grffile->cargo_map[cargo_type], ind, ind->type, ind->location.tile); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 18a398521a..59cc3fcc80 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -191,7 +191,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus { if (ti->tileh != SLOPE_FLAT) { bool draw_old_one = true; - if (HasBit(inds->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) { + if (inds->callback_mask.Test(IndustryTileCallbackMask::DrawFoundations)) { /* Called to determine the type (if any) of foundation to draw for industry tile */ uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile); if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(inds->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res); @@ -258,11 +258,11 @@ uint16_t GetSimpleIndustryCallback(CallbackID callback, uint32_t param1, uint32_ /** Helper class for animation control. */ struct IndustryAnimationBase : public AnimationBase > { - static const CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED; - static const CallbackID cb_animation_next_frame = CBID_INDTILE_ANIM_NEXT_FRAME; + static constexpr CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED; + static constexpr CallbackID cb_animation_next_frame = CBID_INDTILE_ANIM_NEXT_FRAME; - static const IndustryTileCallbackMask cbm_animation_speed = CBM_INDT_ANIM_SPEED; - static const IndustryTileCallbackMask cbm_animation_next_frame = CBM_INDT_ANIM_NEXT_FRAME; + static constexpr IndustryTileCallbackMask cbm_animation_speed = IndustryTileCallbackMask::AnimationSpeed; + static constexpr IndustryTileCallbackMask cbm_animation_next_frame = IndustryTileCallbackMask::AnimationNextFrame; }; void AnimateNewIndustryTile(TileIndex tile) diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 832f9769ae..d1e2a0eecf 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -531,8 +531,8 @@ struct ObjectAnimationBase : public AnimationBase { TimerGameCalendar::Date introduction_date; ///< From when can this object be built. TimerGameCalendar::Date end_of_life_date; ///< When can't this object be built anymore. ObjectFlags flags; ///< Flags/settings related to the object. - uint16_t callback_mask; ///< Bitmask of requested/allowed callbacks. + ObjectCallbackMasks callback_mask; ///< Bitmask of requested/allowed callbacks. uint8_t height; ///< The height of this structure, in heightlevels; max MAX_TILE_HEIGHT. uint8_t views; ///< The number of views. uint8_t generate_amount; ///< Number of objects which are attempted to be generated per 256^2 map during world generation. diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 0ee59bdbd1..58ae873c63 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -350,11 +350,11 @@ struct RoadStopAnimationFrameAnimationHelper { /** Helper class for animation control. */ struct RoadStopAnimationBase : public AnimationBase { - static const CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED; - static const CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME; + static constexpr CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED; + static constexpr CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME; - static const RoadStopCallbackMask cbm_animation_speed = CBM_ROAD_STOP_ANIMATION_SPEED; - static const RoadStopCallbackMask cbm_animation_next_frame = CBM_ROAD_STOP_ANIMATION_NEXT_FRAME; + static constexpr RoadStopCallbackMask cbm_animation_speed = RoadStopCallbackMask::AnimationSpeed; + static constexpr RoadStopCallbackMask cbm_animation_next_frame = RoadStopCallbackMask::AnimationNextFrame; }; void AnimateRoadStopTile(TileIndex tile) diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index ce454477fd..d01f3d04ab 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -14,6 +14,7 @@ #include "newgrf_animation_type.h" #include "newgrf_spritegroup.h" +#include "newgrf_callbacks.h" #include "newgrf_class.h" #include "newgrf_commons.h" #include "newgrf_town.h" @@ -144,7 +145,7 @@ struct RoadStopSpec : NewGRFSpecBase { RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL; RoadStopDrawMode draw_mode = ROADSTOP_DRAW_MODE_ROAD | ROADSTOP_DRAW_MODE_OVERLAY; - uint8_t callback_mask = 0; + RoadStopCallbackMasks callback_mask{}; uint16_t flags = 0; CargoTypes cargo_triggers = 0; ///< Bitmask of cargo types which cause trigger re-randomizing diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp index 6bff1edda2..48958dcf68 100644 --- a/src/newgrf_sound.cpp +++ b/src/newgrf_sound.cpp @@ -151,7 +151,7 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force) if (file == nullptr) return false; /* Check that the vehicle type uses the sound effect callback */ - if (!HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_SOUND_EFFECT)) return false; + if (!EngInfo(v->engine_type)->callback_mask.Test(VehicleCallbackMask::SoundEffect)) return false; callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v); /* Play default sound if callback fails */ diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 6f21b47ee7..9057b64fa6 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -785,7 +785,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station); if (statspec == nullptr) return false; - if (HasBit(statspec->callback_mask, CBM_STATION_DRAW_TILE_LAYOUT)) { + if (statspec->callback_mask.Test(StationCallbackMask::DrawTileLayout)) { uint16_t callback = GetStationCallback(CBID_STATION_DRAW_TILE_LAYOUT, 0, 0, statspec, nullptr, INVALID_TILE); if (callback != CALLBACK_FAILED) tile = callback & ~1; } @@ -863,11 +863,11 @@ uint16_t GetAnimStationCallback(CallbackID callback, uint32_t param1, uint32_t p /** Helper class for animation control. */ struct StationAnimationBase : public AnimationBase > { - static const CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED; - static const CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME; + static constexpr CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED; + static constexpr CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME; - static const StationCallbackMask cbm_animation_speed = CBM_STATION_ANIMATION_SPEED; - static const StationCallbackMask cbm_animation_next_frame = CBM_STATION_ANIMATION_NEXT_FRAME; + static constexpr StationCallbackMask cbm_animation_speed = StationCallbackMask::AnimationSpeed; + static constexpr StationCallbackMask cbm_animation_next_frame = StationCallbackMask::AnimationNextFrame; }; void AnimateStationTile(TileIndex tile) diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 3d282cfaae..c7f5b933fe 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -156,7 +156,7 @@ struct StationSpec : NewGRFSpecBase { CargoTypes cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing - uint8_t 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 diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 0b9eb1e9fc..30e3fbf7dd 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -109,7 +109,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u /* If the object wants only one colour, then give it that colour. */ if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF; - if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) { + if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) { uint16_t res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile); if (res != CALLBACK_FAILED) { if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_COLOUR, res); @@ -189,7 +189,7 @@ void UpdateObjectColours(const Company *c) const ObjectSpec *spec = ObjectSpec::GetByTile(obj->location.tile); /* Using the object colour callback, so not using company colour. */ - if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) continue; + if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) continue; const Livery *l = c->livery; obj->colour = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? (l->colour2 * 16) : 0) + l->colour1; @@ -274,7 +274,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, for (TileIndex t : ta) { uint16_t callback = CALLBACK_FAILED; - if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) { + if (spec->callback_mask.Test(ObjectCallbackMask::SlopeCheck)) { TileIndex diff = t - tile; callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t), TileY(diff) << 4 | TileX(diff), spec, nullptr, t, view); } @@ -929,7 +929,7 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int const ObjectSpec *spec = ObjectSpec::Get(type); /* Call callback 'disable autosloping for objects'. */ - if (HasBit(spec->callback_mask, CBM_OBJ_AUTOSLOPE)) { + if (spec->callback_mask.Test(ObjectCallbackMask::Autoslope)) { /* If the callback fails, allow autoslope. */ uint16_t res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile); if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); diff --git a/src/object_gui.cpp b/src/object_gui.cpp index d2fa46ff4e..a66d3dc112 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -224,7 +224,7 @@ public: if (spec == nullptr) break; /* Get the extra message for the GUI */ - if (HasBit(spec->callback_mask, CBM_OBJ_FUND_MORE_TEXT)) { + if (spec->callback_mask.Test(ObjectCallbackMask::FundMoreText)) { uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, _object_gui.sel_view); if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { if (callback_res > 0x400) { diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 52150d300f..b28d0fbf28 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -83,7 +83,7 @@ static void ShowSignalBuilder(Window *parent); */ static bool IsStationAvailable(const StationSpec *statspec) { - if (statspec == nullptr || !HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) return true; + if (statspec == nullptr || !statspec->callback_mask.Test(StationCallbackMask::Avail)) return true; uint16_t cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE); if (cb_res == CALLBACK_FAILED) return true; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 0403bb5400..b51d56b74e 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -103,7 +103,7 @@ static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type) if (spec == nullptr) return true; if (!IsRoadStopEverAvailable(spec, type)) return false; - if (!HasBit(spec->callback_mask, CBM_ROAD_STOP_AVAIL)) return true; + if (!spec->callback_mask.Test(RoadStopCallbackMask::Avail)) return true; uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, nullptr, INVALID_TILE, _cur_roadtype, type, 0); if (cb_res == CALLBACK_FAILED) return true; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f379b76aae..3b74efeef1 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -889,7 +889,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_ uint invalid_dirs = 5 << axis; const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index); - bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK); + bool slope_cb = statspec != nullptr && statspec->callback_mask.Test(StationCallbackMask::SlopeCheck); CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false); if (ret.Failed()) return ret; @@ -1408,7 +1408,7 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp if (HasBit(statspec->disallowed_lengths, std::min(plat_len - 1, 7))) return CommandCost(STR_ERROR_STATION_DISALLOWED_LENGTH); /* Check if the station is buildable */ - if (HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) { + if (statspec->callback_mask.Test(StationCallbackMask::Avail)) { uint16_t cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE); if (cb_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res)) return CMD_ERROR; } @@ -2032,7 +2032,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8_t width, /* Perform NewGRF checks */ /* Check if the road stop is buildable */ - if (HasBit(roadstopspec->callback_mask, CBM_ROAD_STOP_AVAIL)) { + if (roadstopspec->callback_mask.Test(RoadStopCallbackMask::Avail)) { uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, roadstopspec, nullptr, INVALID_TILE, rt, is_truck_stop ? StationType::Truck : StationType::Bus, 0); if (cb_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(roadstopspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res)) return CMD_ERROR; } @@ -3108,7 +3108,7 @@ static void DrawTile_Station(TileInfo *ti) if (statspec != nullptr) { tile_layout = GetStationGfx(ti->tile); - if (HasBit(statspec->callback_mask, CBM_STATION_DRAW_TILE_LAYOUT)) { + if (statspec->callback_mask.Test(StationCallbackMask::DrawTileLayout)) { uint16_t callback = GetStationCallback(CBID_STATION_DRAW_TILE_LAYOUT, 0, 0, statspec, st, ti->tile); if (callback != CALLBACK_FAILED) tile_layout = (callback & ~1) + GetRailStationAxis(ti->tile); } @@ -3879,7 +3879,7 @@ static void UpdateStationRating(Station *st) if (_cheats.station_rating.value) { ge->rating = rating = MAX_STATION_RATING; skip = true; - } else if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) { + } else if (cs->callback_mask.Test(CargoCallbackMask::StationRatingCalc)) { /* Perform custom station rating. If it succeeds the speed, days in transit and * waiting cargo ratings must not be executed. */ diff --git a/src/strings.cpp b/src/strings.cpp index dc32126338..b62324b6f8 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1543,7 +1543,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara break; } - if (HasBit(e->info.callback_mask, CBM_VEHICLE_NAME)) { + if (e->info.callback_mask.Test(VehicleCallbackMask::Name)) { uint16_t callback = GetVehicleCallback(CBID_VEHICLE_NAME, static_cast(arg >> 32), 0, e->index, nullptr); /* Not calling ErrorUnknownCallbackResult due to being inside string processing. */ if (callback != CALLBACK_FAILED && callback < 0x400) { diff --git a/src/table/airporttiles.h b/src/table/airporttiles.h index 0393cf7a5f..ed4bc799ab 100644 --- a/src/table/airporttiles.h +++ b/src/table/airporttiles.h @@ -11,9 +11,9 @@ #define AIRPORTTILES_H /** Writes all airport tile properties in the AirportTile struct */ -#define AT(num_frames, anim_speed) {{num_frames, ANIM_STATUS_LOOPING, anim_speed, 0}, STR_NULL, 0, 0, true, GRFFileProps(INVALID_AIRPORTTILE)} +#define AT(num_frames, anim_speed) {{num_frames, ANIM_STATUS_LOOPING, anim_speed, 0}, STR_NULL, AirportTileCallbackMasks{}, 0, true, GRFFileProps(INVALID_AIRPORTTILE)} /** Writes an airport tile without animation in the AirportTile struct */ -#define AT_NOANIM {{0, ANIM_STATUS_NO_ANIMATION, 2, 0}, STR_NULL, 0, 0, true, GRFFileProps(INVALID_AIRPORTTILE)} +#define AT_NOANIM {{0, ANIM_STATUS_NO_ANIMATION, 2, 0}, STR_NULL, AirportTileCallbackMasks{}, 0, true, GRFFileProps(INVALID_AIRPORTTILE)} /** * All default airport tiles. diff --git a/src/table/build_industry.h b/src/table/build_industry.h index a71ff53381..c63eb404b1 100644 --- a/src/table/build_industry.h +++ b/src/table/build_industry.h @@ -1133,7 +1133,7 @@ enum IndustryTypes : uint8_t { {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}, \ {{im1, 0}, {im2, 0}, {im3, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, \ pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \ - 0, true, GRFFileProps(IT_INVALID), snd, \ + IndustryCallbackMasks{}, true, GRFFileProps(IT_INVALID), snd, \ {{p1, p2}}, {{a1, a2, a3}}} /* Format: tile table count and sounds table @@ -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, 0, {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}, INDTILE_SPECIAL_NONE, true, GRFFileProps(INVALID_INDUSTRYTILE), {c1, c2, c3} \ } static const IndustryTileSpec _origin_industry_tile_specs[NEW_INDUSTRYTILEOFFSET] = { /* Coal Mine */ diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index 39c1154c84..c769182bda 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -44,7 +44,7 @@ * @param classes Classes of this cargo type. @see CargoClass */ #define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, tae, str_plural, str_singular, str_volume, classes) \ - {label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, 0, \ + {label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, CargoCallbackMasks{}, \ MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \ MK_SPRITE(str_plural), nullptr, nullptr, 0} diff --git a/src/table/engines.h b/src/table/engines.h index fc1f91f86e..eef9c0d8d6 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -24,7 +24,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a multiple-unit train into the EngineInfo struct. @@ -37,7 +37,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 1 << EF_RAIL_IS_MU, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 1 << EF_RAIL_IS_MU, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a train carriage into the EngineInfo struct. @@ -50,7 +50,7 @@ * @see MT * @note the 5 between b and f is the load amount */ -#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a road vehicle into the EngineInfo struct. @@ -63,7 +63,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, 0, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of a ship into the EngineInfo struct. @@ -75,7 +75,7 @@ * @param f Bitmask of the climates * @note the 10 between b and f is the load amount */ -#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 10, f, INVALID_CARGO, e, 0, 8, 0, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 10, f, INVALID_CARGO, e, 0, 8, 0, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /** * Writes the properties of an aeroplane into the EngineInfo struct. @@ -86,7 +86,7 @@ * @param e Bitmask of the climates * @note the 20 between b and e is the load amount */ -#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, 0, 0, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, 0, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } /* Climates * T = Temperate diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index d5e0995544..86a119bcf7 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -26,21 +26,21 @@ #define NICV(cb_id, bit) NIC(cb_id, Engine, info.callback_mask, bit) static const NICallback _nic_vehicles[] = { - NICV(CBID_VEHICLE_VISUAL_EFFECT, CBM_VEHICLE_VISUAL_EFFECT), - NICV(CBID_VEHICLE_LENGTH, CBM_VEHICLE_LENGTH), - NICV(CBID_VEHICLE_LOAD_AMOUNT, CBM_VEHICLE_LOAD_AMOUNT), - NICV(CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY), - NICV(CBID_VEHICLE_ARTIC_ENGINE, CBM_VEHICLE_ARTIC_ENGINE), - NICV(CBID_VEHICLE_CARGO_SUFFIX, CBM_VEHICLE_CARGO_SUFFIX), - NICV(CBID_TRAIN_ALLOW_WAGON_ATTACH, CBM_NO_BIT), - NICV(CBID_VEHICLE_ADDITIONAL_TEXT, CBM_NO_BIT), - NICV(CBID_VEHICLE_COLOUR_MAPPING, CBM_VEHICLE_COLOUR_REMAP), - NICV(CBID_VEHICLE_START_STOP_CHECK, CBM_NO_BIT), - NICV(CBID_VEHICLE_32DAY_CALLBACK, CBM_NO_BIT), - NICV(CBID_VEHICLE_SOUND_EFFECT, CBM_VEHICLE_SOUND_EFFECT), - NICV(CBID_VEHICLE_AUTOREPLACE_SELECTION, CBM_NO_BIT), - NICV(CBID_VEHICLE_MODIFY_PROPERTY, CBM_NO_BIT), - NICV(CBID_VEHICLE_NAME, CBM_VEHICLE_NAME), + NICV(CBID_VEHICLE_VISUAL_EFFECT, VehicleCallbackMask::VisualEffect), + NICV(CBID_VEHICLE_LENGTH, VehicleCallbackMask::Length), + NICV(CBID_VEHICLE_LOAD_AMOUNT, VehicleCallbackMask::LoadAmount), + NICV(CBID_VEHICLE_REFIT_CAPACITY, VehicleCallbackMask::RefitCapacity), + NICV(CBID_VEHICLE_ARTIC_ENGINE, VehicleCallbackMask::ArticEngine), + NICV(CBID_VEHICLE_CARGO_SUFFIX, VehicleCallbackMask::CargoSuffix), + NICV(CBID_TRAIN_ALLOW_WAGON_ATTACH, std::monostate{}), + NICV(CBID_VEHICLE_ADDITIONAL_TEXT, std::monostate{}), + NICV(CBID_VEHICLE_COLOUR_MAPPING, VehicleCallbackMask::ColourRemap), + NICV(CBID_VEHICLE_START_STOP_CHECK, std::monostate{}), + NICV(CBID_VEHICLE_32DAY_CALLBACK, std::monostate{}), + NICV(CBID_VEHICLE_SOUND_EFFECT, VehicleCallbackMask::SoundEffect), + NICV(CBID_VEHICLE_AUTOREPLACE_SELECTION, std::monostate{}), + NICV(CBID_VEHICLE_MODIFY_PROPERTY, std::monostate{}), + NICV(CBID_VEHICLE_NAME, VehicleCallbackMask::Name), }; @@ -93,13 +93,13 @@ static const NIFeature _nif_vehicle = { #define NICS(cb_id, bit) NIC(cb_id, StationSpec, callback_mask, bit) static const NICallback _nic_stations[] = { - NICS(CBID_STATION_AVAILABILITY, CBM_STATION_AVAIL), - NICS(CBID_STATION_DRAW_TILE_LAYOUT, CBM_STATION_DRAW_TILE_LAYOUT), - NICS(CBID_STATION_BUILD_TILE_LAYOUT,CBM_NO_BIT), - NICS(CBID_STATION_ANIM_START_STOP, CBM_NO_BIT), - NICS(CBID_STATION_ANIM_NEXT_FRAME, CBM_STATION_ANIMATION_NEXT_FRAME), - NICS(CBID_STATION_ANIMATION_SPEED, CBM_STATION_ANIMATION_SPEED), - NICS(CBID_STATION_LAND_SLOPE_CHECK, CBM_STATION_SLOPE_CHECK), + NICS(CBID_STATION_AVAILABILITY, StationCallbackMask::Avail), + NICS(CBID_STATION_DRAW_TILE_LAYOUT, StationCallbackMask::DrawTileLayout), + NICS(CBID_STATION_BUILD_TILE_LAYOUT,std::monostate{}), + NICS(CBID_STATION_ANIM_START_STOP, std::monostate{}), + NICS(CBID_STATION_ANIM_NEXT_FRAME, StationCallbackMask::AnimationNextFrame), + NICS(CBID_STATION_ANIMATION_SPEED, StationCallbackMask::AnimationSpeed), + NICS(CBID_STATION_LAND_SLOPE_CHECK, StationCallbackMask::SlopeCheck), }; static const NIVariable _niv_stations[] = { @@ -156,21 +156,21 @@ static const NIFeature _nif_station = { #define NICH(cb_id, bit) NIC(cb_id, HouseSpec, callback_mask, bit) static const NICallback _nic_house[] = { - NICH(CBID_HOUSE_ALLOW_CONSTRUCTION, CBM_HOUSE_ALLOW_CONSTRUCTION), - NICH(CBID_HOUSE_ANIMATION_NEXT_FRAME, CBM_HOUSE_ANIMATION_NEXT_FRAME), - NICH(CBID_HOUSE_ANIMATION_START_STOP, CBM_HOUSE_ANIMATION_START_STOP), - NICH(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE), - NICH(CBID_HOUSE_COLOUR, CBM_HOUSE_COLOUR), - NICH(CBID_HOUSE_CARGO_ACCEPTANCE, CBM_HOUSE_CARGO_ACCEPTANCE), - NICH(CBID_HOUSE_ANIMATION_SPEED, CBM_HOUSE_ANIMATION_SPEED), - NICH(CBID_HOUSE_DESTRUCTION, CBM_HOUSE_DESTRUCTION), - NICH(CBID_HOUSE_ACCEPT_CARGO, CBM_HOUSE_ACCEPT_CARGO), - NICH(CBID_HOUSE_PRODUCE_CARGO, CBM_HOUSE_PRODUCE_CARGO), - NICH(CBID_HOUSE_DENY_DESTRUCTION, CBM_HOUSE_DENY_DESTRUCTION), - NICH(CBID_HOUSE_WATCHED_CARGO_ACCEPTED, CBM_NO_BIT), - NICH(CBID_HOUSE_CUSTOM_NAME, CBM_NO_BIT), - NICH(CBID_HOUSE_DRAW_FOUNDATIONS, CBM_HOUSE_DRAW_FOUNDATIONS), - NICH(CBID_HOUSE_AUTOSLOPE, CBM_HOUSE_AUTOSLOPE), + NICH(CBID_HOUSE_ALLOW_CONSTRUCTION, HouseCallbackMask::AllowConstruction), + NICH(CBID_HOUSE_ANIMATION_NEXT_FRAME, HouseCallbackMask::AnimationNextFrame), + NICH(CBID_HOUSE_ANIMATION_START_STOP, HouseCallbackMask::AnimationStartStop), + NICH(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, HouseCallbackMask::ConstructionStateChange), + NICH(CBID_HOUSE_COLOUR, HouseCallbackMask::Colour), + NICH(CBID_HOUSE_CARGO_ACCEPTANCE, HouseCallbackMask::CargoAcceptance), + NICH(CBID_HOUSE_ANIMATION_SPEED, HouseCallbackMask::AnimationSpeed), + NICH(CBID_HOUSE_DESTRUCTION, HouseCallbackMask::Destruction), + NICH(CBID_HOUSE_ACCEPT_CARGO, HouseCallbackMask::AcceptCargo), + NICH(CBID_HOUSE_PRODUCE_CARGO, HouseCallbackMask::ProduceCargo), + NICH(CBID_HOUSE_DENY_DESTRUCTION, HouseCallbackMask::DenyDestruction), + NICH(CBID_HOUSE_WATCHED_CARGO_ACCEPTED, std::monostate{}), + NICH(CBID_HOUSE_CUSTOM_NAME, std::monostate{}), + NICH(CBID_HOUSE_DRAW_FOUNDATIONS, HouseCallbackMask::DrawFoundations), + NICH(CBID_HOUSE_AUTOSLOPE, HouseCallbackMask::Autoslope), }; static const NIVariable _niv_house[] = { @@ -220,14 +220,14 @@ static const NIFeature _nif_house = { #define NICIT(cb_id, bit) NIC(cb_id, IndustryTileSpec, callback_mask, bit) static const NICallback _nic_industrytiles[] = { - NICIT(CBID_INDTILE_ANIM_START_STOP, CBM_NO_BIT), - NICIT(CBID_INDTILE_ANIM_NEXT_FRAME, CBM_INDT_ANIM_NEXT_FRAME), - NICIT(CBID_INDTILE_ANIMATION_SPEED, CBM_INDT_ANIM_SPEED), - NICIT(CBID_INDTILE_CARGO_ACCEPTANCE, CBM_INDT_CARGO_ACCEPTANCE), - NICIT(CBID_INDTILE_ACCEPT_CARGO, CBM_INDT_ACCEPT_CARGO), - NICIT(CBID_INDTILE_SHAPE_CHECK, CBM_INDT_SHAPE_CHECK), - NICIT(CBID_INDTILE_DRAW_FOUNDATIONS, CBM_INDT_DRAW_FOUNDATIONS), - NICIT(CBID_INDTILE_AUTOSLOPE, CBM_INDT_AUTOSLOPE), + NICIT(CBID_INDTILE_ANIM_START_STOP, std::monostate{}), + NICIT(CBID_INDTILE_ANIM_NEXT_FRAME, IndustryTileCallbackMask::AnimationNextFrame), + NICIT(CBID_INDTILE_ANIMATION_SPEED, IndustryTileCallbackMask::AnimationSpeed), + NICIT(CBID_INDTILE_CARGO_ACCEPTANCE, IndustryTileCallbackMask::CargoAcceptance), + NICIT(CBID_INDTILE_ACCEPT_CARGO, IndustryTileCallbackMask::AcceptCargo), + NICIT(CBID_INDTILE_SHAPE_CHECK, IndustryTileCallbackMask::ShapeCheck), + NICIT(CBID_INDTILE_DRAW_FOUNDATIONS, IndustryTileCallbackMask::DrawFoundations), + NICIT(CBID_INDTILE_AUTOSLOPE, IndustryTileCallbackMask::Autoslope), }; static const NIVariable _niv_industrytiles[] = { @@ -309,19 +309,19 @@ static const NIProperty _nip_industries[] = { #define NICI(cb_id, bit) NIC(cb_id, IndustrySpec, callback_mask, bit) static const NICallback _nic_industries[] = { - NICI(CBID_INDUSTRY_PROBABILITY, CBM_IND_PROBABILITY), - NICI(CBID_INDUSTRY_LOCATION, CBM_IND_LOCATION), - NICI(CBID_INDUSTRY_PRODUCTION_CHANGE, CBM_IND_PRODUCTION_CHANGE), - NICI(CBID_INDUSTRY_MONTHLYPROD_CHANGE, CBM_IND_MONTHLYPROD_CHANGE), - NICI(CBID_INDUSTRY_CARGO_SUFFIX, CBM_IND_CARGO_SUFFIX), - NICI(CBID_INDUSTRY_FUND_MORE_TEXT, CBM_IND_FUND_MORE_TEXT), - NICI(CBID_INDUSTRY_WINDOW_MORE_TEXT, CBM_IND_WINDOW_MORE_TEXT), - NICI(CBID_INDUSTRY_SPECIAL_EFFECT, CBM_IND_SPECIAL_EFFECT), - NICI(CBID_INDUSTRY_REFUSE_CARGO, CBM_IND_REFUSE_CARGO), - NICI(CBID_INDUSTRY_DECIDE_COLOUR, CBM_IND_DECIDE_COLOUR), - NICI(CBID_INDUSTRY_INPUT_CARGO_TYPES, CBM_IND_INPUT_CARGO_TYPES), - NICI(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, CBM_IND_OUTPUT_CARGO_TYPES), - NICI(CBID_INDUSTRY_PROD_CHANGE_BUILD, CBM_IND_PROD_CHANGE_BUILD), + NICI(CBID_INDUSTRY_PROBABILITY, IndustryCallbackMask::Probability), + NICI(CBID_INDUSTRY_LOCATION, IndustryCallbackMask::Location), + NICI(CBID_INDUSTRY_PRODUCTION_CHANGE, IndustryCallbackMask::ProductionChange), + NICI(CBID_INDUSTRY_MONTHLYPROD_CHANGE, IndustryCallbackMask::MonthlyProdChange), + NICI(CBID_INDUSTRY_CARGO_SUFFIX, IndustryCallbackMask::CargoSuffix), + NICI(CBID_INDUSTRY_FUND_MORE_TEXT, IndustryCallbackMask::FundMoreText), + NICI(CBID_INDUSTRY_WINDOW_MORE_TEXT, IndustryCallbackMask::WindowMoreText), + NICI(CBID_INDUSTRY_SPECIAL_EFFECT, IndustryCallbackMask::SpecialEffect), + NICI(CBID_INDUSTRY_REFUSE_CARGO, IndustryCallbackMask::RefuseCargo), + NICI(CBID_INDUSTRY_DECIDE_COLOUR, IndustryCallbackMask::DecideColour), + NICI(CBID_INDUSTRY_INPUT_CARGO_TYPES, IndustryCallbackMask::InputCargoTypes), + NICI(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, IndustryCallbackMask::OutputCargoTypes), + NICI(CBID_INDUSTRY_PROD_CHANGE_BUILD, IndustryCallbackMask::ProdChangeBuild), }; static const NIVariable _niv_industries[] = { @@ -387,13 +387,13 @@ static const NIFeature _nif_industry = { #define NICO(cb_id, bit) NIC(cb_id, ObjectSpec, callback_mask, bit) static const NICallback _nic_objects[] = { - NICO(CBID_OBJECT_LAND_SLOPE_CHECK, CBM_OBJ_SLOPE_CHECK), - NICO(CBID_OBJECT_ANIMATION_NEXT_FRAME, CBM_OBJ_ANIMATION_NEXT_FRAME), - NICO(CBID_OBJECT_ANIMATION_START_STOP, CBM_NO_BIT), - NICO(CBID_OBJECT_ANIMATION_SPEED, CBM_OBJ_ANIMATION_SPEED), - NICO(CBID_OBJECT_COLOUR, CBM_OBJ_COLOUR), - NICO(CBID_OBJECT_FUND_MORE_TEXT, CBM_OBJ_FUND_MORE_TEXT), - NICO(CBID_OBJECT_AUTOSLOPE, CBM_OBJ_AUTOSLOPE), + NICO(CBID_OBJECT_LAND_SLOPE_CHECK, ObjectCallbackMask::SlopeCheck), + NICO(CBID_OBJECT_ANIMATION_NEXT_FRAME, ObjectCallbackMask::AnimationNextFrame), + NICO(CBID_OBJECT_ANIMATION_START_STOP, std::monostate{}), + NICO(CBID_OBJECT_ANIMATION_SPEED, ObjectCallbackMask::AnimationSpeed), + NICO(CBID_OBJECT_COLOUR, ObjectCallbackMask::Colour), + NICO(CBID_OBJECT_FUND_MORE_TEXT, ObjectCallbackMask::FundMoreText), + NICO(CBID_OBJECT_AUTOSLOPE, ObjectCallbackMask::Autoslope), }; static const NIVariable _niv_objects[] = { @@ -476,10 +476,10 @@ static const NIFeature _nif_railtype = { #define NICAT(cb_id, bit) NIC(cb_id, AirportTileSpec, callback_mask, bit) static const NICallback _nic_airporttiles[] = { - NICAT(CBID_AIRPTILE_DRAW_FOUNDATIONS, CBM_AIRT_DRAW_FOUNDATIONS), - NICAT(CBID_AIRPTILE_ANIM_START_STOP, CBM_NO_BIT), - NICAT(CBID_AIRPTILE_ANIM_NEXT_FRAME, CBM_AIRT_ANIM_NEXT_FRAME), - NICAT(CBID_AIRPTILE_ANIMATION_SPEED, CBM_AIRT_ANIM_SPEED), + NICAT(CBID_AIRPTILE_DRAW_FOUNDATIONS, AirportTileCallbackMask::DrawFoundations), + NICAT(CBID_AIRPTILE_ANIM_START_STOP, std::monostate{}), + NICAT(CBID_AIRPTILE_ANIM_NEXT_FRAME, AirportTileCallbackMask::AnimationNextFrame), + NICAT(CBID_AIRPTILE_ANIMATION_SPEED, AirportTileCallbackMask::AnimationSpeed), }; class NIHAirportTile : public NIHelper { @@ -645,10 +645,10 @@ static const NIFeature _nif_tramtype = { #define NICRS(cb_id, bit) NIC(cb_id, RoadStopSpec, callback_mask, bit) static const NICallback _nic_roadstops[] = { - NICRS(CBID_STATION_AVAILABILITY, CBM_ROAD_STOP_AVAIL), - NICRS(CBID_STATION_ANIM_START_STOP, CBM_NO_BIT), - NICRS(CBID_STATION_ANIM_NEXT_FRAME, CBM_ROAD_STOP_ANIMATION_NEXT_FRAME), - NICRS(CBID_STATION_ANIMATION_SPEED, CBM_ROAD_STOP_ANIMATION_SPEED), + NICRS(CBID_STATION_AVAILABILITY, RoadStopCallbackMask::Avail), + NICRS(CBID_STATION_ANIM_START_STOP, std::monostate{}), + NICRS(CBID_STATION_ANIM_NEXT_FRAME, RoadStopCallbackMask::AnimationNextFrame), + NICRS(CBID_STATION_ANIMATION_SPEED, RoadStopCallbackMask::AnimationSpeed), }; static const NIVariable _nif_roadstops[] = { diff --git a/src/table/object_land.h b/src/table/object_land.h index 195e2db9d6..24b3ee8c31 100644 --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -121,7 +121,7 @@ static const DrawTileSprites _object_hq[] = { #undef TILE_SPRITE_LINE -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, GRFFilePropsBase<2>(), {0, 0, 0, 0}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, 0, height, 1, gen_amount} +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) {{INVALID_OBJECT_CLASS, 0}, GRFFilePropsBase<2>(), {0, 0, 0, 0}, name, climate, size, build_cost_multiplier, clear_cost_multiplier, TimerGameCalendar::Date{}, CalendarTime::MAX_DATE + 1, flags, ObjectCallbackMasks{}, height, 1, gen_amount} /* Climates * T = Temperate diff --git a/src/table/town_land.h b/src/table/town_land.h index 5e5d24dfd8..6556d0f82e 100644 --- a/src/table/town_land.h +++ b/src/table/town_land.h @@ -1813,7 +1813,7 @@ static_assert(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4); {TimerGameCalendar::Year{mnd}, TimerGameCalendar::Year{mxd}, p, rc, bn, rr, mg, \ {ca1, ca2, ca3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \ {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}, \ - bf, ba, true, GRFFileProps(INVALID_HOUSE_ID), 0, {COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN}, \ + bf, ba, true, GRFFileProps(INVALID_HOUSE_ID), HouseCallbackMasks{}, {COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN}, \ 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0, {cg1, cg2, cg3}, } /** House specifications from original data */ extern const HouseSpec _original_house_specs[] = { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 962c7fc3d9..f23d2a187c 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -333,7 +333,7 @@ static Foundation GetFoundation_Town(TileIndex tile, Slope tileh) */ if (hid >= NEW_HOUSE_OFFSET) { const HouseSpec *hs = HouseSpec::Get(hid); - if (hs->grf_prop.spritegroup[0] != nullptr && HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) { + if (hs->grf_prop.spritegroup[0] != nullptr && hs->callback_mask.Test(HouseCallbackMask::DrawFoundations)) { uint32_t callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, hid, Town::GetByTile(tile), tile); if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE; } @@ -631,7 +631,7 @@ static void TileLoop_Town(TileIndex tile) StationFinder stations(TileArea(tile, 1, 1)); - if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { + if (hs->callback_mask.Test(HouseCallbackMask::ProduceCargo)) { for (uint i = 0; i < 256; i++) { uint16_t callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile); @@ -756,7 +756,7 @@ static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced) const HouseSpec *hs = HouseSpec::Get(house_id); Town *t = Town::GetByTile(tile); - if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { + if (hs->callback_mask.Test(HouseCallbackMask::ProduceCargo)) { for (uint i = 0; i < 256; i++) { uint16_t callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile); @@ -814,7 +814,7 @@ void AddAcceptedCargoOfHouse(TileIndex tile, HouseID house, const HouseSpec *hs, } /* Check for custom accepted cargo types */ - if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { + if (hs->callback_mask.Test(HouseCallbackMask::AcceptCargo)) { uint16_t callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, house, t, tile, tile == INVALID_TILE); if (callback != CALLBACK_FAILED) { /* Replace accepted cargo types with translated values from callback */ @@ -825,7 +825,7 @@ void AddAcceptedCargoOfHouse(TileIndex tile, HouseID house, const HouseSpec *hs, } /* Check for custom cargo acceptance */ - if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { + if (hs->callback_mask.Test(HouseCallbackMask::CargoAcceptance)) { uint16_t callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, house, t, tile, tile == INVALID_TILE); if (callback != CALLBACK_FAILED) { AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted); @@ -2868,7 +2868,7 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile) uint8_t random_bits = Random(); - if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { + if (hs->callback_mask.Test(HouseCallbackMask::AllowConstruction)) { uint16_t callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile, true, random_bits); if (callback_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_ALLOW_CONSTRUCTION, callback_res)) continue; } @@ -4098,7 +4098,7 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, int z /* Call the autosloping callback per tile, not for the whole building at once. */ house = GetHouseType(tile); hs = HouseSpec::Get(house); - if (HasBit(hs->callback_mask, CBM_HOUSE_AUTOSLOPE)) { + if (hs->callback_mask.Test(HouseCallbackMask::Autoslope)) { /* If the callback fails, allow autoslope. */ uint16_t res = GetHouseCallback(CBID_HOUSE_AUTOSLOPE, 0, 0, house, Town::GetByTile(tile), tile); if (res != CALLBACK_FAILED && ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_AUTOSLOPE, res)) allow_terraform = false; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 515e8bf941..10508e5992 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -1374,7 +1374,7 @@ void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id const DrawTileSprites *dts = reinterpret_cast(group)->ProcessRegisters(&stage); PaletteID palette = GENERAL_SPRITE_COLOUR(spec->random_colour[0]); - if (HasBit(spec->callback_mask, CBM_HOUSE_COLOUR)) { + if (spec->callback_mask.Test(HouseCallbackMask::Colour)) { uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, nullptr, INVALID_TILE, true, view); if (callback != CALLBACK_FAILED) { /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 2c1f7371f9..7ce88b4662 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -212,7 +212,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) { ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); } - } else if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { + } else if (e_u->info.callback_mask.Test(VehicleCallbackMask::Length)) { /* Use callback 11 */ veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); } @@ -2067,7 +2067,7 @@ CommandCost CmdReverseTrainDirection(DoCommandFlag flags, VehicleID veh_id, bool if (reverse_single_veh) { /* turn a single unit around */ - if (v->IsMultiheaded() || HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) { + if (v->IsMultiheaded() || EngInfo(v->engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) { return CommandCost(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c733620407..d2204548e5 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2100,7 +2100,7 @@ static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, Eng const Engine *e = Engine::Get(engine_type); /* Check if we should use the colour map callback */ - if (HasBit(e->info.callback_mask, CBM_VEHICLE_COLOUR_REMAP)) { + if (e->info.callback_mask.Test(VehicleCallbackMask::ColourRemap)) { uint16_t callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); /* Failure means "use the default two-colour" */ if (callback != CALLBACK_FAILED) { @@ -2676,7 +2676,7 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change) } /* Check powered wagon / visual effect callback */ - if (HasBit(e->info.callback_mask, CBM_VEHICLE_VISUAL_EFFECT)) { + if (e->info.callback_mask.Test(VehicleCallbackMask::VisualEffect)) { uint16_t callback = GetVehicleCallback(CBID_VEHICLE_VISUAL_EFFECT, 0, 0, this->engine_type, this); if (callback != CALLBACK_FAILED) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 595df7e023..2f5f298fe2 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -606,7 +606,7 @@ uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_ca subtypes.clear(); for (; v_from != nullptr; v_from = v_from->HasArticulatedPart() ? v_from->GetNextArticulatedPart() : nullptr) { const Engine *e_from = v_from->GetEngine(); - if (!e_from->CanCarryCargo() || !HasBit(e_from->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue; + if (!e_from->CanCarryCargo() || !e_from->info.callback_mask.Test(VehicleCallbackMask::CargoSuffix)) continue; include(subtypes, GetCargoSubtypeText(v_from)); } @@ -616,7 +616,7 @@ uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_ca /* Check whether any articulated part is refittable to 'dest_cargo_type' with a subtype listed in 'subtypes' */ for (Vehicle *v = v_for; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) { const Engine *e = v->GetEngine(); - if (!e->CanCarryCargo() || !HasBit(e->info.callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) continue; + if (!e->CanCarryCargo() || !e->info.callback_mask.Test(VehicleCallbackMask::CargoSuffix)) continue; if (!HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type) continue; CargoType old_cargo_type = v->cargo_type; @@ -790,7 +790,7 @@ struct RefitWindow : public Window { if (v->type == VEH_TRAIN && std::ranges::find(vehicles_to_refit, v->index) == vehicles_to_refit.end()) continue; const Engine *e = v->GetEngine(); CargoTypes cmask = e->info.refit_mask; - uint8_t callback_mask = e->info.callback_mask; + VehicleCallbackMasks callback_mask = e->info.callback_mask; /* Skip this engine if it does not carry anything */ if (!e->CanCarryCargo()) continue; @@ -814,7 +814,7 @@ struct RefitWindow : public Window { * This is not supported for ordered refits, since subtypes only have a meaning * for a specific vehicle at a specific point in time, which conflicts with shared orders, * autoreplace, autorenew, clone, order restoration, ... */ - if (this->order == INVALID_VEH_ORDER_ID && HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) { + if (this->order == INVALID_VEH_ORDER_ID && callback_mask.Test(VehicleCallbackMask::CargoSuffix)) { /* Make a note of the original cargo type. It has to be * changed to test the cargo & subtype... */ CargoType temp_cargo = v->cargo_type; @@ -1404,7 +1404,7 @@ uint ShowRefitOptionsList(int left, int right, int y, EngineID engine) /** Get the cargo subtype text from NewGRF for the vehicle details window. */ StringID GetCargoSubtypeText(const Vehicle *v) { - if (HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) { + if (EngInfo(v->engine_type)->callback_mask.Test(VehicleCallbackMask::CargoSuffix)) { uint16_t cb = GetVehicleCallback(CBID_VEHICLE_CARGO_SUFFIX, 0, 0, v->engine_type, v); if (cb != CALLBACK_FAILED) { if (cb > 0x400) ErrorUnknownCallbackResult(v->GetGRFID(), CBID_VEHICLE_CARGO_SUFFIX, cb);