Changeset - r6426:9f7d304cfd93
[Not reviewed]
master
0 2 0
maedhros - 17 years ago 2007-04-04 14:21:46
maedhros@openttd.org
(svn r9562) -Fix: When cloning, pay for the refit costs as well.
2 files changed with 19 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -446,31 +446,35 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		_cmd_text = NULL;
 
		return false;
 
	}
 

	
 
	/* Some commands have a different output in dryrun than the realrun
 
	 *  e.g.: if you demolish a whole town, the dryrun would say okay.
 
	 *  but by really destroying, your rating drops and at a certain point
 
	 *  it will fail. so res and res2 are different
 
	 * CMD_REMOVE_ROAD: This command has special local authority
 
	 * restrictions which may cause the test run to fail (the previous
 
	 * road fragments still stay there and the town won't let you
 
	 * disconnect the road system), but the exec will succeed and this
 
	 * fact will trigger an assertion failure. --pasky */
 
	 * fact will trigger an assertion failure. --pasky
 
	 * CMD_CLONE_VEHICLE: You can only refit vehicles once they have been
 
	 * bought, so you can't estimate the cost of cloning if the vehicle to be
 
	 * cloned has been refitted. */
 
	notest =
 
		(cmd & 0xFF) == CMD_CLEAR_AREA ||
 
		(cmd & 0xFF) == CMD_CONVERT_RAIL ||
 
		(cmd & 0xFF) == CMD_LEVEL_LAND ||
 
		(cmd & 0xFF) == CMD_REMOVE_ROAD ||
 
		(cmd & 0xFF) == CMD_REMOVE_LONG_ROAD;
 
		(cmd & 0xFF) == CMD_REMOVE_LONG_ROAD ||
 
		(cmd & 0xFF) == CMD_CLONE_VEHICLE;
 

	
 
	_docommand_recursive = 1;
 

	
 
	/* cost estimation only? */
 
	if (!IsGeneratingWorld() &&
 
			_shift_pressed &&
 
			IsLocalPlayer() &&
 
			!(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR)) &&
 
			(cmd & 0xFF) != CMD_PAUSE) {
 
		/* estimate the cost. */
 
		res = proc(tile, flags, p1, p2);
 
		if (CmdFailed(res)) {
src/vehicle.cpp
Show inline comments
 
@@ -1798,28 +1798,27 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 
	Vehicle *v_front, *v;
 
	Vehicle *w_front, *w, *w_rear;
 
	int cost, total_cost = 0;
 
	uint32 build_argument = 2;
 

	
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
	v = GetVehicle(p1);
 
	v_front = v;
 
	w = NULL;
 
	w_front = NULL;
 
	w_rear = NULL;
 

	
 

	
 
	/*
 
	 * v_front is the front engine in the original vehicle
 
	 * v is the car/vehicle of the original vehicle, that is currently being copied
 
	 * v is the car/vehicle of the original vehicle that is currently being copied
 
	 * w_front is the front engine of the cloned vehicle
 
	 * w is the car/vehicle currently being cloned
 
	 * w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
 
	 */
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR;
 

	
 
	/* check that we can allocate enough vehicles */
 
	if (!(flags & DC_EXEC)) {
 
		int veh_counter = 0;
 
@@ -1846,29 +1845,36 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 

	
 
		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));
 
					break; // We learned that the engine in question needed a refit. No need to check anymore
 
					/* 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). */
 
					cost = DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, GetCmdRefitVeh(v));
 
					if (CmdFailed(cost)) return cost;
 

	
 
					total_cost += cost;
 

	
 
					/* The refit command will refit all the remaining
 
					 * articulated parts if possible, so we don't need to
 
					 * carry on checking. */
 
					break;
 
				}
 
			} 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);
 
			} else {
0 comments (0 inline, 0 general)