mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
Codechange: Use EnumBitSet for GRFBug enum.
This commit is contained in:
parent
292f4baf46
commit
877fa54f66
@ -327,7 +327,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
|
|||||||
|
|
||||||
/* show a warning once for each GRF after each game load */
|
/* 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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ void Gamelog::Print(std::function<void(const std::string &)> proc)
|
|||||||
{
|
{
|
||||||
/* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */
|
/* 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);
|
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);
|
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);
|
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 bug type of bug, @see enum GRFBugs
|
||||||
* @param data additional data
|
* @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);
|
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) {
|
for (const auto &lc : la.change) {
|
||||||
if (lc->ct == GLCT_GRFBUG) {
|
if (lc->ct == GLCT_GRFBUG) {
|
||||||
LoggedChangeGRFBug *bug = static_cast<LoggedChangeGRFBug *>(lc.get());
|
LoggedChangeGRFBug *bug = static_cast<LoggedChangeGRFBug *>(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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -493,7 +493,7 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->StartAction(GLAT_GRFBUG);
|
this->StartAction(GLAT_GRFBUG);
|
||||||
this->GRFBug(grfid, GBUG_VEH_LENGTH, internal_id);
|
this->GRFBug(grfid, GRFBug::VehLength, internal_id);
|
||||||
this->StopAction();
|
this->StopAction();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
void GRFAddList(const GRFConfigList &newg);
|
void GRFAddList(const GRFConfigList &newg);
|
||||||
void GRFRemove(uint32_t grfid);
|
void GRFRemove(uint32_t grfid);
|
||||||
void GRFAdd(const GRFConfig &newg);
|
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);
|
bool GRFBugReverse(uint32_t grfid, uint16_t internal_id);
|
||||||
void GRFCompatible(const GRFIdentifier &newg);
|
void GRFCompatible(const GRFIdentifier &newg);
|
||||||
void GRFMove(uint32_t grfid, int32_t offset);
|
void GRFMove(uint32_t grfid, int32_t offset);
|
||||||
|
@ -124,13 +124,13 @@ struct LoggedChangeSettingChanged : LoggedChange {
|
|||||||
|
|
||||||
struct LoggedChangeGRFBug : LoggedChange {
|
struct LoggedChangeGRFBug : LoggedChange {
|
||||||
LoggedChangeGRFBug() : LoggedChange(GLCT_GRFBUG) {}
|
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) {}
|
LoggedChange(GLCT_GRFBUG), data(data), grfid(grfid), bug(bug) {}
|
||||||
void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
|
void FormatTo(std::back_insert_iterator<std::string> &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) override;
|
||||||
|
|
||||||
uint64_t data; ///< additional data
|
uint64_t data; ///< additional data
|
||||||
uint32_t grfid; ///< ID of problematic GRF
|
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 {
|
struct LoggedChangeEmergencySave : LoggedChange {
|
||||||
|
@ -506,8 +506,8 @@ void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
|
|||||||
{
|
{
|
||||||
GRFConfig *grfconfig = GetGRFConfig(grfid);
|
GRFConfig *grfconfig = GetGRFConfig(grfid);
|
||||||
|
|
||||||
if (!HasBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT)) {
|
if (grfconfig->grf_bugs.Test(GRFBug::UnknownCbResult)) {
|
||||||
SetBit(grfconfig->grf_bugs, GBUG_UNKNOWN_CB_RESULT);
|
grfconfig->grf_bugs.Set(GRFBug::UnknownCbResult);
|
||||||
SetDParamStr(0, grfconfig->GetName());
|
SetDParamStr(0, grfconfig->GetName());
|
||||||
SetDParam(1, cbid);
|
SetDParam(1, cbid);
|
||||||
SetDParam(2, cb_res);
|
SetDParam(2, cb_res);
|
||||||
|
@ -38,13 +38,14 @@ enum GRFStatus : uint8_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Encountered GRF bugs */
|
/** Encountered GRF bugs */
|
||||||
enum GRFBugs : uint8_t {
|
enum class GRFBug : uint8_t {
|
||||||
GBUG_VEH_LENGTH, ///< Length of rail vehicle changes when not inside a depot
|
VehLength = 0, ///< 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
|
VehRefit = 1, ///< 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
|
VehPoweredWagon = 2, ///< Powered wagon changed poweredness state when not inside a depot
|
||||||
GBUG_UNKNOWN_CB_RESULT, ///< A callback returned an unknown/invalid result
|
UnknownCbResult = 3, ///< A callback returned an unknown/invalid result
|
||||||
GBUG_VEH_CAPACITY, ///< Capacity of vehicle changes when not refitting or arranging
|
VehCapacity = 4, ///< Capacity of vehicle changes when not refitting or arranging
|
||||||
};
|
};
|
||||||
|
using GRFBugs = EnumBitSet<GRFBug, uint8_t>;
|
||||||
|
|
||||||
/** Status of post-gameload GRF compatibility check */
|
/** Status of post-gameload GRF compatibility check */
|
||||||
enum GRFListCompatibility : uint8_t {
|
enum GRFListCompatibility : uint8_t {
|
||||||
@ -173,7 +174,7 @@ struct GRFConfig {
|
|||||||
uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define
|
uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define
|
||||||
uint8_t flags = 0; ///< NOSAVE: GCF_Flags, bitset
|
uint8_t flags = 0; ///< NOSAVE: GCF_Flags, bitset
|
||||||
GRFStatus status = GCS_UNKNOWN; ///< NOSAVE: GRFStatus, enum
|
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 num_valid_params = MAX_NUM_PARAMS; ///< NOSAVE: Number of valid parameters (action 0x14)
|
||||||
uint8_t palette = 0; ///< GRFPalette, bitset
|
uint8_t palette = 0; ///< GRFPalette, bitset
|
||||||
bool has_param_defaults = false; ///< NOSAVE: did this newgrf specify any defaults for it's parameters
|
bool has_param_defaults = false; ///< NOSAVE: did this newgrf specify any defaults for it's parameters
|
||||||
|
@ -199,7 +199,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
|||||||
u->cargo_cap = new_cap;
|
u->cargo_cap = new_cap;
|
||||||
} else {
|
} else {
|
||||||
/* Verify capacity hasn't changed. */
|
/* 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);
|
u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_TRAIN_CARGO_AGE_PERIOD, e_u->info.cargo_age_period);
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ uint Vehicle::Crash(bool)
|
|||||||
* @param bug_type Flag to check and set in grfconfig
|
* @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?
|
* @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);
|
const Engine *e = Engine::Get(engine);
|
||||||
GRFConfig *grfconfig = GetGRFConfig(e->GetGRFID());
|
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. */
|
/* Missing GRF. Nothing useful can be done in this situation. */
|
||||||
if (grfconfig == nullptr) return;
|
if (grfconfig == nullptr) return;
|
||||||
|
|
||||||
if (!HasBit(grfconfig->grf_bugs, bug_type)) {
|
if (!grfconfig->grf_bugs.Test(bug_type)) {
|
||||||
SetBit(grfconfig->grf_bugs, bug_type);
|
grfconfig->grf_bugs.Set(bug_type);
|
||||||
SetDParamStr(0, grfconfig->GetName());
|
SetDParamStr(0, grfconfig->GetName());
|
||||||
SetDParam(1, engine);
|
SetDParam(1, engine);
|
||||||
ShowErrorMessage(part1, part2, WL_CRITICAL);
|
ShowErrorMessage(part1, part2, WL_CRITICAL);
|
||||||
@ -349,8 +349,8 @@ void VehicleLengthChanged(const Vehicle *u)
|
|||||||
const Engine *engine = u->GetEngine();
|
const Engine *engine = u->GetEngine();
|
||||||
uint32_t grfid = engine->grf_prop.grfid;
|
uint32_t grfid = engine->grf_prop.grfid;
|
||||||
GRFConfig *grfconfig = GetGRFConfig(grfid);
|
GRFConfig *grfconfig = GetGRFConfig(grfid);
|
||||||
if (_gamelog.GRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) {
|
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, GBUG_VEH_LENGTH, true);
|
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)) {
|
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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_ca
|
|||||||
|
|
||||||
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
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);
|
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = nullptr);
|
||||||
|
|
||||||
void DecreaseVehicleValue(Vehicle *v);
|
void DecreaseVehicleValue(Vehicle *v);
|
||||||
|
Loading…
Reference in New Issue
Block a user