summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-05 13:32:03 +0000
committertron <tron@openttd.org>2005-01-05 13:32:03 +0000
commit67161506ad98a7636d3c9f141b5595481d079e93 (patch)
treeb9a5829b3d37c53a2de48d1ef28960f41804f4dc
parent2543158c8e0d105148bc38522fba43aa3428d76a (diff)
downloadopenttd-67161506ad98a7636d3c9f141b5595481d079e93.tar.xz
(svn r1386) Move TileIndexDiff to map.h
Move _tileoffs_by_dir to map.[ch] and encapsulate it in TileOffsByDir()
-rw-r--r--ai.c42
-rw-r--r--ai_build.c2
-rw-r--r--ai_new.c38
-rw-r--r--clear_cmd.c2
-rw-r--r--disaster_cmd.c4
-rw-r--r--macros.h8
-rw-r--r--map.c7
-rw-r--r--map.h11
-rw-r--r--misc.c7
-rw-r--r--pathfind.c6
-rw-r--r--rail_gui.c2
-rw-r--r--road_gui.c2
-rw-r--r--roadveh_cmd.c6
-rw-r--r--ship_cmd.c2
-rw-r--r--station_cmd.c10
-rw-r--r--town_cmd.c2
-rw-r--r--train_cmd.c8
-rw-r--r--tunnelbridge_cmd.c5
-rw-r--r--variables.h2
-rw-r--r--water_cmd.c4
20 files changed, 87 insertions, 83 deletions
diff --git a/ai.c b/ai.c
index 2be8243c1..e9b913ddf 100644
--- a/ai.c
+++ b/ai.c
@@ -1716,7 +1716,7 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
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 @@ static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd
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 @@ static bool AiDoFollowTrack(Player *p)
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 @@ static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile,
// 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 @@ static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
{
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 @@ static void AiBuildRailConstruct(Player *p)
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 @@ static bool AiRemoveTileAndGoForward(Player *p)
// 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 @@ static bool AiRemoveTileAndGoForward(Player *p)
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 @@ static bool AiRemoveTileAndGoForward(Player *p)
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 @@ static void AiStateBuildRail(Player *p)
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 @@ static void AiStateBuildRail(Player *p)
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 @@ static bool AiEnumFollowRoad(uint tile, AiRoadEnum *a, int track, uint length, b
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 @@ static bool AiCheckRoadFinished(Player *p)
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 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile,
// 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 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
{
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 @@ do_some_terraform:
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 @@ pos_3:
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 @@ pos_3:
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,
diff --git a/ai_build.c b/ai_build.c
index 2530a78b6..e8f9edf95 100644
--- a/ai_build.c
+++ b/ai_build.c
@@ -250,7 +250,7 @@ int AiNew_Build_Depot(Player *p, uint tile, byte direction, byte flag) {
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;
diff --git a/ai_new.c b/ai_new.c
index 56370f68e..66b28c454 100644
--- a/ai_new.c
+++ b/ai_new.c
@@ -745,16 +745,16 @@ static void AiNew_State_FindDepot(Player *p) {
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 @@ static void AiNew_State_FindDepot(Player *p) {
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 @@ static void AiNew_State_BuildPath(Player *p) {
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 @@ static void AiNew_State_BuildPath(Player *p) {
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 @@ static void AiNew_State_BuildPath(Player *p) {
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 @@ static void AiNew_State_BuildPath(Player *p) {
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 @@ static void AiNew_State_BuildDepot(Player *p) {
}
// 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);
diff --git a/clear_cmd.c b/clear_cmd.c
index 319412592..4356cb729 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -751,7 +751,7 @@ void GenerateClearTile()
_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;
}
diff --git a/disaster_cmd.c b/disaster_cmd.c
index 141d1840f..d82167e9c 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -646,7 +646,7 @@ static void DisasterTick_5_and_6(Vehicle *v)
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 @@ static void Disaster7_Init()
{
uint tile = i->xy;
- int step = _tileoffs_by_dir[Random() & 3];
+ int step = TileOffsByDir(Random() & 3);
int count = 30;
do {
DisasterClearSquare(tile);
diff --git a/macros.h b/macros.h
index 61351d9e1..24be9a911 100644
--- a/macros.h
+++ b/macros.h
@@ -148,13 +148,7 @@ static inline int FindFirstBit2x64(int value)
}
-#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)))
diff --git a/map.c b/map.c
index 1c349e40f..b67355ecf 100644
--- a/map.c
+++ b/map.c
@@ -14,3 +14,10 @@ byte _map3_hi [MAP_SIZE];
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),
+};
diff --git a/map.h b/map.h
index a62f65f34..7a5ed5ff4 100644
--- a/map.h
+++ b/map.h
@@ -24,4 +24,15 @@ static inline uint MapMaxY(void) { return MapSizeY() - 1; }
/* 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
diff --git a/misc.c b/misc.c
index a1bd0fc15..67bc2c8ff 100644
--- a/misc.c
+++ b/misc.c
@@ -361,13 +361,6 @@ StringID RealAllocateName(const byte *name, byte skip, bool check_double)
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[] = {
diff --git a/pathfind.c b/pathfind.c
index fc71369e0..730c26aa4 100644
--- a/pathfind.c
+++ b/pathfind.c
@@ -140,7 +140,7 @@ static void TPFMode2(TrackPathFinder *tpf, uint tile, int direction)
// 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 @@ static void TPFMode1(TrackPathFinder *tpf, uint tile, int direction)
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 @@ restart:
tile_org = tile;
for(;;) {
- tile += _tileoffs_by_dir[direction];
+ tile += TileOffsByDir(direction);
// too long search length? bail out.
if (++si.cur_length >= tpf->maxlength)
diff --git a/rail_gui.c b/rail_gui.c
index 70e484a20..f80590e68 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -98,7 +98,7 @@ void CcRailDepot(bool success, uint tile, uint32 p1, uint32 p2)
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]);
diff --git a/road_gui.c b/road_gui.c
index 5d78fb621..c87b692a2 100644
--- a/road_gui.c
+++ b/road_gui.c
@@ -65,7 +65,7 @@ static void PlaceRoad_Tunnel(uint tile)
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);
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 37196cc86..35e92cef0 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -866,7 +866,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
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 @@ static int RoadFindPathToDest(Vehicle *v, uint tile, int direction)
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 @@ static void RoadVehEventHandler(Vehicle *v)
// 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;
diff --git a/ship_cmd.c b/ship_cmd.c
index 9d7a8553e..a7da76f95 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -546,7 +546,7 @@ static int ChooseShipTrack(Vehicle *v, uint tile, int dir, uint tracks)
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;
diff --git a/station_cmd.c b/station_cmd.c
index 8d6ec1bcd..eab8a70c9 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -1812,7 +1812,7 @@ int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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 @@ static int32 RemoveDock(Station *st, uint32 flags)
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 @@ static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y)
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) ||
diff --git a/town_cmd.c b/town_cmd.c
index 5c40cbf11..dcd45050f 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -655,7 +655,7 @@ build_road_and_exit:
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?
diff --git a/train_cmd.c b/train_cmd.c
index 63d541338..257d8714c 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -984,7 +984,7 @@ static void ReverseTrainDirection(Vehicle *v)
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 @@ static byte ChooseTrainTrack(Vehicle *v, uint tile, int direction, byte trackbit
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 @@ red_light: {
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 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
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];
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 53dc96c9f..4a373d9ab 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -397,7 +397,7 @@ static bool DoCheckTunnelInWay(uint tile, uint z, uint dir)
TileInfo ti;
int delta;
- delta = _tileoffs_by_dir[dir];
+ delta = TileOffsByDir(dir);
do {
tile -= delta;
@@ -588,7 +588,8 @@ uint CheckTunnelBusy(uint tile, int *length)
{
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;
diff --git a/variables.h b/variables.h
index b12ed7ce6..2532a6b67 100644
--- a/variables.h
+++ b/variables.h
@@ -416,8 +416,6 @@ extern const TileTypeProcs * const _tile_type_procs[16];
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];
diff --git a/water_cmd.c b/water_cmd.c
index 85b307b50..4a79fad21 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -121,7 +121,7 @@ static int32 DoBuildShiplift(uint tile, int dir, uint32 flags)
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 DoBuildShiplift(uint tile, int dir, uint32 flags)
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))