diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 68d626e059..3845385958 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -327,7 +327,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v) /* show a warning once for each GRF after each game load */ if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) { - ShowNewGrfVehicleError(engine->index, STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ARTICULATED_CARGO, GBUG_VEH_REFIT, false); + ShowNewGrfVehicleError(engine->index, STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ARTICULATED_CARGO, GRFBug::VehRefit, false); } } diff --git a/src/gamelog.cpp b/src/gamelog.cpp index 44864f36ad..6c3b08ac89 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -293,7 +293,7 @@ void Gamelog::Print(std::function proc) { /* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */ auto gm = grf_names.find(this->grfid); - assert(this->bug == GBUG_VEH_LENGTH); + assert(this->bug == GRFBug::VehLength); fmt::format_to(output_iterator, "Rail vehicle changes length outside a depot: GRF ID {:08X}, internal ID 0x{:X}", std::byteswap(this->grfid), this->data); AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); @@ -463,7 +463,7 @@ void Gamelog::TestMode() * @param bug type of bug, @see enum GRFBugs * @param data additional data */ -void Gamelog::GRFBug(uint32_t grfid, uint8_t bug, uint64_t data) +void Gamelog::GRFBug(uint32_t grfid, ::GRFBug bug, uint64_t data) { assert(this->action_type == GLAT_GRFBUG); @@ -485,7 +485,7 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id) for (const auto &lc : la.change) { if (lc->ct == GLCT_GRFBUG) { LoggedChangeGRFBug *bug = static_cast(lc.get()); - if (bug->grfid == grfid && bug->bug == GBUG_VEH_LENGTH && bug->data == internal_id) { + if (bug->grfid == grfid && bug->bug == GRFBug::VehLength && bug->data == internal_id) { return false; } } @@ -493,7 +493,7 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id) } this->StartAction(GLAT_GRFBUG); - this->GRFBug(grfid, GBUG_VEH_LENGTH, internal_id); + this->GRFBug(grfid, GRFBug::VehLength, internal_id); this->StopAction(); return true; diff --git a/src/gamelog.h b/src/gamelog.h index 3bc50562a0..e7a75e4427 100644 --- a/src/gamelog.h +++ b/src/gamelog.h @@ -80,7 +80,7 @@ public: void GRFAddList(const GRFConfigList &newg); void GRFRemove(uint32_t grfid); void GRFAdd(const GRFConfig &newg); - void GRFBug(uint32_t grfid, uint8_t bug, uint64_t data); + void GRFBug(uint32_t grfid, ::GRFBug bug, uint64_t data); bool GRFBugReverse(uint32_t grfid, uint16_t internal_id); void GRFCompatible(const GRFIdentifier &newg); void GRFMove(uint32_t grfid, int32_t offset); diff --git a/src/gamelog_internal.h b/src/gamelog_internal.h index 0bf467ecdc..1d9fdec3fe 100644 --- a/src/gamelog_internal.h +++ b/src/gamelog_internal.h @@ -124,13 +124,13 @@ struct LoggedChangeSettingChanged : LoggedChange { struct LoggedChangeGRFBug : LoggedChange { LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG) {} - LoggedChangeGRFBug(uint64_t data, uint32_t grfid, uint8_t bug) : + LoggedChangeGRFBug(uint64_t data, uint32_t grfid, GRFBug bug) : LoggedChange(GLCT_GRFBUG), data(data), grfid(grfid), bug(bug) {} void FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override; uint64_t data; ///< additional data uint32_t grfid; ///< ID of problematic GRF - uint8_t bug; ///< type of bug, @see enum GRFBugs + GRFBug bug; ///< type of bug, @see enum GRFBugs }; struct LoggedChangeEmergencySave : LoggedChange { diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index f34a771825..576efbf37a 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -506,8 +506,8 @@ void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res) { GRFConfig *grfconfig = GetGRFConfig(grfid); - if (!HasBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT)) { - SetBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT); + if (grfconfig->grf_bugs.Test(GRFBug::UnknownCbResult)) { + grfconfig->grf_bugs.Set(GRFBug::UnknownCbResult); SetDParamStr(0, grfconfig->GetName()); SetDParam(1, cbid); SetDParam(2, cb_res); diff --git a/src/newgrf_config.h b/src/newgrf_config.h index b2554ebc8b..77436a84a5 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -38,13 +38,14 @@ enum GRFStatus : uint8_t { }; /** Encountered GRF bugs */ -enum GRFBugs : uint8_t { - GBUG_VEH_LENGTH, ///< Length of rail vehicle changes when not inside a depot - GBUG_VEH_REFIT, ///< Articulated vehicles carry different cargoes resp. are differently refittable than specified in purchase list - GBUG_VEH_POWERED_WAGON, ///< Powered wagon changed poweredness state when not inside a depot - GBUG_UNKNOWN_CB_RESULT, ///< A callback returned an unknown/invalid result - GBUG_VEH_CAPACITY, ///< Capacity of vehicle changes when not refitting or arranging +enum class GRFBug : uint8_t { + VehLength = 0, ///< Length of rail vehicle changes when not inside a depot + VehRefit = 1, ///< Articulated vehicles carry different cargoes resp. are differently refittable than specified in purchase list + VehPoweredWagon = 2, ///< Powered wagon changed poweredness state when not inside a depot + UnknownCbResult = 3, ///< A callback returned an unknown/invalid result + VehCapacity = 4, ///< Capacity of vehicle changes when not refitting or arranging }; +using GRFBugs = EnumBitSet; /** Status of post-gameload GRF compatibility check */ enum GRFListCompatibility : uint8_t { @@ -173,7 +174,7 @@ struct GRFConfig { uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define uint8_t flags = 0; ///< NOSAVE: GCF_Flags, bitset GRFStatus status = GCS_UNKNOWN; ///< NOSAVE: GRFStatus, enum - uint32_t grf_bugs = 0; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs + GRFBugs grf_bugs = {}; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs uint8_t num_valid_params = MAX_NUM_PARAMS; ///< NOSAVE: Number of valid parameters (action 0x14) uint8_t palette = 0; ///< GRFPalette, bitset bool has_param_defaults = false; ///< NOSAVE: did this newgrf specify any defaults for it's parameters diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 9aaa144870..cbe2b66c55 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -199,7 +199,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) u->cargo_cap = new_cap; } else { /* Verify capacity hasn't changed. */ - if (new_cap != u->cargo_cap) ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_CAPACITY, GBUG_VEH_CAPACITY, true); + if (new_cap != u->cargo_cap) ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_CAPACITY, GRFBug::VehCapacity, true); } u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_TRAIN_CARGO_AGE_PERIOD, e_u->info.cargo_age_period); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 40bb5bc0da..9b7817766f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -314,7 +314,7 @@ uint Vehicle::Crash(bool) * @param bug_type Flag to check and set in grfconfig * @param critical Shall the "OpenTTD might crash"-message be shown when the player tries to unpause? */ -void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical) +void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBug bug_type, bool critical) { const Engine *e = Engine::Get(engine); GRFConfig *grfconfig = GetGRFConfig(e->GetGRFID()); @@ -322,8 +322,8 @@ void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRF /* Missing GRF. Nothing useful can be done in this situation. */ if (grfconfig == nullptr) return; - if (!HasBit(grfconfig->grf_bugs, bug_type)) { - SetBit(grfconfig->grf_bugs, bug_type); + if (!grfconfig->grf_bugs.Test(bug_type)) { + grfconfig->grf_bugs.Set(bug_type); SetDParamStr(0, grfconfig->GetName()); SetDParam(1, engine); ShowErrorMessage(part1, part2, WL_CRITICAL); @@ -349,8 +349,8 @@ void VehicleLengthChanged(const Vehicle *u) const Engine *engine = u->GetEngine(); uint32_t grfid = engine->grf_prop.grfid; GRFConfig *grfconfig = GetGRFConfig(grfid); - if (_gamelog.GRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { - ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true); + if (_gamelog.GRFBugReverse(grfid, engine->grf_prop.local_id) || !grfconfig->grf_bugs.Test(GRFBug::VehLength)) { + ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GRFBug::VehLength, true); } } @@ -2717,7 +2717,7 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change) if (!allow_power_change && powered_before != HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) { ToggleBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); - ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GBUG_VEH_POWERED_WAGON, false); + ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GRFBug::VehPoweredWagon, false); } } diff --git a/src/vehicle_func.h b/src/vehicle_func.h index b46d5210c1..25c1027c6e 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -57,7 +57,7 @@ uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_ca void ViewportAddVehicles(DrawPixelInfo *dpi); -void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical); +void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBug bug_type, bool critical); CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = nullptr); void DecreaseVehicleValue(Vehicle *v);