(svn r1386) Move TileIndexDiff to map.h
authortron
Wed, 05 Jan 2005 13:32:03 +0000
changeset 900 feed1801fd35
parent 899 93b0626ddfce
child 901 c92d5da1acb3
(svn r1386) Move TileIndexDiff to map.h
Move _tileoffs_by_dir to map.[ch] and encapsulate it in TileOffsByDir()
ai.c
ai_build.c
ai_new.c
clear_cmd.c
disaster_cmd.c
macros.h
map.c
map.h
misc.c
pathfind.c
rail_gui.c
road_gui.c
roadveh_cmd.c
ship_cmd.c
station_cmd.c
town_cmd.c
train_cmd.c
tunnelbridge_cmd.c
variables.h
water_cmd.c
--- a/ai.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/ai.c	Wed Jan 05 13:32:03 2005 +0000
@@ -1716,7 +1716,7 @@
 	unk &= (int)r;
 
 	do {
-		tile = TILE_MASK(tile + _tileoffs_by_dir[dir]);
+		tile = TILE_MASK(tile + TileOffsByDir(dir));
 
 		r >>= 2;
 		if (r&2) {
@@ -1822,7 +1822,7 @@
 
 	while (p->mode != 3 || !((--cmd) & 0x80)) p++;
 
-	return tile + p->tileoffs - _tileoffs_by_dir[*dir = p->attr];
+	return tile + p->tileoffs - TileOffsByDir(*dir = p->attr);
 }
 
 typedef struct AiRailPathFindData {
@@ -1855,7 +1855,7 @@
 	arpfd.tile2 = p->ai.cur_tile_a;
 	arpfd.flag = false;
 	arpfd.count = 0;
-	FollowTrack(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a], 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
+	FollowTrack(p->ai.cur_tile_a + TileOffsByDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
 		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
 	return arpfd.count > 8;
 }
@@ -1961,8 +1961,8 @@
 		// Allow bridges directly over bottom tiles
 		flag = arf->ti.z == 0;
 		for(;;) {
-			if (tile_new < -_tileoffs_by_dir[dir2]) return; // Wraping around map, no bridge possible!
-			tile_new = TILE_MASK(tile_new + _tileoffs_by_dir[dir2]);
+			if (tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
+			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
 			FindLandscapeHeightByTile(&arf->ti, tile_new);
 			if (arf->ti.tileh != 0 || arf->ti.type == MP_CLEAR || arf->ti.type == MP_TREES) {
 				if (!flag) return;
@@ -2008,7 +2008,7 @@
 {
 	const byte *p;
 
-	tile = TILE_MASK(tile + _tileoffs_by_dir[dir]);
+	tile = TILE_MASK(tile + TileOffsByDir(dir));
 
 	// Reached destination?
 	if (tile == arf->final_tile) {
@@ -2126,7 +2126,7 @@
 		return;
 	}
 
-	p->ai.cur_tile_a += _tileoffs_by_dir[p->ai.cur_dir_a];
+	p->ai.cur_tile_a += TileOffsByDir(p->ai.cur_dir_a);
 
 	if (arf.best_ptr[0]&0x80) {
 		int i;
@@ -2183,7 +2183,7 @@
 			// Clear the tunnel and continue at the other side of it.
 			if (DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
 				return false;
-			p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - _tileoffs_by_dir[p->ai.cur_dir_a]);
+			p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDir(p->ai.cur_dir_a));
 			return true;
 		}
 
@@ -2195,7 +2195,7 @@
 				return false;
 
 			// Find other side of bridge.
-			offs = _tileoffs_by_dir[p->ai.cur_dir_a];
+			offs = TileOffsByDir(p->ai.cur_dir_a);
 			do {
 				tile = TILE_MASK(tile - offs);
 			} while (_map5[tile] & 0x40);
@@ -2233,7 +2233,7 @@
 	p->ai.cur_dir_a = ptr[1] ^ 2;
 
 	// And then also switch tile.
-	p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - _tileoffs_by_dir[p->ai.cur_dir_a]);
+	p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - TileOffsByDir(p->ai.cur_dir_a));
 
 	return true;
 }
@@ -2332,7 +2332,7 @@
 	p->ai.cur_tile_a = tile;
 	p->ai.start_dir_a = dir;
 	p->ai.cur_dir_a = dir;
-	DoCommandByTile(TILE_MASK(tile + _tileoffs_by_dir[dir]), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
+	DoCommandByTile(TILE_MASK(tile + TileOffsByDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
 
 	assert(TILE_MASK(tile) != 0xFF00);
 
@@ -2343,7 +2343,7 @@
 	p->ai.cur_tile_b = tile;
 	p->ai.start_dir_b = dir;
 	p->ai.cur_dir_b = dir;
-	DoCommandByTile(TILE_MASK(tile + _tileoffs_by_dir[dir]), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
+	DoCommandByTile(TILE_MASK(tile + TileOffsByDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
 
 	assert(TILE_MASK(tile) != 0xFF00);
 
@@ -2771,7 +2771,7 @@
 	uint tile2;
 
 	if (dist <= a->best_dist) {
-		tile2 = TILE_MASK(tile + _tileoffs_by_dir[_dir_by_track[track]]);
+		tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
 		if (IS_TILETYPE(tile2, MP_STREET) &&
 				(_map5[tile2]&0xF0) == 0) {
 			a->best_dist = dist;
@@ -2799,7 +2799,7 @@
 	int i;
 
 	are.dest = p->ai.cur_tile_b;
-	tile = TILE_MASK(p->ai.cur_tile_a + _tileoffs_by_dir[dir]);
+	tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(dir));
 
 	bits = GetTileTrackStatus(tile, TRANSPORT_ROAD) & _ai_road_table_and[dir];
 	if (bits == 0) {
@@ -2850,8 +2850,8 @@
 		// Allow bridges directly over bottom tiles
 		flag = arf->ti.z == 0;
 		for(;;) {
-			if (tile_new < -_tileoffs_by_dir[dir2]) return; // Wraping around map, no bridge possible!
-			tile_new = TILE_MASK(tile_new + _tileoffs_by_dir[dir2]);
+			if (tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
+			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
 			FindLandscapeHeightByTile(&arf->ti, tile_new);
 			if (arf->ti.tileh != 0 || arf->ti.type == MP_CLEAR || arf->ti.type == MP_TREES) {
 				// Allow a bridge if either we have a tile that's water, rail or street,
@@ -2899,7 +2899,7 @@
 {
 	const byte *p;
 
-	tile = TILE_MASK(tile + _tileoffs_by_dir[dir]);
+	tile = TILE_MASK(tile + TileOffsByDir(dir));
 
 	// Reached destination?
 	if (tile == arf->final_tile) {
@@ -3001,14 +3001,14 @@
 		if (++p->ai.state_counter == 21) {
 			p->ai.state_mode = 1;
 
-			p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a]);
+			p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(p->ai.cur_dir_a));
 			p->ai.cur_dir_a ^= 2;
 			p->ai.state_counter = 0;
 		}
 		return;
 	}
 
-	tile = TILE_MASK(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a]);
+	tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(p->ai.cur_dir_a));
 
 	if (arf.best_ptr[0]&0x80) {
 		int i;
@@ -3696,7 +3696,7 @@
 			static const byte _depot_bits[] = {0x19,0x16,0x25,0x2A};
 
 			m5 &= 3;
-			if (GetRailTrackStatus(tile + _tileoffs_by_dir[m5]) & _depot_bits[m5])
+			if (GetRailTrackStatus(tile + TileOffsByDir(m5)) & _depot_bits[m5])
 				return;
 
 			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
@@ -3732,7 +3732,7 @@
 
 			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 			DoCommandByTile(
-				TILE_MASK(tile + _tileoffs_by_dir[dir]),
+				TILE_MASK(tile + TileOffsByDir(dir)),
 				8 >> (dir ^ 2),
 				0,
 				DC_EXEC,
--- a/ai_build.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/ai_build.c	Wed Jan 05 13:32:03 2005 +0000
@@ -250,7 +250,7 @@
     	r = DoCommandByTile(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
     	if (r == CMD_ERROR) return r;
     	// Try to build the road from the depot
-    	r2 = DoCommandByTile(tile + _tileoffs_by_dir[direction], _roadbits_by_dir[direction], 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
+    	r2 = DoCommandByTile(tile + TileOffsByDir(direction), _roadbits_by_dir[direction], 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
     	// If it fails, ignore it..
     	if (r2 == CMD_ERROR) return r;
     	return r + r2;
--- a/ai_new.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/ai_new.c	Wed Jan 05 13:32:03 2005 +0000
@@ -745,16 +745,16 @@
 
 	for (i=2;i<p->ainew.path_info.route_length-2;i++) {
 		tile = p->ainew.path_info.route[i];
-		for (j=0;j<lengthof(_tileoffs_by_dir);j++) {
-			if (IS_TILETYPE(tile + _tileoffs_by_dir[j], MP_STREET)) {
+		for (j = 0; j < 4; j++) {
+			if (IS_TILETYPE(tile + TileOffsByDir(j), MP_STREET)) {
 				// Its a street, test if it is a depot
-				if (_map5[tile + _tileoffs_by_dir[j]] & 0x20) {
+				if (_map5[tile + TileOffsByDir(j)] & 0x20) {
 					// We found a depot, is it ours? (TELL ME!!!)
-					if (_map_owner[tile + _tileoffs_by_dir[j]] == _current_player) {
+					if (_map_owner[tile + TileOffsByDir(j)] == _current_player) {
 						// Now, is it pointing to the right direction.........
-						if ((_map5[tile + _tileoffs_by_dir[j]] & 3) == (j ^ 2)) {
+						if ((_map5[tile + TileOffsByDir(j)] & 3) == (j ^ 2)) {
 							// Yeah!!!
-							p->ainew.depot_tile = tile + _tileoffs_by_dir[j];
+							p->ainew.depot_tile = tile + TileOffsByDir(j);
 							p->ainew.depot_direction = j ^ 2; // Reverse direction
 							p->ainew.state = AI_STATE_VERIFY_ROUTE;
 							return;
@@ -781,28 +781,28 @@
 
 		tile = p->ainew.path_info.route[i];
 
-		for (j=0;j<lengthof(_tileoffs_by_dir);j++) {
+		for (j = 0; j < 4; j++) {
 			// It may not be placed on the road/rail itself
 			// And because it is not build yet, we can't see it on the tile..
 			// So check the surrounding tiles :)
-			if (tile + _tileoffs_by_dir[j] == p->ainew.path_info.route[i-1] ||
-				tile + _tileoffs_by_dir[j] == p->ainew.path_info.route[i+1]) continue;
+			if (tile + TileOffsByDir(j) == p->ainew.path_info.route[i-1] ||
+					tile + TileOffsByDir(j) == p->ainew.path_info.route[i+1]) continue;
 			// Not around a bridge?
 			if (p->ainew.path_info.route_extra[i] != 0) continue;
 			if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) continue;
 			// Is the terrain clear?
-			if (IS_TILETYPE(tile + _tileoffs_by_dir[j], MP_CLEAR) ||
-				IS_TILETYPE(tile + _tileoffs_by_dir[j], MP_TREES)) {
+			if (IS_TILETYPE(tile + TileOffsByDir(j), MP_CLEAR) ||
+					IS_TILETYPE(tile + TileOffsByDir(j), MP_TREES)) {
 				TileInfo ti;
 				FindLandscapeHeightByTile(&ti, tile);
 				// If the current tile is on a slope (tileh != 0) then we do not allow this
 				if (ti.tileh != 0) continue;
 				// Check if everything went okay..
-				r = AiNew_Build_Depot(p, tile + _tileoffs_by_dir[j], j ^ 2, 0);
+				r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0);
 				if (r == CMD_ERROR) continue;
 				// Found a spot!
 				p->ainew.new_cost += r;
-				p->ainew.depot_tile = tile + _tileoffs_by_dir[j];
+				p->ainew.depot_tile = tile + TileOffsByDir(j);
 				p->ainew.depot_direction = j ^ 2; // Reverse direction
 				p->ainew.state = AI_STATE_VERIFY_ROUTE;
 				return;
@@ -984,14 +984,14 @@
         	int i, r;
         	for (i=0;i<2;i++) {
             	if (i == 0) {
-            		tile = p->ainew.from_tile + _tileoffs_by_dir[p->ainew.from_direction];
+            		tile = p->ainew.from_tile + TileOffsByDir(p->ainew.from_direction);
             		dir1 = p->ainew.from_direction - 1;
             		if (dir1 < 0) dir1 = 3;
             		dir2 = p->ainew.from_direction + 1;
             		if (dir2 > 3) dir2 = 0;
             		dir3 = p->ainew.from_direction;
             	} else {
-            		tile = p->ainew.to_tile + _tileoffs_by_dir[p->ainew.to_direction];
+            		tile = p->ainew.to_tile + TileOffsByDir(p->ainew.to_direction);
             		dir1 = p->ainew.to_direction - 1;
             		if (dir1 < 0) dir1 = 3;
             		dir2 = p->ainew.to_direction + 1;
@@ -1001,7 +1001,7 @@
 
             	r = DoCommandByTile(tile, _roadbits_by_dir[dir1], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 				if (r != CMD_ERROR) {
-					dir1 = _tileoffs_by_dir[dir1];
+					dir1 = TileOffsByDir(dir1);
 					if (IS_TILETYPE(tile+dir1, MP_CLEAR) || IS_TILETYPE(tile+dir1, MP_TREES)) {
 						r = DoCommandByTile(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						if (r != CMD_ERROR) {
@@ -1013,7 +1013,7 @@
 
 				r = DoCommandByTile(tile, _roadbits_by_dir[dir2], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 				if (r != CMD_ERROR) {
-					dir2 = _tileoffs_by_dir[dir2];
+					dir2 = TileOffsByDir(dir2);
 					if (IS_TILETYPE(tile+dir2, MP_CLEAR) || IS_TILETYPE(tile+dir2, MP_TREES)) {
 						r = DoCommandByTile(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						if (r != CMD_ERROR) {
@@ -1025,7 +1025,7 @@
 
 				r = DoCommandByTile(tile, _roadbits_by_dir[dir3^2], 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 				if (r != CMD_ERROR) {
-					dir3 = _tileoffs_by_dir[dir3];
+					dir3 = TileOffsByDir(dir3);
 					if (IS_TILETYPE(tile+dir3, MP_CLEAR) || IS_TILETYPE(tile+dir3, MP_TREES)) {
 						r = DoCommandByTile(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
 						if (r != CMD_ERROR) {
@@ -1061,7 +1061,7 @@
 	}
 
 	// There is a bus on the tile we want to build road on... idle till he is gone! (BAD PERSON! :p)
-	if (!EnsureNoVehicle(p->ainew.depot_tile + _tileoffs_by_dir[p->ainew.depot_direction]))
+	if (!EnsureNoVehicle(p->ainew.depot_tile + TileOffsByDir(p->ainew.depot_direction)))
 		return;
 
 	res = AiNew_Build_Depot(p, p->ainew.depot_tile, p->ainew.depot_direction, DC_EXEC);
--- a/clear_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/clear_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -751,7 +751,7 @@
 				_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (2<<2));
 				do {
 					if (--j == 0) goto get_out;
-					tile_new = tile + _tileoffs_by_dir[Random() & 3];
+					tile_new = tile + TileOffsByDir(Random() & 3);
 				} while (!IS_TILETYPE(tile_new, MP_CLEAR));
 				tile = tile_new;
 			}
--- a/disaster_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/disaster_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -646,7 +646,7 @@
 	if (!(v->tick_counter&1))
 		return;
 
-	tile = v->tile + _tileoffs_by_dir[v->direction >> 1];
+	tile = v->tile + TileOffsByDir(v->direction >> 1);
 	if (IsValidTile(tile) &&
 			(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
 			!CHANCE16(1,90)) {
@@ -909,7 +909,7 @@
 
 				{
 					uint tile = i->xy;
-					int step = _tileoffs_by_dir[Random() & 3];
+					int step = TileOffsByDir(Random() & 3);
 					int count = 30;
 					do {
 						DisasterClearSquare(tile);
--- a/macros.h	Wed Jan 05 13:15:27 2005 +0000
+++ b/macros.h	Wed Jan 05 13:32:03 2005 +0000
@@ -148,13 +148,7 @@
 }
 
 
-#if TILE_X_BITS + TILE_Y_BITS <= 16
-	typedef uint16 TileIndex;
-	typedef int16 TileIndexDiff;
-#else
-	typedef uint32 TileIndex;
-	typedef int32 TileIndexDiff;
-#endif
+typedef uint16 TileIndex;
 
 /* [min,max), strictly less than */
 #define IS_BYTE_INSIDE(a,min,max) ((byte)((a)-(min)) < (byte)((max)-(min)))
--- a/map.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/map.c	Wed Jan 05 13:32:03 2005 +0000
@@ -14,3 +14,10 @@
 byte   _map_owner           [MAP_SIZE];
 uint16 _map2                [MAP_SIZE];
 byte   _map_extra_bits      [MAP_SIZE / 4];
+
+const TileIndexDiff _tileoffs_by_dir[4] = {
+	TILE_XY(-1, 0),
+	TILE_XY(0, 1),
+	TILE_XY(1, 0),
+	TILE_XY(0, -1),
+};
--- a/map.h	Wed Jan 05 13:15:27 2005 +0000
+++ b/map.h	Wed Jan 05 13:32:03 2005 +0000
@@ -24,4 +24,15 @@
 /* The number of tiles in the map */
 static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); }
 
+typedef int16 TileIndexDiff;
+
+
+static inline TileIndexDiff TileOffsByDir(uint dir)
+{
+	extern const TileIndexDiff _tileoffs_by_dir[4];
+
+	assert(dir < lengthof(_tileoffs_by_dir));
+	return _tileoffs_by_dir[dir];
+}
+
 #endif
--- a/misc.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/misc.c	Wed Jan 05 13:32:03 2005 +0000
@@ -361,13 +361,6 @@
 	return free_item | 0x7800 | (skip << 8);
 }
 
-const TileIndexDiff _tileoffs_by_dir[4] = {
-	TILE_XY(-1, 0),
-	TILE_XY(0, 1),
-	TILE_XY(1, 0),
-	TILE_XY(0, -1),
-};
-
 
 #define M(a,b) ((a<<5)|b)
 static const uint16 _month_date_from_year_day[] = {
--- a/pathfind.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/pathfind.c	Wed Jan 05 13:32:03 2005 +0000
@@ -140,7 +140,7 @@
 	// This addition will sometimes overflow by a single tile.
 	// The use of TILE_MASK here makes sure that we still point at a valid
 	// tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail.
-	tile = TILE_MASK(tile + _tileoffs_by_dir[direction]);
+	tile = TILE_MASK(tile + TileOffsByDir(direction));
 
 	/* Check in case of rail if the owner is the same */
 	if (tpf->tracktype == TRANSPORT_RAIL) {
@@ -283,7 +283,7 @@
 			return;
 		tile = SkipToEndOfTunnel(tpf, tile, direction);
 	}
-	tile += _tileoffs_by_dir[direction];
+	tile += TileOffsByDir(direction);
 
 	/* Check in case of rail if the owner is the same */
 	if (tpf->tracktype == TRANSPORT_RAIL) {
@@ -638,7 +638,7 @@
 	tile_org = tile;
 
 	for(;;) {
-		tile += _tileoffs_by_dir[direction];
+		tile += TileOffsByDir(direction);
 
 		// too long search length? bail out.
 		if (++si.cur_length >= tpf->maxlength)
--- a/rail_gui.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/rail_gui.c	Wed Jan 05 13:32:03 2005 +0000
@@ -98,7 +98,7 @@
 		SndPlayTileFx(SND_20_SPLAT_2, tile);
 		ResetObjectToPlace();
 
-		tile += _tileoffs_by_dir[dir];
+		tile += TileOffsByDir(dir);
 
 		if (IS_TILETYPE(tile, MP_RAILWAY)) {
 			PlaceExtraDepotRail(tile, _place_depot_extra[dir]);
--- a/road_gui.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/road_gui.c	Wed Jan 05 13:32:03 2005 +0000
@@ -65,7 +65,7 @@
 static void BuildRoadOutsideStation(uint tile, int direction)
 {
 	static const byte _roadbits_by_dir[4] = {2,1,8,4};
-	tile += _tileoffs_by_dir[direction];
+	tile += TileOffsByDir(direction);
 	// if there is a roadpiece just outside of the station entrance, build a connecting route
 	if (IS_TILETYPE(tile, MP_STREET) && !(_map5[tile]&0x20)) {
 		DoCommandP(tile, _roadbits_by_dir[direction], 0, NULL, CMD_BUILD_ROAD);
--- a/roadveh_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/roadveh_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -866,7 +866,7 @@
 	if (FindRoadVehToOvertake(&od))
 		return;
 
-	od.tile = v->tile + _tileoffs_by_dir[v->direction>>1];
+	od.tile = v->tile + TileOffsByDir(v->direction >> 1);
 	if (FindRoadVehToOvertake(&od))
 		return;
 
@@ -1009,7 +1009,7 @@
 		if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
 			m5 -= 0x43;
 do_it:;
-			desttile += _tileoffs_by_dir[m5&3];
+			desttile += TileOffsByDir(m5 & 3);
 			if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) {
 				return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3]));
 			}
@@ -1178,7 +1178,7 @@
 
 // switch to another tile
 	if (rd.x & 0x80) {
-		uint tile = v->tile + _tileoffs_by_dir[rd.x&3];
+		uint tile = v->tile + TileOffsByDir(rd.x & 3);
 		int dir = RoadFindPathToDest(v, tile, rd.x&3);
 		int tmp;
 		uint32 r;
--- a/ship_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/ship_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -546,7 +546,7 @@
 	uint tile2;
 
 	assert(dir>=0 && dir<=3);
-	tile2 = TILE_ADD(tile, -_tileoffs_by_dir[dir]);
+	tile2 = TILE_ADD(tile, -TileOffsByDir(dir));
 	dir ^= 2;
 	tot_dist = (uint)-1;
 	b = GetTileShipTrackStatus(tile2) & _ship_sometracks[dir] & v->u.ship.state;
--- a/station_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/station_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -1812,7 +1812,7 @@
 	if (cost == CMD_ERROR)
 		return CMD_ERROR;
 
-	tile_cur = (tile=ti.tile) + _tileoffs_by_dir[direction];
+	tile_cur = (tile=ti.tile) + TileOffsByDir(direction);
 
 	if (!EnsureNoVehicle(tile_cur))
 		return CMD_ERROR;
@@ -1825,7 +1825,7 @@
 	if (cost == CMD_ERROR)
 		return CMD_ERROR;
 
-	tile_cur = tile_cur + _tileoffs_by_dir[direction];
+	tile_cur = tile_cur + TileOffsByDir(direction);
 	FindLandscapeHeightByTile(&ti, tile_cur);
 	if (ti.tileh != 0 || ti.type != MP_WATER)
 		return_cmd_error(STR_304B_SITE_UNSUITABLE);
@@ -1887,7 +1887,7 @@
 			st->index,
 			direction + 0x4C);
 
-		ModifyTile(tile + _tileoffs_by_dir[direction],
+		ModifyTile(tile + TileOffsByDir(direction),
 			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR |
 			MP_MAP5,
@@ -1909,7 +1909,7 @@
 		return CMD_ERROR;
 
 	tile1 = st->dock_tile;
-	tile2 = tile1 + _tileoffs_by_dir[_map5[tile1] - 0x4C];
+	tile2 = tile1 + TileOffsByDir(_map5[tile1] - 0x4C);
 
 	if (!EnsureNoVehicle(tile1))
 		return CMD_ERROR;
@@ -2174,7 +2174,7 @@
 
 	if (v->type == VEH_Train) {
 		if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == 0 &&
-			!IsTrainStationTile(tile + _tileoffs_by_dir[v->direction >> 1])) {
+			!IsTrainStationTile(tile + TileOffsByDir(v->direction >> 1))) {
 
 			station_id = _map2[tile];
 			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
--- a/town_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/town_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -655,7 +655,7 @@
 	do {
 		if (++j == 0)
 			goto build_road_and_exit;
-		tmptile = TILE_MASK(tmptile + _tileoffs_by_dir[i]);
+		tmptile = TILE_MASK(tmptile + TileOffsByDir(i));
 	} while (IS_WATER_TILE(tmptile));
 
 	// no water tiles in between?
--- a/train_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/train_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -984,7 +984,7 @@
 			t = (t - 1) & 3;
 		}
 		/* Calculate next tile */
-		tile += _tileoffs_by_dir[t];
+		tile += TileOffsByDir(t);
 		/* Test if we have a rail/road-crossing */
 		if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0)==0x10) {
 			/* Check if there is a train on the tile itself */
@@ -1471,7 +1471,7 @@
 		fd.best_bird_dist = (uint)-1;
 		fd.best_track_dist = (uint)-1;
 		fd.best_track = 0xFF;
-		NewTrainPathfind(tile - _tileoffs_by_dir[direction], direction, (TPFEnumProc*)TrainTrackFollower, &fd, NULL);
+		NewTrainPathfind(tile - TileOffsByDir(direction), direction, (TPFEnumProc*)TrainTrackFollower, &fd, NULL);
 
 //		printf("Train %d %s\n", v->unitnumber, fd.best_track_dist == -1 ? "NOTFOUND" : "FOUND");
 
@@ -2271,7 +2271,7 @@
 			v->subspeed = 0;
 			v->progress = 255-10;
 			if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) {
-				uint o_tile = gp.new_tile + _tileoffs_by_dir[dir>>1];
+				uint o_tile = gp.new_tile + TileOffsByDir(dir >> 1);
 				/* check if a train is waiting on the other side */
 				if (VehicleFromPos(o_tile, (void*)( (o_tile<<8) | (dir^4)), (VehicleFromPosProc*)CheckVehicleAtSignal) == NULL)
 					return;
@@ -2452,7 +2452,7 @@
 		t = (t - 1) & 3;
 	}
 	/* Calculate next tile */
-	tile += _tileoffs_by_dir[t];
+	tile += TileOffsByDir(t);
 	// determine the track status on the next tile.
  	ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _reachable_tracks[t];
 
--- a/tunnelbridge_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/tunnelbridge_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -397,7 +397,7 @@
 	TileInfo ti;
 	int delta;
 
-	delta = _tileoffs_by_dir[dir];
+	delta = TileOffsByDir(dir);
 
 	do {
 		tile -= delta;
@@ -588,7 +588,8 @@
 {
 	int z = GetTileZ(tile);
 	byte m5 = _map5[tile];
-	int delta = _tileoffs_by_dir[m5 & 3], len = 0;
+	int delta = TileOffsByDir(m5 & 3);
+	int len = 0;
 	uint starttile = tile;
 	Vehicle *v;
 
--- a/variables.h	Wed Jan 05 13:15:27 2005 +0000
+++ b/variables.h	Wed Jan 05 13:32:03 2005 +0000
@@ -416,8 +416,6 @@
 extern const byte _airport_size_x[5];
 extern const byte _airport_size_y[5];
 
-extern const TileIndexDiff _tileoffs_by_dir[4];
-
 /* misc */
 VARDEF byte str_buffr[512];
 VARDEF char _screenshot_name[128];
--- a/water_cmd.c	Wed Jan 05 13:15:27 2005 +0000
+++ b/water_cmd.c	Wed Jan 05 13:32:03 2005 +0000
@@ -121,7 +121,7 @@
 	ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 	if (ret == CMD_ERROR) return CMD_ERROR;
 
-	delta = _tileoffs_by_dir[dir];
+	delta = TileOffsByDir(dir);
 	// lower tile
 	ret = DoCommandByTile(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 	if (ret == CMD_ERROR) return CMD_ERROR;
@@ -143,7 +143,7 @@
 
 static int32 RemoveShiplift(uint tile, uint32 flags)
 {
-	int delta = _tileoffs_by_dir[_map5[tile] & 3];
+	int delta = TileOffsByDir(_map5[tile] & 3);
 
 	// make sure no vehicle is on the tile.
 	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))