src/autoreplace_cmd.cpp
changeset 7231 1fbf0b9881e9
parent 7202 9d98a1c9958b
child 7242 d72363a4042d
equal deleted inserted replaced
7230:a80428b3e1fa 7231:1fbf0b9881e9
   193 		if (old_v->type == VEH_TRAIN && !IsFrontEngine(old_v)) {
   193 		if (old_v->type == VEH_TRAIN && !IsFrontEngine(old_v)) {
   194 			/* this is a railcar. We need to move the car into the train
   194 			/* this is a railcar. We need to move the car into the train
   195 			 * We add the new engine after the old one instead of replacing it. It will give the same result anyway when we
   195 			 * We add the new engine after the old one instead of replacing it. It will give the same result anyway when we
   196 			 * sell the old engine in a moment
   196 			 * sell the old engine in a moment
   197 			 */
   197 			 */
       
   198 			/* Get the vehicle in front of the one we move out */
   198 			Vehicle *front = GetPrevVehicleInChain(old_v);
   199 			Vehicle *front = GetPrevVehicleInChain(old_v);
       
   200 			/* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
       
   201 			if (IsMultiheaded(front) && !IsTrainEngine(front)) front = GetPrevVehicleInChain(front);
   199 			/* Now we move the old one out of the train */
   202 			/* Now we move the old one out of the train */
   200 			DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
   203 			DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
   201 			/* Add the new vehicle */
   204 			/* Add the new vehicle */
   202 			DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
   205 			DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
   203 		} else {
   206 		} else {