summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2009-03-09 19:14:36 +0000
committermichi_cc <michi_cc@openttd.org>2009-03-09 19:14:36 +0000
commite982100fe6ece587e29acccca8a4118ed5dff48c (patch)
tree65561c8519f5b3cdda7d44abf8c952c59e03d6a1
parentcfea2d428b6a29429dd76f8ab922f3e6e3deb354 (diff)
downloadopenttd-e982100fe6ece587e29acccca8a4118ed5dff48c.tar.xz
(svn r15655) -Codechange: Initialise vehicle vars only after a placement new so possible default constructors don't overwrite the values.
-rw-r--r--src/articulated_vehicles.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 07eac790d..153e0b50f 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -261,31 +261,13 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
EngineID engine_type = GetNewEngineID(GetEngineGRF(v->engine_type), type, GB(callback, 0, 7));
bool flip_image = HasBit(callback, 7);
- /* 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->subtype = 0;
- u->cur_image = 0xAC2;
- u->random_bits = VehicleRandomBits();
-
const Engine *e_artic = GetEngine(engine_type);
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN:
u = new (u) Train();
+ u->subtype = 0;
previous->SetNext(u);
u->u.rail.track = v->u.rail.track;
u->u.rail.railtype = v->u.rail.railtype;
@@ -305,6 +287,7 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
case VEH_ROAD:
u = new (u) RoadVehicle();
+ u->subtype = 0;
previous->SetNext(u);
u->u.road.first_engine = v->engine_type;
u->u.road.cached_veh_length = 8; // Callback is called when the consist is finished
@@ -326,6 +309,24 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type)
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 = 0xAC2;
+ u->random_bits = VehicleRandomBits();
+
if (flip_image) u->spritenum++;
VehiclePositionChanged(u);