From a7a025623e34abf00a83d7c8d1098f683a9d611c Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 4 May 2026 22:58:05 +0100 Subject: [PATCH] Codechange: make RailVehicleType a scoped enum (#15576) --- src/autoreplace_cmd.cpp | 8 ++++---- src/autoreplace_gui.cpp | 2 +- src/build_vehicle_gui.cpp | 24 ++++++++++++------------ src/engine.cpp | 14 +++++++------- src/engine_type.h | 10 +++++----- src/newgrf.cpp | 6 +++--- src/newgrf/newgrf_act0_trains.cpp | 10 +++++----- src/rail.cpp | 4 ++-- src/saveload/vehicle_sl.cpp | 8 ++++---- src/table/engines.h | 6 +++--- src/train_cmd.cpp | 12 ++++++------ src/train_gui.cpp | 2 +- src/vehicle.cpp | 6 +++--- src/vehicle_cmd.cpp | 6 +++--- 14 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index a19bfd9de1..eb9980b560 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -74,7 +74,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company) if (!GetAllCompatibleRailTypes(e_from->VehInfo().railtypes).Any(GetAllCompatibleRailTypes(e_to->VehInfo().railtypes))) return false; /* make sure we do not replace wagons with engines or vice versa */ - if ((e_from->VehInfo().railveh_type == RAILVEH_WAGON) != (e_to->VehInfo().railveh_type == RAILVEH_WAGON)) return false; + if ((e_from->VehInfo().railveh_type == RailVehicleType::Wagon) != (e_to->VehInfo().railveh_type == RailVehicleType::Wagon)) return false; break; } @@ -573,7 +573,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago for (auto it = std::rbegin(replacements); it != std::rend(replacements); ++it) { Vehicle *append = it->GetVehicle(); - if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue; + if (RailVehInfo(append->engine_type)->railveh_type == RailVehicleType::Wagon) continue; if (it->new_veh != nullptr) { /* Move the old engine to a separate row with DoCommandFlag::AutoReplace. Else @@ -600,7 +600,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago assert(last_engine != nullptr); Vehicle *append = it->GetVehicle(); - if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) { + if (RailVehInfo(append->engine_type)->railveh_type == RailVehicleType::Wagon) { /* Insert wagon after 'last_engine' */ CommandCost res = CmdMoveVehicle(append, last_engine, DoCommandFlag::Execute, false); @@ -630,7 +630,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago if (wagon == nullptr) continue; if (wagon->First() == new_head) break; - assert(RailVehInfo(wagon->engine_type)->railveh_type == RAILVEH_WAGON); + assert(RailVehInfo(wagon->engine_type)->railveh_type == RailVehicleType::Wagon); /* Sell wagon */ [[maybe_unused]] CommandCost ret = Command::Do(DoCommandFlag::Execute, wagon->index, false, false, INVALID_CLIENT_ID); diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 69cbfc0e76..1f59762917 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -108,7 +108,7 @@ class ReplaceVehicleWindow : public Window { const RailVehicleInfo *rvi = RailVehInfo(e); /* Ensure that the wagon/engine selection fits the engine. */ - if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false; + if ((rvi->railveh_type == RailVehicleType::Wagon) == show_engines) return false; if (draw_left && this->sel_railtype != INVALID_RAILTYPE) { /* Ensure that the railtype is specific to the selected one */ diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 98990e0b98..8b7705cb3c 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -267,8 +267,8 @@ static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngin const RailVehicleInfo *rvi_a = RailVehInfo(a.engine_id); const RailVehicleInfo *rvi_b = RailVehInfo(b.engine_id); - int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); - int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); + int va = GetTotalCapacityOfArticulatedParts(a.engine_id) * (rvi_a->railveh_type == RailVehicleType::Multihead ? 2 : 1); + int vb = GetTotalCapacityOfArticulatedParts(b.engine_id) * (rvi_b->railveh_type == RailVehicleType::Multihead ? 2 : 1); int r = va - vb; /* Use EngineID to sort instead since we want consistent sorting */ @@ -279,8 +279,8 @@ static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngin /** Determines order of train engines by engine / wagon. @copydoc GUIList::Sorter */ static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b) { - int val_a = (RailVehInfo(a.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0); - int val_b = (RailVehInfo(b.engine_id)->railveh_type == RAILVEH_WAGON ? 1 : 0); + int val_a = (RailVehInfo(a.engine_id)->railveh_type == RailVehicleType::Wagon ? 1 : 0); + int val_b = (RailVehInfo(b.engine_id)->railveh_type == RailVehicleType::Wagon ? 1 : 0); int r = val_a - val_b; /* Use EngineID to sort instead since we want consistent sorting */ @@ -842,7 +842,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, switch (e->type) { default: NOT_REACHED(); case VehicleType::Train: - if (e->VehInfo().railveh_type == RAILVEH_WAGON) { + if (e->VehInfo().railveh_type == RailVehicleType::Wagon) { y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->VehInfo(), te); } else { y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->VehInfo(), te); @@ -877,7 +877,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, } /* Draw details that apply to all types except rail wagons. */ - if (e->type != VehicleType::Train || e->VehInfo().railveh_type != RAILVEH_WAGON) { + if (e->type != VehicleType::Train || e->VehInfo().railveh_type != RailVehicleType::Wagon) { /* Design date - Life length */ DrawString(left, right, y, GetString(STR_PURCHASE_INFO_DESIGNED_LIFE, ymd.year, TimerGameCalendar::DateToYear(e->GetLifeLengthInDays()))); y += GetCharacterHeight(FontSize::Normal); @@ -1062,7 +1062,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li break; case STR_SORT_BY_TRACTIVE_EFFORT: /* Allow trucks, and allow trains that are not wagons */ - if (type == VehicleType::Road || (type == VehicleType::Train && e->VehInfo().railveh_type != RAILVEH_WAGON)) { + if (type == VehicleType::Road || (type == VehicleType::Train && e->VehInfo().railveh_type != RailVehicleType::Wagon)) { auto max_te = e->GetDisplayMaxTractiveEffort(); if (max_te != 0) { sort_prop_detail = GetString(STR_PURCHASE_SORT_DETAILS_MAX_TE, max_te); @@ -1089,7 +1089,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li } break; case STR_SORT_BY_RELIABILITY: - if (auto isWagon = e->type == VehicleType::Train && e->VehInfo().railveh_type == RAILVEH_WAGON; !isWagon) { + if (auto isWagon = e->type == VehicleType::Train && e->VehInfo().railveh_type == RailVehicleType::Wagon; !isWagon) { sort_prop_detail = GetString(STR_PURCHASE_SORT_DETAILS_RELIABILITY, ToPercent16(e->reliability)); } break; @@ -1097,7 +1097,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li uint total_capacity; switch (type) { case VehicleType::Train: - total_capacity = GetTotalCapacityOfArticulatedParts(item.engine_id) * (e->VehInfo().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); + total_capacity = GetTotalCapacityOfArticulatedParts(item.engine_id) * (e->VehInfo().railveh_type == RailVehicleType::Multihead ? 2 : 1); break; case VehicleType::Road: total_capacity = GetTotalCapacityOfArticulatedParts(item.engine_id); @@ -1479,7 +1479,7 @@ struct BuildVehicleWindow : Window { list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); - if (rvi->railveh_type != RAILVEH_WAGON) num_engines++; + if (rvi->railveh_type != RailVehicleType::Wagon) num_engines++; /* Add all parent variants of this engine to the variant list */ EngineID parent = e->info.variant_id; @@ -1495,7 +1495,7 @@ struct BuildVehicleWindow : Window { if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) { const Engine *e = Engine::Get(variant); list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlag::Shaded, 0); - if (e->VehInfo().railveh_type != RAILVEH_WAGON) num_engines++; + if (e->VehInfo().railveh_type != RailVehicleType::Wagon) num_engines++; } } @@ -1696,7 +1696,7 @@ struct BuildVehicleWindow : Window { CargoType cargo = this->cargo_filter_criteria; if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO; - if (this->vehicle_type == VehicleType::Train && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) { + if (this->vehicle_type == VehicleType::Train && RailVehInfo(sel_eng)->railveh_type == RailVehicleType::Wagon) { Command::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID); } else { Command::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID); diff --git a/src/engine.cpp b/src/engine.cpp index 761081ad20..68e24749bf 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -137,7 +137,7 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + local_id; /* Set the default model life of original wagons to "infinite" */ - if (rvi.railveh_type == RAILVEH_WAGON) this->info.base_life = TimerGameCalendar::Year{0xFF}; + if (rvi.railveh_type == RailVehicleType::Wagon) this->info.base_life = TimerGameCalendar::Year{0xFF}; break; } @@ -253,7 +253,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->VehInfo().capacity, v); /* In purchase list add the capacity of the second head. Always use the plain property for this. */ - if (v == nullptr && this->VehInfo().railveh_type == RAILVEH_MULTIHEAD) capacity += this->VehInfo().capacity; + if (v == nullptr && this->VehInfo().railveh_type == RailVehicleType::Multihead) capacity += this->VehInfo().capacity; break; case VehicleType::Road: @@ -351,7 +351,7 @@ Money Engine::GetCost() const break; case VehicleType::Train: - if (this->VehInfo().railveh_type == RAILVEH_WAGON) { + if (this->VehInfo().railveh_type == RailVehicleType::Wagon) { base_price = Price::BuildVehicleWagon; cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo().cost_factor); } else { @@ -435,7 +435,7 @@ uint Engine::GetDisplayWeight() const /* Only trains and road vehicles have 'weight'. */ switch (this->type) { case VehicleType::Train: - return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->VehInfo().weight) << (this->VehInfo().railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); + return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->VehInfo().weight) << (this->VehInfo().railveh_type == RailVehicleType::Multihead ? 1 : 0); case VehicleType::Road: return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->VehInfo().weight) / 4; @@ -651,7 +651,7 @@ void ShowEnginePreviewWindow(EngineID engine); static bool IsWagon(EngineID index) { const Engine *e = Engine::Get(index); - return e->type == VehicleType::Train && e->VehInfo().railveh_type == RAILVEH_WAGON; + return e->type == VehicleType::Train && e->VehInfo().railveh_type == RailVehicleType::Wagon; } /** @@ -727,7 +727,7 @@ void SetYearEngineAgingStops() /* Exclude certain engines */ if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue; - if (e->type == VehicleType::Train && e->VehInfo().railveh_type == RAILVEH_WAGON) continue; + if (e->type == VehicleType::Train && e->VehInfo().railveh_type == RailVehicleType::Wagon) continue; /* Base year ending date on half the model life */ TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength.base() * CalendarTime::DAYS_IN_LEAP_YEAR) / 2); @@ -1344,7 +1344,7 @@ void CheckEngines() if (!e->IsEnabled()) continue; /* Don't consider train wagons, we need a powered engine available. */ - if (e->type == VehicleType::Train && e->VehInfo().railveh_type == RAILVEH_WAGON) continue; + if (e->type == VehicleType::Train && e->VehInfo().railveh_type == RailVehicleType::Wagon) continue; /* We have an available engine... yay! */ if (e->flags.Test(EngineFlag::Available) && e->company_avail.Any()) return; diff --git a/src/engine_type.h b/src/engine_type.h index 2942ac32ec..54af76069f 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -28,10 +28,10 @@ using EngineID = PoolID; class Engine; /** Available types of rail vehicles. */ -enum RailVehicleTypes : uint8_t { - RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive - RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives - RAILVEH_WAGON, ///< simple wagon, not motorized +enum class RailVehicleType : uint8_t { + Singlehead, ///< indicates a "standalone" locomotive + Multihead, ///< indicates a combination of two locomotives + Wagon, ///< simple wagon, not motorized }; /** Type of rail engine. */ @@ -73,7 +73,7 @@ enum VisualEffect : uint8_t { /** Information about a rail vehicle. */ struct RailVehicleInfo { uint8_t image_index = 0; - RailVehicleTypes railveh_type = RAILVEH_WAGON; + RailVehicleType railveh_type = RailVehicleType::Wagon; ///< Type of rail vehicle. uint8_t cost_factor = 0; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices. RailTypes railtypes{RAILTYPE_RAIL}; ///< Railtypes, mangled if elrail is disabled. RailTypes intended_railtypes{RAILTYPE_RAIL}; ///< Intended railtypes, regardless of elrail being enabled or disabled. diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 19a1293dba..b04fa5888a 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -726,7 +726,7 @@ static void CalculateRefitMasks() break; } e->VehInfo().old_refittable = true; - } else if (e->type == VehicleType::Train && e->VehInfo().railveh_type != RAILVEH_WAGON) { + } else if (e->type == VehicleType::Train && e->VehInfo().railveh_type != RailVehicleType::Wagon) { /* Train engines default to all cargoes, so you can build single-cargo consists with fast engines. * Trains loading multiple cargoes may start stations accepting unwanted cargoes. */ _gted[engine].cargo_allowed = {CargoClass::Passengers, CargoClass::Mail, CargoClass::Armoured, CargoClass::Express, CargoClass::Bulk, CargoClass::PieceGoods, CargoClass::Liquid}; @@ -829,7 +829,7 @@ static void CalculateRefitMasks() ei->cargo_type = *ei->refit_mask.begin(); } } - if (!IsValidCargoType(ei->cargo_type) && e->type == VehicleType::Train && e->VehInfo().railveh_type != RAILVEH_WAGON && e->VehInfo().capacity == 0) { + if (!IsValidCargoType(ei->cargo_type) && e->type == VehicleType::Train && e->VehInfo().railveh_type != RailVehicleType::Wagon && e->VehInfo().capacity == 0) { /* For train engines which do not carry cargo it does not matter if their cargo type is invalid. * Fallback to the first available instead, if the cargo type has not been changed (as indicated by * cargo_label not being CT_INVALID). */ @@ -886,7 +886,7 @@ static void FinaliseEngineArray() } /* Skip wagons, there livery is defined via the engine */ - if (e->type != VehicleType::Train || e->VehInfo().railveh_type != RAILVEH_WAGON) { + if (e->type != VehicleType::Train || e->VehInfo().railveh_type != RailVehicleType::Wagon) { LiveryScheme ls = GetEngineLiveryScheme(e->index, EngineID::Invalid(), nullptr); SetBit(_loaded_newgrf_features.used_liveries, ls); /* Note: For ships and roadvehicles we assume that they cannot be refitted between passenger and freight */ diff --git a/src/newgrf/newgrf_act0_trains.cpp b/src/newgrf/newgrf_act0_trains.cpp index a69e5aa8f6..25fd6a25ab 100644 --- a/src/newgrf/newgrf_act0_trains.cpp +++ b/src/newgrf/newgrf_act0_trains.cpp @@ -77,11 +77,11 @@ ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, ByteRead /* Set engine / wagon state based on power */ if (rvi->power != 0) { - if (rvi->railveh_type == RAILVEH_WAGON) { - rvi->railveh_type = RAILVEH_SINGLEHEAD; + if (rvi->railveh_type == RailVehicleType::Wagon) { + rvi->railveh_type = RailVehicleType::Singlehead; } } else { - rvi->railveh_type = RAILVEH_WAGON; + rvi->railveh_type = RailVehicleType::Wagon; } break; @@ -114,10 +114,10 @@ ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, ByteRead uint8_t dual = buf.ReadByte(); if (dual != 0) { - rvi->railveh_type = RAILVEH_MULTIHEAD; + rvi->railveh_type = RailVehicleType::Multihead; } else { rvi->railveh_type = rvi->power == 0 ? - RAILVEH_WAGON : RAILVEH_SINGLEHEAD; + RailVehicleType::Wagon : RailVehicleType::Singlehead; } break; } diff --git a/src/rail.cpp b/src/rail.cpp index 6f9d84b90b..1624dbf1f1 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -145,7 +145,7 @@ RailTypes GetCompanyRailTypes(CompanyID company, bool introduces) (e->company_avail.Test(company) || TimerGameCalendar::date >= e->intro_date + CalendarTime::DAYS_IN_YEAR)) { const RailVehicleInfo *rvi = &e->VehInfo(); - if (rvi->railveh_type != RAILVEH_WAGON) { + if (rvi->railveh_type != RailVehicleType::Wagon) { assert(rvi->railtypes.Any()); if (introduces) { rts.Set(GetAllIntroducesRailTypes(rvi->railtypes)); @@ -174,7 +174,7 @@ RailTypes GetRailTypes(bool introduces) if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue; const RailVehicleInfo *rvi = &e->VehInfo(); - if (rvi->railveh_type != RAILVEH_WAGON) { + if (rvi->railveh_type != RailVehicleType::Wagon) { assert(rvi->railtypes.Any()); if (introduces) { rts.Set(GetAllIntroducesRailTypes(rvi->railtypes)); diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index aa78e99f6d..ade104197a 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -122,7 +122,7 @@ void ConvertOldMultiheadToNew() ClrBit(u->subtype, 7); switch (u->subtype) { case 0: // TS_Front_Engine - if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded(); + if (rvi->railveh_type == RailVehicleType::Multihead) u->SetMultiheaded(); u->SetFrontEngine(); u->SetEngine(); break; @@ -134,17 +134,17 @@ void ConvertOldMultiheadToNew() case 2: // TS_Not_First u->subtype = 0; - if (rvi->railveh_type == RAILVEH_WAGON) { + if (rvi->railveh_type == RailVehicleType::Wagon) { /* normal wagon */ u->SetWagon(); break; } - if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) { + if (rvi->railveh_type == RailVehicleType::Multihead && rvi->image_index == u->spritenum - 1) { /* rear end of a multiheaded engine */ u->SetMultiheaded(); break; } - if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded(); + if (rvi->railveh_type == RailVehicleType::Multihead) u->SetMultiheaded(); u->SetEngine(); break; diff --git a/src/table/engines.h b/src/table/engines.h index ddee79c721..bf80cc41f0 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -385,9 +385,9 @@ static constexpr EngineInfo _orig_engine_info[] = { * Air drag value depends on the top speed of the vehicle. */ #define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, j, 0, d, e, f, g, h, k, i, 0, 0, VE_DEFAULT, 0, 76, 0, 0, 0 } -#define M RAILVEH_MULTIHEAD -#define W RAILVEH_WAGON -#define G RAILVEH_SINGLEHEAD +#define M RailVehicleType::Multihead +#define W RailVehicleType::Wagon +#define G RailVehicleType::Singlehead #define S EngineClass::Steam #define D EngineClass::Diesel #define E EngineClass::Electric diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index a5971462b7..dfc96207ab 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -160,7 +160,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) /* Update powered-wagon-status and visual effect */ u->UpdateVisualEffect(true); - if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON && + if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RailVehicleType::Wagon && UsesWagonOverride(u) && !HasBit(u->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) { /* wagon is powered */ u->flags.Set(VehicleRailFlag::PoweredWagon); // cache 'powered' status @@ -183,7 +183,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) } /* max speed is the minimum of the speed limits of all vehicles in the consist */ - if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) { + if ((rvi_u->railveh_type != RailVehicleType::Wagon || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) { uint16_t speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed); if (speed != 0) max_speed = std::min(speed, max_speed); } @@ -554,7 +554,7 @@ static void GetRailIcon(EngineID engine, bool rear_head, int &y, EngineImageType void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type) { - if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) { + if (RailVehInfo(engine)->railveh_type == RailVehicleType::Multihead) { int yf = y; int yr = y; @@ -610,7 +610,7 @@ void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, xoffs = UnScaleGUI(rect.left); yoffs = UnScaleGUI(rect.top); - if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) { + if (RailVehInfo(engine)->railveh_type == RailVehicleType::Multihead) { GetRailIcon(engine, true, y, image_type, &seq); seq.GetBounds(&rect); @@ -793,7 +793,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlags flags, TileIndex tile, const Engi { const RailVehicleInfo *rvi = &e->VehInfo(); - if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(flags, tile, e, ret); + if (rvi->railveh_type == RailVehicleType::Wagon) return CmdBuildRailWagon(flags, tile, e, ret); /* Check if depot and new engine uses the same kind of tracks * * We need to see if the engine got power on the tile to avoid electric engines in non-electric depots */ @@ -850,7 +850,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlags flags, TileIndex tile, const Engi if (prob.has_value()) v->flags.Set(VehicleRailFlag::Flipped, prob.value()); v->UpdatePosition(); - if (rvi->railveh_type == RAILVEH_MULTIHEAD) { + if (rvi->railveh_type == RailVehicleType::Multihead) { AddRearEngineToMultiheadedTrain(v); } else { AddArticulatedParts(v); diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 4b79fd9d67..60cbc07ee7 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -238,7 +238,7 @@ static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int rig static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y) { std::string str; - if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) { + if (RailVehInfo(v->engine_type)->railveh_type == RailVehicleType::Wagon) { str = GetString(STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->value); } else { str = GetString(STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->build_year, v->value); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 52deb8ec50..6b9225a1e8 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1993,7 +1993,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ switch (e->type) { default: NOT_REACHED(); case VehicleType::Train: - if (v != nullptr && parent_engine_type != EngineID::Invalid() && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->VehInfo().railveh_type != RAILVEH_WAGON))) { + if (v != nullptr && parent_engine_type != EngineID::Invalid() && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->VehInfo().railveh_type != RailVehicleType::Wagon))) { /* Wagonoverrides use the colour scheme of the front engine. * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ engine_type = parent_engine_type; @@ -2004,7 +2004,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ if (!IsValidCargoType(cargo_type)) cargo_type = e->GetDefaultCargoType(); if (!IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(CT_GOODS); // The vehicle does not carry anything, let's pick some freight cargo assert(IsValidCargoType(cargo_type)); - if (e->VehInfo().railveh_type == RAILVEH_WAGON) { + if (e->VehInfo().railveh_type == RailVehicleType::Wagon) { if (!CargoSpec::Get(cargo_type)->is_freight) { if (parent_engine_type == EngineID::Invalid()) { return LS_PASSENGER_WAGON_STEAM; @@ -2710,7 +2710,7 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change) (!HasBit(visual_effect, VE_DISABLE_EFFECT) && GB(visual_effect, VE_TYPE_START, VE_TYPE_COUNT) == VE_TYPE_DEFAULT)) { /* Only train engines have default effects. * Note: This is independent of whether the engine is a front engine or articulated part or whatever. */ - if (e->type != VehicleType::Train || e->VehInfo().railveh_type == RAILVEH_WAGON || !IsInsideMM(e->VehInfo().engclass, EngineClass::Steam, EngineClass::Monorail)) { + if (e->type != VehicleType::Train || e->VehInfo().railveh_type == RailVehicleType::Wagon || !IsInsideMM(e->VehInfo().engclass, EngineClass::Steam, EngineClass::Monorail)) { if (visual_effect == VE_DEFAULT) { visual_effect = 1 << VE_DISABLE_EFFECT; } else { diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 872c15836e..f01ad910f6 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -133,7 +133,7 @@ std::tuple CmdBuildVehicle(D /* Check whether the number of vehicles we need to build can be built according to pool space. */ uint num_vehicles; switch (type) { - case VehicleType::Train: num_vehicles = (e->VehInfo().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid); break; + case VehicleType::Train: num_vehicles = (e->VehInfo().railveh_type == RailVehicleType::Multihead ? 2 : 1) + CountArticulatedParts(eid); break; case VehicleType::Road: num_vehicles = 1 + CountArticulatedParts(eid); break; case VehicleType::Ship: num_vehicles = 1; break; case VehicleType::Aircraft: num_vehicles = e->VehInfo().subtype & AIR_CTOL ? 2 : 3; break; @@ -144,7 +144,7 @@ std::tuple CmdBuildVehicle(D /* Check whether we can allocate a unit number. Autoreplace does not allocate * an unit number as it will (always) reuse the one of the replaced vehicle * and (train) wagons don't have an unit number in any scenario. */ - UnitID unit_num = (flags.Test(DoCommandFlag::QueryCost) || flags.Test(DoCommandFlag::AutoReplace) || (type == VehicleType::Train && e->VehInfo().railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type); + UnitID unit_num = (flags.Test(DoCommandFlag::QueryCost) || flags.Test(DoCommandFlag::AutoReplace) || (type == VehicleType::Train && e->VehInfo().railveh_type == RailVehicleType::Wagon)) ? 0 : GetFreeUnitNumber(type); if (unit_num == UINT16_MAX) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), VehicleID::Invalid(), 0, 0, {} }; /* If we are refitting we need to temporarily purchase the vehicle to be able to @@ -336,7 +336,7 @@ static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoTyp break; case VehicleType::Train: - base_price = (e->VehInfo().railveh_type == RAILVEH_WAGON) ? Price::BuildVehicleWagon : Price::BuildVehicleTrain; + base_price = (e->VehInfo().railveh_type == RailVehicleType::Wagon) ? Price::BuildVehicleWagon : Price::BuildVehicleTrain; cost_factor <<= 1; expense_type = ExpensesType::TrainRun; break;