Codechange: Use EnumBitSet for callback masks.

This commit is contained in:
Peter Nelson
2025-01-30 19:32:41 +00:00
committed by Peter Nelson
parent 1dd4adc50c
commit 40aeedeade
47 changed files with 396 additions and 316 deletions

View File

@@ -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);