summaryrefslogtreecommitdiff
path: root/src/articulated_vehicles.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-05-13 21:38:23 +0000
committersmatz <smatz@openttd.org>2009-05-13 21:38:23 +0000
commita1addc1d9540b3cd80581d36ac341a1303ce302f (patch)
tree6f052a1162bd3c124b508400ac8a0d4c33b5bf08 /src/articulated_vehicles.cpp
parentc0ed9f779b7c21acf868b30782f6d7e98b919ca1 (diff)
downloadopenttd-a1addc1d9540b3cd80581d36ac341a1303ce302f.tar.xz
(svn r16302) -Codechange: remove Vehicle::AllocateList
Diffstat (limited to 'src/articulated_vehicles.cpp')
-rw-r--r--src/articulated_vehicles.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index fd710795b..6ef5162e9 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -283,10 +283,10 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
}
}
-void AddArticulatedParts(Vehicle **vl, VehicleType type)
+void AddArticulatedParts(Vehicle *first, VehicleType type)
{
- const Vehicle *v = vl[0];
- Vehicle *u = vl[0];
+ const Vehicle *v = first;
+ Vehicle *u = first;
if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_ARTIC_ENGINE)) return;
@@ -294,23 +294,20 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, v->engine_type, v);
if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) return;
- /* Attempt to use pre-allocated vehicles until they run out. This can happen
- * if the callback returns different values depending on the cargo type. */
- u->SetNext(vl[i]);
- if (u->Next() == NULL) return;
-
- Vehicle *previous = u;
- u = u->Next();
+ /* 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));
bool flip_image = HasBit(callback, 7);
+ Vehicle *previous = u;
const Engine *e_artic = GetEngine(engine_type);
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN:
- u = new (u) Train();
+ u = new Train();
u->subtype = 0;
previous->SetNext(u);
u->u.rail.track = v->u.rail.track;
@@ -330,7 +327,7 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
break;
case VEH_ROAD:
- u = new (u) RoadVehicle();
+ u = new RoadVehicle();
u->subtype = 0;
previous->SetNext(u);
u->u.road.first_engine = v->engine_type;