summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-24 13:03:24 +0000
committerrubidium <rubidium@openttd.org>2007-07-24 13:03:24 +0000
commit9c9fc1a79ef08d1c3822bc7a4a1373d84dbfa70b (patch)
tree5cdf2bf8f653ee2e63246b1d6b2dd6cffe3a62f7 /src
parente66ab3b6f1343968730b9a7069376f5408fb6d4d (diff)
downloadopenttd-9c9fc1a79ef08d1c3822bc7a4a1373d84dbfa70b.tar.xz
(svn r10672) -Codechange: typify some parameters/variables.
Diffstat (limited to 'src')
-rw-r--r--src/ai/default/default.cpp86
-rw-r--r--src/ai/trolly/trolly.cpp56
-rw-r--r--src/clear_cmd.cpp2
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/map.h23
-rw-r--r--src/player.h16
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/table/ai_rail.h38
-rw-r--r--src/tree_cmd.cpp2
9 files changed, 118 insertions, 109 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index d0b5e7fba..a47e91fce 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -1774,7 +1774,7 @@ static const byte _terraform_down_flags[] = {
8, 4
};
-static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
+static void AiDoTerraformLand(TileIndex tile, DiagDirection dir, int unk, int mode)
{
PlayerID old_player;
uint32 r;
@@ -1793,10 +1793,8 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
r >>= 2;
if (r & 2) {
- dir++;
- if (r & 1) dir -= 2;
+ dir = ChangeDiagDir(dir, (r & 1) ? DIAGDIRDIFF_90LEFT : DIAGDIRDIFF_90RIGHT);
}
- dir &= 3;
} while (--unk >= 0);
slope = GetTileSlope(tile, &h);
@@ -1855,7 +1853,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
if (rule == -1) {
// cannot build, terraform after a while
if (p->ai.state_counter >= 600) {
- AiDoTerraformLand(aib->use_tile, Random() & 3, 3, (int8)p->ai.state_mode);
+ AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)p->ai.state_mode);
}
// also try the other terraform direction
if (++p->ai.state_counter >= 1000) {
@@ -1888,7 +1886,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
p->ai.state_mode = 255;
}
-static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd, int *dir)
+static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd, DiagDirection *dir)
{
const AiDefaultBlockData *p = _default_rail_track_data[rule]->data;
@@ -1926,18 +1924,18 @@ 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 + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, 0, (DiagDirection)(p->ai.cur_dir_a ^ 2),
+ FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, 0, ReverseDiagDir(p->ai.cur_dir_a),
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
return arpfd.count > 8;
}
struct AiRailFinder {
TileIndex final_tile;
- byte final_dir;
+ DiagDirection final_dir;
byte depth;
byte recursive_mode;
- byte cur_best_dir;
- byte best_dir;
+ DiagDirection cur_best_dir;
+ DiagDirection best_dir;
byte cur_best_depth;
byte best_depth;
uint cur_best_dist;
@@ -1988,7 +1986,7 @@ static void AiBanTile(Player* p, TileIndex tile, byte val)
}
}
-static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir);
+static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir);
static bool AiCheckRailPathBetter(AiRailFinder *arf, const byte *p)
{
@@ -2027,7 +2025,7 @@ static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile,
uint z;
bool flag;
- int dir2 = p[0] & 3;
+ DiagDirection dir2 = (DiagDirection)(p[0] & 3);
tileh = GetTileSlope(tile, &z);
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) {
@@ -2071,14 +2069,14 @@ static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile,
CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) {
- AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
+ AiBuildRailRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3));
if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
}
}
}
-static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
+static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir)
{
const byte *p;
@@ -2086,7 +2084,7 @@ static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
// Reached destination?
if (tile == arf->final_tile) {
- if (arf->final_dir != (dir ^ 2)) {
+ if (arf->final_dir != ReverseDiagDir(dir)) {
if (arf->recursive_mode != 2) arf->recursive_mode = 1;
} else if (arf->recursive_mode != 2) {
arf->recursive_mode = 2;
@@ -2125,7 +2123,7 @@ static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
// Make sure the tile is not in the list of banned tiles and that a rail can be built here.
if (!AiIsTileBanned(arf->player, tile, p[0]) &&
CmdSucceeded(DoCommand(tile, arf->player->ai.railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
- AiBuildRailRecursive(arf, tile, p[1]);
+ AiBuildRailRecursive(arf, tile, (DiagDirection)p[1]);
}
// At the bottom depth?
@@ -2228,7 +2226,7 @@ static void AiBuildRailConstruct(Player *p)
p->ai.state_counter = 0;
} else {
// rail
- p->ai.cur_dir_a = arf.best_ptr[1];
+ p->ai.cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3);
DoCommand(p->ai.cur_tile_a, p->ai.railtype_to_use, arf.best_ptr[0],
DC_EXEC | DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL);
p->ai.state_counter = 0;
@@ -2290,9 +2288,9 @@ static bool AiRemoveTileAndGoForward(Player *p)
return false;
// Find the direction at the other edge of the rail.
- ptr = _ai_table_15[p->ai.cur_dir_a ^ 2];
+ ptr = _ai_table_15[ReverseDiagDir(p->ai.cur_dir_a)];
while (ptr[0] != bit) ptr += 2;
- p->ai.cur_dir_a = ptr[1] ^ 2;
+ p->ai.cur_dir_a = ReverseDiagDir((DiagDirection)ptr[1]);
// And then also switch tile.
p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - TileOffsByDiagDir(p->ai.cur_dir_a));
@@ -2351,7 +2349,7 @@ static void AiStateBuildRail(Player *p)
AiBuildRec *aib;
byte cmd;
TileIndex tile;
- int dir;
+ DiagDirection dir;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -2751,7 +2749,7 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
if (rule == -1) {
// cannot build, terraform after a while
if (p->ai.state_counter >= 600) {
- AiDoTerraformLand(aib->use_tile, Random() & 3, 3, (int8)p->ai.state_mode);
+ AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)p->ai.state_mode);
}
// also try the other terraform direction
if (++p->ai.state_counter >= 1000) {
@@ -2788,11 +2786,11 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
struct AiRoadFinder {
TileIndex final_tile;
- byte final_dir;
+ DiagDirection final_dir;
byte depth;
byte recursive_mode;
- byte cur_best_dir;
- byte best_dir;
+ DiagDirection cur_best_dir;
+ DiagDirection best_dir;
byte cur_best_depth;
byte best_depth;
uint cur_best_dist;
@@ -2810,13 +2808,13 @@ struct AiRoadEnum {
uint best_dist;
};
-static const byte _dir_by_track[] = {
- 0, 1, 0, 1, 2, 1,
- 0, 0,
- 2, 3, 3, 2, 3, 0,
+static const DiagDirection _dir_by_track[] = {
+ DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE,
+ DIAGDIR_NE, DIAGDIR_NE,
+ DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE,
};
-static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir);
+static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir);
static bool AiCheckRoadPathBetter(AiRoadFinder *arf, const byte *p)
{
@@ -2880,7 +2878,7 @@ static bool AiCheckRoadFinished(Player *p)
{
AiRoadEnum are;
TileIndex tile;
- int dir = p->ai.cur_dir_a;
+ DiagDirection dir = p->ai.cur_dir_a;
uint32 bits;
int i;
@@ -2926,7 +2924,7 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile,
uint z;
bool flag;
- int dir2 = p[0] & 3;
+ DiagDirection dir2 = (DiagDirection)(p[0] & 3);
tileh = GetTileSlope(tile, &z);
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) {
@@ -2971,7 +2969,7 @@ static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile,
CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) {
- AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
+ AiBuildRoadRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3));
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p);
}
}
@@ -2979,7 +2977,7 @@ static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile,
-static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
+static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir)
{
const byte *p;
@@ -2987,7 +2985,7 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
// Reached destination?
if (tile == arf->final_tile) {
- if ((arf->final_dir ^ 2) == dir) {
+ if (ReverseDiagDir(arf->final_dir) == dir) {
arf->recursive_mode = 2;
arf->cur_best_depth = arf->depth;
}
@@ -3020,7 +3018,7 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
do {
// Make sure that a road can be built here.
if (AiBuildRoadHelper(tile, DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, p[0])) {
- AiBuildRoadRecursive(arf, tile, p[1]);
+ AiBuildRoadRecursive(arf, tile, (DiagDirection)p[1]);
}
// At the bottom depth?
@@ -3081,7 +3079,7 @@ do_some_terraform:
p->ai.state_mode = 1;
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.cur_dir_a = ReverseDiagDir(p->ai.cur_dir_a);
p->ai.state_counter = 0;
}
return;
@@ -3121,7 +3119,7 @@ do_some_terraform:
if (!AiBuildRoadHelper(tile, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, arf.best_ptr[0]))
goto do_some_terraform;
- p->ai.cur_dir_a = arf.best_ptr[1];
+ p->ai.cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3);
p->ai.cur_tile_a = tile;
p->ai.state_counter = 0;
}
@@ -3157,7 +3155,7 @@ static void AiBuildRoad(Player *p)
}
}
-static TileIndex AiGetRoadBlockEdge(byte rule, TileIndex tile, int *dir)
+static TileIndex AiGetRoadBlockEdge(byte rule, TileIndex tile, DiagDirection *dir)
{
const AiDefaultBlockData *p = _road_default_block_data[rule]->data;
while (p->mode != 1) p++;
@@ -3172,7 +3170,7 @@ static void AiStateBuildRoad(Player *p)
AiBuildRec *aib;
byte cmd;
TileIndex tile;
- int dir;
+ DiagDirection dir;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -3477,7 +3475,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
if (rule == -1) {
// cannot build, terraform after a while
if (p->ai.state_counter >= 600) {
- AiDoTerraformLand(aib->use_tile, Random() & 3, 3, (int8)p->ai.state_mode);
+ AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)p->ai.state_mode);
}
// also try the other terraform direction
if (++p->ai.state_counter >= 1000) {
@@ -3682,7 +3680,7 @@ is_rail_crossing:;
if (rails & TRACK_BIT_3WAY_NE) {
pos_0:
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & TRACK_BIT_3WAY_SW) == 0) {
- p->ai.cur_dir_a = 0;
+ p->ai.cur_dir_a = DIAGDIR_NE;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return;
@@ -3692,7 +3690,7 @@ pos_0:
if (rails & TRACK_BIT_3WAY_SE) {
pos_1:
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & TRACK_BIT_3WAY_NW) == 0) {
- p->ai.cur_dir_a = 1;
+ p->ai.cur_dir_a = DIAGDIR_SE;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return;
@@ -3702,7 +3700,7 @@ pos_1:
if (rails & TRACK_BIT_3WAY_SW) {
pos_2:
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & TRACK_BIT_3WAY_NE) == 0) {
- p->ai.cur_dir_a = 2;
+ p->ai.cur_dir_a = DIAGDIR_SW;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return;
@@ -3712,7 +3710,7 @@ pos_2:
if (rails & TRACK_BIT_3WAY_NW) {
pos_3:
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & TRACK_BIT_3WAY_SE) == 0) {
- p->ai.cur_dir_a = 3;
+ p->ai.cur_dir_a = DIAGDIR_NW;
p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return;
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index 0b2beddac..36cb793da 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -573,7 +573,7 @@ static void AiNew_State_FindStation(Player *p)
int count = 0;
EngineID i;
TileIndex new_tile = 0;
- byte direction = 0;
+ DiagDirection direction = DIAGDIR_NE;
Town *town = NULL;
assert(p->ainew.state == AI_STATE_FIND_STATION);
@@ -692,13 +692,13 @@ static void AiNew_State_FindStation(Player *p)
r = AiNew_Build_Station(p, p->ainew.tbt, new_tile, 0, 0, 0, DC_QUERY_COST);
p->ainew.new_cost += r.GetCost();
- direction = AI_PATHFINDER_NO_DIRECTION;
+ direction = (DiagDirection)AI_PATHFINDER_NO_DIRECTION;
} else if (new_tile == 0 && p->ainew.tbt == AI_TRUCK) {
// Truck station locater works differently.. a station can be on any place
// as long as it is in range. So we give back code AI_STATION_RANGE
// so the pathfinder routine can work it out!
new_tile = AI_STATION_RANGE;
- direction = AI_PATHFINDER_NO_DIRECTION;
+ direction = (DiagDirection)AI_PATHFINDER_NO_DIRECTION;
}
if (p->ainew.from_tile == 0) {
@@ -1035,58 +1035,54 @@ static void AiNew_State_BuildPath(Player *p)
if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) {
// If they not queue, they have to go up and down to try again at a station...
// We don't want that, so try building some road left or right of the station
- int dir1, dir2, dir3;
+ DiagDirection dir1, dir2, dir3;
TileIndex tile;
CommandCost ret;
for (int i = 0; i < 2; i++) {
if (i == 0) {
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;
+ dir1 = ChangeDiagDir(p->ainew.from_direction, DIAGDIRDIFF_90LEFT);
+ dir2 = ChangeDiagDir(p->ainew.from_direction, DIAGDIRDIFF_90RIGHT);
dir3 = p->ainew.from_direction;
} else {
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;
- if (dir2 > 3) dir2 = 0;
+ dir1 = ChangeDiagDir(p->ainew.to_direction, DIAGDIRDIFF_90LEFT);
+ dir2 = ChangeDiagDir(p->ainew.to_direction, DIAGDIRDIFF_90RIGHT);
dir3 = p->ainew.to_direction;
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- 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);
+ TileIndex offset = TileOffsByDiagDir(dir1);
+ if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
+ ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES))
- AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES))
+ AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
}
}
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- 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);
+ TileIndex offset = TileOffsByDiagDir(dir2);
+ if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
+ ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES))
- AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES))
+ AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
}
}
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- 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);
+ TileIndex offset = TileOffsByDiagDir(dir3);
+ if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
+ ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdSucceeded(ret)) {
- if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES))
- AI_DoCommand(tile+dir3+dir3, AiNew_GetRoadDirection(tile+dir3, tile+dir3+dir3, tile+dir3+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES))
+ AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
}
}
}
diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp
index ed04ac8e8..1dfb61608 100644
--- a/src/clear_cmd.cpp
+++ b/src/clear_cmd.cpp
@@ -758,7 +758,7 @@ void GenerateClearTile()
SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
do {
if (--j == 0) goto get_out;
- tile_new = tile + TileOffsByDiagDir(GB(Random(), 0, 2));
+ tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
tile = tile_new;
}
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 5be1730ab..615f27b32 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -986,7 +986,7 @@ static void Disaster_CoalMine_Init()
{
TileIndex tile = i->xy;
- TileIndexDiff step = TileOffsByDiagDir(GB(Random(), 0, 2));
+ TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
uint n;
for (n = 0; n < 30; n++) {
diff --git a/src/map.h b/src/map.h
index b97eca52a..811a12bca 100644
--- a/src/map.h
+++ b/src/map.h
@@ -6,6 +6,7 @@
#define MAP_H
#include "stdafx.h"
+#include "direction.h"
extern uint _map_tile_mask;
@@ -190,17 +191,19 @@ static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
uint TileAddWrap(TileIndex tile, int addx, int addy);
-static inline TileIndexDiffC TileIndexDiffCByDiagDir(uint dir) {
- extern const TileIndexDiffC _tileoffs_by_diagdir[4];
+static inline TileIndexDiffC TileIndexDiffCByDiagDir(DiagDirection dir)
+{
+ extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END];
- assert(dir < lengthof(_tileoffs_by_diagdir));
+ assert(IsValidDiagDirection(dir));
return _tileoffs_by_diagdir[dir];
}
/* Returns tile + the diff given in diff. If the result tile would end up
* outside of the map, INVALID_TILE is returned instead.
*/
-static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff) {
+static inline TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
+{
int x = TileX(tile) + diff.x;
int y = TileY(tile) + diff.y;
if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY())
@@ -247,19 +250,19 @@ uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the ma
} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \
}
-static inline TileIndexDiff TileOffsByDiagDir(uint dir)
+static inline TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
{
- extern const TileIndexDiffC _tileoffs_by_diagdir[4];
+ extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END];
- assert(dir < lengthof(_tileoffs_by_diagdir));
+ assert(IsValidDiagDirection(dir));
return ToTileIndexDiff(_tileoffs_by_diagdir[dir]);
}
-static inline TileIndexDiff TileOffsByDir(uint dir)
+static inline TileIndexDiff TileOffsByDir(Direction dir)
{
- extern const TileIndexDiffC _tileoffs_by_dir[8];
+ extern const TileIndexDiffC _tileoffs_by_dir[DIR_END];
- assert(dir < lengthof(_tileoffs_by_dir));
+ assert(IsValidDirection(dir));
return ToTileIndexDiff(_tileoffs_by_dir[dir]);
}
diff --git a/src/player.h b/src/player.h
index 45a7a4518..70bf94d84 100644
--- a/src/player.h
+++ b/src/player.h
@@ -53,13 +53,13 @@ struct PlayerAI {
TileIndex start_tile_a;
TileIndex cur_tile_a;
- byte cur_dir_a;
- byte start_dir_a;
+ DiagDirectionByte cur_dir_a;
+ DiagDirectionByte start_dir_a;
TileIndex start_tile_b;
TileIndex cur_tile_b;
- byte cur_dir_b;
- byte start_dir_b;
+ DiagDirectionByte cur_dir_b;
+ DiagDirectionByte start_dir_b;
Vehicle *cur_veh; ///< only used by some states
@@ -77,8 +77,8 @@ struct Ai_PathFinderInfo {
TileIndex start_tile_br; ///< br = bottom-right
TileIndex end_tile_tl; ///< tl = top-left
TileIndex end_tile_br; ///< br = bottom-right
- byte start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
- byte end_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
+ DiagDirection start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
+ DiagDirection end_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
TileIndex route[500];
byte route_extra[500]; ///< Some extra information about the route like bridge/tunnel
@@ -127,8 +127,8 @@ struct PlayerAiNew {
TileIndex from_tile;
TileIndex to_tile;
- byte from_direction;
- byte to_direction;
+ DiagDirectionByte from_direction;
+ DiagDirectionByte to_direction;
bool from_deliver; ///< True if this is the station that GIVES cargo
bool to_deliver;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index b09bc3ab2..d7c574fe1 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1481,7 +1481,7 @@ static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev)
(_opt.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking][v->u.road.frame + 1];
if (rd.x & RDE_NEXT_TILE) {
- TileIndex tile = v->tile + TileOffsByDiagDir(rd.x & 3);
+ TileIndex tile = v->tile + TileOffsByDiagDir((DiagDirection)(rd.x & 3));
Trackdir dir;
uint32 r;
Direction newdir;
diff --git a/src/table/ai_rail.h b/src/table/ai_rail.h
index 7fe518968..c95ccfb6f 100644
--- a/src/table/ai_rail.h
+++ b/src/table/ai_rail.h
@@ -2,7 +2,7 @@
struct AiDefaultBlockData {
byte mode;
- byte attr;
+ DiagDirection attr;
TileIndexDiffC tileoffs;
};
@@ -22,11 +22,11 @@ struct AiDefaultRoadBlock {
#define MKHDR(a, b, c, d, e) a, b, c, d, e,
-#define MKDEPOT(a, b, c) {0, a, {b, c}}
-#define MKSTATION(a, b, c) {1, a, {b, c}}
-#define MKRAIL(a, b, c) {2, a, {b, c}}
-#define MKCLRRAIL(a, b, c) {3, a, {b, c}}
-#define MKEND {4, 0, {0, 0}}
+#define MKDEPOT(a, b, c) {0, (DiagDirection)a, {b, c}}
+#define MKSTATION(a, b, c) {1, (DiagDirection)a, {b, c}}
+#define MKRAIL(a, b, c) {2, (DiagDirection)a, {b, c}}
+#define MKCLRRAIL(a, b, c) {3, (DiagDirection)a, {b, c}}
+#define MKEND {4, (DiagDirection)0, {0, 0}}
static const AiDefaultBlockData _raildata_ai_0_data[] = {
MKDEPOT(2, -1, 1),
@@ -555,38 +555,50 @@ static const AiDefaultRoadBlock * const _road_default_block_data[] = {
NULL
};
-#define MKAIR(a, b, c) {0, a, {b, c}}
+#undef MKHDR
+#undef MKDEPOT
+#undef MKSTATION
+#undef MKRAIL
+#undef MKCLRRAIL
+#undef MKEND
+
+
+#define MKAIR(a, b, c) {0, (DiagDirection)a, {b, c}}
+#define MKEND() {1, (DiagDirection)0, {0, 0}}
static const AiDefaultBlockData _airportdata_ai_0[] = {
MKAIR(1, 0, 0),
- {1, 0, {0, 0}},
+ MKEND(),
};
static const AiDefaultBlockData _airportdata_ai_1[] = {
MKAIR(0, 0, 0),
- {1, 0, {0, 0}}
+ MKEND(),
};
static const AiDefaultBlockData _airportdata_ai_3[] = {
MKAIR(3, 0, 0),
- {1, 0, {0, 0}},
+ MKEND(),
};
static const AiDefaultBlockData _airportdata_ai_4[] = {
MKAIR(4, 0, 0),
- {1, 0, {0, 0}},
+ MKEND(),
};
static const AiDefaultBlockData _airportdata_ai_5[] = {
MKAIR(5, 0, 0),
- {1, 0, {0, 0}},
+ MKEND(),
};
static const AiDefaultBlockData _airportdata_ai_7[] = {
MKAIR(7, 0, 0),
- {1, 0, {0, 0}}
+ MKEND(),
};
+#undef MKAIR
+#undef MDEND
+
static const AiDefaultBlockData * const _airport_default_block_data[] = {
_airportdata_ai_7, // intercontinental airport
_airportdata_ai_4, // international airport
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index 8f5500300..a19ff0ce7 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -560,7 +560,7 @@ static void TileLoop_Trees(TileIndex tile)
case 2: { /* add a neighbouring tree */
TreeType treetype = GetTreeType(tile);
- tile += TileOffsByDir(Random() & 7);
+ tile += TileOffsByDir((Direction)(Random() & 7));
if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return;