Changeset - r6506:88a213cce8e6
[Not reviewed]
master
0 1 0
bjarni - 17 years ago 2007-04-20 17:08:55
bjarni@openttd.org
(svn r9689) -Fix: Clone vehicles will no longer refit for free
1 file changed with 12 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -1834,47 +1834,58 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 
			veh_counter++;
 
		} while ((v = v->next) != NULL);
 

	
 
		if (!AllocateVehicles(NULL, veh_counter)) {
 
			return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
		}
 
	}
 

	
 
	v = v_front;
 

	
 
	do {
 

	
 
		if (!(flags & DC_EXEC)) {
 
			/* Get the refit cost.
 
			 * This is only needed when estimating as when the command is executed, the cost from the refit command is used.
 
			 * This needs to be done for every single unit, so it should be done before checking if it's a multiheaded engine. */
 
			CargoID new_cargo_type = GetEngineCargoType(v->engine_type);
 

	
 
			if (new_cargo_type != v->cargo_type && new_cargo_type != CT_INVALID) {
 
				total_cost += GetRefitCost(v->engine_type);
 
			}
 
		}
 

	
 
		if (IsMultiheaded(v) && !IsTrainEngine(v)) {
 
			/* we build the rear ends of multiheaded trains with the front ones */
 
			continue;
 
		}
 

	
 
		cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v));
 
		build_argument = 3; // ensure that we only assign a number to the first engine
 

	
 
		if (CmdFailed(cost)) return cost;
 

	
 
		total_cost += cost;
 

	
 
		if (flags & DC_EXEC) {
 
			w = GetVehicle(_new_vehicle_id);
 

	
 
			Vehicle *w2 = w;
 
			Vehicle *v2 = v;
 
			do {
 
				if (v2->cargo_type != w2->cargo_type || v2->cargo_subtype != w2->cargo_subtype) {
 
					/* We can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build.
 
					 * If we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert.
 
					 * We need to check the whole chain if it is a train because some newgrf articulated engines can refit some units only (and not the front) */
 
					DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v));
 
					total_cost += DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v));
 
					break; // We learned that the engine in question needed a refit. No need to check anymore
 
				}
 
			} while (v->type == VEH_TRAIN && (w2 = w2->next) != NULL && (v2 = v2->next) != NULL);
 

	
 
			if (v->type == VEH_TRAIN && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) {
 
				SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION);
 
			}
 

	
 
			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);
0 comments (0 inline, 0 general)