diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -221,19 +221,7 @@ bool IsArticulatedVehicleCarryingDiffere } } - switch (v->type) { - case VEH_TRAIN: - v = Train::From(v)->HasArticulatedPart() ? Train::From(v)->GetNextArticulatedPart() : NULL; - break; - - case VEH_ROAD: - v = RoadVehicle::From(v)->HasArticulatedPart() ? v->Next() : NULL; - break; - - default: - v = NULL; - break; - } + v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL; } while (v != NULL); if (cargo_type != NULL) *cargo_type = first_cargo; @@ -268,19 +256,7 @@ void CheckConsistencyOfArticulatedVehicl assert(v->cargo_type < NUM_CARGO); real_default_capacity[v->cargo_type] += v->cargo_cap; - switch (v->type) { - case VEH_TRAIN: - v = Train::From(v)->HasArticulatedPart() ? Train::From(v)->GetNextArticulatedPart() : NULL; - break; - - case VEH_ROAD: - v = RoadVehicle::From(v)->HasArticulatedPart() ? v->Next() : NULL; - break; - - default: - v = NULL; - break; - } + v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL; } while (v != NULL); /* Check whether the vehicle carries more cargos than expected */ diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -101,18 +101,18 @@ static void TransferCargo(Vehicle *old_v assert(!part_of_chain || new_head->IsPrimaryVehicle()); /* Loop through source parts */ for (Vehicle *src = old_veh; src != NULL; src = src->Next()) { - if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !Train::From(src)->IsArticulatedPart()) { + if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) { /* Skip vehicles, which do not belong to old_veh */ - src = Train::From(src)->GetLastEnginePart(); + src = src->GetLastEnginePart(); continue; } if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue; /* Find free space in the new chain */ for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) { - if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !Train::From(dest)->IsArticulatedPart()) { + if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) { /* Skip vehicles, which do not belong to new_head */ - dest = Train::From(dest)->GetLastEnginePart(); + dest = dest->GetLastEnginePart(); continue; } if (dest->cargo_type != src->cargo_type) continue; @@ -218,7 +218,7 @@ static CargoID GetNewCargoTypeForReplace */ static EngineID GetNewEngineType(const Vehicle *v, const Company *c) { - assert(v->type != VEH_TRAIN || !Train::From(v)->IsArticulatedPart()); + assert(v->type != VEH_TRAIN || !v->IsArticulatedPart()); if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) { /* we build the rear ends of multiheaded trains with the front ones */ diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -797,7 +797,7 @@ struct DepotWindow : Window { loaded [w->cargo_type] += w->cargo.Count(); } - if (w->type == VEH_TRAIN && !Train::From(w)->HasArticulatedPart()) { + if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) { num++; if (!whole_chain) break; } @@ -911,7 +911,7 @@ struct DepotWindow : Window { } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { this->vehicle_over = INVALID_VEHICLE; TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); - } else if (gdvp.head != NULL && Train::From(gdvp.head)->IsFrontEngine()) { + } else if (gdvp.head != NULL && gdvp.head->IsFrontEngine()) { ShowVehicleViewWindow(gdvp.head); } } diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2298,7 +2298,7 @@ static int WhoCanServiceIndustry(Industr /* Check whether it accepts the right kind of cargo */ bool c_accepts = false; bool c_produces = false; - if (v->type == VEH_TRAIN && Train::From(v)->IsFrontEngine()) { + if (v->type == VEH_TRAIN && v->IsFrontEngine()) { for (const Vehicle *u = v; u != NULL; u = u->Next()) { CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces); } diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -31,9 +31,7 @@ */ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y) { - const RoadVehicle *rv = RoadVehicle::From(v); - - uint y_offset = rv->HasArticulatedPart() ? 15 : 0; // Draw the first line below the sprite of an articulated RV instead of after it. + uint y_offset = v->HasArticulatedPart() ? 15 : 0; // Draw the first line below the sprite of an articulated RV instead of after it. StringID str; Money feeder_share = 0; @@ -42,7 +40,7 @@ void DrawRoadVehDetails(const Vehicle *v SetDParam(2, v->value); DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP); - if (rv->HasArticulatedPart()) { + if (v->HasArticulatedPart()) { CargoArray max_cargo; StringID subtype_text[NUM_CARGO]; char capacity[512]; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2953,7 +2953,7 @@ static VehicleEnterTileStatus VehicleEnt if (v->type == VEH_TRAIN) { StationID station_id = GetStationIndex(tile); if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE; - if (!IsRailStation(tile) || !Train::From(v)->IsFrontEngine()) return VETSB_CONTINUE; + if (!IsRailStation(tile) || !v->IsFrontEngine()) return VETSB_CONTINUE; int station_ahead; int station_length; diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -626,7 +626,7 @@ 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: - return !Train::From(this)->IsArticulatedPart() && // tenders and other articulated parts + 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; @@ -1538,7 +1538,7 @@ LiveryScheme GetEngineLiveryScheme(Engin switch (e->type) { default: NOT_REACHED(); case VEH_TRAIN: - if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (Train::From(v)->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) { + if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->u.rail.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) */ engine_type = parent_engine_type; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -671,7 +671,7 @@ CommandCost CmdCloneVehicle(TileIndex ti CommandCost ret = CheckOwnership(v->owner); if (ret.Failed()) return ret; - if (v->type == VEH_TRAIN && (!Train::From(v)->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR; + if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR; /* check that we can allocate enough vehicles */ if (!(flags & DC_EXEC)) { @@ -719,7 +719,7 @@ CommandCost CmdCloneVehicle(TileIndex ti SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION); } - if (v->type == VEH_TRAIN && !Train::From(v)->IsFrontEngine()) { + if (v->type == VEH_TRAIN && !v->IsFrontEngine()) { /* this s a train car * add this unit to the end of the train */ CommandCost result = DoCommand(0, w->index | 1 << 20, w_rear->index, flags, CMD_MOVE_RAIL_VEHICLE); @@ -737,7 +737,7 @@ CommandCost CmdCloneVehicle(TileIndex ti } 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 = Train::From(v)->GetNextVehicle()) != NULL); + } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != NULL); if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) { /* for trains this needs to be the front engine due to the callback function */ @@ -772,10 +772,8 @@ CommandCost CmdCloneVehicle(TileIndex ti if (cost.Succeeded()) total_cost.AddCost(cost); } - if (w->type == VEH_TRAIN && Train::From(w)->HasArticulatedPart()) { - w = Train::From(w)->GetNextArticulatedPart(); - } else if (w->type == VEH_ROAD && RoadVehicle::From(w)->HasArticulatedPart()) { - w = w->Next(); + if (w->IsGroundVehicle() && w->HasArticulatedPart()) { + w = w->GetNextArticulatedPart(); } else { break; } @@ -788,17 +786,15 @@ CommandCost CmdCloneVehicle(TileIndex ti } } - if (v->type == VEH_TRAIN && Train::From(v)->HasArticulatedPart()) { - v = Train::From(v)->GetNextArticulatedPart(); - } else if (v->type == VEH_ROAD && RoadVehicle::From(v)->HasArticulatedPart()) { - v = v->Next(); + if (w->IsGroundVehicle() && w->HasArticulatedPart()) { + w = w->GetNextArticulatedPart(); } else { break; } } while (v != NULL); - if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = Train::From(w)->GetNextVehicle(); - } while (v->type == VEH_TRAIN && (v = Train::From(v)->GetNextVehicle()) != NULL); + if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = w->GetNextVehicle(); + } while (v->type == VEH_TRAIN && (v = v->GetNextVehicle()) != NULL); if (flags & DC_EXEC) { /* diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1785,7 +1785,7 @@ struct VehicleDetailsWindow : Window { uint GetRoadVehDetailsHeight(const Vehicle *v) { uint desired_height; - if (RoadVehicle::From(v)->HasArticulatedPart()) { + if (v->HasArticulatedPart()) { /* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */ desired_height = WD_FRAMERECT_TOP + 15 + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM; /* Add space for the cargo amount for each part. */ @@ -1962,7 +1962,7 @@ struct VehicleDetailsWindow : Window { uint text_right = r.right - (rtl ? sprite_width : 0); /* Articulated road vehicles use a complete line. */ - if (v->type == VEH_ROAD && RoadVehicle::From(v)->HasArticulatedPart()) { + if (v->type == VEH_ROAD && v->HasArticulatedPart()) { DrawVehicleImage(v, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, 0); } else { uint sprite_left = rtl ? text_right : r.left;