(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
DiagDirections, and add TileOffsByDir that handles Directions.
-Codechange: Make the treeloop use TileOffsByDir().
--- a/ai/default/default.c Tue Sep 05 23:11:41 2006 +0000
+++ b/ai/default/default.c Tue Sep 05 23:21:41 2006 +0000
@@ -1701,7 +1701,7 @@
unk &= (int)r;
do {
- tile = TILE_MASK(tile + TileOffsByDir(dir));
+ tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
r >>= 2;
if (r & 2) {
@@ -1808,7 +1808,7 @@
while (p->mode != 3 || !((--cmd) & 0x80)) p++;
- return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDir(*dir = p->attr);
+ return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDiagDir(*dir = p->attr);
}
typedef struct AiRailPathFindData {
@@ -1840,7 +1840,7 @@
arpfd.tile2 = p->ai.cur_tile_a;
arpfd.flag = false;
arpfd.count = 0;
- FollowTrack(p->ai.cur_tile_a + TileOffsByDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
+ FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
return arpfd.count > 8;
}
@@ -1952,8 +1952,8 @@
for (;;) {
TileType type;
- if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
- tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
+ if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible!
+ tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2));
type = GetTileType(tile_new);
if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
@@ -1996,7 +1996,7 @@
{
const byte *p;
- tile = TILE_MASK(tile + TileOffsByDir(dir));
+ tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
// Reached destination?
if (tile == arf->final_tile) {
@@ -2111,7 +2111,7 @@
return;
}
- p->ai.cur_tile_a += TileOffsByDir(p->ai.cur_dir_a);
+ p->ai.cur_tile_a += TileOffsByDiagDir(p->ai.cur_dir_a);
if (arf.best_ptr[0] & 0x80) {
int i;
@@ -2168,7 +2168,7 @@
// Clear the tunnel and continue at the other side of it.
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
return false;
- p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDir(p->ai.cur_dir_a));
+ p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(p->ai.cur_dir_a));
return true;
}
@@ -2179,7 +2179,7 @@
tile = GetOtherBridgeEnd(tile);
- tilenew = TILE_MASK(tile - TileOffsByDir(p->ai.cur_dir_a));
+ tilenew = TILE_MASK(tile - TileOffsByDiagDir(p->ai.cur_dir_a));
// And clear the bridge.
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
return false;
@@ -2211,7 +2211,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 - TileOffsByDir(p->ai.cur_dir_a));
+ p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - TileOffsByDiagDir(p->ai.cur_dir_a));
return true;
}
@@ -2314,7 +2314,7 @@
p->ai.cur_tile_a = tile;
p->ai.start_dir_a = dir;
p->ai.cur_dir_a = dir;
- DoCommand(TILE_MASK(tile + TileOffsByDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
+ DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
assert(TILE_MASK(tile) != 0xFF00);
@@ -2325,7 +2325,7 @@
p->ai.cur_tile_b = tile;
p->ai.start_dir_b = dir;
p->ai.cur_dir_b = dir;
- DoCommand(TILE_MASK(tile + TileOffsByDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
+ DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir&1)?1:0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
assert(TILE_MASK(tile) != 0xFF00);
@@ -2773,7 +2773,7 @@
uint dist = DistanceManhattan(tile, a->dest);
if (dist <= a->best_dist) {
- TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
+ TileIndex tile2 = TILE_MASK(tile + TileOffsByDiagDir(_dir_by_track[track]));
if (IsTileType(tile2, MP_STREET) && GetRoadTileType(tile2) == ROAD_TILE_NORMAL) {
a->best_dist = dist;
@@ -2801,7 +2801,7 @@
int i;
are.dest = p->ai.cur_tile_b;
- tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(dir));
+ tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDiagDir(dir));
bits = GetTileTrackStatus(tile, TRANSPORT_ROAD) & _ai_road_table_and[dir];
if (bits == 0) return false;
@@ -2852,8 +2852,8 @@
for (;;) {
TileType type;
- if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
- tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
+ if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible!
+ tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2));
type = GetTileType(tile_new);
if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != SLOPE_FLAT) {
@@ -2898,7 +2898,7 @@
{
const byte *p;
- tile = TILE_MASK(tile + TileOffsByDir(dir));
+ tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
// Reached destination?
if (tile == arf->final_tile) {
@@ -2995,14 +2995,14 @@
if (++p->ai.state_counter == 21) {
p->ai.state_mode = 1;
- p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(p->ai.cur_dir_a));
+ p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a + TileOffsByDiagDir(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 + TileOffsByDir(p->ai.cur_dir_a));
+ tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a));
if (arf.best_ptr[0]&0x80) {
int i;
@@ -3644,7 +3644,7 @@
DiagDirection dir = GetRailDepotDirection(tile);
- if (GetRailTrackStatus(tile + TileOffsByDir(dir)) & _depot_bits[dir])
+ if (GetRailTrackStatus(tile + TileOffsByDiagDir(dir)) & _depot_bits[dir])
return;
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
@@ -3675,7 +3675,7 @@
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
DoCommand(
- TILE_MASK(tile + TileOffsByDir(dir)),
+ TILE_MASK(tile + TileOffsByDiagDir(dir)),
DiagDirToRoadBits(ReverseDiagDir(dir)),
0,
DC_EXEC,
--- a/ai/trolly/build.c Tue Sep 05 23:11:41 2006 +0000
+++ b/ai/trolly/build.c Tue Sep 05 23:21:41 2006 +0000
@@ -292,7 +292,7 @@
ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
if (CmdFailed(ret)) return ret;
// Try to build the road from the depot
- ret2 = AI_DoCommand(tile + TileOffsByDir(direction), DiagDirToRoadBits(ReverseDiagDir(direction)), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret2 = AI_DoCommand(tile + TileOffsByDiagDir(direction), DiagDirToRoadBits(ReverseDiagDir(direction)), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
// If it fails, ignore it..
if (CmdFailed(ret2)) return ret;
return ret + ret2;
--- a/ai/trolly/pathfinder.c Tue Sep 05 23:11:41 2006 +0000
+++ b/ai/trolly/pathfinder.c Tue Sep 05 23:21:41 2006 +0000
@@ -175,8 +175,8 @@
if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION) {
// The station is pointing to a direction, add a tile towards that direction, so the H-value is more accurate
- r = DistanceManhattan(current->tile, PathFinderInfo->end_tile_tl + TileOffsByDir(PathFinderInfo->end_direction));
- r2 = DistanceManhattan(current->tile, PathFinderInfo->end_tile_br + TileOffsByDir(PathFinderInfo->end_direction));
+ r = DistanceManhattan(current->tile, PathFinderInfo->end_tile_tl + TileOffsByDiagDir(PathFinderInfo->end_direction));
+ r2 = DistanceManhattan(current->tile, PathFinderInfo->end_tile_br + TileOffsByDiagDir(PathFinderInfo->end_direction));
} else {
// No direction, so just get the fastest route to the station
r = DistanceManhattan(current->tile, PathFinderInfo->end_tile_tl);
@@ -225,7 +225,7 @@
// Go through all surrounding tiles and check if they are within the limits
for (i = 0; i < 4; i++) {
TileIndex ctile = current->path.node.tile; // Current tile
- TileIndex atile = ctile + TileOffsByDir(i); // Adjacent tile
+ TileIndex atile = ctile + TileOffsByDiagDir(i); // Adjacent tile
if (TileX(atile) > 1 && TileX(atile) < MapMaxX() - 1 &&
TileY(atile) > 1 && TileY(atile) < MapMaxY() - 1) {
@@ -327,10 +327,10 @@
// Bridges can only be build on land that is not flat
// And if there is a road or rail blocking
if (tileh != SLOPE_FLAT ||
- (PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_STREET)) ||
- (!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_RAILWAY))) {
+ (PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDiagDir(dir), MP_STREET)) ||
+ (!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDiagDir(dir), MP_RAILWAY))) {
for (;;) {
- new_tile += TileOffsByDir(dir);
+ new_tile += TileOffsByDiagDir(dir);
// Precheck, is the length allowed?
if (!CheckBridge_Stuff(0, GetBridgeLength(tile, new_tile))) break;
--- a/ai/trolly/trolly.c Tue Sep 05 23:11:41 2006 +0000
+++ b/ai/trolly/trolly.c Tue Sep 05 23:21:41 2006 +0000
@@ -799,7 +799,7 @@
for (i=2;i<p->ainew.path_info.route_length-2;i++) {
tile = p->ainew.path_info.route[i];
for (j = 0; j < 4; j++) {
- TileIndex t = tile + TileOffsByDir(j);
+ TileIndex t = tile + TileOffsByDiagDir(j);
if (IsTileType(t, MP_STREET) &&
GetRoadTileType(t) == ROAD_TILE_DEPOT &&
@@ -830,7 +830,7 @@
tile = p->ainew.path_info.route[i];
for (j = 0; j < 4; j++) {
- TileIndex t = tile + TileOffsByDir(j);
+ TileIndex t = tile + TileOffsByDiagDir(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..
@@ -1040,14 +1040,14 @@
int i, ret;
for (i=0;i<2;i++) {
if (i == 0) {
- tile = p->ainew.from_tile + TileOffsByDir(p->ainew.from_direction);
+ tile = p->ainew.from_tile + TileOffsByDiagDir(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 + TileOffsByDir(p->ainew.to_direction);
+ tile = p->ainew.to_tile + TileOffsByDiagDir(p->ainew.to_direction);
dir1 = p->ainew.to_direction - 1;
if (dir1 < 0) dir1 = 3;
dir2 = p->ainew.to_direction + 1;
@@ -1057,7 +1057,7 @@
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
- dir1 = TileOffsByDir(dir1);
+ dir1 = TileOffsByDiagDir(dir1);
if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) {
ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
@@ -1069,7 +1069,7 @@
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
- dir2 = TileOffsByDir(dir2);
+ dir2 = TileOffsByDiagDir(dir2);
if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) {
ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
@@ -1081,7 +1081,7 @@
ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
- dir3 = TileOffsByDir(dir3);
+ dir3 = TileOffsByDiagDir(dir3);
if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) {
ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
@@ -1119,7 +1119,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 + TileOffsByDir(p->ainew.depot_direction)))
+ if (!EnsureNoVehicle(p->ainew.depot_tile + TileOffsByDiagDir(p->ainew.depot_direction)))
return;
res = AiNew_Build_Depot(p, p->ainew.depot_tile, p->ainew.depot_direction, DC_EXEC);
--- a/bridge_map.c Tue Sep 05 23:11:41 2006 +0000
+++ b/bridge_map.c Tue Sep 05 23:21:41 2006 +0000
@@ -7,7 +7,7 @@
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
{
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
assert(DiagDirToAxis(dir) == GetBridgeAxis(tile));
@@ -27,7 +27,7 @@
TileIndex GetOtherBridgeEnd(TileIndex tile)
{
- TileIndexDiff delta = TileOffsByDir(GetBridgeRampDirection(tile));
+ TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
do {
tile += delta;
--- a/clear_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/clear_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -729,7 +729,7 @@
SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
do {
if (--j == 0) goto get_out;
- tile_new = tile + TileOffsByDir(GB(Random(), 0, 2));
+ tile_new = tile + TileOffsByDiagDir(GB(Random(), 0, 2));
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
tile = tile_new;
}
--- a/disaster_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/disaster_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -670,7 +670,7 @@
if (!(v->tick_counter & 1)) return;
- tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
+ tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
if (IsValidTile(tile) &&
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
!CHANCE16(1,90)) {
@@ -924,7 +924,7 @@
{
TileIndex tile = i->xy;
- TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2));
+ TileIndexDiff step = TileOffsByDiagDir(GB(Random(), 0, 2));
uint n;
for (n = 0; n < 30; n++) {
--- a/elrail.c Tue Sep 05 23:11:41 2006 +0000
+++ b/elrail.c Tue Sep 05 23:21:41 2006 +0000
@@ -183,7 +183,7 @@
AdjustTileh(ti->tile, &tileh[TS_HOME]);
for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
- TileIndex neighbour = ti->tile + TileOffsByDir(i);
+ TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
uint foundation = 0;
int k;
--- a/map.c Tue Sep 05 23:11:41 2006 +0000
+++ b/map.c Tue Sep 05 23:21:41 2006 +0000
@@ -120,11 +120,22 @@
return INVALID_TILE;
}
+const TileIndexDiffC _tileoffs_by_diagdir[] = {
+ {-1, 0}, // DIAGDIR_NE
+ { 0, 1}, // DIAGDIR_SE
+ { 1, 0}, // DIAGDIR_SW
+ { 0, -1} // DIAGDIR_NW
+};
+
const TileIndexDiffC _tileoffs_by_dir[] = {
- {-1, 0},
- { 0, 1},
- { 1, 0},
- { 0, -1}
+ {-1, -1}, // DIR_N
+ {-1, 0}, // DIR_NE
+ {-1, 1}, // DIR_E
+ { 0, 1}, // DIR_SE
+ { 1, 1}, // DIR_S
+ { 1, 0}, // DIR_SW
+ { 1, -1}, // DIR_W
+ { 0, -1} // DIR_NW
};
uint DistanceManhattan(TileIndex t0, TileIndex t1)
--- a/map.h Tue Sep 05 23:11:41 2006 +0000
+++ b/map.h Tue Sep 05 23:21:41 2006 +0000
@@ -157,10 +157,19 @@
} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \
}
+typedef enum DiagDirection DiagDirection;
+static inline TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
+{
+ extern const TileIndexDiffC _tileoffs_by_diagdir[4];
-static inline TileIndexDiff TileOffsByDir(uint dir)
+ assert(dir < lengthof(_tileoffs_by_diagdir));
+ return ToTileIndexDiff(_tileoffs_by_diagdir[dir]);
+}
+
+typedef enum Direction Direction;
+static inline TileIndexDiff TileOffsByDir(Direction dir)
{
- extern const TileIndexDiffC _tileoffs_by_dir[4];
+ extern const TileIndexDiffC _tileoffs_by_dir[8];
assert(dir < lengthof(_tileoffs_by_dir));
return ToTileIndexDiff(_tileoffs_by_dir[dir]);
--- a/npf.c Tue Sep 05 23:11:41 2006 +0000
+++ b/npf.c Tue Sep 05 23:21:41 2006 +0000
@@ -183,7 +183,7 @@
static uint NPFSlopeCost(AyStarNode* current)
{
- TileIndex next = current->tile + TileOffsByDir(TrackdirToExitdir(current->direction));
+ TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir(current->direction));
int x,y;
int8 z1,z2;
--- a/pathfind.c Tue Sep 05 23:11:41 2006 +0000
+++ b/pathfind.c Tue Sep 05 23:21:41 2006 +0000
@@ -145,7 +145,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 + TileOffsByDir(direction));
+ tile = TILE_MASK(tile + TileOffsByDiagDir(direction));
if (++tpf->rd.cur_length > 50)
return;
@@ -199,7 +199,7 @@
*/
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
{
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
uint z = GetTileZ(tile);
FindLengthOfTunnelResult flotr;
@@ -274,7 +274,7 @@
}
tile = SkipToEndOfTunnel(tpf, tile, direction);
}
- tile += TileOffsByDir(direction);
+ tile += TileOffsByDiagDir(direction);
/* Check in case of rail if the owner is the same */
if (tpf->tracktype == TRANSPORT_RAIL) {
@@ -731,7 +731,7 @@
tile_org = tile;
for (;;) {
assert(direction <= 3);
- tile += TileOffsByDir(direction);
+ tile += TileOffsByDiagDir(direction);
// too long search length? bail out.
if (si.cur_length >= tpf->maxlength) {
--- a/rail_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/rail_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -1558,7 +1558,7 @@
// now check all tiles from start to end for a "hidden" vehicle
// NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile?
dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel
- for (; tile != end; tile += TileOffsByDir(direction)) {
+ for (; tile != end; tile += TileOffsByDiagDir(direction)) {
if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
return true;
}
--- a/rail_gui.c Tue Sep 05 23:11:41 2006 +0000
+++ b/rail_gui.c Tue Sep 05 23:21:41 2006 +0000
@@ -111,7 +111,7 @@
SndPlayTileFx(SND_20_SPLAT_2, tile);
ResetObjectToPlace();
- tile += TileOffsByDir(dir);
+ tile += TileOffsByDiagDir(dir);
if (IsTileType(tile, MP_RAILWAY)) {
PlaceExtraDepotRail(tile, _place_depot_extra[dir]);
--- a/road_gui.c Tue Sep 05 23:11:41 2006 +0000
+++ b/road_gui.c Tue Sep 05 23:21:41 2006 +0000
@@ -71,7 +71,7 @@
static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
{
- tile += TileOffsByDir(direction);
+ tile += TileOffsByDiagDir(direction);
// if there is a roadpiece just outside of the station entrance, build a connecting route
if (IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
DoCommandP(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
--- a/roadveh_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/roadveh_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -303,7 +303,7 @@
{
RoadFindDepotData* rfdd = data;
- tile += TileOffsByDir(_road_pf_directions[track]);
+ tile += TileOffsByDiagDir(_road_pf_directions[track]);
if (IsTileType(tile, MP_STREET) &&
GetRoadTileType(tile) == ROAD_TILE_DEPOT &&
@@ -965,7 +965,7 @@
od.tile = v->tile;
if (FindRoadVehToOvertake(&od)) return;
- od.tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
+ od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
if (FindRoadVehToOvertake(&od)) return;
if (od.u->cur_speed == 0 || od.u->vehstatus& VS_STOPPED) {
@@ -1126,7 +1126,7 @@
trackdir = DiagdirToDiagTrackdir(enterdir);
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
- ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE);
+ ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE);
if (ftd.best_trackdir == 0xff) {
/* We are already at our target. Just do something */
//TODO: maybe display error?
@@ -1154,7 +1154,7 @@
/* When we are heading for a depot or station, we just
* pretend we are heading for the tile in front, we'll
* see from there */
- desttile += TileOffsByDir(dir);
+ desttile += TileOffsByDiagDir(dir);
if (desttile == tile && bitmask & _road_pf_table_3[dir]) {
/* If we are already in front of the
* station/depot and we can get in from here,
@@ -1349,7 +1349,7 @@
// switch to another tile
if (rd.x & 0x80) {
- TileIndex tile = v->tile + TileOffsByDir(rd.x & 3);
+ TileIndex tile = v->tile + TileOffsByDiagDir(rd.x & 3);
int dir = RoadFindPathToDest(v, tile, rd.x & 3);
uint32 r;
Direction newdir;
--- a/ship_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/ship_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -554,7 +554,7 @@
} else if (_patches.new_pathfinding_all) {
NPFFindStationOrTileData fstd;
NPFFoundTargetData ftd;
- TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir)));
+ TileIndex src_tile = TILE_ADD(tile, TileOffsByDiagDir(ReverseDiagDir(enterdir)));
byte trackdir = GetVehicleTrackdir(v);
assert (trackdir != 0xFF); /* Check that we are not in a depot */
@@ -577,7 +577,7 @@
int track;
TileIndex tile2;
- tile2 = TILE_ADD(tile, -TileOffsByDir(enterdir));
+ tile2 = TILE_ADD(tile, -TileOffsByDiagDir(enterdir));
tot_dist = (uint)-1;
/* Let's find out how far it would be if we would reverse first */
--- a/station_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/station_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -1265,7 +1265,7 @@
do {
length ++;
- tile += TileOffsByDir(dir);
+ tile += TileOffsByDiagDir(dir);
} while (IsCompatibleTrainStationTile(tile, start_tile));
return length;
@@ -1923,7 +1923,7 @@
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
- tile_cur = tile + TileOffsByDir(direction);
+ tile_cur = tile + TileOffsByDiagDir(direction);
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
@@ -1934,7 +1934,7 @@
cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
- tile_cur += TileOffsByDir(direction);
+ tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
return_cmd_error(STR_304B_SITE_UNSUITABLE);
}
@@ -2002,7 +2002,7 @@
if (!CheckOwnership(st->owner)) return CMD_ERROR;
tile1 = st->dock_tile;
- tile2 = tile1 + TileOffsByDir(GetDockDirection(tile1));
+ tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
if (!EnsureNoVehicle(tile1)) return CMD_ERROR;
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
@@ -2284,7 +2284,7 @@
{
if (v->type == VEH_Train) {
if (IsRailwayStation(tile) && IsFrontEngine(v) &&
- !IsCompatibleTrainStationTile(tile + TileOffsByDir(DirToDiagDir(v->direction)), tile)) {
+ !IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
StationID station_id = GetStationIndex(tile);
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
--- a/station_map.h Tue Sep 05 23:11:41 2006 +0000
+++ b/station_map.h Tue Sep 05 23:21:41 2006 +0000
@@ -293,7 +293,7 @@
static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d)
{
MakeStation(t, o, sid, GFX_DOCK_BASE + d);
- MakeStation(t + TileOffsByDir(d), o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
+ MakeStation(t + TileOffsByDiagDir(d), o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
}
static inline void MakeOilrig(TileIndex t, StationID sid)
--- a/town_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/town_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -680,7 +680,7 @@
do {
if (++j == 0)
goto build_road_and_exit;
- tmptile = TILE_MASK(tmptile + TileOffsByDir(i));
+ tmptile = TILE_MASK(tmptile + TileOffsByDiagDir(i));
} while (IsClearWaterTile(tmptile));
// no water tiles in between?
--- a/train_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/train_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -1650,7 +1650,7 @@
dir = ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT);
}
/* Calculate next tile */
- tile += TileOffsByDir(dir);
+ tile += TileOffsByDiagDir(dir);
/* Check if the train left a rail/road-crossing */
DisableTrainCrossing(tile);
@@ -2267,7 +2267,7 @@
trackdir = GetVehicleTrackdir(v);
assert(trackdir != 0xff);
- ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.compatible_railtypes);
+ ftd = NPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.compatible_railtypes);
if (ftd.best_trackdir == 0xff) {
/* We are already at our target. Just do something */
@@ -2296,7 +2296,7 @@
fd.best_track_dist = (uint)-1;
fd.best_track = 0xFF;
- NewTrainPathfind(tile - TileOffsByDir(enterdir), v->dest_tile,
+ NewTrainPathfind(tile - TileOffsByDiagDir(enterdir), v->dest_tile,
v->u.rail.compatible_railtypes, enterdir, (NTPEnumProc*)NtpCallbFindStation, &fd);
if (fd.best_track == 0xff) {
@@ -3115,7 +3115,7 @@
v->subspeed = 0;
v->progress = 255-10;
if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) {
- TileIndex o_tile = gp.new_tile + TileOffsByDir(enterdir);
+ TileIndex o_tile = gp.new_tile + TileOffsByDiagDir(enterdir);
VehicleAtSignalData vasd;
vasd.tile = o_tile;
vasd.direction = ReverseDir(dir);
@@ -3323,7 +3323,7 @@
dir = ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT);
}
/* Calculate next tile */
- tile += TileOffsByDir(dir);
+ tile += TileOffsByDiagDir(dir);
// determine the track status on the next tile.
ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _reachable_tracks[dir];
--- a/tree_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/tree_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -509,17 +509,6 @@
static void TileLoop_Trees(TileIndex tile)
{
- static const TileIndexDiffC _tileloop_trees_dir[] = {
- {-1, -1},
- { 0, -1},
- { 1, -1},
- {-1, 0},
- { 1, 0},
- {-1, 1},
- { 0, 1},
- { 1, 1}
- };
-
switch (_opt.landscape) {
case LT_DESERT: TileLoopTreesDesert(tile); break;
case LT_HILLY: TileLoopTreesAlps(tile); break;
@@ -556,7 +545,7 @@
case 2: { /* add a neighbouring tree */
TreeType treetype = GetTreeType(tile);
- tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]);
+ tile += TileOffsByDir(Random() & 7);
if (!IsTileType(tile, MP_CLEAR)) return;
--- a/tunnel_map.c Tue Sep 05 23:11:41 2006 +0000
+++ b/tunnel_map.c Tue Sep 05 23:21:41 2006 +0000
@@ -8,7 +8,7 @@
TileIndex GetOtherTunnelEnd(TileIndex tile)
{
DiagDirection dir = GetTunnelDirection(tile);
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
uint z = GetTileZ(tile);
dir = ReverseDiagDir(dir);
@@ -26,7 +26,7 @@
static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
{
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
uint height;
do {
--- a/tunnelbridge_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/tunnelbridge_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -471,7 +471,7 @@
* cost before the loop will yield different costs depending on start-
* position, because of increased-cost-by-length: 'cost += cost >> 3' */
cost = 0;
- delta = TileOffsByDir(direction);
+ delta = TileOffsByDiagDir(direction);
end_tile = start_tile;
for (;;) {
end_tile += delta;
@@ -523,7 +523,7 @@
{
uint z = GetTileZ(tile);
DiagDirection dir = GetTunnelDirection(tile);
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
uint len = 0;
TileIndex starttile = tile;
Vehicle *v;
@@ -670,7 +670,7 @@
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR;
direction = GetBridgeRampDirection(tile);
- delta = TileOffsByDir(direction);
+ delta = TileOffsByDiagDir(direction);
/* Make sure there's no vehicle on the bridge
* Omit tile and endtile, since these are already checked, thus solving the
@@ -823,7 +823,7 @@
YapfNotifyTrackLayoutChange(endtile, track);
}
cost = 2 * (_price.build_rail >> 1);
- delta = TileOffsByDir(GetBridgeRampDirection(tile));
+ delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
for (tile += delta; tile != endtile; tile += delta) {
if (exec) {
SetRailTypeOnBridge(tile, totype);
@@ -1437,7 +1437,7 @@
#else
TileIndex tile = v->tile;
DiagDirection dir = DirToDiagDir(v->direction);
- TileIndexDiff delta = TileOffsByDir(dir);
+ TileIndexDiff delta = TileOffsByDiagDir(dir);
byte z = v->z_pos;
dir = ReverseDiagDir(dir);
--- a/unmovable_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/unmovable_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -374,7 +374,7 @@
j = 20;
do {
if (--j == 0) goto restart;
- tile = TILE_MASK(tile + TileOffsByDir(dir));
+ tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h <= TILE_HEIGHT * 2));
assert(tile == TILE_MASK(tile));
--- a/water_cmd.c Tue Sep 05 23:11:41 2006 +0000
+++ b/water_cmd.c Tue Sep 05 23:21:41 2006 +0000
@@ -124,7 +124,7 @@
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) return CMD_ERROR;
- delta = TileOffsByDir(dir);
+ delta = TileOffsByDiagDir(dir);
// lower tile
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) return CMD_ERROR;
@@ -151,7 +151,7 @@
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
{
- TileIndexDiff delta = TileOffsByDir(GetLockDirection(tile));
+ TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
if (!CheckTileOwnership(tile)) return CMD_ERROR;
--- a/water_map.h Tue Sep 05 23:11:41 2006 +0000
+++ b/water_map.h Tue Sep 05 23:21:41 2006 +0000
@@ -132,7 +132,7 @@
static inline void MakeLock(TileIndex t, Owner o, DiagDirection d)
{
- TileIndexDiff delta = TileOffsByDir(d);
+ TileIndexDiff delta = TileOffsByDiagDir(d);
MakeLockTile(t, o, LOCK_MIDDLE + d);
MakeLockTile(t - delta, o, LOCK_LOWER + d);
--- a/yapf/follow_track.hpp Tue Sep 05 23:11:41 2006 +0000
+++ b/yapf/follow_track.hpp Tue Sep 05 23:21:41 2006 +0000
@@ -78,7 +78,7 @@
m_tiles_skipped = 0;
// normal or station tile
- TileIndexDiff diff = TileOffsByDir(m_exitdir);
+ TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
m_new_tile = TILE_ADD(m_old_tile, diff);
// special handling for stations
@@ -194,7 +194,7 @@
// how big step we must do to get to the last platform tile;
m_tiles_skipped = length - 1;
// move to the platform end
- TileIndexDiff diff = TileOffsByDir(m_exitdir);
+ TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
diff *= m_tiles_skipped;
m_new_tile = TILE_ADD(m_new_tile, diff);
return true;
--- a/yapf/yapf_ship.cpp Tue Sep 05 23:11:41 2006 +0000
+++ b/yapf/yapf_ship.cpp Tue Sep 05 23:21:41 2006 +0000
@@ -44,7 +44,7 @@
}
// move back to the old tile/trackdir (where ship is coming from)
- TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir)));
+ TileIndex src_tile = TILE_ADD(tile, TileOffsByDiagDir(ReverseDiagDir(enterdir)));
Trackdir trackdir = GetVehicleTrackdir(v);
assert(IsValidTrackdir(trackdir));