summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-05-24 12:05:27 +0000
committerfrosch <frosch@openttd.org>2009-05-24 12:05:27 +0000
commit855edb0839c27640ed7cdfd37006f185395ffec6 (patch)
treebf623b0ba195bdeaced3d2094db1b1b34ac591f5 /src
parent033748528492fe64b3a5743cebbdcea663188134 (diff)
downloadopenttd-855edb0839c27640ed7cdfd37006f185395ffec6.tar.xz
(svn r16412) -Cleanup: Shuffle vehicle pointers in AddArticulatedParts(), and remove two of them.
Diffstat (limited to 'src')
-rw-r--r--src/articulated_vehicles.cpp65
1 files changed, 32 insertions, 33 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index d01118acf..e06d6a217 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -286,32 +286,31 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
void AddArticulatedParts(Vehicle *first, VehicleType type)
{
- const Vehicle *v = first;
- Vehicle *u = first;
-
- if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return;
+ if (!HasBit(EngInfo(first->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return;
+ Vehicle *v = first;
for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
- uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, v->engine_type, v);
+ uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, first->engine_type, first);
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) return;
/* In the (very rare) case the GRF reported wrong number of articulated parts
* and we run out of available vehicles, bail out. */
if (!Vehicle::CanAllocateItem()) return;
- EngineID engine_type = GetNewEngineID(GetEngineGRF(v->engine_type), type, GB(callback, 0, 7));
+ EngineID engine_type = GetNewEngineID(GetEngineGRF(first->engine_type), type, GB(callback, 0, 7));
bool flip_image = HasBit(callback, 7);
- Vehicle *previous = u;
const Engine *e_artic = Engine::Get(engine_type);
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: {
- Train *front = (Train *)v;
+ Train *front = (Train *)first;
Train *t = new Train();
+ v->SetNext(t);
+ v = t;
+
t->subtype = 0;
- previous->SetNext(t);
t->track = front->track;
t->railtype = front->railtype;
t->tcache.first_engine = front->engine_type;
@@ -326,14 +325,15 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
}
SetArticulatedPart(t);
- u = t;
} break;
case VEH_ROAD: {
- RoadVehicle *front = (RoadVehicle *)v;
+ RoadVehicle *front = (RoadVehicle *)first;
RoadVehicle *rv = new RoadVehicle();
+ v->SetNext(rv);
+ v = rv;
+
rv->subtype = 0;
- previous->SetNext(rv);
rv->rcache.first_engine = front->engine_type;
rv->rcache.cached_veh_length = 8; // Callback is called when the consist is finished
rv->state = RVSB_IN_DEPOT;
@@ -351,30 +351,29 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
}
SetRoadVehArticPart(rv);
- u = rv;
} break;
}
/* get common values from first engine */
- u->direction = v->direction;
- u->owner = v->owner;
- u->tile = v->tile;
- u->x_pos = v->x_pos;
- u->y_pos = v->y_pos;
- u->z_pos = v->z_pos;
- u->build_year = v->build_year;
- u->vehstatus = v->vehstatus & ~VS_STOPPED;
-
- u->cargo_subtype = 0;
- u->max_speed = 0;
- u->max_age = 0;
- u->engine_type = engine_type;
- u->value = 0;
- u->cur_image = SPR_IMG_QUERY;
- u->random_bits = VehicleRandomBits();
-
- if (flip_image) u->spritenum++;
-
- VehicleMove(u, false);
+ v->direction = first->direction;
+ v->owner = first->owner;
+ v->tile = first->tile;
+ v->x_pos = first->x_pos;
+ v->y_pos = first->y_pos;
+ v->z_pos = first->z_pos;
+ v->build_year = first->build_year;
+ v->vehstatus = first->vehstatus & ~VS_STOPPED;
+
+ v->cargo_subtype = 0;
+ v->max_speed = 0;
+ v->max_age = 0;
+ v->engine_type = engine_type;
+ v->value = 0;
+ v->cur_image = SPR_IMG_QUERY;
+ v->random_bits = VehicleRandomBits();
+
+ if (flip_image) v->spritenum++;
+
+ VehicleMove(v, false);
}
}