src/train_cmd.cpp
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
--- a/src/train_cmd.cpp	Tue Jun 17 10:32:49 2008 +0000
+++ b/src/train_cmd.cpp	Tue Jun 17 13:22:13 2008 +0000
@@ -211,6 +211,8 @@
 		u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine;
 		u->u.rail.railtype = rvi_u->railtype;
 
+		if (IsTrainEngine(u)) first_engine = u->engine_type;
+
 		/* Set user defined data to its default value */
 		u->u.rail.user_def_data = rvi_u->user_def_data;
 	}
@@ -225,8 +227,6 @@
 
 		if (!HasBit(EngInfo(u->engine_type)->misc_flags, EF_RAIL_TILTS)) train_can_tilt = false;
 
-		if (IsTrainEngine(u)) first_engine = u->engine_type;
-
 		/* Cache wagon override sprite group. NULL is returned if there is none */
 		u->u.rail.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->u.rail.first_engine);
 
@@ -549,7 +549,7 @@
 		if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
 
 		/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
-		Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
+		Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
 		memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
 
 		if (!Vehicle::AllocateList(vl, num_vehicles))
@@ -716,7 +716,7 @@
 		if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
 
 		/* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */
-		Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
+		Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
 		memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
 
 		if (!Vehicle::AllocateList(vl, num_vehicles)) {