summaryrefslogtreecommitdiff
path: root/ai
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-09-05 23:21:41 +0000
committerDarkvater <darkvater@openttd.org>2006-09-05 23:21:41 +0000
commit80814dbb1d01f651ba7c60547dc1b52c1c209378 (patch)
treef2f14fca9ac095b0bf6b46615035b8c207e3ce66 /ai
parent516d412a77de7fb3d2278515d59a0c46bb9b461b (diff)
downloadopenttd-80814dbb1d01f651ba7c60547dc1b52c1c209378.tar.xz
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
DiagDirections, and add TileOffsByDir that handles Directions. -Codechange: Make the treeloop use TileOffsByDir().
Diffstat (limited to 'ai')
-rw-r--r--ai/default/default.c42
-rw-r--r--ai/trolly/build.c2
-rw-r--r--ai/trolly/pathfinder.c12
-rw-r--r--ai/trolly/trolly.c16
4 files changed, 36 insertions, 36 deletions
diff --git a/ai/default/default.c b/ai/default/default.c
index e2971a432..aa1058709 100644
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -1701,7 +1701,7 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
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 @@ static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd
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 @@ static bool AiDoFollowTrack(const Player* p)
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 @@ static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile,
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 @@ static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
{
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 @@ static void AiBuildRailConstruct(Player *p)
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 @@ static bool AiRemoveTileAndGoForward(Player *p)
// 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 @@ static bool AiRemoveTileAndGoForward(Player *p)
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 @@ 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 - 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 @@ static void AiStateBuildRail(Player *p)
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 @@ static void AiStateBuildRail(Player *p)
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 @@ static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint leng
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 @@ static bool AiCheckRoadFinished(Player *p)
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 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile,
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 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
{
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 @@ 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 + 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 @@ pos_3:
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 @@ pos_3:
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,
diff --git a/ai/trolly/build.c b/ai/trolly/build.c
index 35359016a..f90336f20 100644
--- a/ai/trolly/build.c
+++ b/ai/trolly/build.c
@@ -292,7 +292,7 @@ int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte f
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;
diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c
index de3ce2a4e..c5ab35122 100644
--- a/ai/trolly/pathfinder.c
+++ b/ai/trolly/pathfinder.c
@@ -175,8 +175,8 @@ static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current,
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 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// 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 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// 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;
diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c
index 8ce569d80..e15356379 100644
--- a/ai/trolly/trolly.c
+++ b/ai/trolly/trolly.c
@@ -799,7 +799,7 @@ 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 < 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 @@ static void AiNew_State_FindDepot(Player *p)
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 @@ static void AiNew_State_BuildPath(Player *p)
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 @@ static void AiNew_State_BuildPath(Player *p)
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 @@ static void AiNew_State_BuildPath(Player *p)
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 @@ static void AiNew_State_BuildPath(Player *p)
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 @@ 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 + 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);