Codechange: make VehicleType a scoped enum

This commit is contained in:
Peter Nelson
2026-04-26 07:00:13 +01:00
committed by Peter Nelson
parent b90aefbf49
commit 77403627a8
100 changed files with 1093 additions and 1054 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ struct AircraftCache {
/**
* Aircraft, helicopters, rotors and their shadows belong to this class.
*/
struct Aircraft final : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
struct Aircraft final : public SpecializedVehicle<Aircraft, VehicleType::Aircraft> {
uint16_t crashed_counter = 0; ///< Timer for handling crash animations.
uint8_t pos = 0; ///< Next desired position of the aircraft.
uint8_t previous_pos = 0; ///< Previous desired position of the aircraft.
+5 -5
View File
@@ -95,7 +95,7 @@ static const SpriteID _aircraft_sprite[] = {
/** @copydoc IsValidImageIndex */
template <>
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8_t image_index)
bool IsValidImageIndex<VehicleType::Aircraft>(uint8_t image_index)
{
return image_index < lengthof(_aircraft_sprite);
}
@@ -178,7 +178,7 @@ void Aircraft::GetImage(Direction direction, EngineImageType image_type, Vehicle
spritenum = this->GetEngine()->original_image_index;
}
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
assert(IsValidImageIndex<VehicleType::Aircraft>(spritenum));
result->Set(direction + _aircraft_sprite[spritenum]);
}
@@ -208,7 +208,7 @@ static void GetAircraftIcon(EngineID engine, EngineImageType image_type, Vehicle
spritenum = e->original_image_index;
}
assert(IsValidImageIndex<VEH_AIRCRAFT>(spritenum));
assert(IsValidImageIndex<VehicleType::Aircraft>(spritenum));
result->Set(DIR_W + _aircraft_sprite[spritenum]);
}
@@ -724,7 +724,7 @@ int GetTileHeightBelowAircraft(const Vehicle *v)
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min_level, int *max_level)
{
int base_altitude = GetTileHeightBelowAircraft(v);
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->subtype == AIR_HELICOPTER) {
if (v->type == VehicleType::Aircraft && Aircraft::From(v)->subtype == AIR_HELICOPTER) {
base_altitude += HELICOPTER_HOLD_MAX_FLYING_ALTITUDE - PLANE_HOLD_MAX_FLYING_ALTITUDE;
}
@@ -2174,7 +2174,7 @@ bool Aircraft::Tick()
*/
Station *GetTargetAirportIfValid(const Aircraft *v)
{
assert(v->type == VEH_AIRCRAFT);
assert(v->type == VehicleType::Aircraft);
Station *st = Station::GetIfValid(v->targetairport);
if (st == nullptr) return nullptr;
+1 -1
View File
@@ -109,7 +109,7 @@ struct BuildAirToolbarWindow : Window {
{
if (!gui_scope) return;
bool can_build = CanBuildVehicleInfrastructure(VEH_AIRCRAFT);
bool can_build = CanBuildVehicleInfrastructure(VehicleType::Aircraft);
this->SetWidgetDisabledState(WID_AT_AIRPORT, !can_build);
if (!can_build) {
CloseWindowById(WC_BUILD_STATION, TRANSPORT_AIR);
+3 -3
View File
@@ -348,7 +348,7 @@ void AddArticulatedParts(Vehicle *first)
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: {
case VehicleType::Train: {
Train *front = Train::From(first);
Train *t = Train::Create();
v->SetNext(t);
@@ -372,7 +372,7 @@ void AddArticulatedParts(Vehicle *first)
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *front = RoadVehicle::From(first);
RoadVehicle *rv = RoadVehicle::Create();
v->SetNext(rv);
@@ -423,7 +423,7 @@ void AddArticulatedParts(Vehicle *first)
if (flip_image) v->spritenum++;
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
auto prob = TestVehicleBuildProbability(v, BuildProbabilityType::Reversed);
if (prob.has_value()) Train::From(v)->flags.Set(VehicleRailFlag::Flipped, prob.value());
}
+17 -17
View File
@@ -69,7 +69,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
if (!IsEngineBuildable(to, type, company)) return false;
switch (type) {
case VEH_TRAIN: {
case VehicleType::Train: {
/* make sure the railtypes are compatible */
if (!GetAllCompatibleRailTypes(e_from->VehInfo<RailVehicleInfo>().railtypes).Any(GetAllCompatibleRailTypes(e_to->VehInfo<RailVehicleInfo>().railtypes))) return false;
@@ -78,7 +78,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
break;
}
case VEH_ROAD:
case VehicleType::Road:
/* make sure the roadtypes are compatible */
if (!GetRoadTypeInfo(e_from->VehInfo<RoadVehicleInfo>().roadtype)->powered_roadtypes.Any(GetRoadTypeInfo(e_to->VehInfo<RoadVehicleInfo>().roadtype)->powered_roadtypes)) return false;
@@ -86,7 +86,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
if (e_from->info.misc_flags.Test(EngineMiscFlag::RoadIsTram) != e_to->info.misc_flags.Test(EngineMiscFlag::RoadIsTram)) return false;
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
/* make sure that we do not replace a plane with a helicopter or vice versa */
if ((e_from->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL) != (e_to->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL)) return false;
break;
@@ -145,7 +145,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
/* Loop through source parts */
for (Vehicle *src = old_veh; src != nullptr; src = src->Next()) {
assert(src->cargo.TotalCount() == src->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) {
if (!part_of_chain && src->type == VehicleType::Train && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to old_veh */
src = src->GetLastEnginePart();
continue;
@@ -155,7 +155,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
/* Find free space in the new chain */
for (Vehicle *dest = new_head; dest != nullptr && src->cargo.TotalCount() > 0; dest = dest->Next()) {
assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) {
if (!part_of_chain && dest->type == VehicleType::Train && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) {
/* Skip vehicles, which do not belong to new_head */
dest = dest->GetLastEnginePart();
continue;
@@ -170,7 +170,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
}
/* Update train weight etc., the old vehicle will be sold anyway */
if (part_of_chain && new_head->type == VEH_TRAIN) Train::From(new_head)->ConsistChanged(CCF_LOADUNLOAD);
if (part_of_chain && new_head->type == VehicleType::Train) Train::From(new_head)->ConsistChanged(CCF_LOADUNLOAD);
}
/**
@@ -184,7 +184,7 @@ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_ty
CargoTypes union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, false);
CargoTypes union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, false);
const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
const Vehicle *u = (v->type == VehicleType::Train) ? v->First() : v;
for (const Order &o : u->Orders()) {
if (!o.IsRefit() || o.IsAutoRefit()) continue;
CargoType cargo_type = o.GetRefitCargo();
@@ -206,7 +206,7 @@ static int GetIncompatibleRefitOrderIdForAutoreplace(const Vehicle *v, EngineID
{
CargoTypes union_refit_mask = GetUnionOfArticulatedRefitMasks(engine_type, false);
const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
const Vehicle *u = (v->type == VehicleType::Train) ? v->First() : v;
const OrderList *orders = u->orders;
if (orders == nullptr) return -1;
@@ -247,7 +247,7 @@ static CargoType GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, boo
}
if (!IsValidCargoType(cargo_type)) {
if (v->type != VEH_TRAIN) return CARGO_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
if (v->type != VehicleType::Train) return CARGO_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine.
if (!part_of_chain) return CARGO_NO_REFIT;
@@ -280,11 +280,11 @@ static CargoType GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, boo
*/
static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool always_replace, EngineID &e)
{
assert(v->type != VEH_TRAIN || !v->IsArticulatedPart());
assert(v->type != VehicleType::Train || !v->IsArticulatedPart());
e = EngineID::Invalid();
if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) {
if (v->type == VehicleType::Train && Train::From(v)->IsRearDualheaded()) {
/* we build the rear ends of multiheaded trains with the front ones */
return CommandCost();
}
@@ -305,7 +305,7 @@ static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool alw
if (e == EngineID::Invalid() || IsEngineBuildable(e, v->type, _current_company)) return CommandCost();
/* The engine we need is not available. Report error to user */
return CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + v->type);
return CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + to_underlying(v->type));
}
/**
@@ -333,7 +333,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
if (!IsValidCargoType(refit_cargo)) {
if (!IsLocalCompany() || !flags.Test(DoCommandFlag::Execute)) return CommandCost();
VehicleID old_veh_id = (old_veh->type == VEH_TRAIN) ? Train::From(old_veh)->First()->index : old_veh->index;
VehicleID old_veh_id = (old_veh->type == VehicleType::Train) ? Train::From(old_veh)->First()->index : old_veh->index;
EncodedString headline;
int order_id = GetIncompatibleRefitOrderIdForAutoreplace(old_veh, e);
@@ -372,7 +372,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
}
/* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */
if (new_veh->type == VEH_TRAIN && Train::From(old_veh)->flags.Test(VehicleRailFlag::Flipped)) {
if (new_veh->type == VehicleType::Train && Train::From(old_veh)->flags.Test(VehicleRailFlag::Flipped)) {
/* Only copy the reverse state if neither old or new vehicle implements reverse-on-build probability callback. */
if (!TestVehicleBuildProbability(old_veh, BuildProbabilityType::Reversed).has_value() &&
!TestVehicleBuildProbability(new_veh, BuildProbabilityType::Reversed).has_value()) {
@@ -536,7 +536,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, (Money)0);
if (old_head->type == VEH_TRAIN) {
if (old_head->type == VehicleType::Train) {
/* Store the length of the old vehicle chain, rounded up to whole tiles */
uint16_t old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;
@@ -754,7 +754,7 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlags flags, VehicleID veh_id)
if (v->vehstatus.Test(VehState::Crashed)) return CMD_ERROR;
bool free_wagon = false;
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
Train *t = Train::From(v);
if (t->IsArticulatedPart() || t->IsRearDualheaded()) return CMD_ERROR;
free_wagon = !t->IsFrontEngine();
@@ -778,7 +778,7 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlags flags, VehicleID veh_id)
CommandCost cost = GetNewEngineType(w, c, false, e);
if (cost.Failed()) return cost;
any_replacements |= (e != EngineID::Invalid());
w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : nullptr);
w = (!free_wagon && w->type == VehicleType::Train ? Train::From(w)->GetNextUnit() : nullptr);
}
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, (Money)0);
+12 -12
View File
@@ -87,7 +87,7 @@ class ReplaceVehicleWindow : public Window {
bool reset_sel_engine = true; ///< Also reset #sel_engine while updating left and/or right and no valid engine selected.
GroupID sel_group = GroupID::Invalid(); ///< Group selected to replace.
int details_height = 0; ///< Minimal needed height of the details panels, in text lines (found so far).
VehicleType vehicle_type = VEH_INVALID; ///< Type of vehicle in this window.
VehicleType vehicle_type = VehicleType::Invalid; ///< Type of vehicle in this window.
uint8_t sort_criteria = 0; ///< Criteria of sorting vehicles.
bool descending_sort_order = false; ///< Order of sorting vehicles.
bool show_hidden_engines = false; ///< Whether to show the hidden engines.
@@ -134,11 +134,11 @@ class ReplaceVehicleWindow : public Window {
if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
EngineID eid = e->index;
switch (type) {
case VEH_TRAIN:
case VehicleType::Train:
if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
break;
case VEH_ROAD:
case VehicleType::Road:
if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
/* Ensure that the roadtype is specific to the selected one */
if (e->VehInfo<RoadVehicleInfo>().roadtype != this->sel_roadtype) continue;
@@ -273,7 +273,7 @@ public:
this->vehicle_type = vehicletype;
this->engines[0].ForceRebuild();
this->engines[1].ForceRebuild();
this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9);
this->details_height = ((vehicletype == VehicleType::Train) ? 10 : 9);
this->sel_engine[0] = EngineID::Invalid();
this->sel_engine[1] = EngineID::Invalid();
this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
@@ -283,7 +283,7 @@ public:
this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_RV_SHOW_HIDDEN_ENGINES);
widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype);
widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + to_underlying(vehicletype), STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + to_underlying(vehicletype));
widget->SetLowered(this->show_hidden_engines);
this->FinishInitNested(vehicletype);
@@ -312,7 +312,7 @@ public:
case WID_RV_LEFT_MATRIX:
case WID_RV_RIGHT_MATRIX:
fill.height = resize.height = GetEngineListHeight(this->window_number);
size.height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize.height;
size.height = (this->vehicle_type <= VehicleType::Road ? 8 : 4) * resize.height;
break;
case WID_RV_LEFT_DETAILS:
@@ -514,14 +514,14 @@ public:
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING:
this->descending_sort_order ^= true;
_engine_sort_last_order[this->window_number] = this->descending_sort_order;
_engine_sort_last_order[this->vehicle_type] = this->descending_sort_order;
this->engines[1].ForceRebuild();
this->SetDirty();
break;
case WID_RV_SHOW_HIDDEN_ENGINES:
this->show_hidden_engines ^= true;
_engine_sort_show_hidden_engines[this->window_number] = this->show_hidden_engines;
_engine_sort_show_hidden_engines[this->vehicle_type] = this->show_hidden_engines;
this->engines[1].ForceRebuild();
this->SetWidgetLoweredState(widget, this->show_hidden_engines);
this->SetDirty();
@@ -633,7 +633,7 @@ public:
case WID_RV_SORT_DROPDOWN:
if (this->sort_criteria != index) {
this->sort_criteria = index;
_engine_sort_last_criteria[this->window_number] = this->sort_criteria;
_engine_sort_last_criteria[this->vehicle_type] = this->sort_criteria;
this->engines[1].ForceRebuild();
this->SetDirty();
}
@@ -891,8 +891,8 @@ void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
{
CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
switch (vehicletype) {
case VEH_TRAIN: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
case VEH_ROAD: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
case VehicleType::Train: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
case VehicleType::Road: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
}
}
+82 -74
View File
@@ -102,10 +102,10 @@ static constexpr std::initializer_list<NWidgetPart> _nested_build_vehicle_widget
bool _engine_sort_direction; ///< \c false = descending, \c true = ascending.
uint8_t _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type.
bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
static CargoType _engine_sort_last_cargo_criteria[] = {CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY}; ///< Last set filter criteria, for each vehicle type.
VehicleTypeIndexArray<uint8_t> _engine_sort_last_criteria = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type.
VehicleTypeIndexArray<bool> _engine_sort_last_order = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
VehicleTypeIndexArray<bool> _engine_sort_show_hidden_engines = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
static VehicleTypeIndexArray<CargoType> _engine_sort_last_cargo_criteria = {CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY, CargoFilterCriteria::CF_ANY}; ///< Last set filter criteria, for each vehicle type.
/** Determines order of engines by engineID. @copydoc GUIList::Sorter */
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
@@ -358,7 +358,8 @@ static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListI
}
/** Sort functions for the vehicle sort criteria, for each vehicle type. */
EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
const VehicleTypeIndexArray<std::initializer_list<EngList_SortTypeFunction * const>> _engine_sort_functions = {{
std::initializer_list<EngList_SortTypeFunction * const>{
/* Trains */
&EngineNumberSorter,
&EngineCostSorter,
@@ -371,7 +372,8 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
&EnginePowerVsRunningCostSorter,
&EngineReliabilitySorter,
&TrainEngineCapacitySorter,
}, {
},
std::initializer_list<EngList_SortTypeFunction * const>{
/* Road vehicles */
&EngineNumberSorter,
&EngineCostSorter,
@@ -384,7 +386,8 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
&EnginePowerVsRunningCostSorter,
&EngineReliabilitySorter,
&RoadVehEngineCapacitySorter,
}, {
},
std::initializer_list<EngList_SortTypeFunction * const>{
/* Ships */
&EngineNumberSorter,
&EngineCostSorter,
@@ -394,7 +397,8 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
&EngineRunningCostSorter,
&EngineReliabilitySorter,
&ShipEngineCapacitySorter,
}, {
},
std::initializer_list<EngList_SortTypeFunction * const>{
/* Aircraft */
&EngineNumberSorter,
&EngineCostSorter,
@@ -405,7 +409,7 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
&EngineReliabilitySorter,
&AircraftEngineCargoSorter,
&AircraftRangeSorter,
}};
}}};
/**
* Get the engine sorter functions for a \c VehicleType
@@ -415,11 +419,12 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
std::span<EngList_SortTypeFunction * const> GetEngineSortFunctions(VehicleType vehicle_type)
{
assert(IsCompanyBuildableVehicleType(vehicle_type));
return _engine_sort_functions[to_underlying(vehicle_type)];
return _engine_sort_functions[vehicle_type];
}
/** Dropdown menu strings for the vehicle sort criteria. */
const std::initializer_list<const StringID> _engine_sort_listing[] = {{
const VehicleTypeIndexArray<std::initializer_list<const StringID>> _engine_sort_listing = {{
std::initializer_list<const StringID>{
/* Trains */
STR_SORT_BY_ENGINE_ID,
STR_SORT_BY_COST,
@@ -432,7 +437,8 @@ const std::initializer_list<const StringID> _engine_sort_listing[] = {{
STR_SORT_BY_POWER_VS_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
STR_SORT_BY_CARGO_CAPACITY,
}, {
},
std::initializer_list<const StringID>{
/* Road vehicles */
STR_SORT_BY_ENGINE_ID,
STR_SORT_BY_COST,
@@ -445,7 +451,8 @@ const std::initializer_list<const StringID> _engine_sort_listing[] = {{
STR_SORT_BY_POWER_VS_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
STR_SORT_BY_CARGO_CAPACITY,
}, {
},
std::initializer_list<const StringID>{
/* Ships */
STR_SORT_BY_ENGINE_ID,
STR_SORT_BY_COST,
@@ -455,7 +462,8 @@ const std::initializer_list<const StringID> _engine_sort_listing[] = {{
STR_SORT_BY_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
STR_SORT_BY_CARGO_CAPACITY,
}, {
},
std::initializer_list<const StringID>{
/* Aircraft */
STR_SORT_BY_ENGINE_ID,
STR_SORT_BY_COST,
@@ -466,7 +474,7 @@ const std::initializer_list<const StringID> _engine_sort_listing[] = {{
STR_SORT_BY_RELIABILITY,
STR_SORT_BY_CARGO_CAPACITY,
STR_SORT_BY_RANGE,
}};
}}};
/**
* Get the engine sorter names for a \c VehicleType
@@ -476,7 +484,7 @@ const std::initializer_list<const StringID> _engine_sort_listing[] = {{
std::span<StringID const> GetEngineSortNames(VehicleType vehicle_type)
{
assert(IsCompanyBuildableVehicleType(vehicle_type));
return _engine_sort_listing[to_underlying(vehicle_type)];
return _engine_sort_listing[vehicle_type];
}
/**
@@ -506,7 +514,7 @@ static uint GetCargoWeight(const CargoArray &cap, VehicleType vtype)
uint weight = 0;
for (CargoType cargo{}; cargo < NUM_CARGO; ++cargo) {
if (cap[cargo] != 0) {
if (vtype == VEH_TRAIN) {
if (vtype == VehicleType::Train) {
weight += CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
} else {
weight += CargoSpec::Get(cargo)->WeightOfNUnits(cap[cargo]);
@@ -545,7 +553,7 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
/* Wagon weight - (including cargo) */
uint weight = e->GetDisplayWeight();
DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VEH_TRAIN) + weight));
GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VehicleType::Train) + weight));
y += GetCharacterHeight(FontSize::Normal);
/* Wagon speed limit, displayed if above zero */
@@ -639,7 +647,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
/* Road vehicle weight - (including cargo) */
int16_t weight = e->GetDisplayWeight();
DrawString(left, right, y, GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VEH_ROAD) + weight));
DrawString(left, right, y, GetString(STR_PURCHASE_INFO_WEIGHT_CWEIGHT, weight, GetCargoWeight(te.all_capacities, VehicleType::Road) + weight));
y += GetCharacterHeight(FontSize::Normal);
/* Max speed - Engine power */
@@ -801,7 +809,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
void TestedEngineDetails::FillDefaultCapacities(const Engine *e)
{
this->cargo = e->GetDefaultCargoType();
if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
if (e->type == VehicleType::Train || e->type == VehicleType::Road) {
this->all_capacities = GetCapacityOfArticulatedParts(e->index);
this->capacity = this->all_capacities[this->cargo];
this->mail_capacity = 0;
@@ -833,7 +841,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
if (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->VehInfo<RailVehicleInfo>(), te);
} else {
@@ -842,16 +850,16 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
articulated_cargo = true;
break;
case VEH_ROAD:
case VehicleType::Road:
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
articulated_cargo = true;
break;
case VEH_SHIP:
case VehicleType::Ship:
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
break;
}
@@ -869,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 != VEH_TRAIN || e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON) {
if (e->type != VehicleType::Train || e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_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);
@@ -916,7 +924,7 @@ static void DrawEngineBadgeColumn(const Rect &r, int column_group, const GUIBadg
*/
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group, const GUIBadgeClasses &badge_classes, uint8_t sort_criteria)
{
static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
static const VehicleTypeIndexArray<int8_t> sprite_y_offsets = { 0, 0, -1, -1 };
auto [first, last] = sb.GetVisibleRangeIterators(eng_list);
@@ -1054,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 == VEH_ROAD || (type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON)) {
if (type == VehicleType::Road || (type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON)) {
auto max_te = e->GetDisplayMaxTractiveEffort();
if (max_te != 0) {
sort_prop_detail = GetString(STR_PURCHASE_SORT_DETAILS_MAX_TE, max_te);
@@ -1081,23 +1089,23 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
}
break;
case STR_SORT_BY_RELIABILITY:
if (auto isWagon = e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON; !isWagon) {
if (auto isWagon = e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON; !isWagon) {
sort_prop_detail = GetString(STR_PURCHASE_SORT_DETAILS_RELIABILITY, ToPercent16(e->reliability));
}
break;
case STR_SORT_BY_CARGO_CAPACITY: {
uint total_capacity;
switch (type) {
case VEH_TRAIN:
case VehicleType::Train:
total_capacity = GetTotalCapacityOfArticulatedParts(item.engine_id) * (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
break;
case VEH_ROAD:
case VehicleType::Road:
total_capacity = GetTotalCapacityOfArticulatedParts(item.engine_id);
break;
case VEH_SHIP:
case VehicleType::Ship:
total_capacity = e->GetDisplayDefaultCapacity();
break;
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
uint16_t mail_cap;
int aircraft_cap = e->GetDisplayDefaultCapacity(&mail_cap);
total_capacity = aircraft_cap + mail_cap;
@@ -1113,7 +1121,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
}
break;
case STR_SORT_BY_RANGE:
if (e->type == VEH_AIRCRAFT) {
if (e->type == VehicleType::Aircraft) {
if (uint16_t range = e->GetRange(); range != 0) {
sort_prop_detail = GetString(STR_PURCHASE_SORT_DETAILS_AIRCRAFT_RANGE, range);
}
@@ -1154,13 +1162,13 @@ void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selecte
{
uint32_t hidden_mask = 0;
/* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
if (vehicle_type == VehicleType::Road && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
SetBit(hidden_mask, 3); // power
SetBit(hidden_mask, 4); // tractive effort
SetBit(hidden_mask, 8); // power by running costs
}
/* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
if (vehicle_type == VEH_TRAIN && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
if (vehicle_type == VehicleType::Train && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
SetBit(hidden_mask, 4); // tractive effort
}
ShowDropDownMenu(w, GetEngineSortNames(vehicle_type), selected, button, 0, hidden_mask);
@@ -1206,7 +1214,7 @@ void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, Engi
/** GUI for building vehicles. */
struct BuildVehicleWindow : Window {
VehicleType vehicle_type = VEH_INVALID; ///< Type of vehicles shown in the window.
VehicleType vehicle_type = VehicleType::Invalid; ///< Type of vehicles shown in the window.
union {
RailType railtype; ///< Rail type to show, or #INVALID_RAILTYPE.
RoadType roadtype; ///< Road type to show, or #INVALID_ROADTYPE.
@@ -1240,9 +1248,9 @@ struct BuildVehicleWindow : Window {
if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria;
if (refit) {
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type);
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + to_underlying(this->vehicle_type), STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + to_underlying(this->vehicle_type));
} else {
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type, STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type);
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + to_underlying(this->vehicle_type), STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + to_underlying(this->vehicle_type));
}
}
@@ -1267,19 +1275,19 @@ struct BuildVehicleWindow : Window {
if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type);
widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + to_underlying(type));
widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type);
widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + to_underlying(type));
widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type, STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type);
widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + to_underlying(type), STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + to_underlying(type));
widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type);
widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + to_underlying(type), STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + to_underlying(type));
widget->SetLowered(this->show_hidden_engines);
this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
this->details_height = ((this->vehicle_type == VehicleType::Train) ? 10 : 9);
if (tile == INVALID_TILE) {
this->FinishInitNested(type);
@@ -1307,7 +1315,7 @@ struct BuildVehicleWindow : Window {
{
switch (this->vehicle_type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
if (this->listview_mode) {
this->filter.railtype = INVALID_RAILTYPE;
} else {
@@ -1315,7 +1323,7 @@ struct BuildVehicleWindow : Window {
}
break;
case VEH_ROAD:
case VehicleType::Road:
if (this->listview_mode) {
this->filter.roadtype = INVALID_ROADTYPE;
} else {
@@ -1326,8 +1334,8 @@ struct BuildVehicleWindow : Window {
}
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
break;
}
}
@@ -1453,13 +1461,13 @@ struct BuildVehicleWindow : Window {
* Also check to see if the previously selected engine is still available,
* and if not, reset selection to EngineID::Invalid(). This could be the case
* when engines become obsolete and are removed */
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (const Engine *e : Engine::IterateType(VehicleType::Train)) {
if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
EngineID eid = e->index;
const RailVehicleInfo *rvi = &e->VehInfo<RailVehicleInfo>();
if (this->filter.railtype != INVALID_RAILTYPE && !HasPowerOnRail(rvi->railtypes, this->filter.railtype)) continue;
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
if (!IsEngineBuildable(eid, VehicleType::Train, _local_company)) continue;
/* Filter now! So num_engines and num_wagons is valid */
if (!FilterSingleEngine(eid)) continue;
@@ -1518,10 +1526,10 @@ struct BuildVehicleWindow : Window {
BadgeTextFilter btf(this->string_filter, GrfSpecFeature::RoadVehicles);
BadgeDropdownFilter bdf(this->badge_filter_choices);
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
for (const Engine *e : Engine::IterateType(VehicleType::Road)) {
if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
if (!IsEngineBuildable(eid, VehicleType::Road, _local_company)) continue;
if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->VehInfo<RoadVehicleInfo>().roadtype, this->filter.roadtype)) continue;
if (!bdf.Filter(e->badges)) continue;
@@ -1544,10 +1552,10 @@ struct BuildVehicleWindow : Window {
BadgeTextFilter btf(this->string_filter, GrfSpecFeature::Ships);
BadgeDropdownFilter bdf(this->badge_filter_choices);
for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
for (const Engine *e : Engine::IterateType(VehicleType::Ship)) {
if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
if (!IsEngineBuildable(eid, VehicleType::Ship, _local_company)) continue;
if (!bdf.Filter(e->badges)) continue;
/* Filter by name or NewGRF extra text */
@@ -1576,10 +1584,10 @@ struct BuildVehicleWindow : Window {
* Also check to see if the previously selected plane is still available,
* and if not, reset selection to EngineID::Invalid(). This could be the case
* when planes become obsolete and are removed */
for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
for (const Engine *e : Engine::IterateType(VehicleType::Aircraft)) {
if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue;
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
if (!IsEngineBuildable(eid, VehicleType::Aircraft, _local_company)) continue;
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
if (!bdf.Filter(e->badges)) continue;
@@ -1609,18 +1617,18 @@ struct BuildVehicleWindow : Window {
switch (this->vehicle_type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
this->GenerateBuildTrainList(list);
GUIEngineListAddChildren(this->eng_list, list);
this->eng_list.RebuildDone();
return;
case VEH_ROAD:
case VehicleType::Road:
this->GenerateBuildRoadVehList();
break;
case VEH_SHIP:
case VehicleType::Ship:
this->GenerateBuildShipList();
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
this->GenerateBuildAircraftList();
break;
}
@@ -1658,7 +1666,7 @@ struct BuildVehicleWindow : Window {
/* Add item for disabling filtering. */
list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY));
/* Specific filters for trains. */
if (this->vehicle_type == VEH_TRAIN) {
if (this->vehicle_type == VehicleType::Train) {
/* Add item for locomotives only in case of trains. */
list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES));
/* Add item for vehicles not carrying anything, e.g. train engines.
@@ -1688,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 == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
if (this->vehicle_type == VehicleType::Train && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
Command<Commands::BuildVehicle>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
} else {
Command<Commands::BuildVehicle>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, TileIndex(this->window_number), sel_eng, true, cargo, INVALID_CLIENT_ID);
@@ -1787,7 +1795,7 @@ struct BuildVehicleWindow : Window {
EngineID sel_eng = this->sel_engine;
if (sel_eng != EngineID::Invalid()) {
this->rename_engine = sel_eng;
ShowQueryString(GetString(STR_ENGINE_NAME, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)), STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
ShowQueryString(GetString(STR_ENGINE_NAME, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)), STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + to_underlying(this->vehicle_type), MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
}
break;
}
@@ -1810,11 +1818,11 @@ struct BuildVehicleWindow : Window {
{
if (!gui_scope) return;
/* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
if (this->vehicle_type == VEH_ROAD &&
if (this->vehicle_type == VehicleType::Road &&
_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL &&
this->sort_criteria > 7) {
this->sort_criteria = 0;
_engine_sort_last_criteria[VEH_ROAD] = 0;
_engine_sort_last_criteria[VehicleType::Road] = 0;
}
this->eng_list.ForceRebuild();
}
@@ -1823,15 +1831,15 @@ struct BuildVehicleWindow : Window {
{
switch (widget) {
case WID_BV_CAPTION:
if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
if (this->vehicle_type == VehicleType::Train && !this->listview_mode) {
const RailTypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
return GetString(rti->strings.build_caption);
}
if (this->vehicle_type == VEH_ROAD && !this->listview_mode) {
if (this->vehicle_type == VehicleType::Road && !this->listview_mode) {
const RoadTypeInfo *rti = GetRoadTypeInfo(this->filter.roadtype);
return GetString(rti->strings.build_caption);
}
return GetString((this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
return GetString((this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + to_underlying(this->vehicle_type));
case WID_BV_SORT_DROPDOWN:
return GetString(GetEngineSortNames(this->vehicle_type)[this->sort_criteria]);
@@ -1842,9 +1850,9 @@ struct BuildVehicleWindow : Window {
case WID_BV_SHOW_HIDE: {
const Engine *e = (this->sel_engine == EngineID::Invalid()) ? nullptr : Engine::Get(this->sel_engine);
if (e != nullptr && e->IsHidden(_local_company)) {
return GetString(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
return GetString(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + to_underlying(this->vehicle_type));
}
return GetString(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
return GetString(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + to_underlying(this->vehicle_type));
}
default:
@@ -1887,15 +1895,15 @@ struct BuildVehicleWindow : Window {
break;
case WID_BV_BUILD:
size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + to_underlying(this->vehicle_type));
size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + to_underlying(this->vehicle_type)));
size.width += padding.width;
size.height += padding.height;
break;
case WID_BV_SHOW_HIDE:
size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + to_underlying(this->vehicle_type));
size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + to_underlying(this->vehicle_type)));
size.width += padding.width;
size.height += padding.height;
break;
@@ -1958,7 +1966,7 @@ struct BuildVehicleWindow : Window {
{
if (!str.has_value()) return;
Command<Commands::RenameEngine>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str);
Command<Commands::RenameEngine>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + to_underlying(this->vehicle_type), this->rename_engine, *str);
}
void OnDropdownSelect(WidgetID widget, int index, int click_result) override
+8 -8
View File
@@ -91,11 +91,11 @@ void CheckCaches()
grf_cache.emplace_back(u->grf_cache);
veh_cache.emplace_back(u->vcache);
switch (u->type) {
case VEH_TRAIN:
case VehicleType::Train:
gro_cache.emplace_back(Train::From(u)->gcache);
tra_cache.emplace_back(Train::From(u)->tcache);
break;
case VEH_ROAD:
case VehicleType::Road:
gro_cache.emplace_back(RoadVehicle::From(u)->gcache);
break;
default:
@@ -104,10 +104,10 @@ void CheckCaches()
}
switch (v->type) {
case VEH_TRAIN: Train::From(v)->ConsistChanged(CCF_TRACK); break;
case VEH_ROAD: RoadVehUpdateCache(RoadVehicle::From(v)); break;
case VEH_AIRCRAFT: UpdateAircraftCache(Aircraft::From(v)); break;
case VEH_SHIP: Ship::From(v)->UpdateCache(); break;
case VehicleType::Train: Train::From(v)->ConsistChanged(CCF_TRACK); break;
case VehicleType::Road: RoadVehUpdateCache(RoadVehicle::From(v)); break;
case VehicleType::Aircraft: UpdateAircraftCache(Aircraft::From(v)); break;
case VehicleType::Ship: Ship::From(v)->UpdateCache(); break;
default: break;
}
@@ -121,7 +121,7 @@ void CheckCaches()
Debug(desync, 2, "warning: vehicle cache mismatch: type {}, vehicle {}, company {}, unit number {}, wagon {}", v->type, v->index, v->owner, v->unitnumber, length);
}
switch (u->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (gro_cache[length] != Train::From(u)->gcache) {
Debug(desync, 2, "warning: train ground vehicle cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
}
@@ -129,7 +129,7 @@ void CheckCaches()
Debug(desync, 2, "warning: train cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
}
break;
case VEH_ROAD:
case VehicleType::Road:
if (gro_cache[length] != RoadVehicle::From(u)->gcache) {
Debug(desync, 2, "warning: road vehicle ground vehicle cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
}
+3 -3
View File
@@ -139,12 +139,12 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
class AIInfo *ai_info = nullptr;
std::unique_ptr<class AIConfig> ai_config{};
std::array<GroupStatistics, VEH_COMPANY_END> group_all{}; ///< NOSAVE: Statistics for the ALL_GROUP group.
std::array<GroupStatistics, VEH_COMPANY_END> group_default{}; ///< NOSAVE: Statistics for the DEFAULT_GROUP group.
VehicleTypeIndexArray<GroupStatistics> group_all{}; ///< NOSAVE: Statistics for the ALL_GROUP group.
VehicleTypeIndexArray<GroupStatistics> group_default{}; ///< NOSAVE: Statistics for the DEFAULT_GROUP group.
CompanyInfrastructure infrastructure{}; ///< NOSAVE: Counts of company owned infrastructure.
std::array<FreeUnitIDGenerator, VEH_COMPANY_END> freeunits{};
VehicleTypeIndexArray<FreeUnitIDGenerator> freeunits{};
FreeUnitIDGenerator freegroups{};
Money GetMaxLoan() const;
+8 -8
View File
@@ -683,10 +683,10 @@ bool CheckTakeoverVehicleLimit(CompanyID cbig, CompanyID csmall)
const Company *c2 = Company::Get(csmall);
/* Do the combined vehicle counts stay within the limits? */
return c1->group_all[VEH_TRAIN].num_vehicle + c2->group_all[VEH_TRAIN].num_vehicle <= _settings_game.vehicle.max_trains &&
c1->group_all[VEH_ROAD].num_vehicle + c2->group_all[VEH_ROAD].num_vehicle <= _settings_game.vehicle.max_roadveh &&
c1->group_all[VEH_SHIP].num_vehicle + c2->group_all[VEH_SHIP].num_vehicle <= _settings_game.vehicle.max_ships &&
c1->group_all[VEH_AIRCRAFT].num_vehicle + c2->group_all[VEH_AIRCRAFT].num_vehicle <= _settings_game.vehicle.max_aircraft;
return c1->group_all[VehicleType::Train].num_vehicle + c2->group_all[VehicleType::Train].num_vehicle <= _settings_game.vehicle.max_trains &&
c1->group_all[VehicleType::Road].num_vehicle + c2->group_all[VehicleType::Road].num_vehicle <= _settings_game.vehicle.max_roadveh &&
c1->group_all[VehicleType::Ship].num_vehicle + c2->group_all[VehicleType::Ship].num_vehicle <= _settings_game.vehicle.max_ships &&
c1->group_all[VehicleType::Aircraft].num_vehicle + c2->group_all[VehicleType::Aircraft].num_vehicle <= _settings_game.vehicle.max_aircraft;
}
/**
@@ -1285,10 +1285,10 @@ int CompanyServiceInterval(const Company *c, VehicleType type)
const VehicleDefaultSettings *vds = (c == nullptr) ? &_settings_client.company.vehicle : &c->settings.vehicle;
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: return vds->servint_trains;
case VEH_ROAD: return vds->servint_roadveh;
case VEH_AIRCRAFT: return vds->servint_aircraft;
case VEH_SHIP: return vds->servint_ships;
case VehicleType::Train: return vds->servint_trains;
case VehicleType::Road: return vds->servint_roadveh;
case VehicleType::Aircraft: return vds->servint_aircraft;
case VehicleType::Ship: return vds->servint_ships;
}
}
+7 -9
View File
@@ -743,10 +743,10 @@ public:
this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
const Group *g = Group::Get(group);
switch (g->vehicle_type) {
case VEH_TRAIN: this->livery_class = LC_GROUP_RAIL; break;
case VEH_ROAD: this->livery_class = LC_GROUP_ROAD; break;
case VEH_SHIP: this->livery_class = LC_GROUP_SHIP; break;
case VEH_AIRCRAFT: this->livery_class = LC_GROUP_AIRCRAFT; break;
case VehicleType::Train: this->livery_class = LC_GROUP_RAIL; break;
case VehicleType::Road: this->livery_class = LC_GROUP_ROAD; break;
case VehicleType::Ship: this->livery_class = LC_GROUP_SHIP; break;
case VehicleType::Aircraft: this->livery_class = LC_GROUP_AIRCRAFT; break;
default: NOT_REACHED();
}
this->sel = group.base();
@@ -925,7 +925,7 @@ public:
}
if (this->vscroll->GetCount() == 0) {
const StringID empty_labels[] = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
constexpr VehicleTypeIndexArray<const StringID> empty_labels = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
DrawString(ir.left, ir.right, y + text_offs, empty_labels[vtype], TC_BLACK);
}
@@ -1942,7 +1942,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_company_widgets = {
};
/** Strings for the company vehicle counts */
static const StringID _company_view_vehicle_count_strings[] = {
static constexpr VehicleTypeIndexArray<const StringID> _company_view_vehicle_count_strings = {
STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
};
@@ -2073,10 +2073,8 @@ struct CompanyWindow : Window
void DrawVehicleCountsWidget(const Rect &r, const Company *c) const
{
static_assert(VEH_COMPANY_END == lengthof(_company_view_vehicle_count_strings));
int y = r.top;
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type < VehicleType::CompanyEnd; type++) {
uint amount = c->group_all[type].num_vehicle;
if (amount != 0) {
DrawString(r.left, r.right, y, GetString(_company_view_vehicle_count_strings[type], amount));
+4 -4
View File
@@ -2026,10 +2026,10 @@ static bool ConCompanies(std::span<std::string_view> argv)
IConsolePrint(CC_INFO, "#:{}({}) Company Name: '{}' Year Founded: {} Money: {} Loan: {} Value: {} (T:{}, R:{}, P:{}, S:{}) {}",
c->index + 1, colour, company_name,
c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)CalculateCompanyValue(c),
c->group_all[VEH_TRAIN].num_vehicle,
c->group_all[VEH_ROAD].num_vehicle,
c->group_all[VEH_AIRCRAFT].num_vehicle,
c->group_all[VEH_SHIP].num_vehicle,
c->group_all[VehicleType::Train].num_vehicle,
c->group_all[VehicleType::Road].num_vehicle,
c->group_all[VehicleType::Aircraft].num_vehicle,
c->group_all[VehicleType::Ship].num_vehicle,
c->is_ai ? "AI" : "");
}
+67 -67
View File
@@ -152,8 +152,8 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh
Command<Commands::MoveRailVehicle>::Post(STR_ERROR_CAN_T_MOVE_VEHICLE, v->tile, v->index, wagon == nullptr ? VehicleID::Invalid() : wagon->index, _ctrl_pressed);
}
static VehicleCellSize _base_block_sizes_depot[VEH_COMPANY_END]; ///< Cell size for vehicle images in the depot view.
static VehicleCellSize _base_block_sizes_purchase[VEH_COMPANY_END]; ///< Cell size for vehicle images in the purchase list.
static VehicleTypeIndexArray<VehicleCellSize> _base_block_sizes_depot; ///< Cell size for vehicle images in the depot view.
static VehicleTypeIndexArray<VehicleCellSize> _base_block_sizes_purchase; ///< Cell size for vehicle images in the purchase list.
static uint _consistent_train_width; ///< Whether trains of all lengths are consistently scaled. Either TRAININFO_DEFAULT_VEHICLE_WIDTH, VEHICLEINFO_FULL_VEHICLE_WIDTH, or 0.
/**
@@ -187,10 +187,10 @@ static void InitBlocksizeForVehicles(VehicleType type, EngineImageType image_typ
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: GetTrainSpriteSize( eid, x, y, x_offs, y_offs, image_type); break;
case VEH_ROAD: GetRoadVehSpriteSize( eid, x, y, x_offs, y_offs, image_type); break;
case VEH_SHIP: GetShipSpriteSize( eid, x, y, x_offs, y_offs, image_type); break;
case VEH_AIRCRAFT: GetAircraftSpriteSize(eid, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Train: GetTrainSpriteSize(eid, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Road: GetRoadVehSpriteSize(eid, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Ship: GetShipSpriteSize(eid, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Aircraft: GetAircraftSpriteSize(eid, x, y, x_offs, y_offs, image_type); break;
}
if (y > max_height) max_height = y;
if (-x_offs > max_extend_left) max_extend_left = -x_offs;
@@ -222,14 +222,14 @@ static void InitBlocksizeForVehicles(VehicleType type, EngineImageType image_typ
*/
void InitDepotWindowBlockSizes()
{
for (VehicleType vt = VEH_BEGIN; vt < VEH_COMPANY_END; vt++) {
for (VehicleType vt = VehicleType::Begin; vt < VehicleType::CompanyEnd; vt++) {
InitBlocksizeForVehicles(vt, EIT_IN_DEPOT);
InitBlocksizeForVehicles(vt, EIT_PURCHASE);
}
_consistent_train_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
bool first = true;
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (const Engine *e : Engine::IterateType(VehicleType::Train)) {
if (!e->IsEnabled()) continue;
uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH;
@@ -261,7 +261,7 @@ const Sprite *GetAircraftSprite(EngineID engine);
struct DepotWindow : Window {
VehicleID sel = VehicleID::Invalid();
VehicleID vehicle_over = VehicleID::Invalid(); ///< Rail vehicle over which another one is dragged, \c VehicleID::Invalid() if none.
VehicleType type = VEH_INVALID;
VehicleType type = VehicleType::Invalid;
bool generate_list = true;
bool check_unitnumber_digits = true;
WidgetID hovered_widget = INVALID_WIDGET; ///< Index of the widget being hovered during drag/drop. \c INVALID_WIDGET if no drag is in progress.
@@ -284,14 +284,14 @@ struct DepotWindow : Window {
this->type = type;
this->CreateNestedTree();
this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : nullptr);
this->hscroll = (this->type == VehicleType::Train ? this->GetScrollbar(WID_D_H_SCROLL) : nullptr);
this->vscroll = this->GetScrollbar(WID_D_V_SCROLL);
/* Don't show 'rename button' of aircraft hangar */
this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VehicleType::Aircraft ? SZSP_NONE : 0);
/* Only train depots have a horizontal scrollbar and a 'sell chain' button */
if (type == VEH_TRAIN) this->GetWidget<NWidgetCore>(WID_D_MATRIX)->SetMatrixDimension(1, 0 /* auto-scale */);
this->GetWidget<NWidgetStacked>(WID_D_SHOW_H_SCROLL)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_HORIZONTAL);
this->GetWidget<NWidgetStacked>(WID_D_SHOW_SELL_CHAIN)->SetDisplayedPlane(type == VEH_TRAIN ? 0 : SZSP_NONE);
if (type == VehicleType::Train) this->GetWidget<NWidgetCore>(WID_D_MATRIX)->SetMatrixDimension(1, 0 /* auto-scale */);
this->GetWidget<NWidgetStacked>(WID_D_SHOW_H_SCROLL)->SetDisplayedPlane(type == VehicleType::Train ? 0 : SZSP_HORIZONTAL);
this->GetWidget<NWidgetStacked>(WID_D_SHOW_SELL_CHAIN)->SetDisplayedPlane(type == VehicleType::Train ? 0 : SZSP_NONE);
this->SetupWidgetData(type);
this->FinishInitNested(tile);
@@ -350,7 +350,7 @@ struct DepotWindow : Window {
Rect image = r.Indent(this->header_width, rtl).Indent(this->count_width, !rtl); /* Rect for vehicle images */
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
const Train *u = Train::From(v);
free_wagon = u->IsFreeWagon();
@@ -369,9 +369,9 @@ struct DepotWindow : Window {
break;
}
case VEH_ROAD: DrawRoadVehImage( v, image, this->sel, EIT_IN_DEPOT); break;
case VEH_SHIP: DrawShipImage( v, image, this->sel, EIT_IN_DEPOT); break;
case VEH_AIRCRAFT: DrawAircraftImage(v, image, this->sel, EIT_IN_DEPOT); break;
case VehicleType::Road: DrawRoadVehImage(v, image, this->sel, EIT_IN_DEPOT); break;
case VehicleType::Ship: DrawShipImage(v, image, this->sel, EIT_IN_DEPOT); break;
case VehicleType::Aircraft: DrawAircraftImage(v, image, this->sel, EIT_IN_DEPOT); break;
default: NOT_REACHED();
}
@@ -416,7 +416,7 @@ struct DepotWindow : Window {
* - All vehicles use VEHICLEINFO_FULL_VEHICLE_WIDTH as reference width.
* - All vehicles are 8/8. This cannot be checked for NewGRF, so instead we check for "all vehicles are original vehicles".
*/
if (this->type == VEH_TRAIN && _consistent_train_width != 0) {
if (this->type == VehicleType::Train && _consistent_train_width != 0) {
int w = ScaleSpriteTrad(2 * _consistent_train_width);
PixelColour col = GetColourGradient(wid->colour, SHADE_NORMAL);
Rect image = ir.Indent(this->header_width, rtl).Indent(this->count_width, !rtl);
@@ -494,7 +494,7 @@ struct DepotWindow : Window {
if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
uint xt = 0, xm = 0, ym = 0;
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
xm = x;
} else {
xt = x / this->resize.step_width;
@@ -508,7 +508,7 @@ struct DepotWindow : Window {
if (row == INT32_MAX || this->vehicle_list.size() + this->wagon_list.size() <= pos) {
/* Clicking on 'line' / 'block' without a vehicle */
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
/* End the dragging */
return {.action = DepotGUIAction::DragVehicle};
} else {
@@ -521,7 +521,7 @@ struct DepotWindow : Window {
if (this->vehicle_list.size() > pos) {
vehicle = this->vehicle_list[pos];
/* Skip vehicles that are scrolled off the list */
if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
if (this->type == VehicleType::Train) x += this->hscroll->GetPosition();
} else {
pos -= (uint)this->vehicle_list.size();
vehicle = this->wagon_list[pos];
@@ -532,16 +532,16 @@ struct DepotWindow : Window {
if (xm <= this->header_width) {
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (is_wagon) return {.action = DepotGUIAction::Error};
[[fallthrough]];
case VEH_ROAD:
case VehicleType::Road:
if (xm <= this->flag_size.width) return {.action = DepotGUIAction::StartStop, .vehicle = vehicle};
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
if (xm <= this->flag_size.width && ym >= (uint)(GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal)) return {.action = DepotGUIAction::StartStop, .vehicle = vehicle};
break;
@@ -550,7 +550,7 @@ struct DepotWindow : Window {
return {.action = DepotGUIAction::ShowVehicle, .vehicle = vehicle};
}
if (this->type != VEH_TRAIN) return {.action = DepotGUIAction::DragVehicle, .vehicle = vehicle};
if (this->type != VehicleType::Train) return {.action = DepotGUIAction::DragVehicle, .vehicle = vehicle};
/* Clicking on the counter */
if (xm >= matrix_widget->current_x - this->count_width) {
@@ -584,13 +584,13 @@ struct DepotWindow : Window {
return;
case DepotGUIAction::DragVehicle: { // start dragging of vehicle
const Vehicle *v = (this->type == VEH_TRAIN) ? result.wagon : result.vehicle;
const Vehicle *v = (this->type == VehicleType::Train) ? result.wagon : result.vehicle;
if (v != nullptr && VehicleClicked(v)) return;
VehicleID sel = this->sel;
if (this->type == VEH_TRAIN && sel != VehicleID::Invalid()) {
if (this->type == VehicleType::Train && sel != VehicleID::Invalid()) {
this->sel = VehicleID::Invalid();
TrainDepotMoveVehicle(v, sel, result.vehicle);
} else if (v != nullptr) {
@@ -625,23 +625,23 @@ struct DepotWindow : Window {
*/
void SetupWidgetData(VehicleType type)
{
this->GetWidget<NWidgetCore>(WID_D_STOP_ALL)->SetToolTip(STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_START_ALL)->SetToolTip(STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetToolTip(STR_DEPOT_TRAIN_SELL_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetToolTip(STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_STOP_ALL)->SetToolTip(STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_START_ALL)->SetToolTip(STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetToolTip(STR_DEPOT_TRAIN_SELL_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetToolTip(STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_BUILD)->SetStringTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_CLONE)->SetStringTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_BUILD)->SetStringTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + to_underlying(type), STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_CLONE)->SetStringTip(STR_DEPOT_CLONE_TRAIN + to_underlying(type), STR_DEPOT_CLONE_TRAIN_DEPOT_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_LOCATION)->SetToolTip(STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetToolTip(STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetToolTip(STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type);
this->GetWidget<NWidgetCore>(WID_D_MATRIX)->SetToolTip(STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type);
this->GetWidget<NWidgetCore>(WID_D_LOCATION)->SetToolTip(STR_DEPOT_TRAIN_LOCATION_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetToolTip(STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetToolTip(STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + to_underlying(type));
this->GetWidget<NWidgetCore>(WID_D_MATRIX)->SetToolTip(STR_DEPOT_TRAIN_LIST_TOOLTIP + to_underlying(type));
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetString(STR_TRAIN);
/* Sprites */
@@ -650,7 +650,7 @@ struct DepotWindow : Window {
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_TRAIN);
break;
case VEH_ROAD:
case VehicleType::Road:
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetString(STR_LORRY);
/* Sprites */
@@ -659,7 +659,7 @@ struct DepotWindow : Window {
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_ROADVEH);
break;
case VEH_SHIP:
case VehicleType::Ship:
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetString(STR_SHIP);
/* Sprites */
@@ -668,7 +668,7 @@ struct DepotWindow : Window {
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_SHIP);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->SetString(STR_PLANE);
/* Sprites */
@@ -691,7 +691,7 @@ struct DepotWindow : Window {
case WID_D_MATRIX: {
uint min_height = 0;
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
this->count_width = GetStringBoundingBox(GetString(STR_JUST_DECIMAL, GetParamMaxValue(1000, 0, FontSize::Small), 1), FontSize::Small).width + WidgetDimensions::scaled.hsep_normal;
} else {
this->count_width = 0;
@@ -699,7 +699,7 @@ struct DepotWindow : Window {
Dimension unumber = GetStringBoundingBox(GetString(STR_JUST_COMMA, GetParamMaxDigits(this->unitnumber_digits)));
if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
if (this->type == VehicleType::Train || this->type == VehicleType::Road) {
min_height = std::max<uint>(unumber.height, this->flag_size.height);
this->header_width = unumber.width + WidgetDimensions::scaled.hsep_normal + this->flag_size.width + WidgetDimensions::scaled.hsep_normal;
} else {
@@ -709,14 +709,14 @@ struct DepotWindow : Window {
int base_width = this->count_width + this->header_width + padding.width;
resize.height = std::max<uint>(this->cell_size.height, min_height + padding.height);
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
resize.width = 1;
size.width = base_width + 2 * ScaleSpriteTrad(29); // about 2 parts
size.height = resize.height * 6;
} else {
resize.width = base_width + this->cell_size.extend_left + this->cell_size.extend_right;
size.width = resize.width * (this->type == VEH_ROAD ? 5 : 3);
size.height = resize.height * (this->type == VEH_ROAD ? 5 : 3);
size.width = resize.width * (this->type == VehicleType::Road ? 5 : 3);
size.height = resize.height * (this->type == VehicleType::Road ? 5 : 3);
}
fill.width = resize.width;
fill.height = resize.height;
@@ -763,7 +763,7 @@ struct DepotWindow : Window {
}
/* determine amount of items for scroller */
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
uint max_width = ScaleSpriteTrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
for (uint num = 0; num < this->vehicle_list.size(); num++) {
uint width = 0;
@@ -813,7 +813,7 @@ struct DepotWindow : Window {
this->ToggleWidgetLoweredState(WID_D_CLONE);
if (this->IsWidgetLowered(WID_D_CLONE)) {
static const CursorID clone_icons[] = {
static constexpr VehicleTypeIndexArray<const CursorID> clone_icons = {
SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
};
@@ -881,13 +881,13 @@ struct DepotWindow : Window {
if (widget != WID_D_MATRIX) return false;
DepotActionResult result = this->GetVehicleFromDepotWndPt(pt.x, pt.y);
const Vehicle *v = this->type == VEH_TRAIN ? result.wagon : result.vehicle;
const Vehicle *v = this->type == VehicleType::Train ? result.wagon : result.vehicle;
if (result.action != DepotGUIAction::DragVehicle || v == nullptr) return false;
CargoArray capacity{}, loaded{};
/* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
bool whole_chain = (this->type == VehicleType::Train && _ctrl_pressed);
/* loop through vehicle chain and collect cargoes */
uint num = 0;
@@ -897,7 +897,7 @@ struct DepotWindow : Window {
loaded [w->cargo_type] += w->cargo.StoredCount();
}
if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) {
if (w->type == VehicleType::Train && !w->HasArticulatedPart()) {
num++;
if (!whole_chain) break;
}
@@ -934,10 +934,10 @@ struct DepotWindow : Window {
{
if (_ctrl_pressed) {
/* Share-clone, do not open new viewport, and keep tool active */
Command<Commands::CloneVehicle>::Post(STR_ERROR_CAN_T_BUY_TRAIN + v->type, TileIndex(this->window_number), v->index, true);
Command<Commands::CloneVehicle>::Post(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying(v->type), TileIndex(this->window_number), v->index, true);
} else {
/* Copy-clone, open viewport for new vehicle, and deselect the tool (assume player wants to change things on new vehicle) */
if (Command<Commands::CloneVehicle>::Post(STR_ERROR_CAN_T_BUY_TRAIN + v->type, CcCloneVehicle, TileIndex(this->window_number), v->index, false)) {
if (Command<Commands::CloneVehicle>::Post(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying(v->type), CcCloneVehicle, TileIndex(this->window_number), v->index, false)) {
ResetObjectToPlace();
}
}
@@ -965,11 +965,11 @@ struct DepotWindow : Window {
})) {
OnVehicleSelect(*begin);
} else {
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + (*begin)->type),
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying((*begin)->type)),
GetEncodedString(STR_ERROR_CAN_T_COPY_ORDER_VEHICLE_LIST), WL_INFO);
}
} else {
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + (*begin)->type),
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying((*begin)->type)),
GetEncodedString(STR_ERROR_CAN_T_CLONE_VEHICLE_LIST), WL_INFO);
}
} else {
@@ -982,11 +982,11 @@ struct DepotWindow : Window {
})) {
OnVehicleSelect(*begin);
} else {
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + (*begin)->type),
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying((*begin)->type)),
GetEncodedString(STR_ERROR_CAN_T_SHARE_ORDER_VEHICLE_LIST), WL_INFO);
}
} else {
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + (*begin)->type),
ShowErrorMessage(GetEncodedString(STR_ERROR_CAN_T_BUY_TRAIN + to_underlying((*begin)->type)),
GetEncodedString(STR_ERROR_CAN_T_CLONE_VEHICLE_LIST), WL_INFO);
}
}
@@ -1034,7 +1034,7 @@ struct DepotWindow : Window {
this->SetWidgetDirty(this->hovered_widget);
}
}
if (this->type != VEH_TRAIN) return;
if (this->type != VehicleType::Train) return;
/* A rail vehicle is dragged.. */
if (widget != WID_D_MATRIX) { // ..outside of the depot matrix.
@@ -1079,7 +1079,7 @@ struct DepotWindow : Window {
this->sel = VehicleID::Invalid();
this->SetDirty();
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
if (result.action == DepotGUIAction::DragVehicle && sel != VehicleID::Invalid()) {
if (result.wagon != nullptr && result.wagon->index == sel && _ctrl_pressed) {
Command<Commands::ReverseTrainDirection>::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true);
@@ -1106,7 +1106,7 @@ struct DepotWindow : Window {
this->sel = VehicleID::Invalid();
this->SetDirty();
bool sell_cmd = (v->type == VEH_TRAIN && (widget == WID_D_SELL_CHAIN || _ctrl_pressed));
bool sell_cmd = (v->type == VehicleType::Train && (widget == WID_D_SELL_CHAIN || _ctrl_pressed));
Command<Commands::SellVehicle>::Post(GetCmdSellVehMsg(v->type), v->tile, v->index, sell_cmd, true, INVALID_CLIENT_ID);
break;
}
@@ -1136,7 +1136,7 @@ struct DepotWindow : Window {
{
this->vscroll->SetCapacityFromWidget(this, WID_D_MATRIX);
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
this->hscroll->SetCapacity(nwi->current_x - this->header_width - this->count_width);
} else {
this->num_columns = nwi->current_x / nwi->resize_x;
@@ -1186,10 +1186,10 @@ void ShowDepotWindow(TileIndex tile, VehicleType type)
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: new DepotWindow(_train_depot_desc, tile, type); break;
case VEH_ROAD: new DepotWindow(_road_depot_desc, tile, type); break;
case VEH_SHIP: new DepotWindow(_ship_depot_desc, tile, type); break;
case VEH_AIRCRAFT: new DepotWindow(_aircraft_depot_desc, tile, type); break;
case VehicleType::Train: new DepotWindow(_train_depot_desc, tile, type); break;
case VehicleType::Road: new DepotWindow(_road_depot_desc, tile, type); break;
case VehicleType::Ship: new DepotWindow(_ship_depot_desc, tile, type); break;
case VehicleType::Aircraft: new DepotWindow(_aircraft_depot_desc, tile, type); break;
}
}
+4 -4
View File
@@ -82,10 +82,10 @@ inline VehicleType GetDepotVehicleType(Tile t)
{
switch (GetTileType(t)) {
default: NOT_REACHED();
case TileType::Railway: return VEH_TRAIN;
case TileType::Road: return VEH_ROAD;
case TileType::Water: return VEH_SHIP;
case TileType::Station: return VEH_AIRCRAFT;
case TileType::Railway: return VehicleType::Train;
case TileType::Road: return VehicleType::Road;
case TileType::Water: return VehicleType::Ship;
case TileType::Station: return VehicleType::Aircraft;
}
}
+3 -3
View File
@@ -338,7 +338,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *ufo)
uint n = 0; // Total number of targetable road vehicles.
for (const Company *c : Company::Iterate()) {
n += c->group_all[VEH_ROAD].num_vehicle;
n += c->group_all[VehicleType::Road].num_vehicle;
}
if (n == 0) {
@@ -368,7 +368,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *ufo)
} else {
/* Target a vehicle */
RoadVehicle *target = RoadVehicle::Get(ufo->dest_tile.base());
assert(target != nullptr && target->type == VEH_ROAD && target->IsFrontEngine());
assert(target != nullptr && target->type == VehicleType::Road && target->IsFrontEngine());
uint dist = Delta(ufo->x_pos, target->x_pos) + Delta(ufo->y_pos, target->y_pos);
@@ -1003,7 +1003,7 @@ void ReleaseDisasterVehicle(VehicleID vehicle)
if (v == nullptr) return;
/* primary disaster vehicles that have chosen target */
assert(v->type == VEH_DISASTER);
assert(v->type == VehicleType::Disaster);
assert(v->subtype == ST_SMALL_UFO);
assert(v->state != 0);
+1 -1
View File
@@ -35,7 +35,7 @@ enum DisasterSubType : uint8_t {
/**
* Disasters, like submarines, skyrangers and their shadows, belong to this class.
*/
struct DisasterVehicle final : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER> {
struct DisasterVehicle final : public SpecializedVehicle<DisasterVehicle, VehicleType::Disaster> {
SpriteID image_override{}; ///< Override for the default disaster vehicle sprite.
VehicleID big_ufo_destroyer_target = VehicleID::Invalid(); ///< The big UFO that this destroyer is supposed to bomb.
VehicleAirFlags flags{}; ///< Flags about the state of the vehicle, @see VehicleAirFlags
+1 -1
View File
@@ -123,7 +123,7 @@ struct BuildDocksToolbarWindow : Window {
{
if (!gui_scope) return;
bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP);
bool can_build = CanBuildVehicleInfrastructure(VehicleType::Ship);
this->SetWidgetsDisabledState(!can_build,
WID_DT_DEPOT,
WID_DT_STATION,
+19 -19
View File
@@ -127,10 +127,10 @@ static Money CalculateCompanyAssetValue(const Company *c)
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->owner != owner) continue;
if (v->type == VEH_TRAIN ||
v->type == VEH_ROAD ||
(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft()) ||
v->type == VEH_SHIP) {
if (v->type == VehicleType::Train ||
v->type == VehicleType::Road ||
(v->type == VehicleType::Aircraft && Aircraft::From(v)->IsNormalAircraft()) ||
v->type == VehicleType::Ship) {
value += v->value * 3 >> 1;
}
}
@@ -1300,7 +1300,7 @@ static uint GetLoadAmount(Vehicle *v)
uint load_amount = e->info.load_amount;
/* The default loadamount for mail is 1/4 of the load amount for passengers */
bool air_mail = v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft();
bool air_mail = v->type == VehicleType::Aircraft && !Aircraft::From(v)->IsNormalAircraft();
if (air_mail) load_amount = CeilDiv(load_amount, 4);
if (_settings_game.order.gradual_loading) {
@@ -1344,12 +1344,12 @@ bool IterateVehicleParts(Vehicle *v, Taction action)
for (Vehicle *w = v; w != nullptr;
w = w->HasArticulatedPart() ? w->GetNextArticulatedPart() : nullptr) {
if (!action(w)) return false;
if (w->type == VEH_TRAIN) {
if (w->type == VehicleType::Train) {
Train *train = Train::From(w);
if (train->IsMultiheaded() && !action(train->other_multiheaded_part)) return false;
}
}
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft()) return action(v->Next());
if (v->type == VehicleType::Aircraft && Aircraft::From(v)->IsNormalAircraft()) return action(v->Next());
return true;
}
@@ -1576,8 +1576,8 @@ static void ReserveConsist(Station *st, Vehicle *u, CargoArray *consist_capleft,
* "articulated chain". Also don't do the reservation if the vehicle is going to refit
* to a different cargo and hasn't tried to do so, yet. */
if (!v->IsArticulatedPart() &&
(v->type != VEH_TRAIN || !Train::From(v)->IsRearDualheaded()) &&
(v->type != VEH_AIRCRAFT || Aircraft::From(v)->IsNormalAircraft()) &&
(v->type != VehicleType::Train || !Train::From(v)->IsRearDualheaded()) &&
(v->type != VehicleType::Aircraft || Aircraft::From(v)->IsNormalAircraft()) &&
(must_reserve || u->current_order.GetRefitCargo() == v->cargo_type)) {
IterateVehicleParts(v, ReserveCargoAction(st, next_station));
}
@@ -1595,7 +1595,7 @@ static void ReserveConsist(Station *st, Vehicle *u, CargoArray *consist_capleft,
*/
static void UpdateLoadUnloadTicks(Vehicle *front, const Station *st, int ticks)
{
if (front->type == VEH_TRAIN && _settings_game.order.station_length_loading_penalty) {
if (front->type == VehicleType::Train && _settings_game.order.station_length_loading_penalty) {
/* Each platform tile is worth 2 rail vehicles. */
int overhang = front->GetGroundVehicleCache()->cached_total_length - st->GetPlatformLength(front->GetMovingFront()->tile) * TILE_SIZE;
if (overhang > 0) {
@@ -1633,7 +1633,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->load_unload_ticks != 0) return;
const Vehicle *moving_front = front->GetMovingFront();
if (front->type == VEH_TRAIN && (!IsTileType(moving_front->tile, TileType::Station) || GetStationIndex(moving_front->tile) != st->index)) {
if (front->type == VehicleType::Train && (!IsTileType(moving_front->tile, TileType::Station) || GetStationIndex(moving_front->tile) != st->index)) {
/* The train reversed in the station. Take the "easy" way
* out and let the train just leave as it always did. */
front->vehicle_flags.Set(VehicleFlag::LoadingFinished);
@@ -1744,16 +1744,16 @@ static void LoadUnloadVehicle(Vehicle *front)
/* update stats */
int t;
switch (front->type) {
case VEH_TRAIN:
case VEH_SHIP:
case VehicleType::Train:
case VehicleType::Ship:
t = front->vcache.cached_max_speed;
break;
case VEH_ROAD:
case VehicleType::Road:
t = front->vcache.cached_max_speed / 2;
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
t = Aircraft::From(front)->GetSpeedOldUnits(); // Convert to old units.
break;
@@ -1829,10 +1829,10 @@ static void LoadUnloadVehicle(Vehicle *front)
}
if (anything_loaded || anything_unloaded) {
if (front->type == VEH_TRAIN) {
if (front->type == VehicleType::Train) {
TriggerStationRandomisation(st, moving_front->tile, StationRandomTrigger::VehicleLoads);
TriggerStationAnimation(st, moving_front->tile, StationAnimationTrigger::VehicleLoads);
} else if (front->type == VEH_ROAD) {
} else if (front->type == VehicleType::Road) {
TriggerRoadStopRandomisation(st, front->tile, StationRandomTrigger::VehicleLoads);
TriggerRoadStopAnimation(st, front->tile, StationAnimationTrigger::VehicleLoads);
}
@@ -1848,7 +1848,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (_settings_game.order.gradual_loading) {
/* The time it takes to load one 'slice' of cargo or passengers depends
* on the vehicle type - the values here are those found in TTDPatch */
const uint gradual_loading_wait_time[] = { 40, 20, 10, 20 };
constexpr VehicleTypeIndexArray<const uint> gradual_loading_wait_time = { 40, 20, 10, 20 };
new_load_unload_ticks = gradual_loading_wait_time[front->type];
}
@@ -1867,7 +1867,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->current_order.GetLoadType() == OrderLoadType::FullLoadAny) {
/* if the aircraft carries passengers and is NOT full, then
* continue loading, no matter how much mail is in */
if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CargoClass::Passengers) && front->cargo_cap > front->cargo.StoredCount()) ||
if ((front->type == VehicleType::Aircraft && IsCargoInClass(front->cargo_type, CargoClass::Passengers) && front->cargo_cap > front->cargo.StoredCount()) ||
(cargo_not_full.Any() && cargo_full.Reset(cargo_not_full).None())) { // There are still non-full cargoes
finished_loading = false;
}
+1 -1
View File
@@ -21,7 +21,7 @@
* - bulldozer (road works)
* - bubbles (industry)
*/
struct EffectVehicle final : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
struct EffectVehicle final : public SpecializedVehicle<EffectVehicle, VehicleType::Effect> {
uint16_t animation_state = 0; ///< State primarily used to change the graphics/behaviour.
uint8_t animation_substate = 0; ///< Sub state to time the change of the graphics/behaviour.
+1 -1
View File
@@ -591,7 +591,7 @@ void SettingsDisableElrail(int32_t new_value)
void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
{
/* walk through all train engines */
for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (Engine *e : Engine::IterateType(VehicleType::Train)) {
RailVehicleInfo *rv_info = &e->VehInfo<RailVehicleInfo>();
/* update railtype of engines intended to use elrail */
if (rv_info->intended_railtypes.Test(RAILTYPE_ELECTRIC)) {
+68 -68
View File
@@ -58,7 +58,7 @@ static TimerGameCalendar::Year _year_engine_aging_stops;
uint8_t GetOriginalEngineCount(VehicleType type)
{
/** Number of engines of each vehicle type in original engine data */
static constexpr uint8_t ENGINE_COUNTS[VEH_COMPANY_END] = {
static constexpr VehicleTypeIndexArray<uint8_t> ENGINE_COUNTS = {
lengthof(_orig_rail_vehicle_info),
lengthof(_orig_road_vehicle_info),
lengthof(_orig_ship_vehicle_info),
@@ -77,7 +77,7 @@ uint8_t GetOriginalEngineCount(VehicleType type)
uint8_t GetOriginalEngineOffset(VehicleType type)
{
/** Offset of the first engine of each vehicle type in original engine data */
static constexpr uint8_t ENGINE_OFFSETS[VEH_COMPANY_END] = {
static constexpr VehicleTypeIndexArray<uint8_t> ENGINE_OFFSETS = {
0,
lengthof(_orig_rail_vehicle_info),
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
@@ -95,7 +95,7 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
this->type = type;
/* Called in the context of loading a savegame. The rest comes from the loader. */
if (type == VEH_INVALID) return;
if (type == VehicleType::Invalid) return;
this->grf_prop.local_id = local_id;
this->list_position = local_id;
@@ -106,17 +106,17 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
if (local_id >= GetOriginalEngineCount(type)) {
/* Initialise default type-specific information. */
switch (type) {
case VEH_TRAIN: this->vehicle_info.emplace<RailVehicleInfo>(); break;
case VEH_ROAD: this->vehicle_info.emplace<RoadVehicleInfo>(); break;
case VEH_SHIP: this->vehicle_info.emplace<ShipVehicleInfo>(); break;
case VEH_AIRCRAFT: this->vehicle_info.emplace<AircraftVehicleInfo>(); break;
case VehicleType::Train: this->vehicle_info.emplace<RailVehicleInfo>(); break;
case VehicleType::Road: this->vehicle_info.emplace<RoadVehicleInfo>(); break;
case VehicleType::Ship: this->vehicle_info.emplace<ShipVehicleInfo>(); break;
case VehicleType::Aircraft: this->vehicle_info.emplace<AircraftVehicleInfo>(); break;
default: break;
}
/* Set model life to maximum to make wagons available */
this->info.base_life = TimerGameCalendar::Year{0xFF};
/* Aircraft must have CT_INVALID as default, as there is no property */
this->info.cargo_type = INVALID_CARGO;
this->info.cargo_label = (type == VEH_AIRCRAFT) ? CT_INVALID : CT_PASSENGERS;
this->info.cargo_label = (type == VehicleType::Aircraft) ? CT_INVALID : CT_PASSENGERS;
/* Set cargo aging period to the default value. */
this->info.cargo_age_period = Ticks::CARGO_AGING_TICKS;
/* Not a variant */
@@ -131,7 +131,7 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: {
case VehicleType::Train: {
RailVehicleInfo &rvi = this->vehicle_info.emplace<RailVehicleInfo>(_orig_rail_vehicle_info[local_id]);
this->original_image_index = rvi.image_index;
this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + local_id;
@@ -142,21 +142,21 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicleInfo &rvi = this->vehicle_info.emplace<RoadVehicleInfo>(_orig_road_vehicle_info[local_id]);
this->original_image_index = rvi.image_index;
this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + local_id;
break;
}
case VEH_SHIP: {
case VehicleType::Ship: {
ShipVehicleInfo &svi = this->vehicle_info.emplace<ShipVehicleInfo>(_orig_ship_vehicle_info[local_id]);
this->original_image_index = svi.image_index;
this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + local_id;
break;
}
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
AircraftVehicleInfo &avi = this->vehicle_info.emplace<AircraftVehicleInfo>(_orig_aircraft_vehicle_info[local_id]);
this->original_image_index = avi.image_index;
this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + local_id;
@@ -198,16 +198,16 @@ bool Engine::CanCarryCargo() const
* Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
*/
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (this->VehInfo<RailVehicleInfo>().capacity == 0) return false;
break;
case VEH_ROAD:
case VehicleType::Road:
if (this->VehInfo<RoadVehicleInfo>().capacity == 0) return false;
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
break;
default: NOT_REACHED();
@@ -234,7 +234,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
CargoType default_cargo = this->GetDefaultCargoType();
CargoType cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CargoClass::Passengers)) {
if (mail_capacity != nullptr && this->type == VehicleType::Aircraft && IsCargoInClass(cargo_type, CargoClass::Passengers)) {
*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->VehInfo<AircraftVehicleInfo>().mail_capacity, v);
}
@@ -249,22 +249,22 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
uint capacity;
uint extra_mail_cap = 0;
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->VehInfo<RailVehicleInfo>().capacity, v);
/* In purchase list add the capacity of the second head. Always use the plain property for this. */
if (v == nullptr && this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD) capacity += this->VehInfo<RailVehicleInfo>().capacity;
break;
case VEH_ROAD:
case VehicleType::Road:
capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->VehInfo<RoadVehicleInfo>().capacity, v);
break;
case VEH_SHIP:
case VehicleType::Ship:
capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->VehInfo<ShipVehicleInfo>().capacity, v);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->VehInfo<AircraftVehicleInfo>().passenger_capacity, v);
if (!IsCargoInClass(cargo_type, CargoClass::Passengers)) {
extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->VehInfo<AircraftVehicleInfo>().mail_capacity, v);
@@ -285,7 +285,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
}
/* Apply multipliers depending on cargo- and vehicletype. */
if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) {
if (new_multipliers || (this->type != VehicleType::Ship && default_cargo != cargo_type)) {
uint16_t default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier;
uint16_t cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier;
capacity *= cargo_multiplier;
@@ -308,24 +308,24 @@ Money Engine::GetRunningCost() const
Price base_price;
uint cost_factor;
switch (this->type) {
case VEH_ROAD:
case VehicleType::Road:
base_price = this->VehInfo<RoadVehicleInfo>().running_cost_class;
if (base_price == Price::Invalid) return 0;
cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->VehInfo<RoadVehicleInfo>().running_cost);
break;
case VEH_TRAIN:
case VehicleType::Train:
base_price = this->VehInfo<RailVehicleInfo>().running_cost_class;
if (base_price == Price::Invalid) return 0;
cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->VehInfo<RailVehicleInfo>().running_cost);
break;
case VEH_SHIP:
case VehicleType::Ship:
base_price = Price::RunningShip;
cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->VehInfo<ShipVehicleInfo>().running_cost);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
base_price = Price::RunningAircraft;
cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->VehInfo<AircraftVehicleInfo>().running_cost);
break;
@@ -345,12 +345,12 @@ Money Engine::GetCost() const
Price base_price;
uint cost_factor;
switch (this->type) {
case VEH_ROAD:
case VehicleType::Road:
base_price = Price::BuildVehicleRoad;
cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->VehInfo<RoadVehicleInfo>().cost_factor);
break;
case VEH_TRAIN:
case VehicleType::Train:
if (this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
base_price = Price::BuildVehicleWagon;
cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo<RailVehicleInfo>().cost_factor);
@@ -360,12 +360,12 @@ Money Engine::GetCost() const
}
break;
case VEH_SHIP:
case VehicleType::Ship:
base_price = Price::BuildVehicleShip;
cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->VehInfo<ShipVehicleInfo>().cost_factor);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
base_price = Price::BuildVehicleAircraft;
cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->VehInfo<AircraftVehicleInfo>().cost_factor);
break;
@@ -383,18 +383,18 @@ Money Engine::GetCost() const
uint Engine::GetDisplayMaxSpeed() const
{
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->VehInfo<RailVehicleInfo>().max_speed);
case VEH_ROAD: {
case VehicleType::Road: {
uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0);
return (max_speed != 0) ? max_speed * 2 : this->VehInfo<RoadVehicleInfo>().max_speed / 2;
}
case VEH_SHIP:
case VehicleType::Ship:
return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->VehInfo<ShipVehicleInfo>().max_speed) / 2;
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0);
if (max_speed != 0) {
return (max_speed * 128) / 10;
@@ -416,9 +416,9 @@ uint Engine::GetPower() const
{
/* Only trains and road vehicles have 'power'. */
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->VehInfo<RailVehicleInfo>().power);
case VEH_ROAD:
case VehicleType::Road:
return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->VehInfo<RoadVehicleInfo>().power) * 10;
default: NOT_REACHED();
@@ -434,9 +434,9 @@ uint Engine::GetDisplayWeight() const
{
/* Only trains and road vehicles have 'weight'. */
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->VehInfo<RailVehicleInfo>().weight) << (this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
case VEH_ROAD:
case VehicleType::Road:
return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->VehInfo<RoadVehicleInfo>().weight) / 4;
default: NOT_REACHED();
@@ -452,9 +452,9 @@ uint Engine::GetDisplayMaxTractiveEffort() const
{
/* Only trains and road vehicles have 'tractive effort'. */
switch (this->type) {
case VEH_TRAIN:
case VehicleType::Train:
return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->VehInfo<RailVehicleInfo>().tractive_effort)) / 256;
case VEH_ROAD:
case VehicleType::Road:
return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->VehInfo<RoadVehicleInfo>().tractive_effort)) / 256;
default: NOT_REACHED();
@@ -479,7 +479,7 @@ uint16_t Engine::GetRange() const
{
if (!_settings_game.vehicle.aircraft_range) return 0;
switch (this->type) {
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->VehInfo<AircraftVehicleInfo>().max_range);
default: NOT_REACHED();
@@ -493,7 +493,7 @@ uint16_t Engine::GetRange() const
StringID Engine::GetAircraftTypeText() const
{
switch (this->type) {
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
switch (this->VehInfo<AircraftVehicleInfo>().subtype) {
case AIR_HELI: return STR_LIVERY_HELICOPTER;
case AIR_CTOL: return STR_LIVERY_SMALL_PLANE;
@@ -535,7 +535,7 @@ bool Engine::IsVariantHidden(CompanyID c) const
void EngineOverrideManager::ResetToDefaultMapping()
{
EngineID id = EngineID::Begin();
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
for (VehicleType type = VehicleType::Train; type <= VehicleType::Aircraft; type++) {
auto &map = this->mappings[type];
map.clear();
for (uint internal_id = 0; internal_id < GetOriginalEngineCount(type); internal_id++, ++id) {
@@ -629,7 +629,7 @@ void SetupEngines()
CloseWindowByClass(WC_ENGINE_PREVIEW);
_engine_pool.CleanPool();
for (VehicleType type = VEH_BEGIN; type != VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type != VehicleType::CompanyEnd; type++) {
const auto &mapping = _engine_mngr.mappings[type];
/* Verify that the engine override manager has at least been set up with the default engines. */
@@ -651,7 +651,7 @@ void ShowEnginePreviewWindow(EngineID engine);
static bool IsWagon(EngineID index)
{
const Engine *e = Engine::Get(index);
return e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON;
return e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON;
}
/**
@@ -727,7 +727,7 @@ void SetYearEngineAgingStops()
/* Exclude certain engines */
if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue;
if (e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
if (e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_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);
@@ -757,7 +757,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
SaveRandomSeeds(&saved_seeds);
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
ei->base_intro.base() ^
e->type ^
to_underlying(e->type) ^
e->GetGRFID());
uint32_t r = Random();
@@ -784,7 +784,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
(re->index.base() << 16) ^ (re->info.base_intro.base() << 12) ^ (re->info.decay_speed << 8) ^
(re->info.lifelength.base() << 4) ^ re->info.retire_early ^
e->type ^
to_underlying(e->type) ^
e->GetGRFID());
/* Base reliability defined as a percentage of UINT16_MAX. */
@@ -861,9 +861,9 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
Company *c = Company::Get(company);
e->company_avail.Set(company);
if (e->type == VEH_TRAIN) {
if (e->type == VehicleType::Train) {
c->avail_railtypes = GetCompanyRailTypes(c->index);
} else if (e->type == VEH_ROAD) {
} else if (e->type == VehicleType::Road) {
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
}
@@ -872,9 +872,9 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
/* Update the toolbar. */
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
if (e->type == VehicleType::Road) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
if (e->type == VehicleType::Ship) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
}
}
@@ -889,9 +889,9 @@ static void DisableEngineForCompany(EngineID eid, CompanyID company)
Company *c = Company::Get(company);
e->company_avail.Reset(company);
if (e->type == VEH_TRAIN) {
if (e->type == VehicleType::Train) {
c->avail_railtypes = GetCompanyRailTypes(c->index);
} else if (e->type == VEH_ROAD) {
} else if (e->type == VehicleType::Road) {
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
}
@@ -944,7 +944,7 @@ static CompanyID GetPreviewCompany(Engine *e)
CompanyID best_company = CompanyID::Invalid();
/* For trains the cargomask has no useful meaning, since you can attach other wagons */
CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
CargoTypes cargomask = e->type != VehicleType::Train ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
int32_t best_hist = -1;
for (const Company *c : Company::Iterate()) {
@@ -976,10 +976,10 @@ static CompanyID GetPreviewCompany(Engine *e)
static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
{
switch (type) {
case VEH_TRAIN: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
case VEH_ROAD: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
case VEH_SHIP: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
case VEH_AIRCRAFT: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
case VehicleType::Train: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
case VehicleType::Road: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
case VehicleType::Ship: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
case VehicleType::Aircraft: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
default: NOT_REACHED();
}
@@ -1132,12 +1132,12 @@ static void NewVehicleAvailable(Engine *e)
/* Do not introduce new rail wagons */
if (IsWagon(index)) return;
if (e->type == VEH_TRAIN) {
if (e->type == VehicleType::Train) {
/* maybe make another rail type available */
assert(e->VehInfo<RailVehicleInfo>().railtypes != RailTypes{});
RailTypes introduced = GetAllIntroducesRailTypes(e->VehInfo<RailVehicleInfo>().railtypes);
for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | introduced, TimerGameCalendar::date);
} else if (e->type == VEH_ROAD) {
} else if (e->type == VehicleType::Road) {
/* maybe make another road type available */
assert(e->VehInfo<RoadVehicleInfo>().roadtype < ROADTYPE_END);
for (Company *c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->introduces_roadtypes, TimerGameCalendar::date);
@@ -1155,9 +1155,9 @@ static void NewVehicleAvailable(Engine *e)
}
/* Update the toolbar. */
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
if (e->type == VehicleType::Road) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
if (e->type == VehicleType::Ship) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
/* Remove from preview windows */
InvalidateWindowClassesData(WC_ENGINE_PREVIEW);
@@ -1292,12 +1292,12 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
if (!e->IsEnabled()) return false;
if (type == VEH_TRAIN && company != OWNER_DEITY) {
if (type == VehicleType::Train && company != OWNER_DEITY) {
/* Check if the rail type is available to this company */
const Company *c = Company::Get(company);
if (!GetAllCompatibleRailTypes(e->VehInfo<RailVehicleInfo>().railtypes).Any(c->avail_railtypes)) return false;
}
if (type == VEH_ROAD && company != OWNER_DEITY) {
if (type == VehicleType::Road && company != OWNER_DEITY) {
/* Check if the road type is available to this company */
const Company *c = Company::Get(company);
if (!GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->powered_roadtypes.Any(c->avail_roadtypes)) return false;
@@ -1344,7 +1344,7 @@ void CheckEngines()
if (!e->IsEnabled()) continue;
/* Don't consider train wagons, we need a powered engine available. */
if (e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
if (e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
/* We have an available engine... yay! */
if (e->flags.Test(EngineFlag::Available) && e->company_avail.Any()) return;
+3 -3
View File
@@ -59,7 +59,7 @@ public:
CompanyID preview_company = CompanyID::Invalid(); ///< Company which is currently being offered a preview \c CompanyID::Invalid() means no company.
uint8_t preview_wait = 0; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company.
uint8_t original_image_index = 0; ///< Original vehicle image index, thus the image index of the overridden vehicle
VehicleType type = VEH_INVALID; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc.
VehicleType type = VehicleType::Invalid; ///< %Vehicle type, ie #VehicleType::Road, #VehicleType::Train, etc.
EngineDisplayFlags display_flags{}; ///< NOSAVE client-side-only display flags for build engine list.
EngineID display_last_variant = EngineID::Invalid(); ///< NOSAVE client-side-only last variant selected.
@@ -154,7 +154,7 @@ public:
*/
inline bool IsGroundVehicle() const
{
return this->type == VEH_TRAIN || this->type == VEH_ROAD;
return this->type == VehicleType::Train || this->type == VehicleType::Road;
}
/**
@@ -225,7 +225,7 @@ struct EngineIDMappingKeyProjection {
* Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get reset in different cases.
*/
struct EngineOverrideManager {
std::array<std::vector<EngineIDMapping>, VEH_COMPANY_END> mappings;
VehicleTypeIndexArray<std::vector<EngineIDMapping>> mappings;
void ResetToDefaultMapping();
EngineID GetID(VehicleType type, uint16_t grf_local_id, uint32_t grfid);
+18 -16
View File
@@ -43,11 +43,13 @@ StringID GetEngineCategoryName(EngineID engine)
const Engine *e = Engine::Get(engine);
switch (e->type) {
default: NOT_REACHED();
case VEH_ROAD:
case VehicleType::Road:
return GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->strings.new_engine;
case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
case VEH_TRAIN:
case VehicleType::Aircraft:
return STR_ENGINE_PREVIEW_AIRCRAFT;
case VehicleType::Ship:
return STR_ENGINE_PREVIEW_SHIP;
case VehicleType::Train:
assert(e->VehInfo<RailVehicleInfo>().railtypes.Any());
return GetRailTypeInfo(e->VehInfo<RailVehicleInfo>().railtypes.GetNthSetBit(0).value())->strings.new_loco;
}
@@ -125,10 +127,10 @@ struct EnginePreviewWindow : Window {
const Engine *e = Engine::Get(engine);
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN: GetTrainSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
case VEH_ROAD: GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
case VEH_SHIP: GetShipSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Train: GetTrainSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Road: GetRoadVehSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Ship: GetShipSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
case VehicleType::Aircraft: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
}
this->vehicle_space = std::max<int>(this->vehicle_space, y - y_offs);
@@ -434,16 +436,16 @@ std::string GetEngineInfoString(EngineID engine)
const Engine &e = *Engine::Get(engine);
switch (e.type) {
case VEH_TRAIN:
case VehicleType::Train:
return GetTrainEngineInfoString(e);
case VEH_ROAD:
case VehicleType::Road:
return GetRoadVehEngineInfoString(e);
case VEH_SHIP:
case VehicleType::Ship:
return GetShipEngineInfoString(e);
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
return GetAircraftEngineInfoString(e);
default: NOT_REACHED();
@@ -465,19 +467,19 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
const Engine *e = Engine::Get(engine);
switch (e->type) {
case VEH_TRAIN:
case VehicleType::Train:
DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_ROAD:
case VehicleType::Road:
DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_SHIP:
case VehicleType::Ship:
DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
break;
+3 -3
View File
@@ -44,9 +44,9 @@ void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine
void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type);
extern bool _engine_sort_direction;
extern uint8_t _engine_sort_last_criteria[];
extern bool _engine_sort_last_order[];
extern bool _engine_sort_show_hidden_engines[];
extern VehicleTypeIndexArray<uint8_t> _engine_sort_last_criteria;
extern VehicleTypeIndexArray<bool> _engine_sort_last_order;
extern VehicleTypeIndexArray<bool> _engine_sort_show_hidden_engines;
std::span<StringID const> GetEngineSortNames(VehicleType vehicle_type);
std::span<EngList_SortTypeFunction * const> GetEngineSortFunctions(VehicleType vehicle_type);
+4 -4
View File
@@ -191,8 +191,8 @@ bool GroundVehicle<T, Type>::IsChainInDepot() const
{
const T *v = this->First();
/* Is the front engine stationary in the depot? */
static_assert((int)TRANSPORT_RAIL == (int)VEH_TRAIN);
static_assert((int)TRANSPORT_ROAD == (int)VEH_ROAD);
static_assert(to_underlying(TRANSPORT_RAIL) == to_underlying(VehicleType::Train));
static_assert(to_underlying(TRANSPORT_ROAD) == to_underlying(VehicleType::Road));
if (!IsDepotTypeTile(v->tile, (TransportType)Type) || v->cur_speed != 0) return false;
/* Check whether the rest is also already trying to enter the depot. */
@@ -204,6 +204,6 @@ bool GroundVehicle<T, Type>::IsChainInDepot() const
}
/* Instantiation for Train */
template struct GroundVehicle<Train, VEH_TRAIN>;
template struct GroundVehicle<Train, VehicleType::Train>;
/* Instantiation for RoadVehicle */
template struct GroundVehicle<RoadVehicle, VEH_ROAD>;
template struct GroundVehicle<RoadVehicle, VehicleType::Road>;
+8 -2
View File
@@ -74,7 +74,7 @@ using GroupFlags = EnumBitSet<GroupFlag, uint8_t>;
struct Group : GroupPool::PoolItem<&_group_pool> {
std::string name{}; ///< Group Name
Owner owner = INVALID_OWNER; ///< Group Owner
VehicleType vehicle_type = VEH_INVALID; ///< Vehicle type of the group
VehicleType vehicle_type = VehicleType::Invalid; ///< Vehicle type of the group
GroupFlags flags{}; ///< Group flags
Livery livery{}; ///< Custom colour scheme for vehicles in this group
@@ -86,7 +86,13 @@ struct Group : GroupPool::PoolItem<&_group_pool> {
GroupID parent = GroupID::Invalid(); ///< Parent group
uint16_t number = 0; ///< Per-company group number.
Group(GroupID index, CompanyID owner = INVALID_OWNER, VehicleType vehicle_type = VEH_INVALID) :
/**
* Create this group.
* @param index Group index.
* @param owner Owner of the group.
* @param vehicle_type Vehicle type of the group.
*/
Group(GroupID index, CompanyID owner = INVALID_OWNER, VehicleType vehicle_type = VehicleType::Invalid) :
GroupPool::PoolItem<&_group_pool>(index), owner(owner), vehicle_type(vehicle_type) {}
};
+9 -9
View File
@@ -121,7 +121,7 @@ uint16_t GroupStatistics::GetNumEngines(EngineID engine) const
{
/* Set up the engine count for all companies */
for (Company *c : Company::Iterate()) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type < VehicleType::CompanyEnd; type++) {
c->group_all[type].Clear();
c->group_default[type].Clear();
}
@@ -216,7 +216,7 @@ uint16_t GroupStatistics::GetNumEngines(EngineID engine) const
{
/* Set up the engine count for all companies */
for (Company *c : Company::Iterate()) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type < VehicleType::CompanyEnd; type++) {
c->group_all[type].ClearProfits();
c->group_default[type].ClearProfits();
}
@@ -243,7 +243,7 @@ uint16_t GroupStatistics::GetNumEngines(EngineID engine) const
{
/* Set up the engine count for all companies */
Company *c = Company::Get(company);
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type < VehicleType::CompanyEnd; type++) {
c->group_all[type].ClearAutoreplace();
c->group_default[type].ClearAutoreplace();
}
@@ -529,13 +529,13 @@ static void AddVehicleToGroup(Vehicle *v, GroupID new_g)
switch (v->type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
SetTrainGroupID(Train::From(v), new_g);
break;
case VEH_ROAD:
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Road:
case VehicleType::Ship:
case VehicleType::Aircraft:
if (v->IsEngineCountable()) UpdateNumEngineGroup(v, v->group_id, new_g);
v->group_id = new_g;
for (Vehicle *u = v; u != nullptr; u = u->Next()) {
@@ -785,7 +785,7 @@ void SetTrainGroupID(Train *v, GroupID new_g)
/* Update the Replace Vehicle Windows */
GroupStatistics::UpdateAutoreplace(v->owner);
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
SetWindowDirty(WC_REPLACE_VEHICLE, VehicleType::Train);
}
@@ -811,7 +811,7 @@ void UpdateTrainGroupID(Train *v)
/* Update the Replace Vehicle Windows */
GroupStatistics::UpdateAutoreplace(v->owner);
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
SetWindowDirty(WC_REPLACE_VEHICLE, VehicleType::Train);
}
/**
+21 -21
View File
@@ -244,7 +244,7 @@ private:
this->column_size[VGC_FOLD] = maxdim(GetScaledSpriteSize(SPR_CIRCLE_FOLDED), GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED));
this->tiny_step_height = this->column_size[VGC_FOLD].height;
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + to_underlying(this->vli.vtype)), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + to_underlying(this->vli.vtype)));
this->column_size[VGC_NAME].width = std::max(170u, this->column_size[VGC_NAME].width) + WidgetDimensions::scaled.hsep_indent;
this->tiny_step_height = std::max(this->tiny_step_height, this->column_size[VGC_NAME].height);
@@ -309,8 +309,8 @@ private:
*/
std::string GetGroupNameString(GroupID g_id) const
{
if (IsAllGroupID(g_id)) return GetString(STR_GROUP_ALL_TRAINS + this->vli.vtype);
if (IsDefaultGroupID(g_id)) return GetString(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype);
if (IsAllGroupID(g_id)) return GetString(STR_GROUP_ALL_TRAINS + to_underlying(this->vli.vtype));
if (IsDefaultGroupID(g_id)) return GetString(STR_GROUP_DEFAULT_TRAINS + to_underlying(this->vli.vtype));
return GetString(STR_GROUP_NAME, g_id);
}
@@ -433,14 +433,14 @@ public:
this->BuildGroupList(vli.company);
this->group_sb->SetCount(this->groups.size());
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->SetSprite(SPR_GROUP_CREATE_TRAIN + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->SetSprite(SPR_GROUP_RENAME_TRAIN + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->SetSprite(SPR_GROUP_DELETE_TRAIN + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->SetSprite(SPR_GROUP_LIVERY_TRAIN + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(SPR_GROUP_REPLACE_OFF_TRAIN + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->SetSprite(SPR_GROUP_CREATE_TRAIN + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->SetSprite(SPR_GROUP_RENAME_TRAIN + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->SetSprite(SPR_GROUP_DELETE_TRAIN + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_LIVERY_GROUP)->SetSprite(SPR_GROUP_LIVERY_TRAIN + to_underlying(this->vli.vtype));
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(SPR_GROUP_REPLACE_OFF_TRAIN + to_underlying(this->vli.vtype));
this->FinishInitNested(window_number);
this->owner = vli.company;
@@ -562,7 +562,7 @@ public:
return GetString(this->GetCargoFilterLabel(this->cargo_filter_criteria));
case WID_GL_AVAILABLE_VEHICLES:
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + to_underlying(this->vli.vtype));
case WID_GL_CAPTION:
/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
@@ -625,7 +625,7 @@ public:
/* If not a default group and the group has replace protection, show an enabled replace sprite. */
uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
if (!IsDefaultGroupID(group) && !IsAllGroupID(group) && Group::Get(group)->flags.Test(GroupFlag::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + to_underlying(this->vli.vtype));
/* Set text of "group by" dropdown widget. */
this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->SetString(std::data(this->vehicle_group_by_names)[this->grouping]);
@@ -749,7 +749,7 @@ public:
return;
case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VehicleType::Train || this->vli.vtype == VehicleType::Road) ? 0 : (1 << 10));
return;
case WID_GL_FILTER_BY_CARGO: { // Select filtering criteria dropdown menu
@@ -1191,32 +1191,32 @@ public:
};
/** Window definitions for the vehicle group windows. */
static WindowDesc _vehicle_group_desc[] = {
{
static VehicleTypeIndexArray<WindowDesc> _vehicle_group_desc = {{
WindowDesc{
WindowPosition::Automatic, "list_groups_train", 525, 246,
WC_TRAINS_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WindowDesc{
WindowPosition::Automatic, "list_groups_roadveh", 460, 246,
WC_ROADVEH_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WindowDesc{
WindowPosition::Automatic, "list_groups_ship", 460, 246,
WC_SHIPS_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WindowDesc{
WindowPosition::Automatic, "list_groups_aircraft", 460, 246,
WC_AIRCRAFT_LIST, WC_NONE,
{},
_nested_group_widgets
},
};
}};
/**
* Show the group window for the given company and vehicle type.
@@ -1230,7 +1230,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
{
if (!Company::IsValidID(company)) return;
assert(vehicle_type < std::size(_vehicle_group_desc));
assert(to_underlying(vehicle_type) < std::size(_vehicle_group_desc));
VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.ToWindowNumber(), vli);
if (w != nullptr) w->SelectGroup(group);
@@ -1289,7 +1289,7 @@ void CcCreateGroup(Commands, const CommandCost &result, GroupID new_group, Vehic
{
if (result.Failed()) return;
assert(vt <= VEH_AIRCRAFT);
assert(IsCompanyBuildableVehicleType(vt));
CcCreateGroup(new_group, vt);
}
+2 -2
View File
@@ -2807,11 +2807,11 @@ int WhoCanServiceIndustry(Industry *ind)
/* Check whether it accepts the right kind of cargo */
bool c_accepts = false;
bool c_produces = false;
if (v->type == VEH_TRAIN && v->IsFrontEngine()) {
if (v->type == VehicleType::Train && v->IsFrontEngine()) {
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
}
} else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) {
} else if (v->type == VehicleType::Road || v->type == VehicleType::Ship || v->type == VehicleType::Aircraft) {
CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces);
} else {
continue;
+1 -1
View File
@@ -105,7 +105,7 @@ bool LinkRefresher::HandleRefit(CargoType refit_cargo)
++refit_it;
/* Special case for aircraft with mail. */
if (v->type == VEH_AIRCRAFT) {
if (v->type == VehicleType::Aircraft) {
if (mail_capacity < refit_it->remaining) {
this->capacities[refit_it->cargo] -= refit_it->remaining - mail_capacity;
refit_it->remaining = mail_capacity;
+3 -3
View File
@@ -229,7 +229,7 @@ public:
/* Rail speed limit */
if (td.rail_speed != 0) {
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, PackVelocity(td.rail_speed, VEH_TRAIN)));
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, PackVelocity(td.rail_speed, VehicleType::Train)));
}
/* Road type name */
@@ -239,7 +239,7 @@ public:
/* Road speed limit */
if (td.road_speed != 0) {
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, PackVelocity(td.road_speed, VEH_ROAD)));
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, PackVelocity(td.road_speed, VehicleType::Road)));
}
/* Tram type name */
@@ -249,7 +249,7 @@ public:
/* Tram speed limit */
if (td.tram_speed != 0) {
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT, PackVelocity(td.tram_speed, VEH_ROAD)));
this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT, PackVelocity(td.tram_speed, VehicleType::Road)));
}
/* Tile protection status */
+4 -4
View File
@@ -1558,10 +1558,10 @@ NetworkCompanyStatsArray NetworkGetCompanyStats()
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
NetworkVehicleType type;
switch (v->type) {
case VEH_TRAIN: type = NetworkVehicleType::Train; break;
case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NetworkVehicleType::Bus : NetworkVehicleType::Truck; break;
case VEH_AIRCRAFT: type = NetworkVehicleType::Aircraft; break;
case VEH_SHIP: type = NetworkVehicleType::Ship; break;
case VehicleType::Train: type = NetworkVehicleType::Train; break;
case VehicleType::Road: type = RoadVehicle::From(v)->IsBus() ? NetworkVehicleType::Bus : NetworkVehicleType::Truck; break;
case VehicleType::Aircraft: type = NetworkVehicleType::Aircraft; break;
case VehicleType::Ship: type = NetworkVehicleType::Ship; break;
default: continue;
}
stats[v->owner].num_vehicle[type]++;
+24 -24
View File
@@ -277,7 +277,7 @@ Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id
/* Resize temporary engine data ... */
_gted.resize(Engine::GetPoolSize());
}
if (type == VEH_TRAIN) {
if (type == VehicleType::Train) {
_gted[e->index].railtypelabels.clear();
for (RailType rt : e->VehInfo<RailVehicleInfo>().railtypes) _gted[e->index].railtypelabels.push_back(GetRailTypeInfo(rt)->label);
}
@@ -434,7 +434,7 @@ void ResetNewGRFData()
_gted.resize(Engine::GetPoolSize());
/* Fill rail type label temporary data for default trains */
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (const Engine *e : Engine::IterateType(VehicleType::Train)) {
_gted[e->index].railtypelabels.clear();
for (RailType rt : e->VehInfo<RailVehicleInfo>().railtypes) _gted[e->index].railtypelabels.push_back(GetRailTypeInfo(rt)->label);
}
@@ -670,7 +670,7 @@ static void CalculateRefitMasks()
/* If the NewGRF did not set any cargo properties, we apply default values. */
if (_gted[engine].defaultcargo_grf == nullptr) {
/* If the vehicle has any capacity, apply the default refit masks */
if (e->type != VEH_TRAIN || e->VehInfo<RailVehicleInfo>().capacity != 0) {
if (e->type != VehicleType::Train || e->VehInfo<RailVehicleInfo>().capacity != 0) {
static constexpr LandscapeType T = LandscapeType::Temperate;
static constexpr LandscapeType A = LandscapeType::Arctic;
static constexpr LandscapeType S = LandscapeType::Tropic;
@@ -696,11 +696,11 @@ static void CalculateRefitMasks()
{{ Y}, CT_CANDY, {CargoClass::PieceGoods, CargoClass::Express}, {CargoClass::Liquid, CargoClass::Passengers}},
};
if (e->type == VEH_AIRCRAFT) {
if (e->type == VehicleType::Aircraft) {
/* Aircraft default to "light" cargoes */
_gted[engine].cargo_allowed = {CargoClass::Passengers, CargoClass::Mail, CargoClass::Armoured, CargoClass::Express};
_gted[engine].cargo_disallowed = {CargoClass::Liquid};
} else if (e->type == VEH_SHIP) {
} else if (e->type == VehicleType::Ship) {
CargoLabel label = GetActiveCargoLabel(ei->cargo_label);
switch (label.base()) {
case CT_PASSENGERS.base():
@@ -726,7 +726,7 @@ static void CalculateRefitMasks()
break;
}
e->VehInfo<ShipVehicleInfo>().old_refittable = true;
} else if (e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON) {
} else if (e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_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};
@@ -802,7 +802,7 @@ static void CalculateRefitMasks()
/* Ensure that the vehicle is either not refittable, or that the default cargo is one of the refittable cargoes.
* Note: Vehicles refittable to no cargo are handle differently to vehicle refittable to a single cargo. The latter might have subtypes. */
if (!only_defaultcargo && (e->type != VEH_SHIP || e->VehInfo<ShipVehicleInfo>().old_refittable) && IsValidCargoType(ei->cargo_type) && !ei->refit_mask.Test(ei->cargo_type)) {
if (!only_defaultcargo && (e->type != VehicleType::Ship || e->VehInfo<ShipVehicleInfo>().old_refittable) && IsValidCargoType(ei->cargo_type) && !ei->refit_mask.Test(ei->cargo_type)) {
ei->cargo_type = INVALID_CARGO;
}
@@ -829,7 +829,7 @@ static void CalculateRefitMasks()
ei->cargo_type = *ei->refit_mask.begin();
}
}
if (!IsValidCargoType(ei->cargo_type) && e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON && e->VehInfo<RailVehicleInfo>().capacity == 0) {
if (!IsValidCargoType(ei->cargo_type) && e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON && e->VehInfo<RailVehicleInfo>().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). */
@@ -840,7 +840,7 @@ static void CalculateRefitMasks()
if (!IsValidCargoType(ei->cargo_type)) ei->climates = {};
/* Clear refit_mask for not refittable ships */
if (e->type == VEH_SHIP && !e->VehInfo<ShipVehicleInfo>().old_refittable) {
if (e->type == VehicleType::Ship && !e->VehInfo<ShipVehicleInfo>().old_refittable) {
ei->refit_mask.Reset();
}
}
@@ -876,22 +876,22 @@ static void FinaliseEngineArray()
if (!e->info.climates.Test(_settings_game.game_creation.landscape)) continue;
switch (e->type) {
case VEH_TRAIN:
case VehicleType::Train:
for (RailType rt : e->VehInfo<RailVehicleInfo>().railtypes) {
AppendCopyableBadgeList(e->badges, GetRailTypeInfo(rt)->badges, GrfSpecFeature::Trains);
}
break;
case VEH_ROAD: AppendCopyableBadgeList(e->badges, GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->badges, GrfSpecFeature::RoadVehicles); break;
case VehicleType::Road: AppendCopyableBadgeList(e->badges, GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->badges, GrfSpecFeature::RoadVehicles); break;
default: break;
}
/* Skip wagons, there livery is defined via the engine */
if (e->type != VEH_TRAIN || e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_WAGON) {
if (e->type != VehicleType::Train || e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_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 */
if (e->type == VEH_TRAIN) {
if (e->type == VehicleType::Train) {
SetBit(_loaded_newgrf_features.used_liveries, LS_FREIGHT_WAGON);
switch (ls) {
case LS_STEAM:
@@ -1699,7 +1699,7 @@ static void AfterLoadGRFs()
InitRailTypes();
InitRoadTypes();
for (Engine *e : Engine::IterateType(VEH_ROAD)) {
for (Engine *e : Engine::IterateType(VehicleType::Road)) {
if (_gted[e->index].rv_max_speed != 0) {
/* Set RV maximum speed from the mph/0.8 unit value */
e->VehInfo<RoadVehicleInfo>().max_speed = _gted[e->index].rv_max_speed * 4;
@@ -1731,7 +1731,7 @@ static void AfterLoadGRFs()
e->info.climates = {};
}
for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (Engine *e : Engine::IterateType(VehicleType::Train)) {
RailTypes railtypes{};
for (RailTypeLabel label : _gted[e->index].railtypelabels) {
auto rt = GetRailTypeByLabel(label);
@@ -1905,10 +1905,10 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
GrfSpecFeature GetGrfSpecFeature(VehicleType type)
{
switch (type) {
case VEH_TRAIN: return GrfSpecFeature::Trains;
case VEH_ROAD: return GrfSpecFeature::RoadVehicles;
case VEH_SHIP: return GrfSpecFeature::Ships;
case VEH_AIRCRAFT: return GrfSpecFeature::Aircraft;
case VehicleType::Train: return GrfSpecFeature::Trains;
case VehicleType::Road: return GrfSpecFeature::RoadVehicles;
case VehicleType::Ship: return GrfSpecFeature::Ships;
case VehicleType::Aircraft: return GrfSpecFeature::Aircraft;
default: return GrfSpecFeature::Invalid;
}
}
@@ -1921,10 +1921,10 @@ GrfSpecFeature GetGrfSpecFeature(VehicleType type)
VehicleType GetVehicleType(GrfSpecFeature feature)
{
switch (feature) {
case GrfSpecFeature::Trains: return VEH_TRAIN;
case GrfSpecFeature::RoadVehicles: return VEH_ROAD;
case GrfSpecFeature::Ships: return VEH_SHIP;
case GrfSpecFeature::Aircraft: return VEH_AIRCRAFT;
default: return VEH_INVALID;
case GrfSpecFeature::Trains: return VehicleType::Train;
case GrfSpecFeature::RoadVehicles: return VehicleType::Road;
case GrfSpecFeature::Ships: return VehicleType::Ship;
case GrfSpecFeature::Aircraft: return VehicleType::Aircraft;
default: return VehicleType::Invalid;
}
}
+2 -2
View File
@@ -31,7 +31,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro
ChangeInfoResult ret = ChangeInfoResult::Success;
for (uint id = first; id < last; ++id) {
Engine *e = GetNewEngine(_cur_gps.grffile, VEH_AIRCRAFT, id);
Engine *e = GetNewEngine(_cur_gps.grffile, VehicleType::Aircraft, id);
if (e == nullptr) return ChangeInfoResult::InvalidId; // No engine could be allocated, so neither can any next vehicles
EngineInfo *ei = &e->info;
@@ -47,7 +47,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint first, uint last, int pro
if (spriteid < CUSTOM_VEHICLE_SPRITENUM) spriteid >>= 1;
if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
if (IsValidNewGRFImageIndex<VehicleType::Aircraft>(spriteid)) {
avi->image_index = spriteid;
} else {
GrfMsg(1, "AircraftVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
+2 -2
View File
@@ -32,7 +32,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B
ChangeInfoResult ret = ChangeInfoResult::Success;
for (uint id = first; id < last; ++id) {
Engine *e = GetNewEngine(_cur_gps.grffile, VEH_ROAD, id);
Engine *e = GetNewEngine(_cur_gps.grffile, VehicleType::Road, id);
if (e == nullptr) return ChangeInfoResult::InvalidId; // No engine could be allocated, so neither can any next vehicles
EngineInfo *ei = &e->info;
@@ -66,7 +66,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint first, uint last, int prop, B
if (spriteid < CUSTOM_VEHICLE_SPRITENUM) spriteid >>= 1;
if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
if (IsValidNewGRFImageIndex<VehicleType::Road>(spriteid)) {
rvi->image_index = spriteid;
} else {
GrfMsg(1, "RoadVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
+2 -2
View File
@@ -33,7 +33,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B
ChangeInfoResult ret = ChangeInfoResult::Success;
for (uint id = first; id < last; ++id) {
Engine *e = GetNewEngine(_cur_gps.grffile, VEH_SHIP, id);
Engine *e = GetNewEngine(_cur_gps.grffile, VehicleType::Ship, id);
if (e == nullptr) return ChangeInfoResult::InvalidId; // No engine could be allocated, so neither can any next vehicles
EngineInfo *ei = &e->info;
@@ -49,7 +49,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint first, uint last, int prop, B
if (spriteid < CUSTOM_VEHICLE_SPRITENUM) spriteid >>= 1;
if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
if (IsValidNewGRFImageIndex<VehicleType::Ship>(spriteid)) {
svi->image_index = spriteid;
} else {
GrfMsg(1, "ShipVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
+2 -2
View File
@@ -31,7 +31,7 @@ ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, ByteRead
ChangeInfoResult ret = ChangeInfoResult::Success;
for (uint id = first; id < last; ++id) {
Engine *e = GetNewEngine(_cur_gps.grffile, VEH_TRAIN, id);
Engine *e = GetNewEngine(_cur_gps.grffile, VehicleType::Train, id);
if (e == nullptr) return ChangeInfoResult::InvalidId; // No engine could be allocated, so neither can any next vehicles
EngineInfo *ei = &e->info;
@@ -101,7 +101,7 @@ ChangeInfoResult RailVehicleChangeInfo(uint first, uint last, int prop, ByteRead
* as an array index, so we need it to be half the original value. */
if (spriteid < CUSTOM_VEHICLE_SPRITENUM) spriteid >>= 1;
if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
if (IsValidNewGRFImageIndex<VehicleType::Train>(spriteid)) {
rvi->image_index = spriteid;
} else {
GrfMsg(1, "RailVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
+6 -6
View File
@@ -308,10 +308,10 @@ struct NewGRFInspectWindow : Window {
VehicleType GetVehicleTypeForWindow() const
{
switch (GetFeatureNum(this->window_number)) {
case GrfSpecFeature::Trains: return VEH_TRAIN;
case GrfSpecFeature::RoadVehicles: return VEH_ROAD;
case GrfSpecFeature::Ships: return VEH_SHIP;
case GrfSpecFeature::Aircraft: return VEH_AIRCRAFT;
case GrfSpecFeature::Trains: return VehicleType::Train;
case GrfSpecFeature::RoadVehicles: return VehicleType::Road;
case GrfSpecFeature::Ships: return VehicleType::Ship;
case GrfSpecFeature::Aircraft: return VehicleType::Aircraft;
default: NOT_REACHED();
}
}
@@ -409,8 +409,8 @@ struct NewGRFInspectWindow : Window {
for (const Vehicle *u = v->First(); u != nullptr; u = u->Next()) {
if (u == v) sel_start = total_width;
switch (u->type) {
case VEH_TRAIN: total_width += Train::From(u)->GetDisplayImageWidth(); break;
case VEH_ROAD: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
case VehicleType::Train: total_width += Train::From(u)->GetDisplayImageWidth(); break;
case VehicleType::Road: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
default: NOT_REACHED();
}
if (u == v) sel_end = total_width;
+35 -35
View File
@@ -78,15 +78,15 @@ void SetEngineGRF(EngineID engine, const GRFFile *file)
static int MapOldSubType(const Vehicle *v)
{
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (Train::From(v)->IsEngine()) return 0;
if (Train::From(v)->IsFreeWagon()) return 4;
return 2;
case VEH_ROAD:
case VEH_SHIP: return 0;
case VEH_AIRCRAFT:
case VEH_DISASTER: return v->subtype;
case VEH_EFFECT: return v->subtype << 1;
case VehicleType::Road:
case VehicleType::Ship: return 0;
case VehicleType::Aircraft:
case VehicleType::Disaster: return v->subtype;
case VehicleType::Effect: return v->subtype << 1;
default: NOT_REACHED();
}
}
@@ -444,7 +444,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
uint8_t user_def_data = 0;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
if (v->type == VehicleType::Train) user_def_data |= Train::From(u)->tcache.user_def_data;
/* Skip empty engines */
if (!u->GetEngine()->CanCarryCargo()) continue;
@@ -504,7 +504,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
return v->grf_cache.company_information;
case 0x44: // Aircraft information
if (v->type != VEH_AIRCRAFT || !Aircraft::From(v)->IsNormalAircraft()) return UINT_MAX;
if (v->type != VehicleType::Aircraft || !Aircraft::From(v)->IsNormalAircraft()) return UINT_MAX;
{
const Vehicle *w = v->Next();
@@ -565,7 +565,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0x4A:
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
RailType rt = GetTileRailType(v->tile);
const RailTypeInfo *rti = GetRailTypeInfo(rt);
return (rti->flags.Test(RailTypeFlag::Catenary) ? 0x200 : 0) |
@@ -573,7 +573,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
GetReverseRailTypeTranslation(rt, object->ro.grffile);
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadType rt = GetRoadType(v->tile, GetRoadTramType(RoadVehicle::From(v)->roadtype));
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
return (rti->flags.Test(RoadTypeFlag::Catenary) ? 0x200 : 0) |
@@ -605,7 +605,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
/* Variables which use the parameter */
case 0x60: // Count consist's engine ID occurrence
if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
if (v->type != VehicleType::Train) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
{
uint count = 0;
@@ -675,7 +675,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
* bit 3: This tile has type 'parameter' or it is considered equivalent (alternate labels).
*/
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
RailType param_type = GetRailTypeTranslation(parameter, object->ro.grffile);
if (param_type == INVALID_RAILTYPE) return 0x00;
RailType tile_type = GetTileRailType(v->tile);
@@ -684,7 +684,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
(IsCompatibleRail(param_type, tile_type) ? 0x02 : 0x00) |
0x01;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadTramType rtt = GetRoadTramType(RoadVehicle::From(v)->roadtype);
RoadType param_type = GetRoadTypeTranslation(rtt, parameter, object->ro.grffile);
if (param_type == INVALID_ROADTYPE) return 0x00;
@@ -697,7 +697,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
}
case 0x64: { // Count consist's badge ID occurrence
if (v->type != VEH_TRAIN) return GetBadgeVariableResult(*object->ro.grffile, v->GetEngine()->badges, parameter);
if (v->type != VehicleType::Train) return GetBadgeVariableResult(*object->ro.grffile, v->GetEngine()->badges, parameter);
/* Look up badge index. */
if (parameter >= std::size(object->ro.grffile->badge_list)) return UINT_MAX;
@@ -714,11 +714,11 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
}
case 0x65:
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
RailType rt = GetRailType(v->tile);
return GetBadgeVariableResult(*object->ro.grffile, GetRailTypeInfo(rt)->badges, parameter);
}
if (v->type == VEH_ROAD) {
if (v->type == VehicleType::Road) {
RoadType rt = GetRoadType(v->tile, GetRoadTramType(RoadVehicle::From(v)->roadtype));
return GetBadgeVariableResult(*object->ro.grffile, GetRoadTypeInfo(rt)->badges, parameter);
}
@@ -730,7 +730,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0xFF: {
uint16_t modflags = 0;
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
const Train *t = Train::From(v);
bool is_powered_wagon = t->flags.Test(VehicleRailFlag::PoweredWagon);
const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype)
@@ -757,7 +757,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
* (see http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#_VehicleArray)
*/
switch (variable - 0x80) {
case 0x00: return v->type + 0x10;
case 0x00: return to_underlying(v->type) + 0x10;
case 0x01: return MapOldSubType(v);
case 0x02: break; // not implemented
case 0x03: break; // not implemented
@@ -780,8 +780,8 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
ticks = v->load_unload_ticks;
} else {
switch (v->type) {
case VEH_TRAIN: ticks = Train::From(v)->wait_counter; break;
case VEH_AIRCRAFT: ticks = Aircraft::From(v)->turn_counter; break;
case VehicleType::Train: ticks = Train::From(v)->wait_counter; break;
case VehicleType::Aircraft: ticks = Aircraft::From(v)->turn_counter; break;
default: ticks = 0; break;
}
}
@@ -797,7 +797,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0x19: {
uint max_speed;
switch (v->type) {
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
break;
@@ -833,8 +833,8 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0x31: break; // not implemented
case 0x32: return v->vehstatus.base();
case 0x33: return 0; // non-existent high byte of vehstatus
case 0x34: return v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed;
case 0x35: return GB(v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 8);
case 0x34: return v->type == VehicleType::Aircraft ? (v->cur_speed * 10) / 128 : v->cur_speed;
case 0x35: return GB(v->type == VehicleType::Aircraft ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 8);
case 0x36: return v->subspeed;
case 0x37: return v->acceleration;
case 0x38: break; // not implemented
@@ -854,7 +854,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0x46: return v->GetEngine()->grf_prop.local_id;
case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
case 0x48:
if (v->type != VEH_TRAIN || v->spritenum != CUSTOM_VEHICLE_SPRITENUM) return v->spritenum;
if (v->type != VehicleType::Train || v->spritenum != CUSTOM_VEHICLE_SPRITENUM) return v->spritenum;
return Train::From(v)->flags.Test(VehicleRailFlag::Flipped) ? CUSTOM_VEHICLE_SPRITENUM_REVERSED : CUSTOM_VEHICLE_SPRITENUM;
case 0x49: return v->day_counter;
@@ -916,7 +916,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
/* Vehicle specific properties */
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
switch (variable - 0x80) {
case 0x62: return t->track;
@@ -933,7 +933,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *rv = RoadVehicle::From(v);
switch (variable - 0x80) {
case 0x62: return rv->state;
@@ -947,7 +947,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
break;
}
case VEH_SHIP: {
case VehicleType::Ship: {
Ship *s = Ship::From(v);
switch (variable - 0x80) {
case 0x62: return s->state;
@@ -955,7 +955,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
break;
}
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
Aircraft *a = Aircraft::From(v);
switch (variable - 0x80) {
case 0x62: return MapAircraftMovementState(a); // Current movement state
@@ -1041,10 +1041,10 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
GrfSpecFeature VehicleResolverObject::GetFeature() const
{
switch (Engine::Get(this->self_scope.self_type)->type) {
case VEH_TRAIN: return GrfSpecFeature::Trains;
case VEH_ROAD: return GrfSpecFeature::RoadVehicles;
case VEH_SHIP: return GrfSpecFeature::Ships;
case VEH_AIRCRAFT: return GrfSpecFeature::Aircraft;
case VehicleType::Train: return GrfSpecFeature::Trains;
case VehicleType::Road: return GrfSpecFeature::RoadVehicles;
case VehicleType::Ship: return GrfSpecFeature::Ships;
case VehicleType::Aircraft: return GrfSpecFeature::Aircraft;
default: return GrfSpecFeature::Invalid;
}
}
@@ -1092,7 +1092,7 @@ VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle
/* For trains we always use cached value, except for callbacks because the override spriteset
* to use may be different than the one cached. It happens for callback 0x15 (refit engine),
* as v->cargo_type is temporary changed to the new type */
if (wagon_override == WO_CACHED && v->type == VEH_TRAIN) {
if (wagon_override == WO_CACHED && v->type == VehicleType::Train) {
this->root_spritegroup = Train::From(v)->tcache.cached_override;
} else {
this->root_spritegroup = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
@@ -1142,7 +1142,7 @@ static void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, En
const Engine *e = Engine::Get(engine);
/* Only valid for helicopters */
assert(e->type == VEH_AIRCRAFT);
assert(e->type == VehicleType::Aircraft);
assert(!(e->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL));
/* We differ from TTDPatch by resolving the sprite using the primary vehicle 'v', and not using the rotor vehicle 'v->Next()->Next()'.
@@ -1186,7 +1186,7 @@ void GetCustomRotorIcon(EngineID engine, EngineImageType image_type, VehicleSpri
*/
bool UsesWagonOverride(const Vehicle *v)
{
assert(v->type == VEH_TRAIN);
assert(v->type == VehicleType::Train);
return Train::From(v)->tcache.cached_override != nullptr;
}
+4 -4
View File
@@ -383,16 +383,16 @@ struct NewsWindow : Window {
if (has_vehicle_id && nwid != nullptr) {
const Vehicle *v = Vehicle::Get(std::get<VehicleID>(ni->ref1));
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
nwid->SetString(STR_TRAIN);
break;
case VEH_ROAD:
case VehicleType::Road:
nwid->SetString(RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY);
break;
case VEH_SHIP:
case VehicleType::Ship:
nwid->SetString(STR_SHIP);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
nwid->SetString(STR_PLANE);
break;
default:
+37 -37
View File
@@ -538,7 +538,7 @@ void OrderList::DebugCheckSanity() const
static inline bool OrderGoesToStation(const Vehicle *v, const Order &o)
{
return o.IsType(OT_GOTO_STATION) ||
(v->type == VEH_AIRCRAFT && o.IsType(OT_GOTO_DEPOT) && o.GetDestination() != StationID::Invalid());
(v->type == VehicleType::Aircraft && o.IsType(OT_GOTO_DEPOT) && o.GetDestination() != StationID::Invalid());
}
/**
@@ -565,12 +565,12 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
case OT_GOTO_WAYPOINT:
case OT_GOTO_STATION:
case OT_IMPLICIT:
if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination().ToStationID())->airport.tile;
if (airport && v->type == VehicleType::Aircraft) return Station::Get(this->GetDestination().ToStationID())->airport.tile;
return BaseStation::Get(this->GetDestination().ToStationID())->xy;
case OT_GOTO_DEPOT:
if (this->GetDestination() == DepotID::Invalid()) return INVALID_TILE;
return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination().ToStationID())->xy : Depot::Get(this->GetDestination().ToDepotID())->xy;
return (v->type == VehicleType::Aircraft) ? Station::Get(this->GetDestination().ToStationID())->xy : Depot::Get(this->GetDestination().ToDepotID())->xy;
default:
return INVALID_TILE;
@@ -605,7 +605,7 @@ uint GetOrderDistance(VehicleOrderID prev, VehicleOrderID cur, const Vehicle *v,
TileIndex prev_tile = orders[prev].GetLocation(v, true);
TileIndex cur_tile = orders[cur].GetLocation(v, true);
if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
return v->type == VehicleType::Aircraft ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
}
/**
@@ -678,7 +678,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
switch (new_order.GetStopLocation()) {
case OrderStopLocation::NearEnd:
case OrderStopLocation::Middle:
if (v->type != VEH_TRAIN) return CMD_ERROR;
if (v->type != VehicleType::Train) return CMD_ERROR;
[[fallthrough]];
case OrderStopLocation::FarEnd:
@@ -693,7 +693,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
case OT_GOTO_DEPOT: {
if (!new_order.GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) {
if (v->type == VEH_AIRCRAFT) {
if (v->type == VehicleType::Aircraft) {
const Station *st = Station::GetIfValid(new_order.GetDestination().ToStationID());
if (st == nullptr) return CMD_ERROR;
@@ -713,15 +713,15 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
if (ret.Failed()) return ret;
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
break;
case VEH_ROAD:
case VehicleType::Road:
if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
break;
case VEH_SHIP:
case VehicleType::Ship:
if (!IsShipDepotTile(dp->xy)) return CMD_ERROR;
break;
@@ -760,7 +760,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
switch (v->type) {
default: return CMD_ERROR;
case VEH_TRAIN: {
case VehicleType::Train: {
if (!wp->facilities.Test(StationFacility::Train)) return CommandCost(STR_ERROR_CAN_T_ADD_ORDER, STR_ERROR_NO_RAIL_WAYPOINT);
ret = CheckOwnership(wp->owner);
@@ -768,7 +768,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
if (!wp->facilities.Test(StationFacility::BusStop) && !wp->facilities.Test(StationFacility::TruckStop)) return CommandCost(STR_ERROR_CAN_T_ADD_ORDER, STR_ERROR_NO_ROAD_WAYPOINT);
ret = CheckOwnership(wp->owner);
@@ -776,7 +776,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
break;
}
case VEH_SHIP:
case VehicleType::Ship:
if (!wp->facilities.Test(StationFacility::Dock)) return CommandCost(STR_ERROR_CAN_T_ADD_ORDER, STR_ERROR_NO_BUOY);
if (wp->owner != OWNER_NONE) {
ret = CheckOwnership(wp->owner);
@@ -802,7 +802,7 @@ CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
if (occ >= OrderConditionComparator::End) return CMD_ERROR;
switch (new_order.GetConditionVariable()) {
case OrderConditionVariable::DrivingBackwards:
if (v->type != VEH_TRAIN) return CMD_ERROR;
if (v->type != VehicleType::Train) return CMD_ERROR;
[[fallthrough]];
case OrderConditionVariable::RequiresService:
@@ -1059,8 +1059,8 @@ CommandCost CmdSkipToOrder(DoCommandFlags flags, VehicleID veh_id, VehicleOrderI
InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
/* We have an aircraft/ship, they have a mini-schedule, so update them all */
if (v->type == VEH_AIRCRAFT) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
if (v->type == VEH_SHIP) SetWindowClassesDirty(WC_SHIPS_LIST);
if (v->type == VehicleType::Aircraft) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
if (v->type == VehicleType::Ship) SetWindowClassesDirty(WC_SHIPS_LIST);
}
return CommandCost();
@@ -1226,7 +1226,7 @@ CommandCost CmdModifyOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
}
case MOF_STOP_LOCATION:
if (v->type != VEH_TRAIN) return CMD_ERROR;
if (v->type != VehicleType::Train) return CMD_ERROR;
if (data >= to_underlying(OrderStopLocation::End)) return CMD_ERROR;
break;
@@ -1289,7 +1289,7 @@ CommandCost CmdModifyOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID s
case MOF_COND_VARIABLE: {
OrderConditionVariable cond_variable = static_cast<OrderConditionVariable>(data);
if (cond_variable >= OrderConditionVariable::End) return CMD_ERROR;
if (cond_variable == OrderConditionVariable::DrivingBackwards && v->type != VEH_TRAIN) return CMD_ERROR;
if (cond_variable == OrderConditionVariable::DrivingBackwards && v->type != VehicleType::Train) return CMD_ERROR;
break;
}
@@ -1521,7 +1521,7 @@ CommandCost CmdCloneOrder(DoCommandFlags flags, CloneOptions action, VehicleID v
if (ret.Failed()) return ret;
/* Trucks can't share orders with busses (and visa versa) */
if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
if (src->type == VehicleType::Road && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
return CMD_ERROR;
}
@@ -1541,7 +1541,7 @@ CommandCost CmdCloneOrder(DoCommandFlags flags, CloneOptions action, VehicleID v
}
/* Check for aircraft range limits. */
if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src)) {
if (dst->type == VehicleType::Aircraft && !CheckAircraftOrderDistance(Aircraft::From(dst), src)) {
return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
}
@@ -1588,7 +1588,7 @@ CommandCost CmdCloneOrder(DoCommandFlags flags, CloneOptions action, VehicleID v
}
/* Check for aircraft range limits. */
if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src)) {
if (dst->type == VehicleType::Aircraft && !CheckAircraftOrderDistance(Aircraft::From(dst), src)) {
return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
}
@@ -1719,7 +1719,7 @@ void CheckOrders(const Vehicle *v)
n_st++;
if (!CanVehicleUseStation(v, st)) {
message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
} else if (v->type == VEH_AIRCRAFT &&
} else if (v->type == VehicleType::Aircraft &&
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
st->airport.GetFTA()->flags.Test(AirportFTAClass::Flag::ShortStrip) &&
!_cheats.no_jetcrash.value &&
@@ -1768,8 +1768,8 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool
/* Go through all vehicles */
for (Vehicle *v : Vehicle::Iterate()) {
if ((v->type == VEH_AIRCRAFT && v->current_order.IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : v->current_order.GetType()) == type &&
(!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
if ((v->type == VehicleType::Aircraft && v->current_order.IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : v->current_order.GetType()) == type &&
(!hangar || v->type == VehicleType::Aircraft) && v->current_order.GetDestination() == destination) {
v->current_order.MakeDummy();
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
}
@@ -1782,8 +1782,8 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool
Order *order = v->orders->GetOrderAt(id);
OrderType ot = order->GetType();
if (ot == OT_GOTO_DEPOT && order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) continue;
if (ot == OT_GOTO_DEPOT && hangar && v->type != VEH_AIRCRAFT) continue; // Not an aircraft? Can't have a hangar order.
if (ot == OT_IMPLICIT || (v->type == VEH_AIRCRAFT && ot == OT_GOTO_DEPOT && !hangar)) ot = OT_GOTO_STATION;
if (ot == OT_GOTO_DEPOT && hangar && v->type != VehicleType::Aircraft) continue; // Not an aircraft? Can't have a hangar order.
if (ot == OT_IMPLICIT || (v->type == VehicleType::Aircraft && ot == OT_GOTO_DEPOT && !hangar)) ot = OT_GOTO_STATION;
if (ot == type && order->GetDestination() == destination) {
/* We want to clear implicit orders, but we don't want to make them
* dummy orders. They should just vanish. Also check the actual order
@@ -1999,9 +1999,9 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
v->current_order.SetDestination(closest_depot.destination);
/* If there is no depot in front, reverse automatically (trains only) */
if (v->type == VEH_TRAIN && closest_depot.reverse) Command<Commands::ReverseTrainDirection>::Do(DoCommandFlag::Execute, v->index, false);
if (v->type == VehicleType::Train && closest_depot.reverse) Command<Commands::ReverseTrainDirection>::Do(DoCommandFlag::Execute, v->index, false);
if (v->type == VEH_AIRCRAFT) {
if (v->type == VehicleType::Aircraft) {
Aircraft *a = Aircraft::From(v);
if (a->state == FLYING && a->targetairport != closest_depot.destination) {
/* The aircraft is now heading for a different hangar than the next in the orders */
@@ -2017,7 +2017,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
UpdateVehicleTimetable(v, true);
v->IncrementRealOrderIndex();
} else {
if (v->type != VEH_AIRCRAFT) {
if (v->type != VehicleType::Aircraft) {
v->SetDestTile(Depot::Get(order->GetDestination().ToStationID())->xy);
} else {
Aircraft *a = Aircraft::From(v);
@@ -2103,7 +2103,7 @@ bool ProcessOrders(Vehicle *v)
return false;
case OT_LEAVESTATION:
if (v->type != VEH_AIRCRAFT) return false;
if (v->type != VehicleType::Aircraft) return false;
break;
default: break;
@@ -2144,8 +2144,8 @@ bool ProcessOrders(Vehicle *v)
}
/* If no order, do nothing. */
if (order == nullptr || (v->type == VEH_AIRCRAFT && !CheckForValidOrders(v))) {
if (v->type == VEH_AIRCRAFT) {
if (order == nullptr || (v->type == VehicleType::Aircraft && !CheckForValidOrders(v))) {
if (v->type == VehicleType::Aircraft) {
/* Aircraft do something vastly different here, so handle separately */
HandleMissingAircraftOrders(Aircraft::From(v));
return false;
@@ -2157,8 +2157,8 @@ bool ProcessOrders(Vehicle *v)
}
/* If it is unchanged, keep it. */
if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != INVALID_TILE) &&
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination().ToStationID())->ship_station.tile != INVALID_TILE)) {
if (order->Equals(v->current_order) && (v->type == VehicleType::Aircraft || v->dest_tile != INVALID_TILE) &&
(v->type != VehicleType::Ship || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination().ToStationID())->ship_station.tile != INVALID_TILE)) {
return false;
}
@@ -2170,12 +2170,12 @@ bool ProcessOrders(Vehicle *v)
default:
NOT_REACHED();
case VEH_ROAD:
case VEH_TRAIN:
case VehicleType::Road:
case VehicleType::Train:
break;
case VEH_AIRCRAFT:
case VEH_SHIP:
case VehicleType::Aircraft:
case VehicleType::Ship:
SetWindowClassesDirty(GetWindowClassForVehicleType(v->type));
break;
}
+16 -16
View File
@@ -282,7 +282,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
}
if (v->type == VEH_TRAIN && !order->GetNonStopType().Test(OrderNonStopFlag::GoVia)) {
if (v->type == VehicleType::Train && !order->GetNonStopType().Test(OrderNonStopFlag::GoVia)) {
/* Only show the stopping location if other than the default chosen by the player. */
if (order->GetStopLocation() != _settings_client.gui.stop_location) {
line += GetString(STR_ORDER_STOP_LOCATION_NEAR_END + to_underlying(order->GetStopLocation()));
@@ -296,12 +296,12 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
if (!order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) {
/* Going to a specific depot. */
line = GetString(STR_ORDER_GO_TO_DEPOT_FORMAT, GetOrderGoToString(*order), v->type, order->GetDestination());
} else if (v->type == VEH_AIRCRAFT) {
} else if (v->type == VehicleType::Aircraft) {
/* Going to the nearest hangar. */
line = GetString(STR_ORDER_GO_TO_NEAREST_HANGAR_FORMAT, GetOrderGoToString(*order));
} else {
/* Going to the nearest depot. */
line = GetString(STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT, GetOrderGoToString(*order), STR_ORDER_TRAIN_DEPOT + v->type);
line = GetString(STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT, GetOrderGoToString(*order), STR_ORDER_TRAIN_DEPOT + to_underlying(v->type));
}
/* Do not show stopping in the depot in the timetable window. */
@@ -350,7 +350,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
/* Check range for aircraft. */
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
if (v->type == VehicleType::Aircraft && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
if (GetOrderDistance(order_index, v->orders->GetNext(order_index), v) > Aircraft::From(v)->acache.cached_max_range_sqr) {
line += GetString(STR_ORDER_OUT_OF_RANGE);
}
@@ -385,7 +385,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
/* check rail waypoint */
if (IsRailWaypointTile(tile) &&
v->type == VEH_TRAIN &&
v->type == VehicleType::Train &&
IsTileOwner(tile, _local_company)) {
order.MakeGoToWaypoint(GetStationIndex(tile));
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType({OrderNonStopFlag::NonStop, OrderNonStopFlag::GoVia});
@@ -394,7 +394,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
/* check road waypoint */
if (IsRoadWaypointTile(tile) &&
v->type == VEH_ROAD &&
v->type == VehicleType::Road &&
IsTileOwner(tile, _local_company)) {
order.MakeGoToWaypoint(GetStationIndex(tile));
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType({OrderNonStopFlag::NonStop, OrderNonStopFlag::GoVia});
@@ -402,7 +402,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
}
/* check buoy (no ownership) */
if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
if (IsBuoyTile(tile) && v->type == VehicleType::Ship) {
order.MakeGoToWaypoint(GetStationIndex(tile));
return order;
}
@@ -420,17 +420,17 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
if (st != nullptr && (st->owner == _local_company || st->owner == OWNER_NONE)) {
StationFacilities facil;
switch (v->type) {
case VEH_SHIP: facil = StationFacility::Dock; break;
case VEH_TRAIN: facil = StationFacility::Train; break;
case VEH_AIRCRAFT: facil = StationFacility::Airport; break;
case VEH_ROAD: facil = {StationFacility::BusStop, StationFacility::TruckStop}; break;
case VehicleType::Ship: facil = StationFacility::Dock; break;
case VehicleType::Train: facil = StationFacility::Train; break;
case VehicleType::Aircraft: facil = StationFacility::Airport; break;
case VehicleType::Road: facil = {StationFacility::BusStop, StationFacility::TruckStop}; break;
default: NOT_REACHED();
}
if (st->facilities.Any(facil)) {
order.MakeGoToStation(st->index);
if (_ctrl_pressed) order.SetLoadType(OrderLoadType::FullLoadAny);
if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(OrderNonStopFlag::NonStop);
order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OrderStopLocation::FarEnd);
order.SetStopLocation(v->type == VehicleType::Train ? (OrderStopLocation)(_settings_client.gui.stop_location) : OrderStopLocation::FarEnd);
return order;
}
}
@@ -777,7 +777,7 @@ public:
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
if (NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_O_DEPOT_ACTION); nwid != nullptr) {
nwid->SetToolTip(STR_ORDER_TRAIN_DEPOT_ACTION_TOOLTIP + v->type);
nwid->SetToolTip(STR_ORDER_TRAIN_DEPOT_ACTION_TOOLTIP + to_underlying(v->type));
}
this->FinishInitNested(v->index);
@@ -1201,7 +1201,7 @@ public:
/* Deselect clicked order */
this->selected_order = -1;
} else if (sel == this->selected_order && click_count > 1) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
if (this->vehicle->type == VehicleType::Train && sel < this->vehicle->GetNumOrders()) {
Command<Commands::ModifyOrder>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
this->vehicle->tile, this->vehicle->index, sel,
MOF_STOP_LOCATION, (to_underlying(this->vehicle->GetOrder(sel)->GetStopLocation()) + 1) % to_underlying(OrderStopLocation::End));
@@ -1259,7 +1259,7 @@ public:
case OPOS_SHARE: sel = 3; break;
default: NOT_REACHED();
}
ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
ShowDropDownMenu(this, this->vehicle->type == VehicleType::Aircraft ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
}
break;
@@ -1302,7 +1302,7 @@ public:
case WID_O_COND_VARIABLE: {
DropDownList list;
for (const auto &ocv : _order_conditional_variable) {
if (ocv == OrderConditionVariable::DrivingBackwards && this->vehicle->type != VEH_TRAIN) continue;
if (ocv == OrderConditionVariable::DrivingBackwards && this->vehicle->type != VehicleType::Train) continue;
list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv), to_underlying(ocv)));
}
ShowDropDownList(this, std::move(list), to_underlying(this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable()), WID_O_COND_VARIABLE);
+1 -1
View File
@@ -63,7 +63,7 @@ struct CFollowTrackT {
inline void Init(const VehicleType *v, RailTypes railtype_override)
{
assert(!IsRailTT() || (v != nullptr && v->type == VEH_TRAIN));
assert(!IsRailTT() || (v != nullptr && v->type == ::VehicleType::Train));
this->veh = v;
Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override);
}
+1 -1
View File
@@ -271,7 +271,7 @@ public:
int cost = 0;
const Train *v = Yapf().GetVehicle();
assert(v != nullptr);
assert(v->type == VEH_TRAIN);
assert(v->type == VehicleType::Train);
assert(v->gcache.cached_total_length != 0);
int missing_platform_length = CeilDiv(v->gcache.cached_total_length, TILE_SIZE) - platform_length;
if (missing_platform_length < 0) {
+1 -1
View File
@@ -381,7 +381,7 @@ public:
/* Check docking tile for occupancy. */
uint count = std::ranges::count_if(VehiclesOnTile(n.GetTile()), [](const Vehicle *v) {
/* Ignore other vehicles (aircraft) and ships inside depot. */
return v->type == VEH_SHIP && !v->vehstatus.Test(VehState::Hidden);
return v->type == VehicleType::Ship && !v->vehstatus.Test(VehState::Hidden);
});
c += count * 3 * YAPF_TILE_LENGTH;
}
+2 -2
View File
@@ -279,7 +279,7 @@ struct FindTrainOnTrackInfo {
static void CheckTrainsOnTrack(FindTrainOnTrackInfo &info, TileIndex tile)
{
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != VEH_TRAIN || v->vehstatus.Test(VehState::Crashed)) continue;
if (v->type != VehicleType::Train || v->vehstatus.Test(VehState::Crashed)) continue;
Train *t = Train::From(v);
if (t->track == TRACK_BIT_WORMHOLE || HasBit(static_cast<TrackBits>(t->track), TrackdirToTrack(info.res.trackdir))) {
@@ -300,7 +300,7 @@ static void CheckTrainsOnTrack(FindTrainOnTrackInfo &info, TileIndex tile)
*/
PBSTileInfo FollowTrainReservation(const Train *consist, Vehicle **train_on_res)
{
assert(consist->type == VEH_TRAIN);
assert(consist->type == VehicleType::Train);
const Train *moving_front = consist->GetMovingFront();
+2 -2
View File
@@ -138,7 +138,7 @@ RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
{
RailTypes rts{};
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (const Engine *e : Engine::IterateType(VehicleType::Train)) {
const EngineInfo *ei = &e->info;
if (ei->climates.Test(_settings_game.game_creation.landscape) &&
@@ -169,7 +169,7 @@ RailTypes GetRailTypes(bool introduces)
{
RailTypes rts{};
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
for (const Engine *e : Engine::IterateType(VehicleType::Train)) {
const EngineInfo *ei = &e->info;
if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue;
+6 -6
View File
@@ -1626,7 +1626,7 @@ CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_
MarkTileDirtyByTile(tile);
/* update power of train on this tile */
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type == VEH_TRAIN) include(affected_trains, Train::From(v)->First());
if (v->type == VehicleType::Train) include(affected_trains, Train::From(v)->First());
}
}
}
@@ -1706,10 +1706,10 @@ CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_
SetRailType(endtile, totype);
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type == VEH_TRAIN) include(affected_trains, Train::From(v)->First());
if (v->type == VehicleType::Train) include(affected_trains, Train::From(v)->First());
}
for (Vehicle *v : VehiclesOnTile(endtile)) {
if (v->type == VEH_TRAIN) include(affected_trains, Train::From(v)->First());
if (v->type == VehicleType::Train) include(affected_trains, Train::From(v)->First());
}
YapfNotifyTrackLayoutChange(tile, track);
@@ -2808,7 +2808,7 @@ static bool ClickTile_Rail(TileIndex tile)
{
if (!IsRailDepot(tile)) return false;
ShowDepotWindow(tile, VEH_TRAIN);
ShowDepotWindow(tile, VehicleType::Train);
return true;
}
@@ -2967,7 +2967,7 @@ int TicksToLeaveDepot(const Train *v)
static VehicleEnterTileStates VehicleEnterTile_Rail(Vehicle *v, TileIndex tile, int x, int y)
{
/* This routine applies only to trains in depot tiles. */
if (v->type != VEH_TRAIN || !IsRailDepotTile(tile)) return {};
if (v->type != VehicleType::Train || !IsRailDepotTile(tile)) return {};
/* Depot direction. */
DiagDirection dir = GetRailDepotDirection(tile);
@@ -3085,7 +3085,7 @@ static CommandCost TerraformTile_Rail(TileIndex tile, DoCommandFlags flags, int
/* Allow clearing the water only if there is no ship */
if (was_water && HasVehicleOnTile(tile, [](const Vehicle *v) {
return v->type == VEH_SHIP;
return v->type == VehicleType::Ship;
})) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY);
/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
+3 -3
View File
@@ -481,7 +481,7 @@ struct BuildRailToolbarWindow : Window {
return;
}
bool can_build = CanBuildVehicleInfrastructure(VEH_TRAIN);
bool can_build = CanBuildVehicleInfrastructure(VehicleType::Train);
for (const WidgetID widget : can_build_widgets) this->SetWidgetDisabledState(widget, !can_build);
if (!can_build) {
CloseWindowById(WC_BUILD_SIGNAL, TRANSPORT_RAIL);
@@ -494,7 +494,7 @@ struct BuildRailToolbarWindow : Window {
bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
{
bool can_build = CanBuildVehicleInfrastructure(VEH_TRAIN);
bool can_build = CanBuildVehicleInfrastructure(VehicleType::Train);
if (can_build) return false;
if (std::ranges::find(can_build_widgets, widget) == std::end(can_build_widgets)) return false;
@@ -562,7 +562,7 @@ struct BuildRailToolbarWindow : Window {
if (widget == WID_RAT_CAPTION) {
const RailTypeInfo *rti = GetRailTypeInfo(this->railtype);
if (rti->max_speed > 0) {
return GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed, VEH_TRAIN));
return GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed, VehicleType::Train));
}
return GetString(rti->strings.toolbar_caption);
}
+2 -2
View File
@@ -211,7 +211,7 @@ RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
{
RoadTypes rts{};
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
for (const Engine *e : Engine::IterateType(VehicleType::Road)) {
const EngineInfo *ei = &e->info;
if (ei->climates.Test(_settings_game.game_creation.landscape) &&
@@ -239,7 +239,7 @@ RoadTypes GetRoadTypes(bool introduces)
{
RoadTypes rts{};
for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
for (const Engine *e : Engine::IterateType(VehicleType::Road)) {
const EngineInfo *ei = &e->info;
if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue;
+5 -5
View File
@@ -2117,7 +2117,7 @@ static bool ClickTile_Road(TileIndex tile)
{
if (!IsRoadDepot(tile)) return false;
ShowDepotWindow(tile, VEH_ROAD);
ShowDepotWindow(tile, VehicleType::Road);
return true;
}
@@ -2297,7 +2297,7 @@ static VehicleEnterTileStates VehicleEnterTile_Road(Vehicle *v, TileIndex tile,
{
switch (GetRoadTileType(tile)) {
case RoadTileType::Depot: {
if (v->type != VEH_ROAD) break;
if (v->type != VehicleType::Road) break;
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
@@ -2574,7 +2574,7 @@ CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_
/* update power of train on this tile */
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type == VEH_ROAD) include(affected_rvs, RoadVehicle::From(v)->First());
if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
}
if (IsRoadDepotTile(tile)) {
@@ -2633,10 +2633,10 @@ CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_
SetRoadType(endtile, rtt, to_type);
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type == VEH_ROAD) include(affected_rvs, RoadVehicle::From(v)->First());
if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
}
for (Vehicle *v : VehiclesOnTile(endtile)) {
if (v->type == VEH_ROAD) include(affected_rvs, RoadVehicle::From(v)->First());
if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
}
if (IsBridge(tile)) {
+2 -2
View File
@@ -389,7 +389,7 @@ struct BuildRoadToolbarWindow : Window {
RoadTramType rtt = GetRoadTramType(this->roadtype);
bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, rtt);
bool can_build = CanBuildVehicleInfrastructure(VehicleType::Road, rtt);
this->SetWidgetsDisabledState(!can_build,
WID_ROT_DEPOT,
WID_ROT_BUILD_WAYPOINT,
@@ -447,7 +447,7 @@ struct BuildRoadToolbarWindow : Window {
if (widget == WID_ROT_CAPTION) {
const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
if (rti->max_speed > 0) {
return GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VEH_ROAD));
return GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VehicleType::Road));
}
return GetString(rti->strings.toolbar_caption);
+1 -1
View File
@@ -334,7 +334,7 @@ void RoadStop::Entry::Rebuild(const RoadStop *rs, int side)
this->length += TILE_SIZE;
for (const Vehicle *v : VehiclesOnTile(tile)) {
/* Not a RV or not in the right direction or crashed :( */
if (v->type != VEH_ROAD || DirToDiagDir(v->direction) != entry_dir || !v->IsPrimaryVehicle() || v->vehstatus.Test(VehState::Crashed)) continue;
if (v->type != VehicleType::Road || DirToDiagDir(v->direction) != entry_dir || !v->IsPrimaryVehicle() || v->vehstatus.Test(VehState::Crashed)) continue;
const RoadVehicle *rv = RoadVehicle::From(v);
/* Don't add ones not in a road stop */
+2 -2
View File
@@ -102,7 +102,7 @@ using RoadVehPathCache = std::vector<RoadVehPathElement>;
/**
* Buses, trucks and trams belong to this class.
*/
struct RoadVehicle final : public GroundVehicle<RoadVehicle, VEH_ROAD> {
struct RoadVehicle final : public GroundVehicle<RoadVehicle, VehicleType::Road> {
RoadVehPathCache path{}; ///< Cached path.
uint8_t state = 0; ///< @see RoadVehicleStates
uint8_t frame = 0;
@@ -120,7 +120,7 @@ struct RoadVehicle final : public GroundVehicle<RoadVehicle, VEH_ROAD> {
/** We want to 'destruct' the right class. */
~RoadVehicle() override { this->PreDestructor(); }
friend struct GroundVehicle<RoadVehicle, VEH_ROAD>; // GroundVehicle needs to use the acceleration functions defined at RoadVehicle.
friend struct GroundVehicle<RoadVehicle, VehicleType::Road>; // GroundVehicle needs to use the acceleration functions defined at RoadVehicle.
void MarkDirty() override;
void UpdateDeltaXY() override;
+7 -7
View File
@@ -67,7 +67,7 @@ static_assert(lengthof(_roadveh_images) == lengthof(_roadveh_full_adder));
/** @copydoc IsValidImageIndex */
template <>
bool IsValidImageIndex<VEH_ROAD>(uint8_t image_index)
bool IsValidImageIndex<VehicleType::Road>(uint8_t image_index)
{
return image_index < lengthof(_roadveh_images);
}
@@ -114,7 +114,7 @@ static void GetRoadVehIcon(EngineID engine, EngineImageType image_type, VehicleS
spritenum = e->original_image_index;
}
assert(IsValidImageIndex<VEH_ROAD>(spritenum));
assert(IsValidImageIndex<VehicleType::Road>(spritenum));
result->Set(DIR_W + _roadveh_images[spritenum]);
}
@@ -130,7 +130,7 @@ void RoadVehicle::GetImage(Direction direction, EngineImageType image_type, Vehi
spritenum = this->GetEngine()->original_image_index;
}
assert(IsValidImageIndex<VEH_ROAD>(spritenum));
assert(IsValidImageIndex<VehicleType::Road>(spritenum));
SpriteID sprite = direction + _roadveh_images[spritenum];
if (this->cargo.StoredCount() >= this->cargo_cap / 2U) sprite += _roadveh_full_adder[spritenum];
@@ -220,7 +220,7 @@ static uint GetRoadVehLength(const RoadVehicle *v)
*/
void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
{
assert(v->type == VEH_ROAD);
assert(v->type == VehicleType::Road);
assert(v->IsFrontEngine());
v->InvalidateNewGRFCacheOfChain();
@@ -582,7 +582,7 @@ static bool RoadVehCheckTrainCrash(RoadVehicle *v)
if (!IsLevelCrossingTile(tile)) continue;
if (HasVehicleNearTileXY(v->x_pos, v->y_pos, 4, [&u](const Vehicle *t) {
return t->type == VEH_TRAIN && abs(t->z_pos - u->z_pos) <= 6;
return t->type == VehicleType::Train && abs(t->z_pos - u->z_pos) <= 6;
})) {
RoadVehCrash(v);
return true;
@@ -635,7 +635,7 @@ static void FindClosestBlockingRoadVeh(Vehicle *v, RoadVehFindData *rvf)
int y_diff = v->y_pos - rvf->y;
/* Not a close Road vehicle when it's not a road vehicle, in the depot, or ourself. */
if (v->type != VEH_ROAD || v->IsInDepot() || rvf->veh->First() == v->First()) return;
if (v->type != VehicleType::Road || v->IsInDepot() || rvf->veh->First() == v->First()) return;
/* Not close when at a different height or when going in a different direction. */
if (abs(v->z_pos - rvf->veh->z_pos) >= 6 || v->direction != rvf->dir) return;
@@ -802,7 +802,7 @@ static bool CheckRoadBlockedForOvertaking(OvertakeData *od)
/* Are there more vehicles on the tile except the two vehicles involved in overtaking */
return HasVehicleOnTile(od->tile, [&](const Vehicle *v) {
return v->type == VEH_ROAD && v->First() == v && v != od->u && v != od->v;
return v->type == VehicleType::Road && v->First() == v && v != od->u && v != od->v;
});
}
+13 -13
View File
@@ -1296,7 +1296,7 @@ bool AfterLoadGame()
} else {
continue;
}
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
Train::From(v)->track = TRACK_BIT_WORMHOLE;
} else {
RoadVehicle::From(v)->state = RVSB_WORMHOLE;
@@ -1435,7 +1435,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_26)) {
for (Station *st : Station::Iterate()) {
st->last_vehicle_type = VEH_INVALID;
st->last_vehicle_type = VehicleType::Invalid;
}
}
@@ -1675,7 +1675,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_57)) {
/* Added a FIFO queue of vehicles loading at stations */
for (Vehicle *v : Vehicle::Iterate()) {
if ((v->type != VEH_TRAIN || Train::From(v)->IsFrontEngine()) && // for all locs
if ((v->type != VehicleType::Train || Train::From(v)->IsFrontEngine()) && // for all locs
!v->vehstatus.Any({VehState::Stopped, VehState::Crashed}) && // not stopped or crashed
v->current_order.IsType(OT_LOADING)) { // loading
Station::Get(v->last_station_visited)->loading_vehicles.push_back(v);
@@ -1826,7 +1826,7 @@ bool AfterLoadGame()
}
v->current_order.ConvertFromOldSavegame();
if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
if (v->type == VehicleType::Road && v->IsPrimaryVehicle() && v->FirstShared() == v) {
for (Order &order : v->Orders()) order.SetNonStopType(OrderNonStopFlag::NonStop);
}
}
@@ -2240,7 +2240,7 @@ bool AfterLoadGame()
for (DisasterVehicle *v : DisasterVehicle::Iterate()) {
if (v->subtype == 2 /* ST_SMALL_UFO */ && v->state != 0) {
const Vehicle *u = Vehicle::GetIfValid(v->dest_tile.base());
if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
if (u == nullptr || u->type != VehicleType::Road || !RoadVehicle::From(u)->IsFrontEngine()) {
delete v;
}
}
@@ -2673,16 +2673,16 @@ bool AfterLoadGame()
v->vehstatus.Set(VehState::Hidden);
switch (v->type) {
case VEH_TRAIN: Train::From(v)->track = TRACK_BIT_WORMHOLE; break;
case VEH_ROAD: RoadVehicle::From(v)->state = RVSB_WORMHOLE; break;
case VehicleType::Train: Train::From(v)->track = TRACK_BIT_WORMHOLE; break;
case VehicleType::Road: RoadVehicle::From(v)->state = RVSB_WORMHOLE; break;
default: NOT_REACHED();
}
} else {
v->vehstatus.Reset(VehState::Hidden);
switch (v->type) {
case VEH_TRAIN: Train::From(v)->track = DiagDirToDiagTrackBits(vdir); break;
case VEH_ROAD: RoadVehicle::From(v)->state = DiagDirToDiagTrackdir(vdir); RoadVehicle::From(v)->frame = frame; break;
case VehicleType::Train: Train::From(v)->track = DiagDirToDiagTrackBits(vdir); break;
case VehicleType::Road: RoadVehicle::From(v)->state = DiagDirToDiagTrackdir(vdir); RoadVehicle::From(v)->frame = frame; break;
default: NOT_REACHED();
}
}
@@ -2740,7 +2740,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_158)) {
for (Vehicle *v : Vehicle::Iterate()) {
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
/* Clear old GOINGUP / GOINGDOWN flags.
@@ -2763,7 +2763,7 @@ bool AfterLoadGame()
t->gv_flags |= FixVehicleInclination(t, t->direction);
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *rv = RoadVehicle::From(v);
ClrBit(rv->gv_flags, GVF_GOINGUP_BIT);
ClrBit(rv->gv_flags, GVF_GOINGDOWN_BIT);
@@ -2793,7 +2793,7 @@ bool AfterLoadGame()
rv->gv_flags |= FixVehicleInclination(rv, dir);
break;
}
case VEH_SHIP:
case VehicleType::Ship:
break;
default:
@@ -2806,7 +2806,7 @@ bool AfterLoadGame()
* by loading and saving the game in a new version. */
v->z_pos = GetSlopePixelZ(v->x_pos, v->y_pos, true);
DiagDirection dir = GetTunnelBridgeDirection(v->tile);
if (v->type == VEH_TRAIN && !v->vehstatus.Test(VehState::Crashed) &&
if (v->type == VehicleType::Train && !v->vehstatus.Test(VehState::Crashed) &&
v->direction != DiagDirToDir(dir)) {
/* If the train has left the bridge, it shouldn't have
* track == TRACK_BIT_WORMHOLE - this could happen
+7
View File
@@ -43,6 +43,13 @@ static const SaveLoad _engine_desc[] = {
static TypedIndexContainer<std::vector<Engine>, EngineID> _temp_engine;
/**
* Get temporary engine data for loading savegame engine information.
* @param index Engine ID of data.
* @param type Vehicle type of engine.
* @param local_id The local index of the engine.
* @return A temporary engine.
*/
Engine *GetTempDataEngine(EngineID index, VehicleType type, uint16_t local_id)
{
if (index < _temp_engine.size()) {
+31 -31
View File
@@ -175,12 +175,12 @@ void FixOldVehicles(LoadgameState &ls)
}
/* Vehicle-subtype is different in TTD(Patch) */
if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
if (v->type == VehicleType::Effect) v->subtype = v->subtype >> 1;
v->name = CopyFromOldName(ls.vehicle_names[v->index.base()]);
/* We haven't used this bit for stations for ages */
if (v->type == VEH_ROAD) {
if (v->type == VehicleType::Road) {
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
ClrBit(rv->state, 2);
@@ -193,7 +193,7 @@ void FixOldVehicles(LoadgameState &ls)
}
/* The subtype should be 0, but it sometimes isn't :( */
if (v->type == VEH_ROAD || v->type == VEH_SHIP) v->subtype = 0;
if (v->type == VehicleType::Road || v->type == VehicleType::Ship) v->subtype = 0;
/* Sometimes primary vehicles would have a nothing (invalid) order
* or vehicles that could not have an order would still have a
@@ -380,10 +380,10 @@ static bool FixTTOEngines()
/* Load the default engine set. Many of them will be overridden later */
{
EngineID j = EngineID::Begin();
for (uint16_t i = 0; i < lengthof(_orig_rail_vehicle_info); ++i, ++j) GetTempDataEngine(j, VEH_TRAIN, i);
for (uint16_t i = 0; i < lengthof(_orig_road_vehicle_info); ++i, ++j) GetTempDataEngine(j, VEH_ROAD, i);
for (uint16_t i = 0; i < lengthof(_orig_ship_vehicle_info); ++i, ++j) GetTempDataEngine(j, VEH_SHIP, i);
for (uint16_t i = 0; i < lengthof(_orig_aircraft_vehicle_info); ++i, ++j) GetTempDataEngine(j, VEH_AIRCRAFT, i);
for (uint16_t i = 0; i < lengthof(_orig_rail_vehicle_info); ++i, ++j) GetTempDataEngine(j, VehicleType::Train, i);
for (uint16_t i = 0; i < lengthof(_orig_road_vehicle_info); ++i, ++j) GetTempDataEngine(j, VehicleType::Road, i);
for (uint16_t i = 0; i < lengthof(_orig_ship_vehicle_info); ++i, ++j) GetTempDataEngine(j, VehicleType::Ship, i);
for (uint16_t i = 0; i < lengthof(_orig_aircraft_vehicle_info); ++i, ++j) GetTempDataEngine(j, VehicleType::Aircraft, i);
}
TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(TimerGameCalendar::Year{2050}, 0, 1));
@@ -1141,12 +1141,12 @@ static bool LoadOldVehicleUnion(LoadgameState &ls, int)
} else {
switch (v->type) {
default: SlErrorCorrupt("Invalid vehicle type");
case VEH_TRAIN : res = LoadChunk(ls, v, vehicle_train_chunk); break;
case VEH_ROAD : res = LoadChunk(ls, v, vehicle_road_chunk); break;
case VEH_SHIP : res = LoadChunk(ls, v, vehicle_ship_chunk); break;
case VEH_AIRCRAFT: res = LoadChunk(ls, v, vehicle_air_chunk); break;
case VEH_EFFECT : res = LoadChunk(ls, v, vehicle_effect_chunk); break;
case VEH_DISASTER: res = LoadChunk(ls, v, vehicle_disaster_chunk); break;
case VehicleType::Train : res = LoadChunk(ls, v, vehicle_train_chunk); break;
case VehicleType::Road : res = LoadChunk(ls, v, vehicle_road_chunk); break;
case VehicleType::Ship : res = LoadChunk(ls, v, vehicle_ship_chunk); break;
case VehicleType::Aircraft: res = LoadChunk(ls, v, vehicle_air_chunk); break;
case VehicleType::Effect : res = LoadChunk(ls, v, vehicle_effect_chunk); break;
case VehicleType::Disaster: res = LoadChunk(ls, v, vehicle_disaster_chunk); break;
}
}
@@ -1270,14 +1270,14 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
uint type = ReadByte(ls);
switch (type) {
default: return false;
case 0x00 /* VEH_INVALID */: v = nullptr; break;
case 0x00 /* VehicleType::Invalid */: v = nullptr; break;
case 0x25 /* MONORAIL */:
case 0x20 /* VEH_TRAIN */: v = Train::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x21 /* VEH_ROAD */: v = RoadVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x22 /* VEH_SHIP */: v = Ship::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x23 /* VEH_AIRCRAFT */: v = Aircraft::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x24 /* VEH_EFFECT */: v = EffectVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x26 /* VEH_DISASTER */: v = DisasterVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x20 /* VehicleType::Train */: v = Train::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x21 /* VehicleType::Road */: v = RoadVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x22 /* VehicleType::Ship */: v = Ship::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x23 /* VehicleType::Aircraft */: v = Aircraft::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x24 /* VehicleType::Effect */: v = EffectVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x26 /* VehicleType::Disaster */: v = DisasterVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
}
if (!LoadChunk(ls, v, vehicle_chunk)) return false;
@@ -1298,7 +1298,7 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
v->sprite_cache.sprite_seq.seq[0].sprite = sprite;
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
static const uint8_t spriteset_rail[] = {
0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
@@ -1309,11 +1309,11 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
break;
}
case VEH_ROAD:
case VehicleType::Road:
if (v->spritenum >= 22) v->spritenum += 12;
break;
case VEH_SHIP:
case VehicleType::Ship:
v->spritenum += 2;
switch (v->spritenum) {
@@ -1347,13 +1347,13 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
/* Read the vehicle type and allocate the right vehicle */
switch (ReadByte(ls)) {
default: SlErrorCorrupt("Invalid vehicle type");
case 0x00 /* VEH_INVALID */: v = nullptr; break;
case 0x10 /* VEH_TRAIN */: v = Train::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x11 /* VEH_ROAD */: v = RoadVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x12 /* VEH_SHIP */: v = Ship::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x13 /* VEH_AIRCRAFT */: v = Aircraft::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x14 /* VEH_EFFECT */: v = EffectVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x15 /* VEH_DISASTER */: v = DisasterVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x00 /* VehicleType::Invalid */: v = nullptr; break;
case 0x10 /* VehicleType::Train */: v = Train::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x11 /* VehicleType::Road */: v = RoadVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x12 /* VehicleType::Ship */: v = Ship::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x13 /* VehicleType::Aircraft */: v = Aircraft::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x14 /* VehicleType::Effect */: v = EffectVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
case 0x15 /* VehicleType::Disaster */: v = DisasterVehicle::CreateAtIndex(VehicleID(_current_vehicle_id)); break;
}
if (!LoadChunk(ls, v, vehicle_chunk)) return false;
@@ -1375,7 +1375,7 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
}
v->current_order.AssignOrder(UnpackOldOrder(_old_order));
if (v->type == VEH_DISASTER) {
if (v->type == VehicleType::Disaster) {
DisasterVehicle::From(v)->state = UnpackOldOrder(_old_order).GetDestination().value;
}
+1 -1
View File
@@ -44,7 +44,7 @@ void ConvertOldMultiheadToNew();
void ConnectMultiheadedTrains();
void ResetTempEngineData();
Engine *GetTempDataEngine(EngineID index, VehicleType type = VEH_INVALID, uint16_t local_id = 0);
Engine *GetTempDataEngine(EngineID index, VehicleType type = VehicleType::Invalid, uint16_t local_id = 0);
void CopyTempEngineData();
extern int32_t _saved_scrollpos_x;
+2 -2
View File
@@ -47,14 +47,14 @@ void MoveBuoysToWaypoints()
/* Buoy orders become waypoint orders */
for (OrderList *ol : OrderList::Iterate()) {
VehicleType vt = ol->GetFirstSharedVehicle()->type;
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
if (vt != VehicleType::Ship && vt != VehicleType::Train) continue;
for (Order &o : ol->GetOrders()) UpdateWaypointOrder(o);
}
for (Vehicle *v : Vehicle::Iterate()) {
VehicleType vt = v->type;
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
if (vt != VehicleType::Ship && vt != VehicleType::Train) continue;
UpdateWaypointOrder(v->current_order);
}
+48 -48
View File
@@ -205,7 +205,7 @@ void UpdateOldAircraft()
for (Station *st : Station::Iterate()) {
for (auto iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); /* nothing */) {
Vehicle *v = *iter;
if (v->type == VEH_AIRCRAFT && !v->current_order.IsType(OT_LOADING)) {
if (v->type == VehicleType::Aircraft && !v->current_order.IsType(OT_LOADING)) {
iter = st->loading_vehicles.erase(iter);
delete v->cargo_payment;
} else {
@@ -225,20 +225,20 @@ void UpdateOldAircraft()
static void CheckValidVehicles()
{
size_t total_engines = Engine::GetPoolSize();
EngineID first_engine[4] = { EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid() };
VehicleTypeIndexArray<EngineID> first_engine = { EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid() };
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; }
for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; }
for (const Engine *e : Engine::IterateType(VehicleType::Train)) { first_engine[VehicleType::Train] = e->index; break; }
for (const Engine *e : Engine::IterateType(VehicleType::Road)) { first_engine[VehicleType::Road] = e->index; break; }
for (const Engine *e : Engine::IterateType(VehicleType::Ship)) { first_engine[VehicleType::Ship] = e->index; break; }
for (const Engine *e : Engine::IterateType(VehicleType::Aircraft)) { first_engine[VehicleType::Aircraft] = e->index; break; }
for (Vehicle *v : Vehicle::Iterate()) {
/* Test if engine types match */
switch (v->type) {
case VEH_TRAIN:
case VEH_ROAD:
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Train:
case VehicleType::Road:
case VehicleType::Ship:
case VehicleType::Aircraft:
if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
v->engine_type = first_engine[v->type];
}
@@ -362,7 +362,7 @@ void AfterLoadVehiclesPhase1(bool part_of_load)
if (IsSavegameVersionBefore(SLV_160)) {
/* In some old savegames there might be some "crap" stored. */
for (Vehicle *v : Vehicle::Iterate()) {
if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) {
if (!v->IsPrimaryVehicle() && v->type != VehicleType::Disaster) {
v->current_order.Free();
v->unitnumber = 0;
}
@@ -439,7 +439,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
if (t->IsFrontEngine() || t->IsFreeWagon()) {
t->gcache.last_speed = t->cur_speed; // update displayed train speed
@@ -448,7 +448,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->IsFrontEngine()) {
rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
@@ -470,7 +470,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
break;
}
case VEH_SHIP:
case VehicleType::Ship:
Ship::From(v)->UpdateCache();
break;
@@ -481,7 +481,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
/* Stop non-front engines */
if (part_of_load && IsSavegameVersionBefore(SLV_112)) {
for (Vehicle *v : Vehicle::Iterate()) {
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
Train *t = Train::From(v);
if (!t->IsFrontEngine()) {
if (t->IsEngine()) t->vehstatus.Set(VehState::Stopped);
@@ -492,7 +492,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
}
/* trains weren't stopping gradually in old OTTD versions (and TTO/TTD)
* other vehicle types didn't have zero speed while stopped (even in 'recent' OTTD versions) */
if (v->vehstatus.Test(VehState::Stopped) && (v->type != VEH_TRAIN || IsSavegameVersionBefore(SLV_2, 1))) {
if (v->vehstatus.Test(VehState::Stopped) && (v->type != VehicleType::Train || IsSavegameVersionBefore(SLV_2, 1))) {
v->cur_speed = 0;
}
}
@@ -500,13 +500,13 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
for (Vehicle *v : Vehicle::Iterate()) {
switch (v->type) {
case VEH_ROAD:
case VEH_TRAIN:
case VEH_SHIP:
case VehicleType::Road:
case VehicleType::Train:
case VehicleType::Ship:
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
if (Aircraft::From(v)->IsNormalAircraft()) {
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_cache.sprite_seq);
@@ -528,7 +528,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
}
break;
case VEH_DISASTER: {
case VehicleType::Disaster: {
auto *dv = DisasterVehicle::From(v);
if (dv->subtype == ST_SMALL_UFO && dv->state != 0) {
RoadVehicle *u = RoadVehicle::GetIfValid(v->dest_tile.base());
@@ -555,7 +555,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load)
v->UpdateDeltaXY();
v->coord.left = INVALID_COORD;
v->sprite_cache.old_coord.left = INVALID_COORD;
if (v->type != VEH_EFFECT) v->UpdatePosition();
if (v->type != VehicleType::Effect) v->UpdatePosition();
v->UpdateViewport(false);
}
}
@@ -569,7 +569,7 @@ void FixupTrainLengths()
/* Vehicle center was moved from 4 units behind the front to half the length
* behind the front. Move vehicles so they end up on the same spot. */
for (Vehicle *v : Vehicle::Iterate()) {
if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
if (v->type == VehicleType::Train && v->IsPrimaryVehicle()) {
/* The vehicle center is now more to the front depending on vehicle length,
* so we need to move all vehicles forward to cover the difference to the
* old center, otherwise wagon spacing in trains would be broken upon load. */
@@ -823,19 +823,19 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_TRAIN) return;
if (v->type != VehicleType::Train) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_TRAIN) return;
if (v->type != VehicleType::Train) return;
SlObject(v, this->GetLoadDescription());
}
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_TRAIN) return;
if (v->type != VehicleType::Train) return;
SlObject(v, this->GetDescription());
}
};
@@ -896,13 +896,13 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_ROAD) return;
if (v->type != VehicleType::Road) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_ROAD) return;
if (v->type != VehicleType::Road) return;
SlObject(v, this->GetLoadDescription());
if (!IsSavegameVersionBefore(SLV_ROADVEH_PATH_CACHE) && IsSavegameVersionBefore(SLV_PATH_CACHE_FORMAT)) {
ConvertPathCache(*static_cast<RoadVehicle *>(v));
@@ -911,7 +911,7 @@ public:
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_ROAD) return;
if (v->type != VehicleType::Road) return;
SlObject(v, this->GetDescription());
}
};
@@ -941,13 +941,13 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_SHIP) return;
if (v->type != VehicleType::Ship) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_SHIP) return;
if (v->type != VehicleType::Ship) return;
SlObject(v, this->GetLoadDescription());
if (IsSavegameVersionBefore(SLV_PATH_CACHE_FORMAT)) {
@@ -959,7 +959,7 @@ public:
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_SHIP) return;
if (v->type != VehicleType::Ship) return;
SlObject(v, this->GetDescription());
}
};
@@ -987,19 +987,19 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_AIRCRAFT) return;
if (v->type != VehicleType::Aircraft) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_AIRCRAFT) return;
if (v->type != VehicleType::Aircraft) return;
SlObject(v, this->GetLoadDescription());
}
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_AIRCRAFT) return;
if (v->type != VehicleType::Aircraft) return;
SlObject(v, this->GetDescription());
}
};
@@ -1032,19 +1032,19 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_EFFECT) return;
if (v->type != VehicleType::Effect) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_EFFECT) return;
if (v->type != VehicleType::Effect) return;
SlObject(v, this->GetLoadDescription());
}
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_EFFECT) return;
if (v->type != VehicleType::Effect) return;
SlObject(v, this->GetDescription());
}
};
@@ -1090,19 +1090,19 @@ public:
void Save(Vehicle *v) const override
{
if (v->type != VEH_DISASTER) return;
if (v->type != VehicleType::Disaster) return;
SlObject(v, this->GetDescription());
}
void Load(Vehicle *v) const override
{
if (v->type != VEH_DISASTER) return;
if (v->type != VehicleType::Disaster) return;
SlObject(v, this->GetLoadDescription());
}
void FixPointers(Vehicle *v) const override
{
if (v->type != VEH_DISASTER) return;
if (v->type != VehicleType::Disaster) return;
SlObject(v, this->GetDescription());
}
};
@@ -1144,13 +1144,13 @@ struct VEHSChunkHandler : ChunkHandler {
VehicleType vtype = (VehicleType)SlReadByte();
switch (vtype) {
case VEH_TRAIN: v = Train::CreateAtIndex(VehicleID(index)); break;
case VEH_ROAD: v = RoadVehicle::CreateAtIndex(VehicleID(index)); break;
case VEH_SHIP: v = Ship::CreateAtIndex(VehicleID(index)); break;
case VEH_AIRCRAFT: v = Aircraft::CreateAtIndex(VehicleID(index)); break;
case VEH_EFFECT: v = EffectVehicle::CreateAtIndex(VehicleID(index)); break;
case VEH_DISASTER: v = DisasterVehicle::CreateAtIndex(VehicleID(index)); break;
case VEH_INVALID: // Savegame shouldn't contain invalid vehicles
case VehicleType::Train: v = Train::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Road: v = RoadVehicle::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Ship: v = Ship::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Aircraft: v = Aircraft::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Effect: v = EffectVehicle::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Disaster: v = DisasterVehicle::CreateAtIndex(VehicleID(index)); break;
case VehicleType::Invalid: // Savegame shouldn't contain invalid vehicles
default: SlErrorCorrupt("Invalid vehicle type");
}
+2 -2
View File
@@ -147,13 +147,13 @@ void MoveWaypointsToBaseStations()
/* Update the orders of vehicles */
for (OrderList *ol : OrderList::Iterate()) {
if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue;
if (ol->GetFirstSharedVehicle()->type != VehicleType::Train) continue;
for (Order &o : ol->GetOrders()) UpdateWaypointOrder(o);
}
for (Vehicle *v : Vehicle::Iterate()) {
if (v->type != VEH_TRAIN) continue;
if (v->type != VehicleType::Train) continue;
UpdateWaypointOrder(v->current_order);
}
+9 -9
View File
@@ -86,8 +86,8 @@
const Engine *e = ::Engine::Get(engine_id);
switch (e->type) {
case VEH_ROAD:
case VEH_TRAIN: {
case VehicleType::Road:
case VehicleType::Train: {
CargoArray capacities = GetCapacityOfArticulatedParts(engine_id);
for (uint &cap : capacities) {
if (cap != 0) return cap;
@@ -95,8 +95,8 @@
return -1;
}
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
return e->GetDisplayDefaultCapacity();
default: NOT_REACHED();
@@ -117,7 +117,7 @@
const Engine *e = ::Engine::Get(engine_id);
uint max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
if (e->type == VehicleType::Aircraft) max_speed /= _settings_game.vehicle.plane_speed;
return max_speed;
}
@@ -181,10 +181,10 @@
if (!IsValidEngine(engine_id)) return ScriptVehicle::VT_INVALID;
switch (::Engine::Get(engine_id)->type) {
case VEH_ROAD: return ScriptVehicle::VT_ROAD;
case VEH_TRAIN: return ScriptVehicle::VT_RAIL;
case VEH_SHIP: return ScriptVehicle::VT_WATER;
case VEH_AIRCRAFT: return ScriptVehicle::VT_AIR;
case VehicleType::Road: return ScriptVehicle::VT_ROAD;
case VehicleType::Train: return ScriptVehicle::VT_RAIL;
case VehicleType::Ship: return ScriptVehicle::VT_WATER;
case VehicleType::Aircraft: return ScriptVehicle::VT_AIR;
default: NOT_REACHED();
}
}
+9 -9
View File
@@ -53,8 +53,8 @@ int32_t ScriptEventEnginePreview::GetCapacity() const
if (!this->IsEngineValid()) return -1;
const Engine *e = ::Engine::Get(this->engine);
switch (e->type) {
case VEH_ROAD:
case VEH_TRAIN: {
case VehicleType::Road:
case VehicleType::Train: {
CargoArray capacities = GetCapacityOfArticulatedParts(this->engine);
for (uint &cap : capacities) {
if (cap != 0) return cap;
@@ -62,8 +62,8 @@ int32_t ScriptEventEnginePreview::GetCapacity() const
return -1;
}
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
return e->GetDisplayDefaultCapacity();
default: NOT_REACHED();
@@ -75,7 +75,7 @@ int32_t ScriptEventEnginePreview::GetMaxSpeed() const
if (!this->IsEngineValid()) return -1;
const Engine *e = ::Engine::Get(this->engine);
int32_t max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
if (e->type == VehicleType::Aircraft) max_speed /= _settings_game.vehicle.plane_speed;
return max_speed;
}
@@ -95,10 +95,10 @@ int32_t ScriptEventEnginePreview::GetVehicleType() const
{
if (!this->IsEngineValid()) return ScriptVehicle::VT_INVALID;
switch (::Engine::Get(this->engine)->type) {
case VEH_ROAD: return ScriptVehicle::VT_ROAD;
case VEH_TRAIN: return ScriptVehicle::VT_RAIL;
case VEH_SHIP: return ScriptVehicle::VT_WATER;
case VEH_AIRCRAFT: return ScriptVehicle::VT_AIR;
case VehicleType::Road: return ScriptVehicle::VT_ROAD;
case VehicleType::Train: return ScriptVehicle::VT_RAIL;
case VehicleType::Ship: return ScriptVehicle::VT_WATER;
case VehicleType::Aircraft: return ScriptVehicle::VT_AIR;
default: NOT_REACHED();
}
}
+2 -2
View File
@@ -251,7 +251,7 @@ static ScriptOrder::OrderPosition RealOrderPositionToScriptOrderPosition(Vehicle
/* We don't know where the nearest depot is... (yet) */
if (order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) return INVALID_TILE;
if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination().ToDepotID())->xy;
if (v->type != VehicleType::Aircraft) return ::Depot::Get(order->GetDestination().ToDepotID())->xy;
/* Aircraft's hangars are referenced by StationID, not DepotID */
const Station *st = ::Station::Get(order->GetDestination().ToStationID());
if (!st->airport.HasHangar()) return INVALID_TILE;
@@ -498,7 +498,7 @@ static ScriptOrder::OrderPosition RealOrderPositionToScriptOrderPosition(Vehicle
} else {
/* Check explicitly if the order is to a station (for aircraft) or
* to a depot (other vehicle types). */
if (::Vehicle::Get(vehicle_id)->type == VEH_AIRCRAFT) {
if (::Vehicle::Get(vehicle_id)->type == VehicleType::Aircraft) {
if (!::IsTileType(destination, TileType::Station)) return false;
order.MakeGoToDepot(::GetStationIndex(destination), odtf, onsf, odaf);
} else {
+19 -19
View File
@@ -33,7 +33,7 @@
{
EnforceDeityOrCompanyModeValid(false);
const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
return v != nullptr && IsCompanyBuildableVehicleType(v) && (v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
return v != nullptr && IsCompanyBuildableVehicleType(v) && (v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (v->IsPrimaryVehicle() || (v->type == ::VehicleType::Train && ::Train::From(v)->IsFreeWagon()));
}
/* static */ bool ScriptVehicle::IsPrimaryVehicle(VehicleID vehicle_id)
@@ -124,8 +124,8 @@
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id));
EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(static_cast<VehicleID>(dest_vehicle_id)) && dest_wagon < GetNumWagons(static_cast<VehicleID>(dest_vehicle_id))));
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(static_cast<VehicleID>(dest_vehicle_id))->type == VEH_TRAIN);
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == ::VehicleType::Train);
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(static_cast<VehicleID>(dest_vehicle_id))->type == ::VehicleType::Train);
const Train *v = ::Train::Get(source_vehicle_id);
while (source_wagon-- > 0) v = v->GetNextUnit();
@@ -172,14 +172,14 @@
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
const Vehicle *v = ::Vehicle::Get(vehicle_id);
return ScriptObject::Command<Commands::SellVehicle>::Do(vehicle_id, v->type == VEH_TRAIN, false, INVALID_CLIENT_ID);
return ScriptObject::Command<Commands::SellVehicle>::Do(vehicle_id, v->type == ::VehicleType::Train, false, INVALID_CLIENT_ID);
}
/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, SQInteger wagon, bool sell_attached_wagons)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == ::VehicleType::Train);
const Train *v = ::Train::Get(vehicle_id);
while (wagon-- > 0) v = v->GetNextUnit();
@@ -237,11 +237,11 @@
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_ROAD || ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == ::VehicleType::Road || ::Vehicle::Get(vehicle_id)->type == ::VehicleType::Train);
switch (::Vehicle::Get(vehicle_id)->type) {
case VEH_ROAD: return ScriptObject::Command<Commands::TurnRoadVehicle>::Do(vehicle_id);
case VEH_TRAIN: return ScriptObject::Command<Commands::ReverseTrainDirection>::Do(vehicle_id, false);
case ::VehicleType::Road: return ScriptObject::Command<Commands::TurnRoadVehicle>::Do(vehicle_id);
case ::VehicleType::Train: return ScriptObject::Command<Commands::ReverseTrainDirection>::Do(vehicle_id, false);
default: NOT_REACHED();
}
}
@@ -265,7 +265,7 @@
if (!IsValidVehicle(vehicle_id)) return INVALID_TILE;
const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_AIRCRAFT) {
if (v->type == ::VehicleType::Aircraft) {
uint x = Clamp(v->x_pos / TILE_SIZE, 0, ScriptMap::GetMapSizeX() - 2);
uint y = Clamp(v->y_pos / TILE_SIZE, 0, ScriptMap::GetMapSizeY() - 2);
return ::TileXY(x, y);
@@ -287,7 +287,7 @@
if (wagon >= GetNumWagons(vehicle_id)) return ::EngineID::Invalid();
const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_TRAIN) {
if (v->type == ::VehicleType::Train) {
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
}
return v->engine_type;
@@ -320,7 +320,7 @@
if (wagon >= GetNumWagons(vehicle_id)) return -1;
const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_TRAIN) {
if (v->type == ::VehicleType::Train) {
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
}
return v->age.base();
@@ -396,11 +396,11 @@
if (!IsValidVehicle(vehicle_id)) return VT_INVALID;
switch (::Vehicle::Get(vehicle_id)->type) {
case VEH_ROAD: return VT_ROAD;
case VEH_TRAIN: return VT_RAIL;
case VEH_SHIP: return VT_WATER;
case VEH_AIRCRAFT: return VT_AIR;
default: return VT_INVALID;
case ::VehicleType::Road: return VT_ROAD;
case ::VehicleType::Train: return VT_RAIL;
case ::VehicleType::Ship: return VT_WATER;
case ::VehicleType::Aircraft: return VT_AIR;
default: return VT_INVALID;
}
}
@@ -452,8 +452,8 @@
const Vehicle *v = ::Vehicle::Get(vehicle_id);
switch (v->type) {
case VEH_ROAD: return ::RoadVehicle::From(v)->HasArticulatedPart();
case VEH_TRAIN: return ::Train::From(v)->HasArticulatedPart();
case ::VehicleType::Road: return ::RoadVehicle::From(v)->HasArticulatedPart();
case ::VehicleType::Train: return ::Train::From(v)->HasArticulatedPart();
default: NOT_REACHED();
}
}
@@ -479,6 +479,6 @@
if (!IsPrimaryVehicle(vehicle_id)) return 0;
const ::Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type != VEH_AIRCRAFT) return 0;
if (v->type != ::VehicleType::Aircraft) return 0;
return ::Aircraft::From(v)->acache.cached_max_range_sqr;
}
+7 -7
View File
@@ -29,7 +29,7 @@ ScriptVehicleList::ScriptVehicleList(HSQUIRRELVM vm)
ScriptList::FillList<Vehicle>(vm, this,
[is_deity, owner](const Vehicle *v) {
return (is_deity || v->owner == owner) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
return (is_deity || v->owner == owner) && (v->IsPrimaryVehicle() || (v->type == VehicleType::Train && ::Train::From(v)->IsFreeWagon()));
}
);
}
@@ -51,7 +51,7 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(HSQUIRRELVM vm)
bool is_deity = ScriptCompanyMode::IsDeity();
::CompanyID owner = ScriptObject::GetCompany();
::VehicleType type = VEH_INVALID;
::VehicleType type = VehicleType::Invalid;
if (nparam == 2) {
SQInteger sqtype;
@@ -63,7 +63,7 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(HSQUIRRELVM vm)
}
FindVehiclesWithOrder(
[is_deity, owner, type](const Vehicle *v) { return (is_deity || v->owner == owner) && (type == VEH_INVALID || v->type == type); },
[is_deity, owner, type](const Vehicle *v) { return (is_deity || v->owner == owner) && (type == VehicleType::Invalid || v->type == type); },
[station_id](const Order *order) { return (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station_id; },
[this](const Vehicle *v) { this->AddItem(v->index.base()); }
);
@@ -95,25 +95,25 @@ ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
switch (GetTileType(tile)) {
case TileType::Station: // Aircraft
if (!IsAirport(tile)) return;
type = VEH_AIRCRAFT;
type = VehicleType::Aircraft;
dest = GetStationIndex(tile);
break;
case TileType::Railway:
if (!IsRailDepot(tile)) return;
type = VEH_TRAIN;
type = VehicleType::Train;
dest = GetDepotIndex(tile);
break;
case TileType::Road:
if (!IsRoadDepot(tile)) return;
type = VEH_ROAD;
type = VehicleType::Road;
dest = GetDepotIndex(tile);
break;
case TileType::Water:
if (!IsShipDepot(tile)) return;
type = VEH_SHIP;
type = VehicleType::Ship;
dest = GetDepotIndex(tile);
break;
+4 -4
View File
@@ -283,10 +283,10 @@ static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType t
if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
switch (type) {
case VEH_TRAIN: return DEF_SERVINT_MINUTES_TRAINS;
case VEH_ROAD: return DEF_SERVINT_MINUTES_ROADVEH;
case VEH_AIRCRAFT: return DEF_SERVINT_MINUTES_AIRCRAFT;
case VEH_SHIP: return DEF_SERVINT_MINUTES_SHIPS;
case VehicleType::Train: return DEF_SERVINT_MINUTES_TRAINS;
case VehicleType::Road: return DEF_SERVINT_MINUTES_ROADVEH;
case VehicleType::Aircraft: return DEF_SERVINT_MINUTES_AIRCRAFT;
case VehicleType::Ship: return DEF_SERVINT_MINUTES_SHIPS;
default: NOT_REACHED();
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ using ShipPathCache = std::vector<ShipPathElement>;
/**
* All ships have this type.
*/
struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
struct Ship final : public SpecializedVehicle<Ship, VehicleType::Ship> {
ShipPathCache path{}; ///< Cached path.
TrackBits state{}; ///< The "track" the ship is following.
Direction rotation = INVALID_DIR; ///< Visible direction.
+4 -4
View File
@@ -68,7 +68,7 @@ static const uint16_t _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
/** @copydoc IsValidImageIndex */
template <>
bool IsValidImageIndex<VEH_SHIP>(uint8_t image_index)
bool IsValidImageIndex<VehicleType::Ship>(uint8_t image_index)
{
return image_index < lengthof(_ship_sprites);
}
@@ -90,7 +90,7 @@ static void GetShipIcon(EngineID engine, EngineImageType image_type, VehicleSpri
spritenum = e->original_image_index;
}
assert(IsValidImageIndex<VEH_SHIP>(spritenum));
assert(IsValidImageIndex<VehicleType::Ship>(spritenum));
result->Set(DIR_W + _ship_sprites[spritenum]);
}
@@ -144,7 +144,7 @@ void Ship::GetImage(Direction direction, EngineImageType image_type, VehicleSpri
spritenum = this->GetEngine()->original_image_index;
}
assert(IsValidImageIndex<VEH_SHIP>(spritenum));
assert(IsValidImageIndex<VehicleType::Ship>(spritenum));
result->Set(_ship_sprites[spritenum] + direction);
}
@@ -384,7 +384,7 @@ static bool CheckShipStayInDepot(Ship *v)
/* Don't leave depot if another vehicle is already entering/leaving */
/* This helps avoid CPU load if many ships are set to start at the same time */
if (HasVehicleOnTile(v->tile, [](const Vehicle *u) {
return u->type == VEH_SHIP && u->cur_speed != 0;
return u->type == VehicleType::Ship && u->cur_speed != 0;
})) return true;
assert(v->GetVehicleTrackdir() == TRACKDIR_X_NE || v->GetVehicleTrackdir() == TRACKDIR_Y_NW);
+1 -1
View File
@@ -200,7 +200,7 @@ static SmallSet<DiagDirection, SIG_GLOB_SIZE> _globset("_globset"); ///< set of
*/
static bool IsTrainAndNotInDepot(const Vehicle *v)
{
return v->type == VEH_TRAIN && Train::From(v)->track != TRACK_BIT_DEPOT;
return v->type == VehicleType::Train && Train::From(v)->track != TRACK_BIT_DEPOT;
}
+2 -2
View File
@@ -609,7 +609,7 @@ uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap inc
}
/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */
static const PixelColour _vehicle_type_colours[6] = {
static constexpr VehicleTypeIndexArray<PixelColour, VehicleType::End> _vehicle_type_colours = {
PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED
};
@@ -953,7 +953,7 @@ protected:
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
{
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == VEH_EFFECT) continue;
if (v->type == VehicleType::Effect) continue;
if (v->vehstatus.Any({VehState::Hidden, VehState::Unclickable})) continue;
/* Remap into flat coordinates. */
+5 -5
View File
@@ -53,10 +53,10 @@ BaseStation::~BaseStation()
{
if (CleaningPool()) return;
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Train, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Road, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Ship, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Aircraft, this->owner, this->index).ToWindowNumber());
this->sign.MarkDirty();
}
@@ -69,7 +69,7 @@ Station::Station(StationID index, TileIndex tile) :
indtype(IT_INVALID),
time_since_load(255),
time_since_unload(255),
last_vehicle_type(VEH_INVALID)
last_vehicle_type(VehicleType::Invalid)
{
/* this->random_bits is set in Station::AddFacility() */
}
+1 -1
View File
@@ -551,7 +551,7 @@ public:
uint8_t time_since_load = 0;
uint8_t time_since_unload = 0;
uint8_t last_vehicle_type = 0;
VehicleType last_vehicle_type = VehicleType::Invalid;
std::list<Vehicle *> loading_vehicles{};
std::array<GoodsEntry, NUM_CARGO> goods; ///< Goods at this station
CargoTypes always_accepted{}; ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
+7 -7
View File
@@ -2275,7 +2275,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlags flags, int repl
/* remove the 'going through road stop' status from all vehicles on that tile */
if (flags.Test(DoCommandFlag::Execute)) {
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != VEH_ROAD) continue;
if (v->type != VehicleType::Road) continue;
/* Okay... we are a road vehicle on a drive through road stop.
* But that road stop has just been removed, so we need to make
* sure we are in a valid state... however, vehicles can also
@@ -2336,7 +2336,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlags flags, int repl
* this station, then look for any currently heading to the tile. */
StationID station_id = st->index;
FindVehiclesWithOrder(
[](const Vehicle *v) { return v->type == VEH_ROAD; },
[](const Vehicle *v) { return v->type == VehicleType::Road; },
[station_id](const Order *order) { return order->IsType(OT_GOTO_STATION) && order->GetDestination() == station_id; },
[station_id, tile](Vehicle *v) {
if (v->current_order.IsType(OT_GOTO_STATION) && v->dest_tile == tile) {
@@ -3849,7 +3849,7 @@ static bool ClickTile_Station(TileIndex tile)
ShowWaypointWindow(Waypoint::From(bst));
} else if (IsHangar(tile)) {
const Station *st = Station::From(bst);
ShowDepotWindow(st->airport.GetHangarTile(st->airport.GetHangarNum(tile)), VEH_AIRCRAFT);
ShowDepotWindow(st->airport.GetHangarTile(st->airport.GetHangarNum(tile)), VehicleType::Aircraft);
} else {
ShowStationViewWindow(bst->index);
}
@@ -3859,7 +3859,7 @@ static bool ClickTile_Station(TileIndex tile)
/** @copydoc VehicleEnterTileProc */
static VehicleEnterTileStates VehicleEnterTile_Station(Vehicle *v, TileIndex tile, int x, int y)
{
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
StationID station_id = GetStationIndex(tile);
if (!IsRailStation(tile) || !v->IsMovingFront()) return {};
Vehicle *consist = v->First();
@@ -3893,7 +3893,7 @@ static VehicleEnterTileStates VehicleEnterTile_Station(Vehicle *v, TileIndex til
if (spd < v->cur_speed) v->cur_speed = spd;
}
}
} else if (v->type == VEH_ROAD) {
} else if (v->type == VehicleType::Road) {
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
if (IsStationRoadStop(tile) && rv->IsFrontEngine()) {
@@ -4055,7 +4055,7 @@ static void UpdateStationRating(Station *st)
| (ClampTo<uint16_t>(ge->max_waiting_cargo) << 8)
| (ClampTo<uint8_t>(last_speed) << 24);
/* Convert to the 'old' vehicle types */
uint32_t var10 = (st->last_vehicle_type == VEH_INVALID) ? 0x0 : (st->last_vehicle_type + 0x10);
uint32_t var10 = (st->last_vehicle_type == VehicleType::Invalid) ? 0x0 : (to_underlying(st->last_vehicle_type) + 0x10);
uint16_t callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, cs);
if (callback != CALLBACK_FAILED) {
skip = true;
@@ -4071,7 +4071,7 @@ static void UpdateStationRating(Station *st)
if (b >= 0) rating += b >> 2;
uint8_t waittime = ge->time_since_pickup;
if (st->last_vehicle_type == VEH_SHIP) waittime >>= 2;
if (st->last_vehicle_type == VehicleType::Ship) waittime >>= 2;
if (waittime <= 21) rating += 25;
if (waittime <= 12) rating += 25;
if (waittime <= 6) rating += 45;
+4 -4
View File
@@ -1361,10 +1361,10 @@ struct StationViewWindow : public Window {
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Train, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Road, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Ship, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Aircraft, this->owner, this->window_number).ToWindowNumber(), false);
SetViewportCatchmentStation(Station::Get(this->window_number), false);
this->Window::Close();
+4 -4
View File
@@ -162,8 +162,8 @@ void StoryPageButtonData::SetCursor(StoryPageButtonCursor cursor)
*/
void StoryPageButtonData::SetVehicleType(VehicleType vehtype)
{
assert(vehtype == VEH_INVALID || vehtype < VEH_COMPANY_END);
SB(this->referenced_id, 16, 8, vehtype);
assert(vehtype == VehicleType::Invalid || vehtype < VehicleType::CompanyEnd);
SB(this->referenced_id, 16, 8, to_underlying(vehtype));
}
/**
@@ -245,8 +245,8 @@ bool StoryPageButtonData::ValidateCursor() const
*/
bool StoryPageButtonData::ValidateVehicleType() const
{
uint8_t vehtype = GB(this->referenced_id, 16, 8);
return vehtype == VEH_INVALID || vehtype < VEH_COMPANY_END;
VehicleType vehtype = static_cast<VehicleType>(GB(this->referenced_id, 16, 8));
return vehtype == VehicleType::Invalid || vehtype < VehicleType::CompanyEnd;
}
/**
+1 -1
View File
@@ -918,7 +918,7 @@ public:
/* Check that the vehicle matches the requested type */
StoryPageButtonData data{ pe->referenced_id };
VehicleType wanted_vehtype = data.GetVehicleType();
if (wanted_vehtype != VEH_INVALID && wanted_vehtype != v->type) return false;
if (wanted_vehtype != VehicleType::Invalid && wanted_vehtype != v->type) return false;
Command<Commands::StoryPageButton>::Post(TileIndex{}, pe->index, v->index);
ResetObjectToPlace();
+7 -7
View File
@@ -950,7 +950,7 @@ static const Units _units_time_years_or_minutes[] = {
*/
static const Units GetVelocityUnits(VehicleType type)
{
uint8_t setting = (type == VEH_SHIP || type == VEH_AIRCRAFT) ? _settings_game.locale.units_velocity_nautical : _settings_game.locale.units_velocity;
uint8_t setting = (type == VehicleType::Ship || type == VehicleType::Aircraft) ? _settings_game.locale.units_velocity_nautical : _settings_game.locale.units_velocity;
assert(setting < lengthof(_units_velocity_calendar));
assert(setting < lengthof(_units_velocity_realtime));
@@ -1637,7 +1637,7 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
case SCC_DEPOT_NAME: { // {DEPOT}
VehicleType vt = args.GetNextParameter<VehicleType>();
if (vt == VEH_AIRCRAFT) {
if (vt == VehicleType::Aircraft) {
auto tmp_params = MakeParameters(args.GetNextParameter<StationID>());
GetStringWithArgs(builder, STR_FORMAT_DEPOT_NAME_AIRCRAFT, tmp_params);
break;
@@ -1649,7 +1649,7 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else {
auto tmp_params = MakeParameters(d->town->index, d->town_cn + 1);
GetStringWithArgs(builder, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->town_cn == 0 ? 0 : 1), tmp_params);
GetStringWithArgs(builder, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * to_underlying(vt) + (d->town_cn == 0 ? 0 : 1), tmp_params);
}
break;
}
@@ -1826,10 +1826,10 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
StringID string_id;
switch (v->type) {
default: string_id = STR_INVALID_VEHICLE; break;
case VEH_TRAIN: string_id = STR_SV_TRAIN_NAME; break;
case VEH_ROAD: string_id = STR_SV_ROAD_VEHICLE_NAME; break;
case VEH_SHIP: string_id = STR_SV_SHIP_NAME; break;
case VEH_AIRCRAFT: string_id = STR_SV_AIRCRAFT_NAME; break;
case VehicleType::Train: string_id = STR_SV_TRAIN_NAME; break;
case VehicleType::Road: string_id = STR_SV_ROAD_VEHICLE_NAME; break;
case VehicleType::Ship: string_id = STR_SV_SHIP_NAME; break;
case VehicleType::Aircraft: string_id = STR_SV_AIRCRAFT_NAME; break;
}
GetStringWithArgs(builder, string_id, tmp_params);
+9
View File
@@ -11,6 +11,7 @@
#define STRINGS_TYPE_H
#include "core/convertible_through_base.hpp"
#include "core/enum_type.hpp"
#include "core/strong_typedef_type.hpp"
/**
@@ -90,6 +91,14 @@ struct StringParameter {
inline StringParameter(const std::string &data) : data(data), type(0) {}
inline StringParameter(const ConvertibleThroughBase auto &data) : data(static_cast<uint64_t>(data.base())), type(0) {}
/**
* Create a StringParameter from a scoped enum.
* @tparam T the type of the scoped enum.
* @param data the scoped enum value.
*/
template <typename T> requires is_scoped_enum_v<T>
inline StringParameter(const T &data) : data(static_cast<uint64_t>(to_underlying(data))), type(0) {}
};
/**
+2 -2
View File
@@ -102,7 +102,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(SocialIntegrationPlugin::State, {
#endif /* DOXYGEN_API */
/** Lookup table to convert a VehicleType to a string. */
static const std::string _vehicle_type_to_string[] = {
static constexpr VehicleTypeIndexArray<std::string_view> _vehicle_type_to_string = {
"train",
"roadveh",
"ship",
@@ -325,7 +325,7 @@ void SurveyCompanies(nlohmann::json &survey)
company["script"] = fmt::format("{}.{}", c->ai_info->GetName(), c->ai_info->GetVersion());
}
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
for (VehicleType type = VehicleType::Begin; type < VehicleType::CompanyEnd; type++) {
uint amount = c->group_all[type].num_vehicle;
company["vehicles"][_vehicle_type_to_string[type]] = amount;
}
+12 -12
View File
@@ -100,9 +100,9 @@ interval = 1
str = STR_CONFIG_SETTING_SERVINT_TRAINS
strhelp = STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_TRAIN, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_TRAIN); }
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VehicleType::Train, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VehicleType::Train, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VehicleType::Train); }
val_cb = ServiceIntervalSettingsValueText
range_cb = GetServiceIntervalRange
@@ -117,9 +117,9 @@ interval = 1
str = STR_CONFIG_SETTING_SERVINT_ROAD_VEHICLES
strhelp = STR_CONFIG_SETTING_SERVINT_ROAD_VEHICLES_HELPTEXT
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_ROAD, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_ROAD); }
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VehicleType::Road, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VehicleType::Road, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VehicleType::Road); }
val_cb = ServiceIntervalSettingsValueText
range_cb = GetServiceIntervalRange
@@ -134,9 +134,9 @@ interval = 1
str = STR_CONFIG_SETTING_SERVINT_SHIPS
strhelp = STR_CONFIG_SETTING_SERVINT_SHIPS_HELPTEXT
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_SHIP, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_SHIP); }
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VehicleType::Ship, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VehicleType::Ship, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VehicleType::Ship); }
val_cb = ServiceIntervalSettingsValueText
range_cb = GetServiceIntervalRange
@@ -151,8 +151,8 @@ interval = 1
str = STR_CONFIG_SETTING_SERVINT_AIRCRAFT
strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_AIRCRAFT, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_AIRCRAFT, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_AIRCRAFT); }
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VehicleType::Aircraft, new_value); }
post_cb = [](auto new_value) { UpdateServiceInterval(VehicleType::Aircraft, new_value); }
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VehicleType::Aircraft); }
val_cb = ServiceIntervalSettingsValueText
range_cb = GetServiceIntervalRange
+1 -1
View File
@@ -179,7 +179,7 @@ CommandCost CmdChangeTimetable(DoCommandFlags flags, VehicleID veh, VehicleOrder
}
if (travel_time != order->GetTravelTime() && order->IsType(OT_CONDITIONAL)) return CMD_ERROR;
if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VehicleType::Aircraft)) return CMD_ERROR;
if (flags.Test(DoCommandFlag::Execute)) {
switch (mtf) {
+1 -1
View File
@@ -351,7 +351,7 @@ struct TimetableWindow : Window {
disable = order == nullptr || ((!order->IsType(OT_GOTO_STATION) || order->GetNonStopType().Test(OrderNonStopFlag::GoVia)) && !order->IsType(OT_CONDITIONAL));
}
}
bool disable_speed = disable || selected % 2 == 0 || v->type == VEH_AIRCRAFT;
bool disable_speed = disable || selected % 2 == 0 || v->type == VehicleType::Aircraft;
this->SetWidgetDisabledState(WID_VT_CHANGE_TIME, disable);
this->SetWidgetDisabledState(WID_VT_CLEAR_TIME, disable);
+12 -12
View File
@@ -785,7 +785,7 @@ static void ToolbarVehicleClick(Window *w, VehicleType veh)
static CallBackFunction ToolbarTrainClick(Window *w)
{
ToolbarVehicleClick(w, VEH_TRAIN);
ToolbarVehicleClick(w, VehicleType::Train);
return CallBackFunction::None;
}
@@ -797,7 +797,7 @@ static CallBackFunction ToolbarTrainClick(Window *w)
*/
static CallBackFunction MenuClickShowTrains(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
ShowVehicleListWindow((CompanyID)index, VehicleType::Train);
return CallBackFunction::None;
}
@@ -805,7 +805,7 @@ static CallBackFunction MenuClickShowTrains(int index)
static CallBackFunction ToolbarRoadClick(Window *w)
{
ToolbarVehicleClick(w, VEH_ROAD);
ToolbarVehicleClick(w, VehicleType::Road);
return CallBackFunction::None;
}
@@ -817,7 +817,7 @@ static CallBackFunction ToolbarRoadClick(Window *w)
*/
static CallBackFunction MenuClickShowRoad(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
ShowVehicleListWindow((CompanyID)index, VehicleType::Road);
return CallBackFunction::None;
}
@@ -825,7 +825,7 @@ static CallBackFunction MenuClickShowRoad(int index)
static CallBackFunction ToolbarShipClick(Window *w)
{
ToolbarVehicleClick(w, VEH_SHIP);
ToolbarVehicleClick(w, VehicleType::Ship);
return CallBackFunction::None;
}
@@ -837,7 +837,7 @@ static CallBackFunction ToolbarShipClick(Window *w)
*/
static CallBackFunction MenuClickShowShips(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
ShowVehicleListWindow((CompanyID)index, VehicleType::Ship);
return CallBackFunction::None;
}
@@ -845,7 +845,7 @@ static CallBackFunction MenuClickShowShips(int index)
static CallBackFunction ToolbarAirClick(Window *w)
{
ToolbarVehicleClick(w, VEH_AIRCRAFT);
ToolbarVehicleClick(w, VehicleType::Aircraft);
return CallBackFunction::None;
}
@@ -857,7 +857,7 @@ static CallBackFunction ToolbarAirClick(Window *w)
*/
static CallBackFunction MenuClickShowAir(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
ShowVehicleListWindow((CompanyID)index, VehicleType::Aircraft);
return CallBackFunction::None;
}
@@ -2059,10 +2059,10 @@ struct MainToolbarWindow : Window {
case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
case MTHK_LEAGUE: ShowFirstLeagueTable(); break;
case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VehicleType::Train); break;
case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VehicleType::Road); break;
case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VehicleType::Ship); break;
case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VehicleType::Aircraft); break;
case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTHK_BUILD_RAIL: ShowBuildRailToolbar(_last_built_railtype); break;
+2 -2
View File
@@ -94,7 +94,7 @@ struct TrainCache {
/**
* 'Train' is either a loco or a wagon.
*/
struct Train final : public GroundVehicle<Train, VEH_TRAIN> {
struct Train final : public GroundVehicle<Train, VehicleType::Train> {
VehicleRailFlags flags{}; ///< Which flags has this train currently set. @see VehicleRailFlag for more details.
uint16_t crash_anim_pos = 0; ///< Crash animation counter.
uint16_t wait_counter = 0; ///< Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.
@@ -115,7 +115,7 @@ struct Train final : public GroundVehicle<Train, VEH_TRAIN> {
/** We want to 'destruct' the right class. */
~Train() override { this->PreDestructor(); }
friend struct GroundVehicle<Train, VEH_TRAIN>; // GroundVehicle needs to use the acceleration functions defined at Train.
friend struct GroundVehicle<Train, VehicleType::Train>; // GroundVehicle needs to use the acceleration functions defined at Train.
void MarkDirty() override;
void UpdateDeltaXY() override;
+11 -11
View File
@@ -55,7 +55,7 @@ static const uint8_t _vehicle_initial_y_fract[4] = { 8, 4, 8, 10};
/** @copydoc IsValidImageIndex */
template <>
bool IsValidImageIndex<VEH_TRAIN>(uint8_t image_index)
bool IsValidImageIndex<VehicleType::Train>(uint8_t image_index)
{
return image_index < lengthof(_engine_sprite_base);
}
@@ -497,7 +497,7 @@ int Train::GetDisplayImageWidth(Point *offset) const
static SpriteID GetDefaultTrainSprite(uint8_t spritenum, Direction direction)
{
assert(IsValidImageIndex<VEH_TRAIN>(spritenum));
assert(IsValidImageIndex<VehicleType::Train>(spritenum));
return ((direction + _engine_sprite_add[spritenum]) & _engine_sprite_and[spritenum]) + _engine_sprite_base[spritenum];
}
@@ -521,7 +521,7 @@ void Train::GetImage(Direction direction, EngineImageType image_type, VehicleSpr
spritenum = this->GetEngine()->original_image_index;
}
assert(IsValidImageIndex<VEH_TRAIN>(spritenum));
assert(IsValidImageIndex<VehicleType::Train>(spritenum));
SpriteID sprite = GetDefaultTrainSprite(spritenum, direction);
if (this->cargo.StoredCount() >= this->cargo_cap / 2U) sprite += _wagon_full_adder[spritenum];
@@ -632,7 +632,7 @@ static std::vector<VehicleID> GetFreeWagonsInDepot(TileIndex tile)
std::vector<VehicleID> free_wagons;
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != VEH_TRAIN) continue;
if (v->type != VehicleType::Train) continue;
if (v->vehstatus.Test(VehState::Crashed)) continue;
if (!Train::From(v)->IsFreeWagon()) continue;
@@ -1031,7 +1031,7 @@ static CommandCost CheckNewTrain(Train *original_dst, Train *dst, Train *origina
/* Get a free unit number and check whether it's within the bounds.
* There will always be a maximum of one new train. */
if (GetFreeUnitNumber(VEH_TRAIN) <= _settings_game.vehicle.max_trains) return CommandCost();
if (GetFreeUnitNumber(VehicleType::Train) <= _settings_game.vehicle.max_trains) return CommandCost();
return CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
}
@@ -1234,7 +1234,7 @@ static void NormaliseTrainHead(Train *head)
/* If we don't have a unit number yet, set one. */
if (head->unitnumber != 0) return;
head->unitnumber = Company::Get(head->owner)->freeunits[head->type].UseID(GetFreeUnitNumber(VEH_TRAIN));
head->unitnumber = Company::Get(head->owner)->freeunits[head->type].UseID(GetFreeUnitNumber(VehicleType::Train));
}
/**
@@ -1719,7 +1719,7 @@ void ReverseTrainSwapVeh(Train *v, int l, int r)
*/
static bool IsTrain(const Vehicle *v)
{
return v->type == VEH_TRAIN;
return v->type == VehicleType::Train;
}
/**
@@ -1743,7 +1743,7 @@ bool TrainOnCrossing(TileIndex tile)
*/
static bool TrainApproachingCrossingEnum(const Vehicle *v, TileIndex tile)
{
if (v->type != VEH_TRAIN || v->vehstatus.Test(VehState::Crashed)) return false;
if (v->type != VehicleType::Train || v->vehstatus.Test(VehState::Crashed)) return false;
const Train *t = Train::From(v);
if (!t->IsMovingFront()) return false;
@@ -3270,7 +3270,7 @@ static uint TrainCrashed(Train *v)
static uint CheckTrainCollision(Vehicle *v, Train *moving_front)
{
/* Make sure we are a train, and are not in a depot. */
if (v->type != VEH_TRAIN) return 0;
if (v->type != VehicleType::Train) return 0;
/* We can't crash into trains in a depot. */
if (Train::From(v)->track == TRACK_BIT_DEPOT) return 0;
@@ -3463,7 +3463,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
/* check if a train is waiting on the other side */
if (!HasVehicleOnTile(o_tile, [&exitdir](const Vehicle *u) {
if (u->type != VEH_TRAIN || u->vehstatus.Test(VehState::Crashed)) return false;
if (u->type != VehicleType::Train || u->vehstatus.Test(VehState::Crashed)) return false;
const Train *t = Train::From(u);
/* not front engine of a train, inside wormhole or depot, crashed */
@@ -3737,7 +3737,7 @@ static void DeleteLastWagon(Train *v)
/* If there are still crashed vehicles on the tile, give the track reservation to them */
TrackBits remaining_trackbits = TRACK_BIT_NONE;
for (const Vehicle *u : VehiclesOnTile(tile)) {
if (u->type != VEH_TRAIN || !u->vehstatus.Test(VehState::Crashed)) continue;
if (u->type != VehicleType::Train || !u->vehstatus.Test(VehState::Crashed)) continue;
TrackBits train_tbits = Train::From(u)->track;
if (train_tbits == TRACK_BIT_WORMHOLE) {
/* Vehicle is inside a wormhole, u->track contains no useful value then. */
+1 -1
View File
@@ -35,7 +35,7 @@ void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uin
/* The non-deterministic order returned from VehiclesOnTile() does not
* matter here as there must only be one locomotive for anything to happen. */
for (const Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != VEH_TRAIN) continue;
if (v->type != VehicleType::Train) continue;
const Train *t = Train::From(v);
if (t->IsFrontEngine() && t->IsStoppedInDepot()) {
+10 -10
View File
@@ -1971,7 +1971,7 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
uint8_t frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
if (IsTunnel(tile)) {
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
Train *t = Train::From(v);
if (t->track != TRACK_BIT_WORMHOLE && dir == vdir) {
@@ -1997,7 +1997,7 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
t->vehstatus.Reset(VehState::Hidden);
return VehicleEnterTileState::EnteredWormhole;
}
} else if (v->type == VEH_ROAD) {
} else if (v->type == VehicleType::Road) {
RoadVehicle *rv = RoadVehicle::From(v);
/* Enter tunnel? */
@@ -2024,11 +2024,11 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
}
}
} else { // IsBridge(tile)
if (v->type != VEH_SHIP) {
if (v->type != VehicleType::Ship) {
/* modify speed of vehicle */
uint16_t spd = GetBridgeSpec(GetBridgeType(tile))->speed;
if (v->type == VEH_ROAD) spd *= 2;
if (v->type == VehicleType::Road) spd *= 2;
Vehicle *first = v->First();
first->cur_speed = std::min(first->cur_speed, spd);
}
@@ -2037,21 +2037,21 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
/* Vehicle enters bridge at the last frame inside this tile. */
if (frame != TILE_SIZE - 1) return {};
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
t->track = TRACK_BIT_WORMHOLE;
PrepareToEnterBridge(t);
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *rv = RoadVehicle::From(v);
rv->state = RVSB_WORMHOLE;
PrepareToEnterBridge(rv);
break;
}
case VEH_SHIP:
case VehicleType::Ship:
Ship::From(v)->state = TRACK_BIT_WORMHOLE;
break;
@@ -2061,7 +2061,7 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
} else if (vdir == ReverseDiagDir(dir)) {
v->tile = tile;
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
if (t->track == TRACK_BIT_WORMHOLE) {
t->track = DiagDirToDiagTrackBits(vdir);
@@ -2070,7 +2070,7 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
break;
}
case VEH_ROAD: {
case VehicleType::Road: {
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->state == RVSB_WORMHOLE) {
rv->state = DiagDirToDiagTrackdir(vdir);
@@ -2080,7 +2080,7 @@ static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileInde
break;
}
case VEH_SHIP: {
case VehicleType::Ship: {
Ship *ship = Ship::From(v);
if (ship->state == TRACK_BIT_WORMHOLE) {
ship->state = DiagDirToDiagTrackBits(vdir);
+89 -89
View File
@@ -174,7 +174,7 @@ bool Vehicle::NeedsAutorenewing(const Company *c, bool use_renew_setting) const
if (this->age - this->max_age < (c->settings.engine_renew_months * 30)) return false;
/* Only engines need renewing */
if (this->type == VEH_TRAIN && !Train::From(this)->IsEngine()) return false;
if (this->type == VehicleType::Train && !Train::From(this)->IsEngine()) return false;
return true;
}
@@ -242,7 +242,7 @@ bool Vehicle::NeedsServicing() const
Money needed_money = c->settings.engine_renew_money;
if (needed_money > GetAvailableMoney(c->index)) return false;
for (const Vehicle *v = this; v != nullptr; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : nullptr) {
for (const Vehicle *v = this; v != nullptr; v = (v->type == VehicleType::Train) ? Train::From(v)->GetNextUnit() : nullptr) {
bool replace_when_old = false;
EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id, &replace_when_old);
@@ -563,10 +563,10 @@ CommandCost EnsureNoVehicleOnGround(TileIndex tile)
* Such a message does not affect MP synchronisation.
*/
for (const Vehicle *v : VehiclesOnTile(tile)) {
if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) continue;
if (v->type == VehicleType::Disaster || (v->type == VehicleType::Aircraft && v->subtype == AIR_SHADOW)) continue;
if (v->z_pos > z) continue;
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + to_underlying(v->type));
}
return CommandCost();
}
@@ -586,9 +586,9 @@ CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle
* Such a message does not affect MP synchronisation.
*/
for (const Vehicle *v : VehiclesOnTile(t)) {
if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) continue;
if (v->type != VehicleType::Train && v->type != VehicleType::Road && v->type != VehicleType::Ship) continue;
if (v == ignore) continue;
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + to_underlying(v->type));
}
}
return CommandCost();
@@ -609,12 +609,12 @@ CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
* Such a message does not affect MP synchronisation.
*/
for (const Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != VEH_TRAIN) continue;
if (v->type != VehicleType::Train) continue;
const Train *t = Train::From(v);
if ((t->track != track_bits) && !TracksOverlap(t->track | track_bits)) continue;
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + to_underlying(v->type));
}
return CommandCost();
}
@@ -715,12 +715,12 @@ uint CountVehiclesInChain(const Vehicle *v)
bool Vehicle::IsEngineCountable() const
{
switch (this->type) {
case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft(); // don't count plane shadows and helicopter rotors
case VEH_TRAIN:
case VehicleType::Aircraft: return Aircraft::From(this)->IsNormalAircraft(); // don't count plane shadows and helicopter rotors
case VehicleType::Train:
return !this->IsArticulatedPart() && // tenders and other articulated parts
!Train::From(this)->IsRearDualheaded(); // rear parts of multiheaded engines
case VEH_ROAD: return RoadVehicle::From(this)->IsFrontEngine();
case VEH_SHIP: return true;
case VehicleType::Road: return RoadVehicle::From(this)->IsFrontEngine();
case VehicleType::Ship: return true;
default: return false; // Only count company buildable vehicles
}
}
@@ -732,10 +732,10 @@ bool Vehicle::IsEngineCountable() const
bool Vehicle::HasEngineType() const
{
switch (this->type) {
case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft();
case VEH_TRAIN:
case VEH_ROAD:
case VEH_SHIP: return true;
case VehicleType::Aircraft: return Aircraft::From(this)->IsNormalAircraft();
case VehicleType::Train:
case VehicleType::Road:
case VehicleType::Ship: return true;
default: return false;
}
}
@@ -848,7 +848,7 @@ void Vehicle::PreDestructor()
Company::Get(this->owner)->freeunits[this->type].ReleaseID(this->unitnumber);
if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) {
if (this->type == VehicleType::Aircraft && this->IsPrimaryVehicle()) {
Aircraft *a = Aircraft::From(this);
Station *st = GetTargetAirportIfValid(a);
if (st != nullptr) {
@@ -858,7 +858,7 @@ void Vehicle::PreDestructor()
}
if (this->type == VEH_ROAD && this->IsPrimaryVehicle()) {
if (this->type == VehicleType::Road && this->IsPrimaryVehicle()) {
RoadVehicle *v = RoadVehicle::From(this);
if (!v->vehstatus.Test(VehState::Crashed) && IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) {
/* Leave the drive through roadstop, when you have not already left it. */
@@ -908,7 +908,7 @@ Vehicle::~Vehicle()
UpdateVehicleTileHash(this, true);
UpdateVehicleViewportHash(this, INVALID_COORD, 0, this->sprite_cache.old_coord.left, this->sprite_cache.old_coord.top);
if (this->type != VEH_EFFECT) {
if (this->type != VehicleType::Effect) {
DeleteVehicleNews(this->index);
DeleteNewGRFInspectWindow(GetGrfSpecFeature(this->type), this->index);
}
@@ -1010,10 +1010,10 @@ void CallVehicleTicks()
switch (v->type) {
default: break;
case VEH_TRAIN:
case VEH_ROAD:
case VEH_AIRCRAFT:
case VEH_SHIP: {
case VehicleType::Train:
case VehicleType::Road:
case VehicleType::Aircraft:
case VehicleType::Ship: {
Vehicle *front = v->First();
if (v->vcache.cached_cargo_age_period != 0) {
@@ -1031,22 +1031,22 @@ void CallVehicleTicks()
if (v->vehstatus.Test(VehState::Hidden)) continue;
/* Do not play any sound when stopped */
if (front->vehstatus.Test(VehState::Stopped) && (front->type != VEH_TRAIN || front->cur_speed == 0)) continue;
if (front->vehstatus.Test(VehState::Stopped) && (front->type != VehicleType::Train || front->cur_speed == 0)) continue;
/* Update motion counter for animation purposes. */
v->motion_counter += front->cur_speed;
/* Check vehicle type specifics */
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (!Train::From(v)->IsEngine()) continue;
break;
case VEH_ROAD:
case VehicleType::Road:
if (!RoadVehicle::From(v)->IsFrontEngine()) continue;
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
if (!Aircraft::From(v)->IsNormalAircraft()) continue;
break;
@@ -1128,7 +1128,7 @@ static void DoDrawVehicle(const Vehicle *v)
/* Check whether the vehicle shall be transparent due to the game state */
bool shadowed = v->vehstatus.Test(VehState::Shadow);
if (v->type == VEH_EFFECT) {
if (v->type == VehicleType::Effect) {
/* Check whether the vehicle shall be transparent/invisible due to GUI settings.
* However, transparent smoke and bubbles look weird, so always hide them. */
TransparencyOption to = EffectVehicle::From(v)->GetTransparencyOption();
@@ -1355,7 +1355,7 @@ void CheckVehicleBreakdown(Vehicle *v)
/* Calculate reliability value to use in comparison. */
rel = v->reliability;
if (v->type == VEH_SHIP) rel += 0x6666;
if (v->type == VehicleType::Ship) rel += 0x6666;
/* Reduce the chance if the player has chosen the Reduced setting. */
if (_settings_game.difficulty.vehicle_breakdowns == VehicleBreakdowns::Reduced) rel += 0x6666;
@@ -1392,14 +1392,14 @@ bool Vehicle::HandleBreakdown()
this->breakdowns_since_last_service++;
}
if (this->type == VEH_AIRCRAFT) {
if (this->type == VehicleType::Aircraft) {
/* Aircraft just need this flag, the rest is handled elsewhere */
this->vehstatus.Set(VehState::AircraftBroken);
} else {
this->cur_speed = 0;
if (!PlayVehicleSound(this, VSE_BREAKDOWN)) {
bool train_or_ship = this->type == VEH_TRAIN || this->type == VEH_SHIP;
bool train_or_ship = this->type == VehicleType::Train || this->type == VehicleType::Ship;
SndPlayVehicleFx((_settings_game.game_creation.landscape != LandscapeType::Toyland) ?
(train_or_ship ? SND_10_BREAKDOWN_TRAIN_SHIP : SND_0F_BREAKDOWN_ROADVEHICLE) :
(train_or_ship ? SND_3A_BREAKDOWN_TRAIN_SHIP_TOYLAND : SND_35_BREAKDOWN_ROADVEHICLE_TOYLAND), this);
@@ -1418,10 +1418,10 @@ bool Vehicle::HandleBreakdown()
[[fallthrough]];
case 1:
/* Aircraft breakdowns end only when arriving at the airport */
if (this->type == VEH_AIRCRAFT) return false;
if (this->type == VehicleType::Aircraft) return false;
/* For trains this function is called twice per tick, so decrease v->breakdown_delay at half the rate */
if ((this->tick_counter & (this->type == VEH_TRAIN ? 3 : 1)) == 0) {
if ((this->tick_counter & (this->type == VehicleType::Train ? 3 : 1)) == 0) {
if (--this->breakdown_delay == 0) {
this->breakdown_ctr = 0;
this->MarkDirty();
@@ -1456,7 +1456,7 @@ void AgeVehicle(Vehicle *v)
{
if (v->age < CalendarTime::MAX_DATE) v->age++;
if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return;
if (!v->IsPrimaryVehicle() && (v->type != VehicleType::Train || !Train::From(v)->IsEngine())) return;
auto age = v->age - v->max_age;
for (int32_t i = 0; i <= 4; i++) {
@@ -1568,7 +1568,7 @@ void VehicleEnterDepot(Vehicle *v)
assert(v == v->First());
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
Train *t = Train::From(v);
SetWindowClassesDirty(WC_TRAINS_LIST);
/* Clear path reservation */
@@ -1583,11 +1583,11 @@ void VehicleEnterDepot(Vehicle *v)
break;
}
case VEH_ROAD:
case VehicleType::Road:
SetWindowClassesDirty(WC_ROADVEH_LIST);
break;
case VEH_SHIP: {
case VehicleType::Ship: {
SetWindowClassesDirty(WC_SHIPS_LIST);
Ship *ship = Ship::From(v);
ship->state = TRACK_BIT_DEPOT;
@@ -1597,13 +1597,13 @@ void VehicleEnterDepot(Vehicle *v)
break;
}
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
SetWindowClassesDirty(WC_AIRCRAFT_LIST);
HandleAircraftEnterHangar(Aircraft::From(v));
break;
default: NOT_REACHED();
}
if (v->type != VEH_TRAIN) {
if (v->type != VehicleType::Train) {
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters.
* We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -1631,7 +1631,7 @@ void VehicleEnterDepot(Vehicle *v)
* Note: The target depot for nearest-/manual-depot-orders is only updated on junctions, but we want to accept every depot. */
if (v->current_order.GetDepotOrderType().Test(OrderDepotTypeFlag::PartOfOrders) &&
real_order != nullptr && !real_order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot) &&
(v->type == VEH_AIRCRAFT ? v->current_order.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) {
(v->type == VehicleType::Aircraft ? v->current_order.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) {
/* We are heading for another depot, keep driving. */
return;
}
@@ -1674,7 +1674,7 @@ void VehicleEnterDepot(Vehicle *v)
/* Announce that the vehicle is waiting to players and AIs. */
if (v->owner == _local_company) {
AddVehicleAdviceNewsItem(AdviceType::VehicleWaiting, GetEncodedString(STR_NEWS_TRAIN_IS_WAITING + v->type, v->index), v->index);
AddVehicleAdviceNewsItem(AdviceType::VehicleWaiting, GetEncodedString(STR_NEWS_TRAIN_IS_WAITING + to_underlying(v->type), v->index), v->index);
}
AI::NewEvent(v->owner, new ScriptEventVehicleWaitingInDepot(v->index));
}
@@ -1785,7 +1785,7 @@ void Vehicle::UpdateViewport(bool dirty)
*/
void Vehicle::UpdatePositionAndViewport()
{
if (this->type != VEH_EFFECT) this->UpdatePosition();
if (this->type != VehicleType::Effect) this->UpdatePosition();
this->UpdateViewport(true);
}
@@ -1919,10 +1919,10 @@ UnitID GetFreeUnitNumber(VehicleType type)
/* Check whether it is allowed to build another vehicle. */
uint max_veh;
switch (type) {
case VEH_TRAIN: max_veh = _settings_game.vehicle.max_trains; break;
case VEH_ROAD: max_veh = _settings_game.vehicle.max_roadveh; break;
case VEH_SHIP: max_veh = _settings_game.vehicle.max_ships; break;
case VEH_AIRCRAFT: max_veh = _settings_game.vehicle.max_aircraft; break;
case VehicleType::Train: max_veh = _settings_game.vehicle.max_trains; break;
case VehicleType::Road: max_veh = _settings_game.vehicle.max_roadveh; break;
case VehicleType::Ship: max_veh = _settings_game.vehicle.max_ships; break;
case VehicleType::Aircraft: max_veh = _settings_game.vehicle.max_aircraft; break;
default: NOT_REACHED();
}
@@ -1950,16 +1950,16 @@ bool CanBuildVehicleInfrastructure(VehicleType type, RoadTramType subtype)
UnitID max;
switch (type) {
case VEH_TRAIN:
case VehicleType::Train:
if (!HasAnyRailTypesAvail(_local_company)) return false;
max = _settings_game.vehicle.max_trains;
break;
case VEH_ROAD:
case VehicleType::Road:
if (!HasAnyRoadTypesAvail(_local_company, subtype)) return false;
max = _settings_game.vehicle.max_roadveh;
break;
case VEH_SHIP: max = _settings_game.vehicle.max_ships; break;
case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break;
case VehicleType::Ship: max = _settings_game.vehicle.max_ships; break;
case VehicleType::Aircraft: max = _settings_game.vehicle.max_aircraft; break;
default: NOT_REACHED();
}
@@ -1967,7 +1967,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, RoadTramType subtype)
if (max > 0) {
/* Can we actually build the vehicle type? */
for (const Engine *e : Engine::IterateType(type)) {
if (type == VEH_ROAD && GetRoadTramType(e->VehInfo<RoadVehicleInfo>().roadtype) != subtype) continue;
if (type == VehicleType::Road && GetRoadTramType(e->VehInfo<RoadVehicleInfo>().roadtype) != subtype) continue;
if (e->company_avail.Test(_local_company)) return true;
}
return false;
@@ -1975,7 +1975,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, RoadTramType subtype)
/* We should be able to build infrastructure when we have the actual vehicle type */
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == VEH_ROAD && GetRoadTramType(RoadVehicle::From(v)->roadtype) != subtype) continue;
if (v->type == VehicleType::Road && GetRoadTramType(RoadVehicle::From(v)->roadtype) != subtype) continue;
if (v->owner == _local_company && v->type == type) return true;
}
@@ -1996,7 +1996,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_
const Engine *e = Engine::Get(engine_type);
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN:
case VehicleType::Train:
if (v != nullptr && parent_engine_type != EngineID::Invalid() && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->VehInfo<RailVehicleInfo>().railveh_type != RAILVEH_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) */
@@ -2039,7 +2039,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_
}
}
case VEH_ROAD:
case VehicleType::Road:
/* Always use the livery of the front */
if (v != nullptr && parent_engine_type != EngineID::Invalid()) {
engine_type = parent_engine_type;
@@ -2059,13 +2059,13 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_
return IsCargoInClass(cargo_type, CargoClass::Passengers) ? LS_BUS : LS_TRUCK;
}
case VEH_SHIP:
case VehicleType::Ship:
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));
return IsCargoInClass(cargo_type, CargoClass::Passengers) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
switch (e->VehInfo<AircraftVehicleInfo>().subtype) {
case AIR_HELI: return LS_HELICOPTER;
case AIR_CTOL: return LS_SMALL_PLANE;
@@ -2219,11 +2219,11 @@ void Vehicle::DeleteUnreachedImplicitOrders()
/**
* Prepare everything to begin the loading when arriving at a station.
* @pre IsTileType(this->tile, TileType::Station) || this->type == VEH_SHIP.
* @pre IsTileType(this->tile, TileType::Station) || this->type == VehicleType::Ship.
*/
void Vehicle::BeginLoading()
{
assert(IsTileType(this->GetMovingFront()->tile, TileType::Station) || this->type == VEH_SHIP);
assert(IsTileType(this->GetMovingFront()->tile, TileType::Station) || this->type == VehicleType::Ship);
TimerGameTick::Ticks travel_time = TimerGameTick::counter - this->last_loading_tick;
if (this->current_order.IsType(OT_GOTO_STATION) &&
@@ -2403,7 +2403,7 @@ void Vehicle::LeaveStation()
HideFillingPercent(&this->fill_percent_te_id);
trip_occupancy = CalcPercentVehicleFilled(this, nullptr);
if (this->type == VEH_TRAIN && !this->vehstatus.Test(VehState::Crashed)) {
if (this->type == VehicleType::Train && !this->vehstatus.Test(VehState::Crashed)) {
/* Trigger station animation (trains only) */
TileIndex tile = this->GetMovingFront()->tile;
if (IsTileType(tile, TileType::Station)) {
@@ -2413,7 +2413,7 @@ void Vehicle::LeaveStation()
Train::From(this)->flags.Set(VehicleRailFlag::LeavingStation);
}
if (this->type == VEH_ROAD && !this->vehstatus.Test(VehState::Crashed)) {
if (this->type == VehicleType::Road && !this->vehstatus.Test(VehState::Crashed)) {
/* Trigger road stop animation */
if (IsStationRoadStopTile(this->tile)) {
TriggerRoadStopRandomisation(st, this->tile, StationRandomTrigger::VehicleDeparts);
@@ -2639,7 +2639,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlags flags, DepotCommandFlags command
}
ClosestDepot closest_depot = this->FindClosestDepot();
static const StringID no_depot[] = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_HANGAR};
static constexpr VehicleTypeIndexArray<const StringID> no_depot = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_HANGAR};
if (!closest_depot.found) return CommandCost(no_depot[this->type]);
if (flags.Test(DoCommandFlag::Execute)) {
@@ -2656,11 +2656,11 @@ CommandCost Vehicle::SendToDepot(DoCommandFlags flags, DepotCommandFlags command
InvalidateWindowData(WC_VEHICLE_VIEW, this->index);
/* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */
if (this->type == VEH_TRAIN && (closest_depot.reverse ^ Train::From(this)->flags.Test(VehicleRailFlag::Reversing))) {
if (this->type == VehicleType::Train && (closest_depot.reverse ^ Train::From(this)->flags.Test(VehicleRailFlag::Reversing))) {
Command<Commands::ReverseTrainDirection>::Do(DoCommandFlag::Execute, this->index, false);
}
if (this->type == VEH_AIRCRAFT) {
if (this->type == VehicleType::Aircraft) {
Aircraft *a = Aircraft::From(this);
if (a->state == FLYING && a->targetairport != closest_depot.destination) {
/* The aircraft is now heading for a different hangar than the next in the orders */
@@ -2685,9 +2685,9 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change)
/* Evaluate properties */
uint8_t visual_effect;
switch (e->type) {
case VEH_TRAIN: visual_effect = e->VehInfo<RailVehicleInfo>().visual_effect; break;
case VEH_ROAD: visual_effect = e->VehInfo<RoadVehicleInfo>().visual_effect; break;
case VEH_SHIP: visual_effect = e->VehInfo<ShipVehicleInfo>().visual_effect; break;
case VehicleType::Train: visual_effect = e->VehInfo<RailVehicleInfo>().visual_effect; break;
case VehicleType::Road: visual_effect = e->VehInfo<RoadVehicleInfo>().visual_effect; break;
case VehicleType::Ship: visual_effect = e->VehInfo<ShipVehicleInfo>().visual_effect; break;
default: visual_effect = 1 << VE_DISABLE_EFFECT; break;
}
@@ -2714,7 +2714,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 != VEH_TRAIN || e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON || !IsInsideMM(e->VehInfo<RailVehicleInfo>().engclass, EC_STEAM, EC_MONORAIL)) {
if (e->type != VehicleType::Train || e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON || !IsInsideMM(e->VehInfo<RailVehicleInfo>().engclass, EC_STEAM, EC_MONORAIL)) {
if (visual_effect == VE_DEFAULT) {
visual_effect = 1 << VE_DISABLE_EFFECT;
} else {
@@ -2759,14 +2759,14 @@ static void SpawnAdvancedVisualEffect(const Vehicle *v)
int8_t l_center = 0;
if (auto_center) {
/* For road vehicles: Compute offset from vehicle position to vehicle center */
if (v->type == VEH_ROAD) l_center = -(int)(VEHICLE_LENGTH - RoadVehicle::From(v)->gcache.cached_veh_length) / 2;
if (v->type == VehicleType::Road) l_center = -(int)(VEHICLE_LENGTH - RoadVehicle::From(v)->gcache.cached_veh_length) / 2;
} else {
/* For trains: Compute offset from vehicle position to sprite position */
if (v->type == VEH_TRAIN) l_center = (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
if (v->type == VehicleType::Train) l_center = (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
}
Direction l_dir = v->direction;
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) l_dir = ReverseDir(l_dir);
if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) l_dir = ReverseDir(l_dir);
Direction t_dir = ChangeDir(l_dir, DIRDIFF_90RIGHT);
int8_t x_center = _vehicle_smoke_pos[l_dir] * l_center;
@@ -2837,7 +2837,7 @@ void Vehicle::ShowVisualEffect() const
/* Use the speed as limited by underground and orders. */
uint max_speed = this->GetCurrentMaxSpeed();
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
const Train *t = Train::From(this);
const Train *moving_front = t->GetMovingFront();
/* For trains, do not show any smoke when:
@@ -2881,7 +2881,7 @@ void Vehicle::ShowVisualEffect() const
IsBridgeAboveVehicle(v) ||
IsDepotTile(v->tile) ||
IsTunnelTile(v->tile) ||
(v->type == VEH_TRAIN &&
(v->type == VehicleType::Train &&
!HasPowerOnRail(Train::From(v)->railtypes, GetTileRailType(v->tile)))) {
continue;
}
@@ -2912,7 +2912,7 @@ void Vehicle::ShowVisualEffect() const
* - up to which speed a diesel vehicle is emitting smoke (with reduced/small setting only until 1/2 of max_speed),
* - in Chance16 - the last value is 512 / 2^smoke_amount (max. smoke when 128 = smoke_amount of 2). */
int power_weight_effect = 0;
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
power_weight_effect = (32 >> (Train::From(this)->gcache.cached_power >> 10)) - (32 >> (Train::From(this)->gcache.cached_weight >> 9));
}
if (this->cur_speed < (max_speed >> (2 >> _settings_game.vehicle.smoke_amount)) &&
@@ -2948,12 +2948,12 @@ void Vehicle::ShowVisualEffect() const
/* The effect offset is relative to a point 4 units behind the vehicle's
* front (which is the center of an 8/8 vehicle). Shorter vehicles need a
* correction factor. */
if (v->type == VEH_TRAIN) effect_offset += (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
if (v->type == VehicleType::Train) effect_offset += (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
int x = _vehicle_smoke_pos[v->direction] * effect_offset;
int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset;
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
x = -x;
y = -y;
}
@@ -3101,19 +3101,19 @@ bool CanVehicleUseStation(EngineID engine_type, const Station *st)
assert(e != nullptr);
switch (e->type) {
case VEH_TRAIN:
case VehicleType::Train:
return st->facilities.Test(StationFacility::Train);
case VEH_ROAD:
case VehicleType::Road:
/* For road vehicles we need the vehicle to know whether it can actually
* use the station, but if it doesn't have facilities for RVs it is
* certainly not possible that the station can be used. */
return st->facilities.Any({StationFacility::BusStop, StationFacility::TruckStop});
case VEH_SHIP:
case VehicleType::Ship:
return st->facilities.Test(StationFacility::Dock);
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
return st->facilities.Test(StationFacility::Airport) &&
st->airport.GetFTA()->flags.Test(e->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL ? AirportFTAClass::Flag::Airplanes : AirportFTAClass::Flag::Helicopters);
@@ -3130,7 +3130,7 @@ bool CanVehicleUseStation(EngineID engine_type, const Station *st)
*/
bool CanVehicleUseStation(const Vehicle *v, const Station *st)
{
if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop(RoadVehicle::From(v)) != nullptr;
if (v->type == VehicleType::Road) return st->GetPrimaryRoadStop(RoadVehicle::From(v)) != nullptr;
return CanVehicleUseStation(v->engine_type, st);
}
@@ -3144,10 +3144,10 @@ bool CanVehicleUseStation(const Vehicle *v, const Station *st)
StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
{
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
return STR_ERROR_NO_RAIL_STATION;
case VEH_ROAD: {
case VehicleType::Road: {
const RoadVehicle *rv = RoadVehicle::From(v);
RoadStop *rs = st->GetPrimaryRoadStop(rv->IsBus() ? RoadStopType::Bus : RoadStopType::Truck);
@@ -3171,10 +3171,10 @@ StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
return err;
}
case VEH_SHIP:
case VehicleType::Ship:
return STR_ERROR_NO_DOCK;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
if (!st->facilities.Test(StationFacility::Airport)) return STR_ERROR_NO_AIRPORT;
if (v->GetEngine()->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL) {
return STR_ERROR_AIRPORT_NO_PLANES;
@@ -3195,7 +3195,7 @@ StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
GroundVehicleCache *Vehicle::GetGroundVehicleCache()
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
return &Train::From(this)->gcache;
} else {
return &RoadVehicle::From(this)->gcache;
@@ -3210,7 +3210,7 @@ GroundVehicleCache *Vehicle::GetGroundVehicleCache()
const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
return &Train::From(this)->gcache;
} else {
return &RoadVehicle::From(this)->gcache;
@@ -3225,7 +3225,7 @@ const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const
uint16_t &Vehicle::GetGroundVehicleFlags()
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
return Train::From(this)->gv_flags;
} else {
return RoadVehicle::From(this)->gv_flags;
@@ -3240,7 +3240,7 @@ uint16_t &Vehicle::GetGroundVehicleFlags()
const uint16_t &Vehicle::GetGroundVehicleFlags() const
{
assert(this->IsGroundVehicle());
if (this->type == VEH_TRAIN) {
if (this->type == VehicleType::Train) {
return Train::From(this)->gv_flags;
} else {
return RoadVehicle::From(this)->gv_flags;
@@ -3257,7 +3257,7 @@ const uint16_t &Vehicle::GetGroundVehicleFlags() const
*/
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
{
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
Train *u = Train::From(v);
/* Only include whole vehicles, so start with the first articulated part */
u = u->GetFirstEnginePart();
+2 -2
View File
@@ -332,7 +332,7 @@ public:
return 0;
}
Vehicle(VehicleID index, VehicleType type = VEH_INVALID);
Vehicle(VehicleID index, VehicleType type = VehicleType::Invalid);
void PreDestructor();
/** We want to 'destruct' the right class. */
@@ -521,7 +521,7 @@ public:
*/
[[debug_inline]] inline bool IsGroundVehicle() const
{
return this->type == VEH_TRAIN || this->type == VEH_ROAD;
return this->type == VehicleType::Train || this->type == VehicleType::Road;
}
/**
+48 -48
View File
@@ -49,7 +49,7 @@
* @{
*/
/** When can't buy such vehicle. */
const StringID _veh_build_msg_table[] = {
VehicleTypeIndexArray<const StringID> _veh_build_msg_table = {
STR_ERROR_CAN_T_BUY_TRAIN,
STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
STR_ERROR_CAN_T_BUY_SHIP,
@@ -57,7 +57,7 @@ const StringID _veh_build_msg_table[] = {
};
/** When can't sell such vehicle. */
const StringID _veh_sell_msg_table[] = {
VehicleTypeIndexArray<const StringID> _veh_sell_msg_table = {
STR_ERROR_CAN_T_SELL_TRAIN,
STR_ERROR_CAN_T_SELL_ROAD_VEHICLE,
STR_ERROR_CAN_T_SELL_SHIP,
@@ -65,7 +65,7 @@ const StringID _veh_sell_msg_table[] = {
};
/** When can't sell all vehicles in depot. */
const StringID _veh_sell_all_msg_table[] = {
VehicleTypeIndexArray<const StringID> _veh_sell_all_msg_table = {
STR_ERROR_CAN_T_SELL_ALL_TRAIN,
STR_ERROR_CAN_T_SELL_ALL_ROAD_VEHICLE,
STR_ERROR_CAN_T_SELL_ALL_SHIP,
@@ -73,7 +73,7 @@ const StringID _veh_sell_all_msg_table[] = {
};
/** When can't autoreplace such vehicle. */
const StringID _veh_autoreplace_msg_table[] = {
VehicleTypeIndexArray<const StringID> _veh_autoreplace_msg_table = {
STR_ERROR_CAN_T_AUTOREPLACE_TRAIN,
STR_ERROR_CAN_T_AUTOREPLACE_ROAD_VEHICLE,
STR_ERROR_CAN_T_AUTOREPLACE_SHIP,
@@ -81,7 +81,7 @@ const StringID _veh_autoreplace_msg_table[] = {
};
/** When can't refit such vehicle. */
const StringID _veh_refit_msg_table[] = {
VehicleTypeIndexArray<const StringID> _veh_refit_msg_table = {
STR_ERROR_CAN_T_REFIT_TRAIN,
STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE,
STR_ERROR_CAN_T_REFIT_SHIP,
@@ -89,7 +89,7 @@ const StringID _veh_refit_msg_table[] = {
};
/** When can't send to depot such vehicle. */
const StringID _send_to_depot_msg_table[] = {
VehicleTypeIndexArray<const StringID> _send_to_depot_msg_table = {
STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT,
STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT,
STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT,
@@ -116,7 +116,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(D
VehicleType type = GetDepotVehicleType(tile);
/* Validate the engine type. */
if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type), VehicleID::Invalid(), 0, 0, {} };
if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + to_underlying(type)), VehicleID::Invalid(), 0, 0, {} };
/* Validate the cargo type. */
if (cargo >= NUM_CARGO && IsValidCargoType(cargo)) return { CMD_ERROR, VehicleID::Invalid(), 0, 0, {} };
@@ -133,10 +133,10 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> 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 VEH_TRAIN: num_vehicles = (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid); break;
case VEH_ROAD: num_vehicles = 1 + CountArticulatedParts(eid); break;
case VEH_SHIP: num_vehicles = 1; break;
case VEH_AIRCRAFT: num_vehicles = e->VehInfo<AircraftVehicleInfo>().subtype & AIR_CTOL ? 2 : 3; break;
case VehicleType::Train: num_vehicles = (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_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<AircraftVehicleInfo>().subtype & AIR_CTOL ? 2 : 3; break;
default: NOT_REACHED(); // Safe due to IsDepotTile()
}
if (!Vehicle::CanAllocateItem(num_vehicles)) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), VehicleID::Invalid(), 0, 0, {} };
@@ -144,7 +144,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> 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 == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type);
UnitID unit_num = (flags.Test(DoCommandFlag::QueryCost) || flags.Test(DoCommandFlag::AutoReplace) || (type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_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
@@ -159,10 +159,10 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(D
Vehicle *v = nullptr;
switch (type) {
case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(subflags, tile, e, &v)); break;
case VEH_ROAD: value.AddCost(CmdBuildRoadVehicle(subflags, tile, e, &v)); break;
case VEH_SHIP: value.AddCost(CmdBuildShip (subflags, tile, e, &v)); break;
case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft (subflags, tile, e, &v)); break;
case VehicleType::Train: value.AddCost(CmdBuildRailVehicle(subflags, tile, e, &v)); break;
case VehicleType::Road: value.AddCost(CmdBuildRoadVehicle(subflags, tile, e, &v)); break;
case VehicleType::Ship: value.AddCost(CmdBuildShip (subflags, tile, e, &v)); break;
case VehicleType::Aircraft: value.AddCost(CmdBuildAircraft (subflags, tile, e, &v)); break;
default: NOT_REACHED(); // Safe due to IsDepotTile()
}
@@ -184,7 +184,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(D
value.AddCost(std::move(cc));
} else {
/* Fill in non-refitted capacities */
if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
if (e->type == VehicleType::Train || e->type == VehicleType::Road) {
cargo_capacities = GetCapacityOfArticulatedParts(eid);
refitted_capacity = cargo_capacities[default_cargo];
refitted_mail_capacity = 0;
@@ -197,7 +197,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(D
}
if (flags.Test(DoCommandFlag::Execute)) {
if (type == VEH_TRAIN && use_free_vehicles && !flags.Test(DoCommandFlag::AutoReplace) && Train::From(v)->IsEngine()) {
if (type == VehicleType::Train && use_free_vehicles && !flags.Test(DoCommandFlag::AutoReplace) && Train::From(v)->IsEngine()) {
/* Move any free wagons to the new vehicle. */
NormalizeTrainVehInDepot(Train::From(v));
}
@@ -256,9 +256,9 @@ CommandCost CmdSellVehicle(DoCommandFlags flags, VehicleID v_id, bool sell_chain
if (front->vehstatus.Test(VehState::Crashed)) return CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED);
if (!front->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
if (!front->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + to_underlying(front->type));
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
ret = CmdSellRailWagon(flags, v, sell_chain, backup_order, client_id);
} else {
ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
@@ -320,22 +320,22 @@ static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoTyp
Price base_price;
int cost_factor = GetRefitCostFactor(v, engine_type, new_cargo_type, new_subtype, auto_refit_allowed);
switch (e->type) {
case VEH_SHIP:
case VehicleType::Ship:
base_price = Price::BuildVehicleShip;
expense_type = EXPENSES_SHIP_RUN;
break;
case VEH_ROAD:
case VehicleType::Road:
base_price = Price::BuildVehicleRoad;
expense_type = EXPENSES_ROADVEH_RUN;
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
base_price = Price::BuildVehicleAircraft;
expense_type = EXPENSES_AIRCRAFT_RUN;
break;
case VEH_TRAIN:
case VehicleType::Train:
base_price = (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) ? Price::BuildVehicleWagon : Price::BuildVehicleTrain;
cost_factor <<= 1;
expense_type = EXPENSES_TRAIN_RUN;
@@ -393,7 +393,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
/* Reset actual_subtype for every new vehicle */
if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
if (v->type == VEH_TRAIN && std::ranges::find(vehicles_to_refit, v->index) == vehicles_to_refit.end() && !only_this) continue;
if (v->type == VehicleType::Train && std::ranges::find(vehicles_to_refit, v->index) == vehicles_to_refit.end() && !only_this) continue;
const Engine *e = v->GetEngine();
if (!e->CanCarryCargo()) continue;
@@ -448,7 +448,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
if (v->cargo_type == new_cargo_type) {
/* Add the old capacity nevertheless, if the cargo matches */
total_capacity += v->cargo_cap;
if (v->type == VEH_AIRCRAFT) total_mail_capacity += v->Next()->cargo_cap;
if (v->type == VehicleType::Aircraft) total_mail_capacity += v->Next()->cargo_cap;
}
continue;
}
@@ -475,7 +475,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
u->cargo_type = new_cargo_type;
u->cargo_cap = result.capacity;
u->cargo_subtype = result.subtype;
if (u->type == VEH_AIRCRAFT) {
if (u->type == VehicleType::Aircraft) {
Vehicle *w = u->Next();
assert(w != nullptr);
w->refit_cap = std::min<uint16_t>(w->refit_cap, result.mail_capacity);
@@ -511,17 +511,17 @@ std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFla
CommandCost ret = CheckOwnership(front->owner);
if (ret.Failed()) return { ret, 0, 0, {} };
bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
bool free_wagon = v->type == VehicleType::Train && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
/* Don't allow shadows and such to be refitted. */
if (v != front && (v->type == VEH_SHIP || v->type == VEH_AIRCRAFT)) return { CMD_ERROR, 0, 0, {} };
if (v != front && (v->type == VehicleType::Ship || v->type == VehicleType::Aircraft)) return { CMD_ERROR, 0, 0, {} };
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
if (!flags.Test(DoCommandFlag::QueryCost) && // used by the refit GUI, including the order refit GUI.
!free_wagon && // used by autoreplace/renew
(!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
!front->IsStoppedInDepot()) { // refit inside depots
return { CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type), 0, 0, {} };
return { CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + to_underlying(front->type)), 0, 0, {} };
}
if (front->vehstatus.Test(VehState::Crashed)) return { CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED), 0, 0, {} };
@@ -530,27 +530,27 @@ std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFla
if (new_cargo_type >= NUM_CARGO) return { CMD_ERROR, 0, 0, {} };
/* For ships and aircraft there is always only one. */
only_this |= front->type == VEH_SHIP || front->type == VEH_AIRCRAFT;
only_this |= front->type == VehicleType::Ship || front->type == VehicleType::Aircraft;
auto [cost, refit_capacity, mail_capacity, cargo_capacities] = RefitVehicle(v, only_this, num_vehicles, new_cargo_type, new_subtype, flags, auto_refit);
if (flags.Test(DoCommandFlag::Execute)) {
/* Update the cached variables */
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
Train::From(front)->ConsistChanged(auto_refit ? CCF_AUTOREFIT : CCF_REFIT);
break;
case VEH_ROAD:
case VehicleType::Road:
RoadVehUpdateCache(RoadVehicle::From(front), auto_refit);
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) RoadVehicle::From(front)->CargoChanged();
break;
case VEH_SHIP:
case VehicleType::Ship:
v->InvalidateNewGRFCacheOfChain();
Ship::From(v)->UpdateCache();
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
v->InvalidateNewGRFCacheOfChain();
UpdateAircraftCache(Aircraft::From(v), true);
break;
@@ -593,15 +593,15 @@ CommandCost CmdStartStopVehicle(DoCommandFlags flags, VehicleID veh_id, bool eva
if (v->vehstatus.Test(VehState::Crashed)) return CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED);
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
if (v->vehstatus.Test(VehState::Stopped) && Train::From(v)->gcache.cached_power == 0) return CommandCost(STR_ERROR_TRAIN_START_NO_POWER);
break;
case VEH_SHIP:
case VEH_ROAD:
case VehicleType::Ship:
case VehicleType::Road:
break;
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
Aircraft *a = Aircraft::From(v);
/* cannot stop airplane when in flight, or when taking off / landing */
if (a->state >= STARTTAKEOFF && a->state < TERM7) return CommandCost(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
@@ -647,7 +647,7 @@ CommandCost CmdStartStopVehicle(DoCommandFlags flags, VehicleID veh_id, bool eva
if (v->IsStoppedInDepot() && !flags.Test(DoCommandFlag::AutoReplace)) DeleteVehicleNews(veh_id, AdviceType::VehicleWaiting);
v->vehstatus.Flip(VehState::Stopped);
if (v->type != VEH_TRAIN) v->cur_speed = 0; // trains can stop 'slowly'
if (v->type != VehicleType::Train) v->cur_speed = 0; // trains can stop 'slowly'
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
@@ -857,7 +857,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
if (ret.Failed()) return { ret, VehicleID::Invalid() };
/* Crashed trains can only be cloned before cleanup begins. */
if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return { CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED), VehicleID::Invalid() };
if (v->type == VehicleType::Train && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return { CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED), VehicleID::Invalid() };
/* check that we can allocate enough vehicles */
if (!flags.Test(DoCommandFlag::Execute)) {
@@ -875,7 +875,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
VehicleID new_veh_id = VehicleID::Invalid();
do {
if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) {
if (v->type == VehicleType::Train && Train::From(v)->IsRearDualheaded()) {
/* we build the rear ends of multiheaded trains with the front ones */
continue;
}
@@ -903,7 +903,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
if (flags.Test(DoCommandFlag::Execute)) {
w = Vehicle::Get(new_veh_id);
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
/* Only copy the reverse state if neither old or new vehicle implements reverse-on-build probability callback. */
if (!TestVehicleBuildProbability(v, BuildProbabilityType::Reversed).has_value() &&
!TestVehicleBuildProbability(w, BuildProbabilityType::Reversed).has_value()) {
@@ -911,7 +911,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
}
}
if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
if (v->type == VehicleType::Train && !v->IsFrontEngine()) {
/* this s a train car
* add this unit to the end of the train */
CommandCost result = Command<Commands::MoveRailVehicle>::Do(flags, w->index, w_rear->index, true);
@@ -931,9 +931,9 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
}
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
}
} while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
} while (v->type == VehicleType::Train && (v = v->GetNextVehicle()) != nullptr);
if (flags.Test(DoCommandFlag::Execute) && v_front->type == VEH_TRAIN) {
if (flags.Test(DoCommandFlag::Execute) && v_front->type == VehicleType::Train) {
/* for trains this needs to be the front engine due to the callback function */
new_veh_id = w_front->index;
}
@@ -988,8 +988,8 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
}
} while (v != nullptr);
if (flags.Test(DoCommandFlag::Execute) && v->type == VEH_TRAIN) w = w->GetNextVehicle();
} while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != nullptr);
if (flags.Test(DoCommandFlag::Execute) && v->type == VehicleType::Train) w = w->GetNextVehicle();
} while (v->type == VehicleType::Train && (v = v->GetNextVehicle()) != nullptr);
if (flags.Test(DoCommandFlag::Execute)) {
/*
+7 -7
View File
@@ -235,7 +235,7 @@ Direction GetDirectionTowards(const Vehicle *v, int x, int y);
*/
inline bool IsCompanyBuildableVehicleType(VehicleType type)
{
return type < VEH_COMPANY_END;
return type < VehicleType::CompanyEnd;
}
/**
@@ -254,12 +254,12 @@ const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, En
SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);
SpriteID GetVehiclePalette(const Vehicle *v);
extern const StringID _veh_build_msg_table[];
extern const StringID _veh_sell_msg_table[];
extern const StringID _veh_sell_all_msg_table[];
extern const StringID _veh_autoreplace_msg_table[];
extern const StringID _veh_refit_msg_table[];
extern const StringID _send_to_depot_msg_table[];
extern VehicleTypeIndexArray<const StringID> _veh_build_msg_table;
extern VehicleTypeIndexArray<const StringID> _veh_sell_msg_table;
extern VehicleTypeIndexArray<const StringID> _veh_sell_all_msg_table;
extern VehicleTypeIndexArray<const StringID> _veh_autoreplace_msg_table;
extern VehicleTypeIndexArray<const StringID> _veh_refit_msg_table;
extern VehicleTypeIndexArray<const StringID> _send_to_depot_msg_table;
/* Functions to find the right command for certain vehicle type */
inline StringID GetCmdBuildVehMsg(VehicleType type)
+96 -95
View File
@@ -50,7 +50,7 @@
#include "safeguards.h"
static std::array<std::array<BaseVehicleListWindow::GroupBy, VEH_COMPANY_END>, VLT_END> _grouping{};
static std::array<VehicleTypeIndexArray<BaseVehicleListWindow::GroupBy>, VLT_END> _grouping{};
static std::array<Sorting, BaseVehicleListWindow::GB_END> _sorting{};
static BaseVehicleListWindow::VehicleIndividualSortFunction VehicleNumberSorter;
@@ -156,7 +156,8 @@ const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group
STR_GROUP_BY_SHARED_ORDERS,
};
const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
/** List of depot name strings for each \c VehicleType. */
const VehicleTypeIndexArray<const StringID> BaseVehicleListWindow::vehicle_depot_name = {
STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
@@ -783,7 +784,7 @@ struct RefitWindow : public Window {
GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
do {
if (v->type == VEH_TRAIN && std::ranges::find(vehicles_to_refit, v->index) == vehicles_to_refit.end()) continue;
if (v->type == VehicleType::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;
VehicleCallbackMasks callback_mask = e->info.callback_mask;
@@ -939,12 +940,12 @@ struct RefitWindow : public Window {
this->vscroll = this->GetScrollbar(WID_VR_SCROLLBAR);
this->hscroll = (v->IsGroundVehicle() ? this->GetScrollbar(WID_VR_HSCROLLBAR) : nullptr);
this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->SetToolTip(STR_REFIT_TRAIN_LIST_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->SetToolTip(STR_REFIT_TRAIN_LIST_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VR_SELECT_HEADER)->SetToolTip(STR_REFIT_TRAIN_LIST_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VR_MATRIX)->SetToolTip(STR_REFIT_TRAIN_LIST_TOOLTIP + to_underlying(v->type));
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VR_REFIT);
nwi->SetStringTip(STR_REFIT_TRAIN_REFIT_BUTTON + v->type, STR_REFIT_TRAIN_REFIT_TOOLTIP + v->type);
nwi->SetStringTip(STR_REFIT_TRAIN_REFIT_BUTTON + to_underlying(v->type), STR_REFIT_TRAIN_REFIT_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetStacked>(WID_VR_SHOW_HSCROLLBAR)->SetDisplayedPlane(v->IsGroundVehicle() ? 0 : SZSP_HORIZONTAL);
this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->SetToolTip((v->type == VEH_TRAIN) ? STR_REFIT_SELECT_VEHICLES_TOOLTIP : STR_NULL);
this->GetWidget<NWidgetCore>(WID_VR_VEHICLE_PANEL_DISPLAY)->SetToolTip((v->type == VehicleType::Train) ? STR_REFIT_SELECT_VEHICLES_TOOLTIP : STR_NULL);
this->FinishInitNested(v->index);
this->owner = v->owner;
@@ -1055,7 +1056,7 @@ struct RefitWindow : public Window {
if (this->order != INVALID_VEH_ORDER_ID) break;
int x = 0;
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
VehicleSet vehicles_to_refit;
GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
@@ -1197,7 +1198,7 @@ struct RefitWindow : public Window {
Vehicle *v = Vehicle::Get(this->window_number);
/* Find the vehicle part that was clicked. */
switch (v->type) {
case VEH_TRAIN: {
case VehicleType::Train: {
/* Don't select anything if we are not clicking in the vehicle. */
if (left_x >= 0) {
const Train *u = Train::From(v);
@@ -1736,10 +1737,10 @@ static void DrawSmallOrderList(const OrderList *orderlist, int left, int right,
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
{
switch (v->type) {
case VEH_TRAIN: DrawTrainImage(Train::From(v), r, selection, image_type, skip); break;
case VEH_ROAD: DrawRoadVehImage(v, r, selection, image_type, skip); break;
case VEH_SHIP: DrawShipImage(v, r, selection, image_type); break;
case VEH_AIRCRAFT: DrawAircraftImage(v, r, selection, image_type); break;
case VehicleType::Train: DrawTrainImage(Train::From(v), r, selection, image_type, skip); break;
case VehicleType::Road: DrawRoadVehImage(v, r, selection, image_type, skip); break;
case VehicleType::Ship: DrawShipImage(v, r, selection, image_type); break;
case VehicleType::Aircraft: DrawAircraftImage(v, r, selection, image_type); break;
default: NOT_REACHED();
}
}
@@ -1755,7 +1756,7 @@ uint GetVehicleListHeight(VehicleType type, uint divisor)
/* Name + vehicle + profit */
uint base = ScaleGUITrad(GetVehicleHeight(type)) + 2 * GetCharacterHeight(FontSize::Small) + WidgetDimensions::scaled.matrix.Vertical();
/* Drawing of the 4 small orders + profit*/
if (type >= VEH_SHIP) base = std::max(base, 6U * GetCharacterHeight(FontSize::Small) + WidgetDimensions::scaled.matrix.Vertical());
if (type >= VehicleType::Ship) base = std::max(base, 6U * GetCharacterHeight(FontSize::Small) + WidgetDimensions::scaled.matrix.Vertical());
if (divisor == 1) return base;
@@ -1789,7 +1790,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
int text_offset = std::max<int>(profit.width, GetUnitNumberWidth(this->unitnumber_digits)) + WidgetDimensions::scaled.hsep_normal;
Rect tr = ir.Indent(text_offset, rtl);
bool show_orderlist = this->vli.vtype >= VEH_SHIP;
bool show_orderlist = this->vli.vtype >= VehicleType::Ship;
Rect olr = ir.Indent(std::max(ScaleGUITrad(100) + text_offset, ir.Width() / 2), rtl);
int image_left = (rtl && show_orderlist) ? olr.right : tr.left;
@@ -1890,10 +1891,10 @@ void BaseVehicleListWindow::UpdateSortingFromGrouping()
* point to the correct global _sorting struct so we are freed
* from having conditionals during window operation */
switch (this->vli.vtype) {
case VEH_TRAIN: this->sorting = &_sorting[this->grouping].train; break;
case VEH_ROAD: this->sorting = &_sorting[this->grouping].roadveh; break;
case VEH_SHIP: this->sorting = &_sorting[this->grouping].ship; break;
case VEH_AIRCRAFT: this->sorting = &_sorting[this->grouping].aircraft; break;
case VehicleType::Train: this->sorting = &_sorting[this->grouping].train; break;
case VehicleType::Road: this->sorting = &_sorting[this->grouping].roadveh; break;
case VehicleType::Ship: this->sorting = &_sorting[this->grouping].ship; break;
case VehicleType::Aircraft: this->sorting = &_sorting[this->grouping].aircraft; break;
default: NOT_REACHED();
}
this->vehgroups.SetSortFuncs(this->GetVehicleSorterFuncs());
@@ -1943,7 +1944,7 @@ public:
this->vscroll = this->GetScrollbar(WID_VL_SCROLLBAR);
/* Set up the window widgets */
this->GetWidget<NWidgetCore>(WID_VL_LIST)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_VL_LIST)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + to_underlying(this->vli.vtype));
NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VL_CAPTION_SELECTION);
if (this->vli.type == VL_SHARED_ORDERS) {
@@ -1954,7 +1955,7 @@ public:
this->SetWidgetDisabledState(WID_VL_GROUP_BY_PULLDOWN, true);
nwi->SetDisplayedPlane(BP_SHARED_ORDERS);
} else {
this->GetWidget<NWidgetCore>(WID_VL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype);
this->GetWidget<NWidgetCore>(WID_VL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + to_underlying(this->vli.vtype));
nwi->SetDisplayedPlane(BP_NORMAL);
}
@@ -1978,12 +1979,12 @@ public:
fill.height = resize.height = GetVehicleListHeight(this->vli.vtype, 1);
switch (this->vli.vtype) {
case VEH_TRAIN:
case VEH_ROAD:
case VehicleType::Train:
case VehicleType::Road:
size.height = 6 * resize.height;
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
size.height = 4 * resize.height;
break;
default: NOT_REACHED();
@@ -2028,7 +2029,7 @@ public:
{
switch (widget) {
case WID_VL_AVAILABLE_VEHICLES:
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + this->vli.vtype);
return GetString(STR_VEHICLE_LIST_AVAILABLE_TRAINS + to_underlying(this->vli.vtype));
case WID_VL_GROUP_BY_PULLDOWN:
return GetString(std::data(this->vehicle_group_by_names)[this->grouping]);
@@ -2134,7 +2135,7 @@ public:
case WID_VL_SORT_BY_PULLDOWN: // Select sorting criteria dropdown menu
ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_VL_SORT_BY_PULLDOWN, 0,
(this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
(this->vli.vtype == VehicleType::Train || this->vli.vtype == VehicleType::Road) ? 0 : (1 << 10));
return;
case WID_VL_FILTER_BY_CARGO: { // Cargo filter dropdown
@@ -2280,38 +2281,38 @@ public:
};
/** Window definitions for the vehicle list windows. */
static WindowDesc _vehicle_list_desc[] = {
{
static VehicleTypeIndexArray<WindowDesc> _vehicle_list_desc = {{
WindowDesc{
WindowPosition::Automatic, "list_vehicles_train", 325, 246,
WC_TRAINS_LIST, WC_NONE,
{},
_nested_vehicle_list
},
{
WindowDesc{
WindowPosition::Automatic, "list_vehicles_roadveh", 260, 246,
WC_ROADVEH_LIST, WC_NONE,
{},
_nested_vehicle_list
},
{
WindowDesc{
WindowPosition::Automatic, "list_vehicles_ship", 260, 246,
WC_SHIPS_LIST, WC_NONE,
{},
_nested_vehicle_list
},
{
WindowDesc{
WindowPosition::Automatic, "list_vehicles_aircraft", 260, 246,
WC_AIRCRAFT_LIST, WC_NONE,
{},
_nested_vehicle_list
}
};
}};
static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32_t unique_number)
{
if (!Company::IsValidID(company) && company != OWNER_NONE) return;
assert(vehicle_type < std::size(_vehicle_list_desc));
assert(IsCompanyBuildableVehicleType(vehicle_type));
VehicleListIdentifier vli(vlt, vehicle_type, company, unique_number);
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], vli.ToWindowNumber(), vli);
}
@@ -2446,7 +2447,7 @@ struct VehicleDetailsWindow : Window {
const Vehicle *v = Vehicle::Get(window_number);
this->CreateNestedTree();
this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr);
this->vscroll = (v->type == VehicleType::Train ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr);
this->FinishInitNested(window_number);
this->owner = v->owner;
@@ -2466,7 +2467,7 @@ struct VehicleDetailsWindow : Window {
}
if (!gui_scope) return;
const Vehicle *v = Vehicle::Get(this->window_number);
if (v->type == VEH_ROAD) {
if (v->type == VehicleType::Road) {
const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_VD_MIDDLE_DETAILS);
uint aimed_height = this->GetRoadVehDetailsHeight(v);
/* If the number of articulated parts changes, the size of the window must change too. */
@@ -2519,15 +2520,15 @@ struct VehicleDetailsWindow : Window {
case WID_VD_MIDDLE_DETAILS: {
const Vehicle *v = Vehicle::Get(this->window_number);
switch (v->type) {
case VEH_ROAD:
case VehicleType::Road:
size.height = this->GetRoadVehDetailsHeight(v) + padding.height;
break;
case VEH_SHIP:
case VehicleType::Ship:
size.height = 4 * GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal * 2 + padding.height;
break;
case VEH_AIRCRAFT:
case VehicleType::Aircraft:
size.height = 5 * GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal * 2 + padding.height;
break;
@@ -2579,10 +2580,10 @@ struct VehicleDetailsWindow : Window {
const VehicleDefaultSettings *vds = &Company::Get(company_id)->settings.vehicle;
switch (vehicle_type) {
default: NOT_REACHED();
case VEH_TRAIN: return vds->servint_trains != 0;
case VEH_ROAD: return vds->servint_roadveh != 0;
case VEH_SHIP: return vds->servint_ships != 0;
case VEH_AIRCRAFT: return vds->servint_aircraft != 0;
case VehicleType::Train: return vds->servint_trains != 0;
case VehicleType::Road: return vds->servint_roadveh != 0;
case VehicleType::Ship: return vds->servint_ships != 0;
case VehicleType::Aircraft: return vds->servint_aircraft != 0;
}
}
@@ -2598,10 +2599,10 @@ struct VehicleDetailsWindow : Window {
static void DrawVehicleDetails(const Vehicle *v, const Rect &r, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
{
switch (v->type) {
case VEH_TRAIN: DrawTrainDetails(Train::From(v), r, vscroll_pos, vscroll_cap, det_tab); break;
case VEH_ROAD: DrawRoadVehDetails(v, r); break;
case VEH_SHIP: DrawShipDetails(v, r); break;
case VEH_AIRCRAFT: DrawAircraftDetails(Aircraft::From(v), r); break;
case VehicleType::Train: DrawTrainDetails(Train::From(v), r, vscroll_pos, vscroll_cap, det_tab); break;
case VehicleType::Road: DrawRoadVehDetails(v, r); break;
case VehicleType::Ship: DrawShipDetails(v, r); break;
case VehicleType::Aircraft: DrawAircraftDetails(Aircraft::From(v), r); break;
default: NOT_REACHED();
}
}
@@ -2632,16 +2633,16 @@ struct VehicleDetailsWindow : Window {
/* Draw max speed */
uint64_t max_speed = PackVelocity(v->GetDisplayMaxSpeed(), v->type);
if (v->type == VEH_TRAIN ||
(v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
if (v->type == VehicleType::Train ||
(v->type == VehicleType::Road && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
if (v->type == VehicleType::Train && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
Train::From(v)->GetAccelerationType() == VehicleAccelerationModel::Maglev)) {
DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, gcache->cached_weight, gcache->cached_power, max_speed));
} else {
DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE, gcache->cached_weight, gcache->cached_power, max_speed, gcache->cached_max_te));
}
} else if (v->type == VEH_AIRCRAFT) {
} else if (v->type == VehicleType::Aircraft) {
StringID type = v->GetEngine()->GetAircraftTypeText();
if (Aircraft::From(v)->GetRange() > 0) {
DrawString(tr, GetString(STR_VEHICLE_INFO_MAX_SPEED_TYPE_RANGE, max_speed, type, Aircraft::From(v)->GetRange()));
@@ -2686,7 +2687,7 @@ struct VehicleDetailsWindow : Window {
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
/* Articulated road vehicles use a complete line. */
if (v->type == VEH_ROAD && v->HasArticulatedPart()) {
if (v->type == VehicleType::Road && v->HasArticulatedPart()) {
DrawVehicleImage(v, tr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), VehicleID::Invalid(), EIT_IN_DETAILS, 0);
} else {
Rect sr = tr.WithWidth(sprite_width, rtl);
@@ -2724,7 +2725,7 @@ struct VehicleDetailsWindow : Window {
{
const Vehicle *v = Vehicle::Get(this->window_number);
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
this->LowerWidget(WID_VD_DETAILS_CARGO_CARRIED + this->tab);
this->vscroll->SetCount(GetTrainDetailsWndVScroll(v->index, this->tab));
}
@@ -2855,7 +2856,7 @@ static void ShowVehicleDetailsWindow(const Vehicle *v)
{
CloseWindowById(WC_VEHICLE_ORDERS, v->index, false);
CloseWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
AllocateWindowDescFront<VehicleDetailsWindow>((v->type == VEH_TRAIN) ? _train_vehicle_details_desc : _nontrain_vehicle_details_desc, v->index);
AllocateWindowDescFront<VehicleDetailsWindow>((v->type == VehicleType::Train) ? _train_vehicle_details_desc : _nontrain_vehicle_details_desc, v->index);
}
@@ -2908,13 +2909,13 @@ static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_view_widgets
/* Just to make sure, nobody has changed the vehicle type constants, as we are
using them for array indexing in a number of places here. */
static_assert(VEH_TRAIN == 0);
static_assert(VEH_ROAD == 1);
static_assert(VEH_SHIP == 2);
static_assert(VEH_AIRCRAFT == 3);
static_assert(to_underlying(VehicleType::Train) == 0);
static_assert(to_underlying(VehicleType::Road) == 1);
static_assert(to_underlying(VehicleType::Ship) == 2);
static_assert(to_underlying(VehicleType::Aircraft) == 3);
/** Zoom levels for vehicle views indexed by vehicle type. */
static const ZoomLevel _vehicle_view_zoom_levels[] = {
static constexpr VehicleTypeIndexArray<const ZoomLevel> _vehicle_view_zoom_levels = {
ZoomLevel::Train,
ZoomLevel::RoadVehicle,
ZoomLevel::Ship,
@@ -2936,7 +2937,7 @@ enum VehicleCommandTranslation : uint8_t {
};
/** Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type. */
static const StringID _vehicle_msg_translation_table[][4] = {
static constexpr VehicleTypeIndexArray<const StringID> _vehicle_msg_translation_table[] = {
{ // VCT_CMD_START_STOP
STR_ERROR_CAN_T_STOP_START_TRAIN,
STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
@@ -3047,7 +3048,7 @@ public:
this->CreateNestedTree();
/* Sprites for the 'send to depot' button indexed by vehicle type. */
static const SpriteID vehicle_view_goto_depot_sprites[] = {
static constexpr VehicleTypeIndexArray<const SpriteID> vehicle_view_goto_depot_sprites = {
SPR_SEND_TRAIN_TODEPOT,
SPR_SEND_ROADVEH_TODEPOT,
SPR_SEND_SHIP_TODEPOT,
@@ -3057,7 +3058,7 @@ public:
this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->SetSprite(vehicle_view_goto_depot_sprites[v->type]);
/* Sprites for the 'clone vehicle' button indexed by vehicle type. */
static const SpriteID vehicle_view_clone_sprites[] = {
static constexpr VehicleTypeIndexArray<const SpriteID> vehicle_view_clone_sprites = {
SPR_CLONE_TRAIN,
SPR_CLONE_ROADVEH,
SPR_CLONE_SHIP,
@@ -3066,17 +3067,17 @@ public:
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->SetSprite(vehicle_view_clone_sprites[v->type]);
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
this->GetWidget<NWidgetCore>(WID_VV_TURN_AROUND)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP);
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(0);
break;
case VEH_ROAD:
case VehicleType::Road:
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(SZSP_NONE);
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
case VehicleType::Ship:
case VehicleType::Aircraft:
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(SZSP_NONE);
this->SelectPlane(SEL_RT_REFIT);
break;
@@ -3087,14 +3088,14 @@ public:
this->owner = v->owner;
this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, static_cast<VehicleID>(this->window_number), ScaleZoomGUI(_vehicle_view_zoom_levels[v->type]));
this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_RENAME)->SetToolTip(STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type);
this->GetWidget<NWidgetCore>(WID_VV_LOCATION)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_REFIT)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_SHOW_ORDERS)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_SHOW_DETAILS)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->SetToolTip(STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->type);
this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_RENAME)->SetToolTip(STR_VEHICLE_DETAILS_TRAIN_RENAME + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_LOCATION)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_REFIT)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_SHOW_ORDERS)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_SHOW_DETAILS)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + to_underlying(v->type));
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->SetToolTip(STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + to_underlying(v->type));
this->UpdatePlanes();
this->UpdateButtons();
@@ -3118,7 +3119,7 @@ public:
break;
case WID_VV_FORCE_PROCEED:
if (v->type != VEH_TRAIN) {
if (v->type != VehicleType::Train) {
size.height = 0;
size.width = 0;
}
@@ -3126,7 +3127,7 @@ public:
case WID_VV_VIEWPORT:
size.width = VV_INITIAL_VIEWPORT_WIDTH;
size.height = (v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
size.height = (v->type == VehicleType::Train) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
break;
}
}
@@ -3147,12 +3148,12 @@ public:
* vehicle to NOT go to the depot. */
this->SetWidgetLoweredState(WID_VV_GOTO_DEPOT, v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotActionType().Test(OrderDepotActionFlag::Halt));
if (v->type == VEH_TRAIN) {
if (v->type == VehicleType::Train) {
this->SetWidgetLoweredState(WID_VV_FORCE_PROCEED, Train::From(v)->force_proceed == TFP_SIGNAL);
this->SetWidgetDisabledState(WID_VV_FORCE_PROCEED, !is_localcompany);
}
if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
if (v->type == VehicleType::Train || v->type == VehicleType::Road) {
this->SetWidgetDisabledState(WID_VV_TURN_AROUND, !is_localcompany);
}
@@ -3185,10 +3186,10 @@ public:
if (v->vehstatus.Test(VehState::Crashed)) return GetString(STR_VEHICLE_STATUS_CRASHED);
if (v->type != VEH_AIRCRAFT && v->breakdown_ctr == 1) return GetString(STR_VEHICLE_STATUS_BROKEN_DOWN);
if (v->type != VehicleType::Aircraft && v->breakdown_ctr == 1) return GetString(STR_VEHICLE_STATUS_BROKEN_DOWN);
if (v->vehstatus.Test(VehState::Stopped) && (!mouse_over_start_stop || v->IsStoppedInDepot())) {
if (v->type != VEH_TRAIN) return GetString(STR_VEHICLE_STATUS_STOPPED);
if (v->type != VehicleType::Train) return GetString(STR_VEHICLE_STATUS_STOPPED);
if (v->cur_speed != 0) return GetString(STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL, PackVelocity(v->GetDisplaySpeed(), v->type));
if (Train::From(v)->gcache.cached_power == 0) return GetString(STR_VEHICLE_STATUS_TRAIN_NO_POWER);
return GetString(STR_VEHICLE_STATUS_STOPPED);
@@ -3196,15 +3197,15 @@ public:
if (v->IsInDepot() && v->IsWaitingForUnbunching()) return GetString(STR_VEHICLE_STATUS_WAITING_UNBUNCHING);
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_TRAIN_STUCK);
if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_TRAIN_STUCK);
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->flags.Test(VehicleAirFlag::DestinationTooFar) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR);
if (v->type == VehicleType::Aircraft && Aircraft::From(v)->flags.Test(VehicleAirFlag::DestinationTooFar) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR);
/* Vehicle is in a "normal" state, show current order. */
if (mouse_over_start_stop) {
if (v->vehstatus.Test(VehState::Stopped)) {
text_colour = TC_RED | TC_FORCED;
} else if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) {
} else if (v->type == VehicleType::Train && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) {
text_colour = TC_ORANGE | TC_FORCED;
}
}
@@ -3239,12 +3240,12 @@ public:
return GetString(STR_VEHICLE_STATUS_LOADING_UNLOADING);
case OT_GOTO_WAYPOINT:
assert(v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP);
assert(v->type == VehicleType::Train || v->type == VehicleType::Road || v->type == VehicleType::Ship);
return GetString(v->vehicle_flags.Test(VehicleFlag::PathfinderLost) ? STR_VEHICLE_STATUS_CANNOT_REACH_WAYPOINT_VEL : STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT_VEL,
v->current_order.GetDestination(),PackVelocity(v->GetDisplaySpeed(), v->type));
case OT_LEAVESTATION:
if (v->type != VEH_AIRCRAFT) {
if (v->type != VehicleType::Aircraft) {
return GetString(STR_VEHICLE_STATUS_LEAVING);
}
[[fallthrough]];
@@ -3284,7 +3285,7 @@ public:
switch (widget) {
case WID_VV_RENAME: { // rename
ShowQueryString(GetString(STR_VEHICLE_NAME, v->index), STR_QUERY_RENAME_TRAIN_CAPTION + v->type,
ShowQueryString(GetString(STR_VEHICLE_NAME, v->index), STR_QUERY_RENAME_TRAIN_CAPTION + to_underlying(v->type),
MAX_LENGTH_VEHICLE_NAME_CHARS, this, CS_ALPHANUMERAL, {QueryStringFlag::EnableDefault, QueryStringFlag::LengthIsInChars});
break;
}
@@ -3353,14 +3354,14 @@ public:
break;
case WID_VV_TURN_AROUND: // turn around
assert(v->IsGroundVehicle());
if (v->type == VEH_ROAD) {
if (v->type == VehicleType::Road) {
Command<Commands::TurnRoadVehicle>::Post(_vehicle_msg_translation_table[VCT_CMD_TURN_AROUND][v->type], v->tile, v->index);
} else {
Command<Commands::ReverseTrainDirection>::Post(_vehicle_msg_translation_table[VCT_CMD_TURN_AROUND][v->type], v->tile, v->index, false);
}
break;
case WID_VV_FORCE_PROCEED: // force proceed
assert(v->type == VEH_TRAIN);
assert(v->type == VehicleType::Train);
Command<Commands::ForceTrainProceed>::Post(STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL, v->tile, v->index);
break;
}
@@ -3384,7 +3385,7 @@ public:
{
if (!str.has_value()) return;
Command<Commands::RenameVehicle>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, static_cast<VehicleID>(this->window_number), *str);
Command<Commands::RenameVehicle>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + to_underlying(Vehicle::Get(this->window_number)->type), static_cast<VehicleID>(this->window_number), *str);
}
void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
@@ -3496,7 +3497,7 @@ static WindowDesc _train_view_desc(
*/
void ShowVehicleViewWindow(const Vehicle *v)
{
AllocateWindowDescFront<VehicleViewWindow>((v->type == VEH_TRAIN) ? _train_view_desc : _vehicle_view_desc, v->index);
AllocateWindowDescFront<VehicleViewWindow>((v->type == VehicleType::Train) ? _train_view_desc : _vehicle_view_desc, v->index);
}
/**
@@ -3575,10 +3576,10 @@ void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_ve
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
{
switch (v->type) {
case VEH_TRAIN:
case VehicleType::Train:
return Train::From(v)->GetDisplayImageWidth();
case VEH_ROAD:
case VehicleType::Road:
return RoadVehicle::From(v)->GetDisplayImageWidth();
default:
@@ -3599,7 +3600,7 @@ int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
*/
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
{
if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
if (v->type == VehicleType::Train || v->type == VehicleType::Road) {
int vehicle_width = 0;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
vehicle_width += GetSingleVehicleWidth(u, image_type);
@@ -3640,14 +3641,14 @@ void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
}
int x_offs = 0;
if (v->type == VEH_TRAIN) x_offs = Train::From(v)->GetCursorImageOffset();
if (v->type == VehicleType::Train) x_offs = Train::From(v)->GetCursorImageOffset();
for (uint i = 0; i < seq.count; ++i) {
PaletteID pal2 = v->vehstatus.Test(VehState::Crashed) || !seq.seq[i].pal ? pal : seq.seq[i].pal;
_cursor.sprites.emplace_back(seq.seq[i].sprite, pal2, rtl ? (-total_width + x_offs) : (total_width + x_offs), y_offset);
}
if (v->type == VEH_AIRCRAFT && v->subtype == AIR_HELICOPTER && !rotor_seq) {
if (v->type == VehicleType::Aircraft && v->subtype == AIR_HELICOPTER && !rotor_seq) {
/* Draw rotor part in the next step. */
rotor_seq = true;
} else {
+5 -5
View File
@@ -73,7 +73,7 @@ void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileInde
*/
inline uint GetVehicleHeight(VehicleType type)
{
return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;
return (type == VehicleType::Train || type == VehicleType::Road) ? 14 : 24;
}
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type);
@@ -98,10 +98,10 @@ inline WindowClass GetWindowClassForVehicleType(VehicleType vt)
{
switch (vt) {
default: NOT_REACHED();
case VEH_TRAIN: return WC_TRAINS_LIST;
case VEH_ROAD: return WC_ROADVEH_LIST;
case VEH_SHIP: return WC_SHIPS_LIST;
case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
case VehicleType::Train: return WC_TRAINS_LIST;
case VehicleType::Road: return WC_ROADVEH_LIST;
case VehicleType::Ship: return WC_SHIPS_LIST;
case VehicleType::Aircraft: return WC_AIRCRAFT_LIST;
}
}
+1 -1
View File
@@ -97,7 +97,7 @@ struct BaseVehicleListWindow : public Window {
ADI_CREATE_GROUP,
};
static const StringID vehicle_depot_name[];
static const VehicleTypeIndexArray<const StringID> vehicle_depot_name;
static const std::initializer_list<const StringID> vehicle_group_by_names;
static const std::initializer_list<const StringID> vehicle_group_none_sorter_names_calendar;
static const std::initializer_list<const StringID> vehicle_group_none_sorter_names_wallclock;
+20 -12
View File
@@ -19,21 +19,21 @@ using VehicleID = PoolID<uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF>;
static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2
/** Available vehicle types. It needs to be 8bits, because we save and load it as such */
enum VehicleType : uint8_t {
VEH_BEGIN,
enum class VehicleType : uint8_t {
Begin, ///< Begin marker.
VEH_TRAIN = VEH_BEGIN, ///< %Train vehicle type.
VEH_ROAD, ///< Road vehicle type.
VEH_SHIP, ///< %Ship vehicle type.
VEH_AIRCRAFT, ///< %Aircraft vehicle type.
Train = VehicleType::Begin, ///< %Train vehicle type.
Road, ///< Road vehicle type.
Ship, ///< %Ship vehicle type.
Aircraft, ///< %Aircraft vehicle type.
VEH_COMPANY_END, ///< Last company-ownable type.
CompanyEnd, ///< Last company-ownable type.
VEH_EFFECT = VEH_COMPANY_END, ///< Effect vehicle type (smoke, explosions, sparks, bubbles)
VEH_DISASTER, ///< Disaster vehicle type.
Effect = VehicleType::CompanyEnd, ///< Effect vehicle type (smoke, explosions, sparks, bubbles)
Disaster, ///< Disaster vehicle type.
End, ///< End marker.
VEH_END,
VEH_INVALID = 0xFF, ///< Non-existing type of vehicle.
Invalid = 0xFF, ///< Non-existing type of vehicle.
};
DECLARE_INCREMENT_DECREMENT_OPERATORS(VehicleType)
DECLARE_ENUM_AS_ADDABLE(VehicleType)
@@ -48,7 +48,7 @@ struct DisasterVehicle;
/** Base vehicle class. */
struct BaseVehicle {
VehicleType type = VEH_INVALID; ///< Type of vehicle
VehicleType type = VehicleType::Invalid; ///< Type of vehicle
};
/** Flags for goto depot commands. */
@@ -90,4 +90,12 @@ enum class VehicleRandomTrigger : uint8_t {
};
using VehicleRandomTriggers = EnumBitSet<VehicleRandomTrigger, uint8_t>;
/**
* Array with \c VehicleType as index.
* @tparam T the type contained within the array.
* @tparam Tend the number of elements in the array.
*/
template <typename T, VehicleType Tend = VehicleType::CompanyEnd>
using VehicleTypeIndexArray = EnumClassIndexContainer<std::array<T, to_underlying(Tend)>, VehicleType>;
#endif /* VEHICLE_TYPE_H */
+3 -3
View File
@@ -24,12 +24,12 @@ WindowNumber VehicleListIdentifier::ToWindowNumber() const
{
uint8_t c = this->company == OWNER_NONE ? 0xF : this->company.base();
assert(c < (1 << 4));
assert(this->vtype < (1 << 2));
assert(to_underlying(this->vtype) < (1 << 2));
assert(this->index < (1 << 20));
assert(this->type < VLT_END);
static_assert(VLT_END <= (1 << 3));
return c << 28 | this->type << 23 | this->vtype << 26 | this->index;
return c << 28 | this->type << 23 | to_underlying(this->vtype) << 26 | this->index;
}
/**
@@ -48,7 +48,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
for (Vehicle *v : VehiclesOnTile(tile)) {
if (v->type != type || !v->IsInDepot()) continue;
if (type == VEH_TRAIN) {
if (type == VehicleType::Train) {
const Train *t = Train::From(v);
if (t->IsArticulatedPart()) continue;
if (wagons != nullptr && t->First()->IsFreeWagon()) {
+4 -4
View File
@@ -1073,7 +1073,7 @@ static void FloodVehicleProc(Vehicle *v, int z)
switch (v->type) {
default: break;
case VEH_AIRCRAFT: {
case VehicleType::Aircraft: {
if (!IsAirportTile(v->tile) || GetTileMaxZ(v->tile) != 0) break;
if (v->subtype == AIR_SHADOW) break;
@@ -1087,8 +1087,8 @@ static void FloodVehicleProc(Vehicle *v, int z)
break;
}
case VEH_TRAIN:
case VEH_ROAD: {
case VehicleType::Train:
case VehicleType::Road: {
if (v->z_pos > z) break;
FloodVehicle(v->First());
break;
@@ -1415,7 +1415,7 @@ static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode,
static bool ClickTile_Water(TileIndex tile)
{
if (GetWaterTileType(tile) == WaterTileType::Depot) {
ShowDepotWindow(GetShipDepotNorthTile(tile), VEH_SHIP);
ShowDepotWindow(GetShipDepotNorthTile(tile), VehicleType::Ship);
return true;
}
return false;
+9 -9
View File
@@ -34,7 +34,7 @@
/** GUI for accessing waypoints and buoys. */
struct WaypointWindow : Window {
private:
VehicleType vt = VEH_INVALID; ///< Vehicle type using the waypoint.
VehicleType vt = VehicleType::Invalid; ///< Vehicle type using the waypoint.
Waypoint *wp = nullptr; ///< Waypoint displayed by the window.
/**
@@ -47,15 +47,15 @@ private:
StationType type;
switch (this->vt) {
case VEH_TRAIN:
case VehicleType::Train:
type = StationType::RailWaypoint;
break;
case VEH_ROAD:
case VehicleType::Road:
type = StationType::RoadWaypoint;
break;
case VEH_SHIP:
case VehicleType::Ship:
type = StationType::Buoy;
break;
@@ -75,19 +75,19 @@ public:
{
this->wp = Waypoint::Get(window_number);
if (wp->string_id == STR_SV_STNAME_WAYPOINT) {
this->vt = HasBit(this->wp->waypoint_flags, WPF_ROAD) ? VEH_ROAD : VEH_TRAIN;
this->vt = HasBit(this->wp->waypoint_flags, WPF_ROAD) ? VehicleType::Road : VehicleType::Train;
} else {
this->vt = VEH_SHIP;
this->vt = VehicleType::Ship;
}
this->CreateNestedTree();
if (this->vt == VEH_TRAIN) {
if (this->vt == VehicleType::Train) {
this->GetWidget<NWidgetCore>(WID_W_SHOW_VEHICLES)->SetStringTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP);
}
if (this->vt == VEH_ROAD) {
if (this->vt == VehicleType::Road) {
this->GetWidget<NWidgetCore>(WID_W_SHOW_VEHICLES)->SetStringTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP);
}
if (this->vt != VEH_SHIP) {
if (this->vt != VehicleType::Ship) {
this->GetWidget<NWidgetCore>(WID_W_CENTER_VIEW)->SetToolTip(STR_WAYPOINT_VIEW_CENTER_TOOLTIP);
this->GetWidget<NWidgetCore>(WID_W_RENAME)->SetToolTip(STR_WAYPOINT_VIEW_EDIT_TOOLTIP);
}