summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2011-01-29 17:30:25 +0000
committerterkhen <terkhen@openttd.org>2011-01-29 17:30:25 +0000
commit734994c9ba642f5c75b709d4b44e0c4b993a949a (patch)
treef7f6264f438d4707aaa7e4bfe4c2a223a0c4abba
parent50b0e1002621720c6b2cd4b8e20856b86da0b61d (diff)
downloadopenttd-734994c9ba642f5c75b709d4b44e0c4b993a949a.tar.xz
(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.
-Cleanup: Avoid conversions to Train and RoadVehicle that are no longer required.
-rw-r--r--src/articulated_vehicles.cpp28
-rw-r--r--src/autoreplace_cmd.cpp10
-rw-r--r--src/depot_gui.cpp4
-rw-r--r--src/industry_cmd.cpp2
-rw-r--r--src/roadveh_gui.cpp6
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/vehicle.cpp4
-rw-r--r--src/vehicle_cmd.cpp22
-rw-r--r--src/vehicle_gui.cpp4
9 files changed, 26 insertions, 56 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 824611ddc..ae6b9d5e6 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -221,19 +221,7 @@ bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *carg
}
}
- 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 CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
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
index 72fa1ffc4..b2360e583 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -101,18 +101,18 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
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(Vehicle *v, EngineID engine_type, bool
*/
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
index b057278b1..6d32fd761 100644
--- 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
index 51e623943..84e35181b 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2298,7 +2298,7 @@ static 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 && 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
index 029234c26..0cbaee06c 100644
--- 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, int left, int right, int y)
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
index 68f5c14ef..9d3a0be68 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2953,7 +2953,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
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
index f69cf03a5..fe5cf1842 100644
--- 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(EngineID engine_type, EngineID parent_engine_
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
index fca07e86e..ac3b90eac 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -671,7 +671,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
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 tile, DoCommandFlag flags, uint32 p1, uint
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 tile, DoCommandFlag flags, uint32 p1, uint
}
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 tile, DoCommandFlag flags, uint32 p1, uint
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 tile, DoCommandFlag flags, uint32 p1, uint
}
}
- 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
index 9c94fea4b..e16b8deee 100644
--- 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;