.getSpeed((int) t0);
.getSpeed(tBase);
    private TrainPathFunction buildPathFunction(TrainPath tp, TrainModel tm,	    boolean outOfWater) {	trainModelViewer.setTrainModel(tm);	ArrayList segList = new ArrayList();	ArrayList mapCoords = tp.getMapCoordArray();	// tail of PathToDestination coincides with head of train	IntLine il = tp.getLastSegment();	Point p1 = new Point();	Point p2 = new Point();	p1.setLocation(il.x2, il.y2);	p2.setLocation(il.x1, il.y1);	TrackTile.deltasToTileCoords(p1);	TrackTile.deltasToTileCoords(p2);	float s0 = 0;	float t0 = (float) ((GameTime) world.get(ITEM.TIME,		    Player.AUTHORITATIVE)).getTime();	int mass = trainModelViewer.getTotalMass();	EngineType et = (EngineType) world.get(KEY.ENGINE_TYPES,		    tm.getEngineType(), Player.AUTHORITATIVE);	float power = et.getPowerOutput();		if (outOfWater)	    power /= 2;		float maxTractiveForce = et.getMaxTractiveForce();	float v0 = 0;       if (tm.getTrainMotionModel().getPathFunction() != null)	    v0 = tm.getTrainMotionModel().getPathFunction()		.getSpeed((int) t0);	// add segment for path from current pos to centre of tile	if (p1.equals(p2)) {	    // Last segment is from train head to centre of tile	    TrainPathSegment seg = getNewSegment(p1, p2, t0, v0, s0, mass,		    power, (float) il.getLength().getLength(), et);	    segList.add(seg);	    t0 = seg.getTMax();	    if (t0 < 0) {		// train doesn't have enough power/traction to clmb hill!		return null;	    }	    s0 = seg.getDistance(t0);	    v0 = seg.getSpeed(t0);	    p1.setLocation(p2);	}	int prefChunks = 1;	for (int i = mapCoords.size() - 1; i >= 0; i--) {	    p2 = (Point) mapCoords.get(i);	    float sMax = getSMax(s0, p1, p2);	    int currentChunk = 0;	    int maxChunks = prefChunks;	    float currentS0 = s0;	    do {		TrainPathSegment seg = getNewSegment(p1, p2, t0, v0,			currentS0, mass, power, s0 + (sMax - s0) *			((float) (currentChunk + 1) / maxChunks), et);		float newT0;		newT0 = seg.getTMax();		float vDiff = Math.abs(seg.getSpeed(newT0) -				seg.getSpeed(t0));		float a = Math.abs(seg.getAcceleration());		if (prefChunks <= maxChunks && (newT0 < t0 || (vDiff > a * 4 &&				vDiff > 0.0001))) {		    // need a better approximation		    // try smaller chunks		    maxChunks <<= 1;		    currentChunk <<= 1;		    if (maxChunks > 4096) {			// hill is too steep			return null;		    }		    continue;		} else if (prefChunks >= maxChunks && 			(currentChunk % 2) == 0 &&			maxChunks > 1 && vDiff <= a) {		    // try larger chunks		    maxChunks >>= 1;		    currentChunk >>= 1;		    continue;		}		t0 = newT0;		segList.add(seg);		currentS0 = seg.getDistance(t0);		v0 = seg.getSpeed(t0);		currentChunk++;		prefChunks = maxChunks;	    } while (currentChunk < maxChunks);	    s0 = currentS0;	    p1.setLocation(p2);	}	return new TrainPathFunction(segList);    }