(svn r2487) Replace TILE_XY by TileXY/TileDiffXY
authortron
Sat, 25 Jun 2005 16:44:57 +0000
changeset 1981 3c9c682f1212
parent 1980 6c5917cfcb78
child 1982 720b3501bed7
(svn r2487) Replace TILE_XY by TileXY/TileDiffXY
ai.c
ai.h
ai_new.c
ai_pathfinder.c
clear_cmd.c
disaster_cmd.c
dock_gui.c
economy.c
industry_cmd.c
industry_gui.c
landscape.c
macros.h
main_gui.c
map.c
map.h
npf.c
openttd.c
order_gui.c
rail_cmd.c
rail_gui.c
road_cmd.c
smallmap_gui.c
station_cmd.c
terraform_gui.c
tile.c
town_cmd.c
tree_cmd.c
tunnelbridge_cmd.c
unmovable_cmd.c
water_cmd.c
--- a/ai.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/ai.c	Sat Jun 25 16:44:57 2005 +0000
@@ -633,7 +633,7 @@
 
 static TileIndex AiGetPctTileBetween(TileIndex a, TileIndex b, byte pct)
 {
-	return TILE_XY(
+	return TileXY(
 		TileX(a) + ((TileX(b) - TileX(a)) * pct >> 8),
 		TileY(a) + ((TileY(b) - TileY(a)) * pct >> 8)
 	);
@@ -3656,7 +3656,7 @@
 
 			if (m5&0x25) {
 pos_0:
-				if (!(GetRailTrackStatus(TILE_MASK(tile-TILE_XY(1,0)))&0x19)) {
+				if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & 0x19)) {
 					p->ai.cur_dir_a = 0;
 					p->ai.cur_tile_a = tile;
 					p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@@ -3666,7 +3666,7 @@
 
 			if (m5&0x2A) {
 pos_1:
-				if (!(GetRailTrackStatus(TILE_MASK(tile+TILE_XY(0,1)))&0x16)) {
+				if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & 0x16)) {
 					p->ai.cur_dir_a = 1;
 					p->ai.cur_tile_a = tile;
 					p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@@ -3676,7 +3676,7 @@
 
 			if (m5&0x19) {
 pos_2:
-				if (!(GetRailTrackStatus(TILE_MASK(tile+TILE_XY(1,0)))&0x25)) {
+				if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & 0x25)) {
 					p->ai.cur_dir_a = 2;
 					p->ai.cur_tile_a = tile;
 					p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@@ -3686,7 +3686,7 @@
 
 			if (m5&0x16) {
 pos_3:
-				if (!(GetRailTrackStatus(TILE_MASK(tile-TILE_XY(0,1)))&0x2A)) {
+				if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & 0x2A)) {
 					p->ai.cur_dir_a = 3;
 					p->ai.cur_tile_a = tile;
 					p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@@ -3712,20 +3712,20 @@
 			int dir;
 
 			// Check if there are any stations around.
-			if (IsTileType(tile + TILE_XY(-1,0), MP_STATION) &&
-					IsTileOwner(tile + TILE_XY(-1, 0), _current_player))
-						return;
-
-			if (IsTileType(tile + TILE_XY(1,0), MP_STATION) &&
-					IsTileOwner(tile + TILE_XY(1, 0), _current_player))
+			if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) &&
+					IsTileOwner(tile + TileDiffXY(-1, 0), _current_player))
 						return;
 
-			if (IsTileType(tile + TILE_XY(0,-1), MP_STATION) &&
-					IsTileOwner(tile + TILE_XY(0, -1), _current_player))
+			if (IsTileType(tile + TileDiffXY(1, 0), MP_STATION) &&
+					IsTileOwner(tile + TileDiffXY(1, 0), _current_player))
 						return;
 
-			if (IsTileType(tile + TILE_XY(0,1), MP_STATION) &&
-					IsTileOwner(tile + TILE_XY(0, 1), _current_player))
+			if (IsTileType(tile + TileDiffXY(0, -1), MP_STATION) &&
+					IsTileOwner(tile + TileDiffXY(0, -1), _current_player))
+						return;
+
+			if (IsTileType(tile + TileDiffXY(0, 1), MP_STATION) &&
+					IsTileOwner(tile + TileDiffXY(0, 1), _current_player))
 						return;
 
 			dir = _map5[tile] & 3;
--- a/ai.h	Sat Jun 25 06:15:43 2005 +0000
+++ b/ai.h	Sat Jun 25 16:44:57 2005 +0000
@@ -222,7 +222,7 @@
 
 #define AI_NO_CARGO 0xFF // Means that there is no cargo defined yet (used for industry)
 #define AI_NEED_CARGO 0xFE // Used when the AI needs to find out a cargo for the route
-#define AI_STATION_RANGE TILE_XY(MapMaxX(), MapMaxY())
+#define AI_STATION_RANGE TileXY(MapMaxX(), MapMaxY())
 
 #define AI_PATHFINDER_NO_DIRECTION (byte)-1
 
--- a/ai_new.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/ai_new.c	Sat Jun 25 16:44:57 2005 +0000
@@ -621,7 +621,7 @@
 	    //   taking eachothers passangers away (bad result when it does not)
 	    for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) {
 	    	for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) {
-	    		new_tile = TILE_XY(x,y);
+	    		new_tile = TileXY(x, y);
 	    		if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) {
 	    			// This tile we can build on!
 	    			// Check acceptance
@@ -695,8 +695,8 @@
     	// Init path_info
     	if (p->ainew.from_tile == AI_STATION_RANGE) {
     		// For truck routes we take a range around the industry
-	    	p->ainew.path_info.start_tile_tl = GetIndustry(p->ainew.from_ic)->xy - TILE_XY(1,1);
-	    	p->ainew.path_info.start_tile_br = GetIndustry(p->ainew.from_ic)->xy + TILE_XY(GetIndustry(p->ainew.from_ic)->width, GetIndustry(p->ainew.from_ic)->height) + TILE_XY(1,1);
+	    	p->ainew.path_info.start_tile_tl = GetIndustry(p->ainew.from_ic)->xy - TileDiffXY(1, 1);
+	    	p->ainew.path_info.start_tile_br = GetIndustry(p->ainew.from_ic)->xy + TileDiffXY(GetIndustry(p->ainew.from_ic)->width, GetIndustry(p->ainew.from_ic)->height) + TileDiffXY(1, 1);
 	    	p->ainew.path_info.start_direction = p->ainew.from_direction;
 	    } else {
 	    	p->ainew.path_info.start_tile_tl = p->ainew.from_tile;
@@ -705,8 +705,8 @@
 	    }
 
 	    if (p->ainew.to_tile == AI_STATION_RANGE) {
-	    	p->ainew.path_info.end_tile_tl = GetIndustry(p->ainew.to_ic)->xy - TILE_XY(1,1);
-	    	p->ainew.path_info.end_tile_br = GetIndustry(p->ainew.to_ic)->xy + TILE_XY(GetIndustry(p->ainew.to_ic)->width, GetIndustry(p->ainew.to_ic)->height) + TILE_XY(1,1);
+	    	p->ainew.path_info.end_tile_tl = GetIndustry(p->ainew.to_ic)->xy - TileDiffXY(1, 1);
+	    	p->ainew.path_info.end_tile_br = GetIndustry(p->ainew.to_ic)->xy + TileDiffXY(GetIndustry(p->ainew.to_ic)->width, GetIndustry(p->ainew.to_ic)->height) + TileDiffXY(1, 1);
 	   	    p->ainew.path_info.end_direction = p->ainew.to_direction;
     	} else {
 	   	    p->ainew.path_info.end_tile_tl = p->ainew.to_tile;
--- a/ai_pathfinder.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/ai_pathfinder.c	Sat Jun 25 16:44:57 2005 +0000
@@ -115,7 +115,7 @@
 	// Now we add all the starting tiles
 	for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
 		for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
-			start_node.node.tile = TILE_XY(x, y);
+			start_node.node.tile = TileXY(x, y);
 			result->addstart(result, &start_node.node, 0);
 		}
 	}
@@ -144,9 +144,9 @@
 	// Now we add all the starting tiles
 	for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
 		for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
-			if (!(IsTileType(TILE_XY(x, y), MP_CLEAR) || IsTileType(TILE_XY(x, y), MP_TREES))) continue;
-			if (!TestCanBuildStationHere(TILE_XY(x, y), TEST_STATION_NO_DIR)) continue;
-			start_node.node.tile = TILE_XY(x, y);
+			if (!(IsTileType(TileXY(x, y), MP_CLEAR) || IsTileType(TileXY(x, y), MP_TREES))) continue;
+			if (!TestCanBuildStationHere(TileXY(x, y), TEST_STATION_NO_DIR)) continue;
+			start_node.node.tile = TileXY(x, y);
 			aystar->addstart(aystar, &start_node.node, 0);
 		}
 	}
--- a/clear_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/clear_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -76,9 +76,9 @@
 
 static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
 {
-	TerraformAddDirtyTile(ts, tile+TILE_XY(0,-1));
-	TerraformAddDirtyTile(ts, tile+TILE_XY(-1,-1));
-	TerraformAddDirtyTile(ts, tile+TILE_XY(-1,0));
+	TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
+	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
+	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1,  0));
 	TerraformAddDirtyTile(ts, tile);
 }
 
@@ -152,17 +152,10 @@
 	if (nh < 0 || height == nh)
 		return false;
 
-	if (TerraformProc(ts, tile, 0)<0)
-		return false;
-
-	if (TerraformProc(ts, tile + TILE_XY(0,-1), 1)<0)
-		return false;
-
-	if (TerraformProc(ts, tile + TILE_XY(-1,-1), 2)<0)
-		return false;
-
-	if (TerraformProc(ts, tile + TILE_XY(-1,0), 3)<0)
-		return false;
+	if (TerraformProc(ts, tile, 0) < 0) return false;
+	if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false;
+	if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false;
+	if (TerraformProc(ts, tile + TileDiffXY(-1,  0), 3) < 0) return false;
 
 	mod = ts->modheight;
 	count = ts->modheight_count;
@@ -239,29 +232,29 @@
 	tile = TileVirtXY(x, y);
 
 	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
-	if (tile + TILE_XY(1,1) > MapSize()) return CMD_ERROR;
+	if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR;
 
 	if (p1 & 1) {
-		if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),
-				TileHeight(tile + TILE_XY(1, 0)) + direction))
+		if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0),
+				TileHeight(tile + TileDiffXY(1, 0)) + direction))
 					return CMD_ERROR;
 	}
 
 	if (p1 & 2) {
-		if (!TerraformTileHeight(&ts, tile+TILE_XY(1,1),
-				TileHeight(tile + TILE_XY(1, 1)) + direction))
+		if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1),
+				TileHeight(tile + TileDiffXY(1, 1)) + direction))
 					return CMD_ERROR;
 	}
 
 	if (p1 & 4) {
-		if (!TerraformTileHeight(&ts, tile+TILE_XY(0,1),
-				TileHeight(tile + TILE_XY(0, 1)) + direction))
+		if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1),
+				TileHeight(tile + TileDiffXY(0, 1)) + direction))
 					return CMD_ERROR;
 	}
 
 	if (p1 & 8) {
-		if (!TerraformTileHeight(&ts, tile+TILE_XY(0,0),
-				TileHeight(tile + TILE_XY(0, 0)) + direction))
+		if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0),
+				TileHeight(tile + TileDiffXY(0, 0)) + direction))
 					return CMD_ERROR;
 	}
 
@@ -274,12 +267,12 @@
 			uint z, t;
 			TileIndex tile = *ti;
 
-			z = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,0));
-			t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,0));
+			z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
+			t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
 			if (t <= z) z = t;
-			t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,1));
+			t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
 			if (t <= z) z = t;
-			t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,1));
+			t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
 			if (t <= z) z = t;
 
 			if (!CheckTunnelInWay(tile, z*8))
@@ -351,7 +344,7 @@
 	sy = TileY(p1);
 	if (ex < sx) intswap(ex, sx);
 	if (ey < sy) intswap(ey, sy);
-	tile = TILE_XY(sx,sy);
+	tile = TileXY(sx, sy);
 
 	size_x = ex-sx+1;
 	size_y = ey-sy+1;
@@ -710,11 +703,11 @@
 	if (GetMapExtraBits(tile) == 1) {
 		_map5[tile] = 0x17;
 	} else {
-		if (GetMapExtraBits(tile+TILE_XY(1,0)) != 1 &&
-				GetMapExtraBits(tile+TILE_XY(-1,0)) != 1 &&
-				GetMapExtraBits(tile+TILE_XY(0,1)) != 1 &&
-				GetMapExtraBits(tile+TILE_XY(0,-1)) != 1)
-					return;
+		if (GetMapExtraBits(tile + TileDiffXY( 1,  0)) != 1 &&
+				GetMapExtraBits(tile + TileDiffXY(-1,  0)) != 1 &&
+				GetMapExtraBits(tile + TileDiffXY( 0,  1)) != 1 &&
+				GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
+			return;
 		_map5[tile] = 0x15;
 	}
 
--- a/disaster_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/disaster_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -627,10 +627,10 @@
 				EV_EXPLOSION_SMALL);
 		}
 
-		BEGIN_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
+		BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
 			tile = TILE_MASK(tile);
 			DisasterClearSquare(tile);
-		END_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
+		END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
 	}
 }
 
@@ -744,7 +744,7 @@
 	x = TileX(Random()) * 16 + 8;
 
 	InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
-	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
+	v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
 	v->age = 0;
 
 	// Allocate shadow too?
@@ -846,7 +846,7 @@
 
 	y = MapMaxX() * 16 - 1;
 	InitializeDisasterVehicle(v, x, y, 135, 7, 9);
-	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
+	v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
 	v->age = 0;
 
 	// Allocate shadow too?
@@ -912,7 +912,7 @@
 
 				SetDParam(0, i->town->index);
 				AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
-					NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0);
+					NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
 
 				{
 					TileIndex tile = i->xy;
--- a/dock_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/dock_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -168,11 +168,11 @@
 		TileIndex tile_to;
 
 		tile_from = tile_to = e->place.tile;
-		switch(GetTileSlope(tile_from, NULL)) {
-		case 3: tile_to += TILE_XY(-1,0); break;
-		case 6:	tile_to += TILE_XY(0,-1);	break;
-		case 9:	tile_to += TILE_XY(0,1);	break;
-		case 12:tile_to += TILE_XY(1,0);	break;
+		switch (GetTileSlope(tile_from, NULL)) {
+			case  3: tile_to += TileDiffXY(-1,  0); break;
+			case  6: tile_to += TileDiffXY( 0, -1); break;
+			case  9: tile_to += TileDiffXY( 0,  1); break;
+			case 12: tile_to += TileDiffXY( 1,  0); break;
 		}
 		VpSetPresizeRange(tile_from, tile_to);
 	} break;
--- a/economy.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/economy.c	Sat Jun 25 16:44:57 2005 +0000
@@ -62,15 +62,15 @@
 	if (val <= _map5[tile])
 		return;
 
-	_map5[tile + TILE_XY(0,0)] = val;
-	_map5[tile + TILE_XY(0,1)] = ++val;
-	_map5[tile + TILE_XY(1,0)] = ++val;
-	_map5[tile + TILE_XY(1,1)] = ++val;
+	_map5[tile + TileDiffXY(0, 0)] =   val;
+	_map5[tile + TileDiffXY(0, 1)] = ++val;
+	_map5[tile + TileDiffXY(1, 0)] = ++val;
+	_map5[tile + TileDiffXY(1, 1)] = ++val;
 
-	MarkTileDirtyByTile(tile + TILE_XY(0,0));
-	MarkTileDirtyByTile(tile + TILE_XY(0,1));
-	MarkTileDirtyByTile(tile + TILE_XY(1,0));
-	MarkTileDirtyByTile(tile + TILE_XY(1,1));
+	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
+	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
+	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
+	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
 }
 
 int64 CalculateCompanyValue(Player *p) {
--- a/industry_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/industry_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -692,9 +692,7 @@
 		break;
 
 	case 24:
-		if (_map5[tile + TILE_XY(0,1)] == 24) {
-			BuildOilRig(tile);
-		}
+		if (_map5[tile + TileDiffXY(0, 1)] == 24) BuildOilRig(tile);
 		break;
 
 	case 143:
@@ -943,7 +941,7 @@
 			_map3_hi[tile] = (_map3_hi[tile] & and) | or;
 		}
 
-		tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
+		tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	} while (--size);
 }
 
@@ -966,7 +964,7 @@
 	size_y = r >> 8;
 
 	/* offset tile to match size */
-	tile = tile - TILE_XY(size_x>>1, size_y>>1);
+	tile -= TileDiffXY(size_x / 2, size_y / 2);
 
 	/* check the amount of bad tiles */
 	count = 0;
@@ -1000,10 +998,10 @@
 		type = _plantfarmfield_type[Random() & 0xF];
 	}
 
-	SetupFarmFieldFence(tile-TILE_XY(1,0), size_y, type, 1);
-	SetupFarmFieldFence(tile-TILE_XY(0,1), size_x, type, 0);
-	SetupFarmFieldFence(tile+TILE_XY(1,0) * (size_x-1), size_y, type, 1);
-	SetupFarmFieldFence(tile+TILE_XY(0,1) * (size_y-1), size_x, type, 0);
+	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, 1);
+	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, 0);
+	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, 1);
+	SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, 0);
 }
 
 static void MaybePlantFarmField(Industry *i)
@@ -1060,7 +1058,7 @@
 				tile += ToTileIndexDiff(_chop_dir[dir]);
 			} while (--j);
 		}
-		tile -= TILE_XY(1,1);
+		tile -= TileDiffXY(1, 1);
 	}
 }
 
@@ -1532,7 +1530,7 @@
 	i->height++;
 
 	if (i->type == IT_FARM || i->type == IT_FARM_2) {
-		tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1));
+		tile = i->xy + TileDiffXY(i->width / 2, i->height / 2);
 		for(j=0; j!=50; j++) {
 			int x = Random() % 31 - 16;
 			int y = Random() % 31 - 16;
@@ -1728,7 +1726,7 @@
 					SetDParam(2, i->type + STR_4802_COAL_MINE);
 					AddNewsItem(percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
 					            NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
-					            i->xy + TILE_XY(1,1), 0);
+					            i->xy + TileDiffXY(1, 1), 0);
 				}
 			}
 			break;
@@ -1740,7 +1738,7 @@
 		SetDParam(0, i->town->index);
 		AddNewsItem(_industry_close_strings[i->type],
 		            NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
-		            i->xy + TILE_XY(1,1), 0);
+		            i->xy + TileDiffXY(1, 1), 0);
 	}
 }
 
@@ -1887,7 +1885,7 @@
 	if (str != STR_NULL) {
 		SetDParam(1, type + STR_4802_COAL_MINE);
 		SetDParam(0, i->town->index);
-		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0);
+		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
 	}
 }
 
--- a/industry_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/industry_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -376,7 +376,7 @@
 			break;
 		case 6:
 			i = GetIndustry(w->window_number);
-			ScrollMainWindowToTile(i->xy + TILE_XY(1,1));
+			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
 			break;
 		}
 		}
@@ -450,7 +450,7 @@
 		WP(w,vp2_d).data_2 = 0;
 		WP(w,vp2_d).data_3 = 0;
 		i = GetIndustry(w->window_number);
-		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1);
+		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TileDiffXY(1, 1), 1);
 	}
 }
 
--- a/landscape.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/landscape.c	Sat Jun 25 16:44:57 2005 +0000
@@ -412,7 +412,7 @@
 		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
 			tile += TILELOOP_SIZE; /* no overflow */
 		} else {
-			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
+			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
 		}
 	} while (--count);
 	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
@@ -525,7 +525,7 @@
 	if (y + h >= MapMaxY() - 1)
 		return;
 
-	tile = &_map_type_and_height[TILE_XY(x, y)];
+	tile = &_map_type_and_height[TileXY(x, y)];
 
 	switch (direction) {
 		case 0:
@@ -538,7 +538,7 @@
 					p++;
 					tile_cur++;
 				}
-				tile += TILE_XY(0, 1);
+				tile += TileDiffXY(0, 1);
 			} while (--h != 0);
 			break;
 
@@ -550,14 +550,14 @@
 				for (h_cur = h; h_cur != 0; --h_cur) {
 					if (*p >= *tile_cur) *tile_cur = *p;
 					p++;
-					tile_cur += TILE_XY(0, 1);
+					tile_cur += TileDiffXY(0, 1);
 				}
 				tile++;
 			} while (--w != 0);
 			break;
 
 		case 2:
-			tile += TILE_XY(w - 1, 0);
+			tile += TileDiffXY(w - 1, 0);
 			do {
 				byte *tile_cur = tile;
 				uint w_cur;
@@ -567,12 +567,12 @@
 					p++;
 					tile_cur--;
 				}
-				tile += TILE_XY(0, 1);
+				tile += TileDiffXY(0, 1);
 			} while (--h != 0);
 			break;
 
 		case 3:
-			tile += TILE_XY(0, h - 1);
+			tile += TileDiffXY(0, h - 1);
 			do {
 				byte *tile_cur = tile;
 				uint h_cur;
@@ -580,7 +580,7 @@
 				for (h_cur = h; h_cur != 0; --h_cur) {
 					if (*p >= *tile_cur) *tile_cur = *p;
 					p++;
-					tile_cur -= TILE_XY(0, 1);
+					tile_cur -= TileDiffXY(0, 1);
 				}
 				tile++;
 			} while (--w != 0);
@@ -684,7 +684,7 @@
 	int rn = rng;
 	uint32 r = Random();
 
-	return TILE_MASK(TILE_XY(
+	return TILE_MASK(TileXY(
 		TileX(a) + ((byte)r * rn * 2 >> 8) - rn,
 		TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn
 	));
--- a/macros.h	Sat Jun 25 06:15:43 2005 +0000
+++ b/macros.h	Sat Jun 25 16:44:57 2005 +0000
@@ -119,7 +119,7 @@
 
 #define END_TILE_LOOP(var,w,h,tile)			\
 			} while (++var, --w_cur != 0);						\
-		} while (var += TILE_XY(0,1) - (w), --h_cur != 0);}
+		} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0);}
 
 
 #define for_each_bit(_i,_b)										\
--- a/main_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/main_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -2421,14 +2421,14 @@
 	switch(_game_mode) {
 	case GM_MENU:
 		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
-		AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
+		AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 //		w = AllocateWindowDesc(&_toolb_intro_desc);
 //		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 		ShowSelectGameWindow();
 		break;
 	case GM_NORMAL:
 		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
-		AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
+		AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 
 		ShowVitalWindows();
 
--- a/map.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/map.c	Sat Jun 25 16:44:57 2005 +0000
@@ -81,9 +81,9 @@
 #endif
 	}
 
-	assert(TILE_XY(x,y) == TILE_MASK(tile + add));
+	assert(TileXY(x,y) == TILE_MASK(tile + add));
 
-	return TILE_XY(x,y);
+	return TileXY(x,y);
 }
 #endif
 
@@ -115,7 +115,7 @@
 //  addx = +3 and addy = -4. This function will now return
 //  INVALID_TILE, because the y is wrapped. This is needed in
 //  for example, farmland. When the tile is not wrapped,
-//  the result will be tile + TILE_XY(addx, addy)
+//  the result will be tile + TileDiffXY(addx, addy)
 uint TileAddWrap(TileIndex tile, int addx, int addy)
 {
 	uint x, y;
@@ -123,8 +123,8 @@
 	y = TileY(tile) + addy;
 
 	// Are we about to wrap?
-		if (x < MapMaxX() && y < MapMaxY())
-		return tile + TILE_XY(addx, addy);
+	if (x < MapMaxX() && y < MapMaxY())
+		return tile + TileDiffXY(addx, addy);
 
 	return INVALID_TILE;
 }
--- a/map.h	Sat Jun 25 06:15:43 2005 +0000
+++ b/map.h	Sat Jun 25 16:44:57 2005 +0000
@@ -3,8 +3,6 @@
 
 #include "stdafx.h"
 
-#define TILE_XY(x,y) (((y) << MapLogX()) + (x))
-
 #define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1))
 #define TILE_ASSERT(x) assert(TILE_MASK(x) == (x));
 
@@ -35,6 +33,17 @@
 uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map
 
 typedef uint32 TileIndex;
+typedef int32 TileIndexDiff;
+
+static inline TileIndex TileXY(uint x, uint y)
+{
+	return (y << MapLogX()) + x;
+}
+
+static inline TileIndexDiff TileDiffXY(int x, int y)
+{
+	return (y << MapLogX()) + x;
+}
 
 static inline TileIndex TileVirtXY(uint x, uint y)
 {
@@ -70,8 +79,6 @@
 }
 
 
-typedef int32 TileIndexDiff;
-
 typedef struct TileIndexDiffC {
 	int16 x;
 	int16 y;
@@ -91,7 +98,7 @@
 	#define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__))
 #endif
 
-#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x, y))
+#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
 
 uint TileAddWrap(TileIndex tile, int addx, int addy);
 
@@ -109,7 +116,7 @@
 	if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
 		return INVALID_TILE;
 	else
-		return TILE_XY(x, y);
+		return TileXY(x, y);
 }
 
 // Functions to calculate distances
--- a/npf.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/npf.c	Sat Jun 25 16:44:57 2005 +0000
@@ -81,7 +81,7 @@
 		ty = y3;
 
 	// return the tile of our target coordinates
-	return TILE_XY(tx,ty);
+	return TileXY(tx, ty);
 };
 
 /* Calcs the heuristic to the target station or tile. For train stations, it
--- a/openttd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/openttd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -1292,7 +1292,7 @@
 	    (0x402) version, so I just check when versions are older, and then
 	    walk through the whole map.. */
 	if (version <= 0x402) {
-		TileIndex tile = TILE_XY(0,0);
+		TileIndex tile = TileXY(0, 0);
 		uint w = MapSizeX();
 		uint h = MapSizeY();
 
--- a/order_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/order_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -227,8 +227,8 @@
 			if (IsTileDepotType(tile, TRANSPORT_WATER) &&
 					IsTileOwner(tile, _local_player)) {
 				switch (_map5[tile]) {
-				case 0x81: tile--; break;
-				case 0x83: tile-= TILE_XY(0,1); break;
+					case 0x81: tile -= TileDiffXY(1, 0); break;
+					case 0x83: tile -= TileDiffXY(0, 1); break;
 				}
 				order.type = OT_GOTO_DEPOT;
 				order.flags = OF_PART_OF_ORDERS;
--- a/rail_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/rail_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -1891,30 +1891,30 @@
 			owner = GetTileOwner(tile);
 
 			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) {
-				if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) ||
-						!IsTileOwner(tile + TILE_XY(0, -1), owner) ||
-						(_map5[tile + TILE_XY(0,-1)]==TRACK_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==TRACK_BIT_LEFT))
+				if (!IsTileType(tile + TileDiffXY(0, -1), MP_RAILWAY) ||
+						!IsTileOwner(tile + TileDiffXY(0, -1), owner) ||
+						(_map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(0, -1)] == TRACK_BIT_LEFT))
 							a2 = RAIL_GROUND_FENCE_NW;
 			}
 
 			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_LEFT)) {
-				if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) ||
-						!IsTileOwner(tile + TILE_XY(0, 1), owner) ||
-						(_map5[tile + TILE_XY(0,1)]==TRACK_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==TRACK_BIT_RIGHT))
+				if (!IsTileType(tile + TileDiffXY(0, 1), MP_RAILWAY) ||
+						!IsTileOwner(tile + TileDiffXY(0, 1), owner) ||
+						(_map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(0, 1)] == TRACK_BIT_RIGHT))
 							a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
 			}
 
 			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_LEFT)) {
-				if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) ||
-						!IsTileOwner(tile + TILE_XY(-1, 0), owner) ||
-						(_map5[tile + TILE_XY(-1,0)]==TRACK_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==TRACK_BIT_RIGHT))
+				if (!IsTileType(tile + TileDiffXY(-1, 0), MP_RAILWAY) ||
+						!IsTileOwner(tile + TileDiffXY(-1, 0), owner) ||
+						(_map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_UPPER || _map5[tile + TileDiffXY(-1, 0)] == TRACK_BIT_RIGHT))
 							a2 = RAIL_GROUND_FENCE_NE;
 			}
 
 			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_LOWER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) {
-				if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) ||
-						!IsTileOwner(tile + TILE_XY(1, 0), owner) ||
-						(_map5[tile + TILE_XY(1,0)]==TRACK_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==TRACK_BIT_LEFT))
+				if (!IsTileType(tile + TileDiffXY(1, 0), MP_RAILWAY) ||
+						!IsTileOwner(tile + TileDiffXY(1, 0), owner) ||
+						(_map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LOWER || _map5[tile + TileDiffXY(1, 0)] == TRACK_BIT_LEFT))
 							a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
 			}
 		}
--- a/rail_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/rail_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -636,7 +636,7 @@
 
 	// TODO: Custom station selector GUI. Now we just try using first custom station
 	// (and fall back to normal stations if it isn't available).
-	DoCommandP(TILE_XY(sx,sy), _railstation.orientation | (w<<8) | (h<<16),_cur_railtype|1<<4, CcStation,
+	DoCommandP(TileXY(sx, sy), _railstation.orientation | (w << 8) | (h << 16), _cur_railtype | 1 << 4, CcStation,
 		CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
 }
 
--- a/road_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/road_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -548,7 +548,7 @@
 
 		if (tile == end_tile) break;
 
-		tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
+		tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	}
 
 	return (cost == 0) ? CMD_ERROR : cost;
@@ -602,7 +602,7 @@
 
 		if (tile == end_tile) break;
 
-		tile += HASBIT(p2, 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
+		tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	}
 
 	return (cost == 0) ? CMD_ERROR : cost;
--- a/smallmap_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/smallmap_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -333,7 +333,7 @@
 		if (xc < MapMaxX() && yc < MapMaxY()) {
 			// check if the dst pointer points to a pixel inside the screen buffer
 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
-				WRITE_PIXELS_OR(dst, proc(TILE_XY(xc, yc)) & mask );
+				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
 		}
 	// switch to next tile in the column
 	} while (xc++, yc++, dst += pitch, --reps != 0);
--- a/station_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/station_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -175,7 +175,7 @@
 static Station *GetStationAround(TileIndex tile, int w, int h, int closest_station)
 {
 	// check around to see if there's any stations there
-	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
+	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 		if (IsTileType(tile_cur, MP_STATION)) {
 			int t;
 			t = _map2[tile_cur];
@@ -193,7 +193,7 @@
 				return CHECK_STATIONS_ERR;
 			}
 		}
-	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
+	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 	return (closest_station == -1) ? NULL : GetStation(closest_station);
 }
 
@@ -550,7 +550,7 @@
 		for (xc = x1; xc != x2; xc++) {
 			if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) {
 				GetProducedCargoProc *gpc;
-				TileIndex tile = TILE_XY(xc, yc);
+				TileIndex tile = TileXY(xc, yc);
 
 				gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc;
 				if (gpc != NULL) {
@@ -596,7 +596,7 @@
 
 	for (yc = y1; yc != y2; yc++) {
 		for (xc = x1; xc != x2; xc++) {
-			TileIndex tile = TILE_XY(xc, yc);
+			TileIndex tile = TileXY(xc, yc);
 
 			if (!IsTileType(tile, MP_STATION)) {
 				AcceptedCargo ac;
@@ -653,14 +653,14 @@
 	if (st->train_tile != 0) {
 		MergePoint(&rect, st->train_tile);
 		MergePoint(&rect,
-			st->train_tile + TILE_XY(st->trainst_w - 1, st->trainst_h - 1)
+			st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
 		);
 	}
 
 	if (st->airport_tile != 0) {
 		MergePoint(&rect, st->airport_tile);
 		MergePoint(&rect,
-			st->airport_tile + TILE_XY(
+			st->airport_tile + TileDiffXY(
 				_airport_size_x[st->airport_type] - 1,
 				_airport_size_y[st->airport_type] - 1
 			)
@@ -687,7 +687,7 @@
 	if (rect.max_x >= rect.min_x) {
 		GetAcceptanceAroundTiles(
 			accepts,
-			TILE_XY(rect.min_x, rect.min_y),
+			TileXY(rect.min_x, rect.min_y),
 			rect.max_x - rect.min_x + 1,
 			rect.max_y - rect.min_y + 1,
 			rad
@@ -831,7 +831,7 @@
 		int y = min(TileY(st->train_tile), TileY(tile));
 		curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
 		curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
-		tile = TILE_XY(x,y);
+		tile = TileXY(x, y);
 	} else {
 		// check so the direction is the same
 		if ((_map5[st->train_tile] & 1) != direction) {
@@ -840,19 +840,19 @@
 		}
 
 		// check if the new station adjoins the old station in either direction
-		if (curw == w && st->train_tile == tile + TILE_XY(0, h)) {
+		if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
 			// above
 			curh += h;
-		} else if (curw == w && st->train_tile == tile - TILE_XY(0, curh)) {
+		} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
 			// below
-			tile -= TILE_XY(0, curh);
+			tile -= TileDiffXY(0, curh);
 			curh += h;
-		} else if (curh == h && st->train_tile == tile + TILE_XY(w, 0)) {
+		} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
 			// to the left
 			curw += w;
-		} else if (curh == h && st->train_tile == tile - TILE_XY(curw, 0)) {
+		} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
 			// to the right
-			tile -= TILE_XY(curw, 0);
+			tile -= TileDiffXY(curw, 0);
 			curw += w;
 		} else {
 			_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
@@ -1040,7 +1040,7 @@
 
 		st->build_date = _date;
 
-		tile_delta = direction ? TILE_XY(0,1) : TILE_XY(1,0);
+		tile_delta = direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
 		statspec = (p2 & 0x10) != 0 ? GetCustomStation(STAT_CLASS_DFLT, p2 >> 8) : NULL;
 		layout_ptr = alloca(numtracks * plat_len);
@@ -1062,7 +1062,7 @@
 
 				tile += tile_delta;
 			} while (--w);
-			tile_org += tile_delta ^ TILE_XY(1,1);
+			tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
 		} while (--numtracks);
 
 		UpdateStationVirtCoordDirty(st);
@@ -1090,24 +1090,42 @@
 	// too small?
 	if (w != 0 && h != 0) {
 		// check the left side, x = constant, y changes
-		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(0,i)) ;)
+		for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(0, i));) {
 			// the left side is unused?
-			if (++i==h) { tile += TILE_XY(1, 0); w--; goto restart; }
+			if (++i == h) {
+				tile += TileDiffXY(1, 0);
+				w--;
+				goto restart;
+			}
+		}
 
 		// check the right side, x = constant, y changes
-		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(w-1,i)) ;)
+		for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(w - 1, i));) {
 			// the right side is unused?
-			if (++i==h) { w--; goto restart; }
+			if (++i == h) {
+				w--;
+				goto restart;
+			}
+		}
 
 		// check the upper side, y = constant, x changes
-		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,0)) ;)
+		for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, 0));) {
 			// the left side is unused?
-			if (++i==w) { tile += TILE_XY(0, 1); h--; goto restart; }
+			if (++i == w) {
+				tile += TileDiffXY(0, 1);
+				h--;
+				goto restart;
+			}
+		}
 
 		// check the lower side, y = constant, x changes
-		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,h-1)) ;)
+		for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, h - 1));) {
 			// the left side is unused?
-			if (++i==w) { h--; goto restart; }
+			if (++i == w) {
+				h--;
+				goto restart;
+			}
+		}
 	} else {
 		tile = 0;
 	}
@@ -1162,7 +1180,7 @@
 
 	len = 0;
 	dir = _map5[tile]&1;
-	delta = dir ? TILE_XY(0,1) : TILE_XY(1,0);
+	delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
 	// find starting tile..
 	t = tile;
@@ -1373,10 +1391,10 @@
 				if (flags & DC_EXEC)
 					DoClearSquare(tile);
 			}
-			tile += TILE_XY(1, 0);
+			tile += TileDiffXY(1, 0);
 		} while (--w);
 		w = w_bak;
-		tile = tile + TILE_XY(-w, 1);
+		tile += TileDiffXY(-w, 1);
 	} while (--h);
 
 	if (flags & DC_EXEC) {
@@ -2712,7 +2730,7 @@
 		max_rad = 4;
 	}
 
-	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad,max_rad))
+	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 		cur_tile = TILE_MASK(cur_tile);
 		if (IsTileType(cur_tile, MP_STATION)) {
 			st_index = _map2[cur_tile];
@@ -2761,7 +2779,7 @@
 					break;
 			}
 		}
-	END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad, max_rad))
+	END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 
 	/* no stations around at all? */
 	if (around[0] == INVALID_STATION)
--- a/terraform_gui.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/terraform_gui.c	Sat Jun 25 16:44:57 2005 +0000
@@ -47,7 +47,7 @@
 	size_y = (ey - sy) + 1;
 
 	_generating_world = true;
-	BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
+	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 		if (GetTileType(tile) != MP_WATER) {
 			SetMapExtraBits(tile, (_ctrl_pressed) ? 0 : 1);
 			DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);
--- a/tile.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/tile.c	Sat Jun 25 16:44:57 2005 +0000
@@ -31,11 +31,11 @@
 	}
 
 	min = a = TileHeight(tile);
-	b = TileHeight(tile + TILE_XY(1,0));
+	b = TileHeight(tile + TileDiffXY(1, 0));
 	if (min >= b) min = b;
-	c = TileHeight(tile + TILE_XY(0,1));
+	c = TileHeight(tile + TileDiffXY(0, 1));
 	if (min >= c) min = c;
-	d = TileHeight(tile + TILE_XY(1,1));
+	d = TileHeight(tile + TileDiffXY(1, 1));
 	if (min >= d) min = d;
 
 	r = 0;
--- a/town_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/town_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -1254,26 +1254,24 @@
 				continue;
 
 			if (_housetype_extra_flags[house]&0x10) {
-				if (CheckFree2x2Area(t,tile) ||
-						CheckFree2x2Area(t,(tile+=TILE_XY(-1,0))) ||
-						CheckFree2x2Area(t,(tile+=TILE_XY(0,-1))) ||
-						CheckFree2x2Area(t,(tile+=TILE_XY(1,0))))
-							break;
-				tile += TILE_XY(0,1);
+				if (CheckFree2x2Area(t, tile) ||
+						CheckFree2x2Area(t, (tile += TileDiffXY(-1,  0))) ||
+						CheckFree2x2Area(t, (tile += TileDiffXY( 0, -1))) ||
+						CheckFree2x2Area(t, (tile += TileDiffXY( 1,  0))))
+					break;
+				tile += TileDiffXY(0,1);
 			} else if (_housetype_extra_flags[house]&4) {
-				if (CheckBuildHouseMode(t, tile+TILE_XY(1,0), slope, 0))
-					break;
+				if (CheckBuildHouseMode(t, tile + TileDiffXY(1, 0), slope, 0)) break;
 
-				if (CheckBuildHouseMode(t, tile+TILE_XY(-1,0), slope, 1)) {
-					tile += TILE_XY(-1,0);
+				if (CheckBuildHouseMode(t, tile + TileDiffXY(-1, 0), slope, 1)) {
+					tile += TileDiffXY(-1, 0);
 					break;
 				}
 			} else if (_housetype_extra_flags[house]&8) {
-				if (CheckBuildHouseMode(t, tile+TILE_XY(0,1), slope, 2))
-					break;
+				if (CheckBuildHouseMode(t, tile + TileDiffXY(0, 1), slope, 2)) break;
 
-				if (CheckBuildHouseMode(t, tile+TILE_XY(0,-1), slope, 3)) {
-					tile += TILE_XY(0,-1);
+				if (CheckBuildHouseMode(t, tile + TileDiffXY(0, -1), slope, 3)) {
+					tile += TileDiffXY(0, -1);
 					break;
 				}
 			} else
@@ -1320,8 +1318,8 @@
 		eflags = _housetype_extra_flags[house];
 
 		if (eflags&0x18) {
-			assert(IsTileType(tile + TILE_XY(0,1), MP_CLEAR));
-			ModifyTile(tile + TILE_XY(0,1),
+			assert(IsTileType(tile + TileDiffXY(0, 1), MP_CLEAR));
+			ModifyTile(tile + TileDiffXY(0, 1),
 				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 				t->index,
 				m3lo,			/* map3_lo */
@@ -1332,8 +1330,8 @@
 		}
 
 		if (eflags&0x14) {
-			assert(IsTileType(tile + TILE_XY(1,0), MP_CLEAR));
-			ModifyTile(tile + TILE_XY(1,0),
+			assert(IsTileType(tile + TileDiffXY(1, 0), MP_CLEAR));
+			ModifyTile(tile + TileDiffXY(1, 0),
 				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 				t->index,
 				m3lo,			/* map3_lo */
@@ -1344,8 +1342,8 @@
 		}
 
 		if (eflags&0x10) {
-			assert(IsTileType(tile + TILE_XY(1,1), MP_CLEAR));
-			ModifyTile(tile + TILE_XY(1,1),
+			assert(IsTileType(tile + TileDiffXY(1, 1), MP_CLEAR));
+			ModifyTile(tile + TileDiffXY(1, 1),
 				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 				t->index,
 				m3lo,			/* map3_lo */
@@ -1393,16 +1391,16 @@
 	if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
 		if (_housetype_extra_flags[house-1] & 0x04) {
 			house--;
-			tile += TILE_XY(-1,0);
+			tile += TileDiffXY(-1, 0);
 		} else if (_housetype_extra_flags[house-1] & 0x18) {
 			house--;
-			tile += TILE_XY(0,-1);
+			tile += TileDiffXY(0, -1);
 		} else if (_housetype_extra_flags[house-2] & 0x10) {
 			house-=2;
-			tile += TILE_XY(-1,0);
+			tile += TileDiffXY(-1, 0);
 		} else if (_housetype_extra_flags[house-3] & 0x10) {
 			house-=3;
-			tile += TILE_XY(-1,-1);
+			tile += TileDiffXY(-1, -1);
 		}
 	}
 
@@ -1434,9 +1432,9 @@
 	// Do the actual clearing of tiles
 	eflags = _housetype_extra_flags[house];
 	DoClearTownHouseHelper(tile);
-	if (eflags & 0x14) DoClearTownHouseHelper(tile + TILE_XY(1,0));
-	if (eflags & 0x18) DoClearTownHouseHelper(tile + TILE_XY(0,1));
-	if (eflags & 0x10) DoClearTownHouseHelper(tile + TILE_XY(1,1));
+	if (eflags & 0x14) DoClearTownHouseHelper(tile + TileDiffXY(1, 0));
+	if (eflags & 0x18) DoClearTownHouseHelper(tile + TileDiffXY(0, 1));
+	if (eflags & 0x10) DoClearTownHouseHelper(tile + TileDiffXY(1, 1));
 }
 
 /** Rename a town (server-only).
--- a/tree_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/tree_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -81,7 +81,7 @@
 
 		dist = myabs(x) + myabs(y);
 
-		cur_tile = TILE_MASK(tile + TILE_XY(x,y));
+		cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
 
 		/* Only on tiles within 13 squares from tile,
 		    on clear tiles, and NOT on farm-tiles or rocks */
--- a/tunnelbridge_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/tunnelbridge_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -669,7 +669,7 @@
 	for(;;) {
 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80)
 			break;
-		tile += direction ? TILE_XY(0,-1) : TILE_XY(-1,0);
+		tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
 	}
 
 	start = tile;
@@ -678,7 +678,7 @@
 	for(;;) {
 		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0)
 			break;
-		tile += direction ? TILE_XY(0,1) : TILE_XY(1,0);
+		tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	}
 
 	*endtile = tile;
@@ -745,8 +745,8 @@
 			Omit tile and endtile, since these are already checked, thus solving the problem
 			of bridges over water, or higher bridges, where z is not increased, eg level bridge
 	*/
-	tile		+= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
-	endtile	-= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
+	tile		+= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
+	endtile	-= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	/* Bridges on slopes might have their Z-value offset..correct this */
 	if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile))) != NULL) {
 		VehicleInTheWayErrMsg(v);
@@ -754,8 +754,8 @@
 	}
 
 	/* Put the tiles back to start/end position */
-	tile		-= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
-	endtile	+= direction ? TILE_XY(0, 1) : TILE_XY( 1,0);
+	tile		-= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
+	endtile	+= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
 
 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
@@ -798,7 +798,7 @@
 clear_it:;
 				DoClearSquare(c);
 			}
-			c += direction ? TILE_XY(0,1) : TILE_XY(1,0);
+			c += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 		} while (c <= endtile);
 
 		SetSignalsOnBothDir(tile, direction);
@@ -898,7 +898,7 @@
 				MarkTileDirtyByTile(tile);
 			}
 			cost += (_price.build_rail>>1);
-			tile += _map5[tile]&1 ? TILE_XY(0,1) : TILE_XY(1,0);
+			tile += _map5[tile] & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 		} while (tile <= endtile);
 
 		return cost;
@@ -910,11 +910,11 @@
 // fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
 static uint GetBridgeHeight(const TileInfo *ti)
 {
-	uint delta;
+	TileIndexDiff delta;
 	TileIndex tile = ti->tile;
 
 	// find the end tile of the bridge.
-	delta = (_map5[tile] & 1) ? TILE_XY(0,1) : TILE_XY(1,0);
+	delta = (_map5[tile] & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	do {
 		assert((_map5[tile] & 0xC0) == 0xC0);	// bridge and middle part
 		tile += delta;
@@ -1267,8 +1267,6 @@
 
 static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 {
-	int delta;
-
 	if ((_map5[tile] & 0x80) == 0) {
 		td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3);
 	} else {
@@ -1276,7 +1274,8 @@
 
 		/* scan to the end of the bridge, that's where the owner is stored */
 		if (_map5[tile] & 0x40) {
-			delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0);
+			TileIndexDiff delta = _map5[tile] & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
+
 			do tile += delta; while (_map5[tile] & 0x40);
 		}
 	}
@@ -1495,7 +1494,7 @@
 TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
 {
 	TileIndex tile;
-	TileIndexDiff delta = (v->direction & 2) ? TILE_XY(0, 1) : TILE_XY(1, 0);
+	TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 	byte z = v->z_pos;
 
 	for (tile = v->tile;; tile += delta) {
--- a/unmovable_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/unmovable_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -41,10 +41,10 @@
 		if (p->location_of_house == 0) return CMD_ERROR;
 
 		if (flags & DC_EXEC) {
-			DoClearSquare(p->location_of_house + TILE_XY(0,0));
-			DoClearSquare(p->location_of_house + TILE_XY(0,1));
-			DoClearSquare(p->location_of_house + TILE_XY(1,0));
-			DoClearSquare(p->location_of_house + TILE_XY(1,1));
+			DoClearSquare(p->location_of_house + TileDiffXY(0, 0));
+			DoClearSquare(p->location_of_house + TileDiffXY(0, 1));
+			DoClearSquare(p->location_of_house + TileDiffXY(1, 0));
+			DoClearSquare(p->location_of_house + TileDiffXY(1, 1));
 			p->location_of_house = 0; // reset HQ position
 			InvalidateWindow(WC_COMPANY, (int)p->index);
 		}
@@ -89,10 +89,10 @@
 
 		p->location_of_house = tile;
 
-		ModifyTile(tile + TILE_XY(0,0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x80);
-		ModifyTile(tile + TILE_XY(0,1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x81);
-		ModifyTile(tile + TILE_XY(1,0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
-		ModifyTile(tile + TILE_XY(1,1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
+		ModifyTile(tile + TileDiffXY(0, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x80);
+		ModifyTile(tile + TileDiffXY(0, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x81);
+		ModifyTile(tile + TileDiffXY(1, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
+		ModifyTile(tile + TileDiffXY(1, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
 		UpdatePlayerHouse(p, score);
 		InvalidateWindow(WC_COMPANY, (int)p->index);
 	}
@@ -322,9 +322,7 @@
 /* checks, if a radio tower is within a 9x9 tile square around tile */
 static bool checkRadioTowerNearby(TileIndex tile)
 {
-	TileIndex tile_s;
-
-	tile_s = TILE_XY(TileX(tile) - 4, TileY(tile) - 4);
+	TileIndex tile_s = tile - TileDiffXY(4, 4);
 
 	BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
 		// already a radio tower here?
@@ -375,10 +373,10 @@
 		dir = r >> 30;
 		r %= (dir == 0 || dir == 2) ? MapMaxY() : MapMaxX();
 		tile =
-			(dir==0)?TILE_XY(0,r):0 +             // left
-			(dir==1)?TILE_XY(r,0):0 +             // top
-			(dir == 2) ? TILE_XY(MapMaxX(), r) : 0 + // right
-			(dir == 3) ? TILE_XY(r, MapMaxY()) : 0;  // bottom
+			(dir == 0) ? TileXY(0, r)         : 0 + // left
+			(dir == 1) ? TileXY(r, 0)         : 0 + // top
+			(dir == 2) ? TileXY(MapMaxX(), r) : 0 + // right
+			(dir == 3) ? TileXY(r, MapMaxY()) : 0;  // bottom
 		j = 20;
 		do {
 			if (--j == 0)
--- a/water_cmd.c	Sat Jun 25 06:15:43 2005 +0000
+++ b/water_cmd.c	Sat Jun 25 16:44:57 2005 +0000
@@ -41,7 +41,7 @@
 	tile = TileVirtXY(x, y);
 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 
-	tile2 = tile + (p1 ? TILE_XY(0,1) : TILE_XY(1,0));
+	tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
 	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
 
 	if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
@@ -87,7 +87,7 @@
 	if (!EnsureNoVehicle(tile))
 		return CMD_ERROR;
 
-	tile2 = tile + ((_map5[tile] & 2) ? TILE_XY(0,1) : TILE_XY(1,0));
+	tile2 = tile + ((_map5[tile] & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
 
 	if (!EnsureNoVehicle(tile2))
 		return CMD_ERROR;
@@ -210,7 +210,7 @@
 	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
 
 	cost = 0;
-	BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
+	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 		ret = 0;
 		if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
 
@@ -306,8 +306,8 @@
 			return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 
 		if (m5 == 0x80 || m5 == 0x82) {}
-		else if (m5 == 0x81) { tile -= TILE_XY(1,0); }
-		else if (m5 == 0x83) { tile -= TILE_XY(0,1); }
+		else if (m5 == 0x81) { tile -= TileDiffXY(1, 0); }
+		else if (m5 == 0x83) { tile -= TileDiffXY(0, 1); }
 		else
 			return CMD_ERROR;
 
@@ -680,7 +680,7 @@
 
 	if (IS_BYTE_INSIDE(m5, 0, 3+1)) {
 		if (m5 & 1)
-			tile += (m5==1) ? TILE_XY(-1,0) : TILE_XY(0,-1);
+			tile += (m5 == 1) ? TileDiffXY(-1, 0) : TileDiffXY(0, -1);
 		ShowShipDepotWindow(tile);
 	}
 }