Changeset - r2934:94158a76ebcf
[Not reviewed]
master
0 6 0
tron - 19 years ago 2006-01-30 17:18:45
tron@openttd.org
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
6 files changed with 10 insertions and 10 deletions:
0 comments (0 inline, 0 general)
clear_cmd.c
Show inline comments
 
@@ -224,25 +224,25 @@ int32 CmdTerraformLand(int x, int y, uin
 
	_terraform_err_tile = 0;
 

	
 
	ts.direction = direction = p2 ? 1 : -1;
 
	ts.flags = flags;
 
	ts.modheight_count = ts.tile_table_count = 0;
 
	ts.cost = 0;
 
	ts.modheight = modheight_data;
 
	ts.tile_table = tile_table_data;
 

	
 
	tile = TileVirtXY(x, y);
 

	
 
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
 
	if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR;
 
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
 

	
 
	if (p1 & 1) {
 
		if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0),
 
				TileHeight(tile + TileDiffXY(1, 0)) + direction))
 
					return CMD_ERROR;
 
	}
 

	
 
	if (p1 & 2) {
 
		if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1),
 
				TileHeight(tile + TileDiffXY(1, 1)) + direction))
 
					return CMD_ERROR;
 
	}
 
@@ -323,25 +323,25 @@ int32 CmdTerraformLand(int x, int y, uin
 
 * @param x,y end tile of area-drag
 
 * @param p1 start tile of area drag
 
 * @param p2 unused
 
 */
 
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int size_x, size_y;
 
	int sx, sy;
 
	uint h, curh;
 
	TileIndex tile;
 
	int32 ret, cost, money;
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// remember level height
 
	h = TileHeight(p1);
 

	
 
	ex >>= 4; ey >>= 4;
 

	
 
	// make sure sx,sy are smaller than ex,ey
 
	sx = TileX(p1);
 
	sy = TileY(p1);
 
	if (ex < sx) intswap(ex, sx);
landscape.c
Show inline comments
 
@@ -298,25 +298,25 @@ int32 CmdLandscapeClear(int x, int y, ui
 
/** Clear a big piece of landscape
 
 * @param x,y end coordinates of area dragging
 
 * @param p1 start tile of area dragging
 
 * @param p2 unused
 
 */
 
int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 cost, ret, money;
 
	int sx,sy;
 
	int x,y;
 
	bool success = false;
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	// make sure sx,sy are smaller than ex,ey
 
	sx = TileX(p1) * 16;
 
	sy = TileY(p1) * 16;
 
	if (ex < sx) intswap(ex, sx);
 
	if (ey < sy) intswap(ey, sy);
 

	
 
	money = GetAvailableMoneyForCommand();
 
	cost = 0;
 

	
rail_cmd.c
Show inline comments
 
@@ -557,25 +557,25 @@ static int32 ValidateAutoDrag(Trackdir *
 
 * - p2 = (bit 7)   - 0 = build, 1 = remove tracks
 
 */
 
static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int ex, ey;
 
	int32 ret, total_cost = 0;
 
	Track track = (Track)GB(p2, 4, 3);
 
	Trackdir trackdir;
 
	byte mode = HASBIT(p2, 7);
 
	RailType railtype = (RailType)GB(p2, 0, 4);
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	trackdir = TrackToTrackdir(track);
 

	
 
	/* unpack end point */
 
	ex = TileX(p1) * TILE_SIZE;
 
	ey = TileY(p1) * TILE_SIZE;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (CmdFailed(ValidateAutoDrag(&trackdir, x, y, ex, ey))) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, TileVirtXY(x, y));
 

	
 
@@ -820,25 +820,25 @@ static int32 CmdSignalTrackHelper(int x,
 
	int ex, ey;
 
	int32 ret, total_cost, signal_ctr;
 
	byte signals;
 
	TileIndex tile = TileVirtXY(x, y);
 
	bool error = true;
 

	
 
	int mode = p2 & 0x1;
 
	Track track = GB(p2, 4, 3);
 
	Trackdir trackdir = TrackToTrackdir(track);
 
	byte semaphores = (HASBIT(p2, 3)) ? 8 : 0;
 
	byte signal_density = (p2 >> 24);
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
 

	
 
	if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* for vertical/horizontal tracks, double the given signals density
 
	* since the original amount will be too dense (shorter tracks) */
 
	if (!IsDiagonalTrack(track))
 
		signal_density *= 2;
 

	
 
	// unpack end tile
 
@@ -979,25 +979,25 @@ extern int32 DoConvertTunnelBridgeRail(T
 
 * @param ex,ey end tile of rail conversion drag
 
 * @param p1 start tile of drag
 
 * @param p2 new railtype to convert to
 
 */
 
int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 ret, cost, money;
 
	int sx, sy, x, y;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (!ValParamRailtype(p2)) return CMD_ERROR;
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	// make sure sx,sy are smaller than ex,ey
 
	sx = TileX(p1) * TILE_SIZE;
 
	sy = TileY(p1) * TILE_SIZE;
 
	if (ex < sx) intswap(ex, sx);
 
	if (ey < sy) intswap(ey, sy);
 

	
 
	money = GetAvailableMoneyForCommand();
 
	cost = 0;
 

	
 
	for (x = sx; x <= ex; x += TILE_SIZE) {
 
		for (y = sy; y <= ey; y += TILE_SIZE) {
road_cmd.c
Show inline comments
 
@@ -509,25 +509,25 @@ int32 DoConvertStreetRail(TileIndex tile
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 */
 
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex start_tile, end_tile, tile;
 
	int32 cost, ret;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	start_tile = p1;
 
	end_tile = TileVirtXY(x, y);
 

	
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
 

	
 
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
 
	if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
 
		TileIndex t = start_tile;
 
		start_tile = end_tile;
 
@@ -564,25 +564,25 @@ int32 CmdBuildLongRoad(int x, int y, uin
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
 
 * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
 
 * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
 
 */
 
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TileIndex start_tile, end_tile, tile;
 
	int32 cost, ret;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	start_tile = p1;
 
	end_tile = TileVirtXY(x, y);
 

	
 
	/* Only drag in X or Y direction dictated by the direction variable */
 
	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
 
	if (HASBIT(p2, 2)  && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
 

	
 
	/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
 
	if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
 
		TileIndex t = start_tile;
 
		start_tile = end_tile;
tunnelbridge_cmd.c
Show inline comments
 
@@ -200,25 +200,25 @@ int32 CmdBuildBridge(int x, int y, uint3
 
	uint odd_middle_part;
 
	uint direction;
 
	uint i;
 
	int32 cost, terraformcost, ret;
 
	bool allow_on_slopes;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* unpack parameters */
 
	bridge_type = GB(p2, 0, 8);
 
	railtype    = GB(p2, 8, 8);
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	// type of bridge
 
	if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
 
		railtype = 0;
 
		rail_or_road = 2;
 
	} else {
 
		if (!ValParamRailtype(railtype)) return CMD_ERROR;
 
		rail_or_road = 0;
 
	}
 

	
 
	sx = TileX(p1) * 16;
 
	sy = TileY(p1) * 16;
water_cmd.c
Show inline comments
 
@@ -206,25 +206,25 @@ int32 CmdBuildLock(int x, int y, uint32 
 

	
 
/** Build a piece of canal.
 
 * @param x,y end tile of stretch-dragging
 
 * @param p1 start tile of stretch-dragging
 
 * @param p2 unused
 
 */
 
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int32 ret, cost;
 
	int size_x, size_y;
 
	int sx, sy;
 

	
 
	if (p1 > MapSize()) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	sx = TileX(p1);
 
	sy = TileY(p1);
 
	/* x,y are in pixel-coordinates, transform to tile-coordinates
 
	 * to be able to use the BEGIN_TILE_LOOP() macro */
 
	x >>= 4; y >>= 4;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	if (x < sx) intswap(x, sx);
 
	if (y < sy) intswap(y, sy);
 
	size_x = (x - sx) + 1;
0 comments (0 inline, 0 general)