(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
authorbjarni
Thu, 11 May 2006 12:42:24 +0000
changeset 3815 b91a1d73a857
parent 3814 5fb36810d6ad
child 3816 28ee8b8c2522
(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
train_cmd.c
vehicle.c
--- a/train_cmd.c	Thu May 11 12:41:02 2006 +0000
+++ b/train_cmd.c	Thu May 11 12:42:24 2006 +0000
@@ -700,6 +700,7 @@
  * @param tile tile of the depot where rail-vehicle is built
  * @param p1 engine type id
  * @param p2 bit 0 prevents any free cars from being added to the train
+ *           bit 1 when set, the train will get number 0, otherwise it will get a free number
  */
 int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -743,10 +744,14 @@
 
 		v = vl[0];
 
-		unit_num = GetFreeUnitNumber(VEH_Train);
-		if (unit_num > _patches.max_trains)
-			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
-
+		if (HASBIT(p2, 1)) {
+			// no number is needed, so we assign 0. The engine is likely intended for a train with more than one engine
+			unit_num = 0;
+		} else {
+			unit_num = GetFreeUnitNumber(VEH_Train);
+			if (unit_num > _patches.max_trains)
+				return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
+		}
 		if (flags & DC_EXEC) {
 			DiagDirection dir = GetRailDepotDirection(tile);
 			int x = TileX(tile) * TILE_SIZE + _vehicle_initial_x_fract[dir];
--- a/vehicle.c	Thu May 11 12:41:02 2006 +0000
+++ b/vehicle.c	Thu May 11 12:42:24 2006 +0000
@@ -1490,6 +1490,7 @@
 	Vehicle *v_front, *v;
 	Vehicle *w_front, *w, *w_rear;
 	int cost, total_cost = 0;
+	uint32 build_argument = 1;
 
 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 	v = GetVehicle(p1);
@@ -1532,7 +1533,7 @@
 			continue;
 		}
 
-		cost = DoCommand(tile, v->engine_type, 1, flags, CMD_BUILD_VEH(v->type));
+		cost = DoCommand(tile, v->engine_type, build_argument, flags, CMD_BUILD_VEH(v->type));
 
 		if (CmdFailed(cost)) return cost;
 
@@ -1555,6 +1556,7 @@
 				DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
 			} else {
 				// this is a front engine or not a train. It need orders
+				build_argument = 3; // set bit 1, so it will not assign numbers to engines in the rest of the train
 				w_front = w;
 				w->service_interval = v->service_interval;
 				DoCommand(0, (v->index << 16) | w->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER);