Files @ r6838:11a1cc4094ae
Branch filter:

Location: cpp/openttd-patchpack/source/src/bridge_map.cpp

bjarni
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
The problem was that if adding units to the clone (wagon by wagon) failed, then cloning wouldn't notice it and it made two half trains
Now it detects this case and it will make cloning fail. The string with the explanation for the failed move will be used in the error message so the user will know why it failed.
/* $Id$ */

/** @file bridge_map.cpp Map accessor functions for bridges. */

#include "stdafx.h"
#include "openttd.h"
#include "bridge_map.h"
#include "bridge.h"
#include "variables.h"


TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
{
	TileIndexDiff delta = TileOffsByDiagDir(dir);

	dir = ReverseDiagDir(dir);
	do {
		tile += delta;
	} while (!IsBridgeTile(tile) || GetBridgeRampDirection(tile) != dir);

	return tile;
}


TileIndex GetNorthernBridgeEnd(TileIndex t)
{
	return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
}


TileIndex GetSouthernBridgeEnd(TileIndex t)
{
	return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
}


TileIndex GetOtherBridgeEnd(TileIndex tile)
{
	assert(IsBridgeTile(tile));
	return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
}

uint GetBridgeHeight(TileIndex t)
{
	uint h;
	Slope tileh = GetTileSlope(t, &h);
	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));

	/* one height level extra if the ramp is on a flat foundation */
	return
		h + TILE_HEIGHT +
		(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
		(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
}