Changeset - r3815:26ed3187c908
[Not reviewed]
master
0 2 0
bjarni - 19 years ago 2006-05-11 12:42:24
bjarni@openttd.org
(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
2 files changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
train_cmd.c
Show inline comments
 
@@ -697,12 +697,13 @@ static void AddRearEngineToMultiheadedTr
 
}
 

	
 
/** Build a railroad vehicle.
 
 * @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)
 
{
 
	const RailVehicleInfo *rvi;
 
	int value;
 
	Vehicle *v;
 
@@ -740,16 +741,20 @@ int32 CmdBuildRailVehicle(TileIndex tile
 
		Vehicle *vl[12]; // Allow for upto 10 artic parts and dual-heads
 
		if (!AllocateVehicles(vl, num_vehicles) || IsOrderPoolFull())
 
			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 

	
 
		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];
 
			int y = TileY(tile) * TILE_SIZE + _vehicle_initial_y_fract[dir];
 

	
 
			v->unitnumber = unit_num;
vehicle.c
Show inline comments
 
@@ -1487,12 +1487,13 @@ void AgeVehicle(Vehicle *v)
 
*/
 
int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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);
 
	v_front = v;
 
	w = NULL;
 
	w_front = NULL;
 
@@ -1529,13 +1530,13 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 

	
 
		if (IsMultiheaded(v) && !IsTrainEngine(v)) {
 
			/* we build the rear ends of multiheaded trains with the front ones */
 
			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;
 

	
 
		total_cost += cost;
 

	
 
		if (flags & DC_EXEC) {
 
@@ -1552,12 +1553,13 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 
			if (v->type == VEH_Train && !IsFrontEngine(v)) {
 
				// this s a train car
 
				// add this unit to the end of the train
 
				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);
 
			}
 
			w_rear = w;	// trains needs to know the last car in the train, so they can add more in next loop
 
		}
0 comments (0 inline, 0 general)