(svn r10672) -Codechange: typify some parameters/variables.

This commit is contained in:
rubidium 2007-07-24 13:03:24 +00:00
parent 01d08680e1
commit 0d9a51de6d
9 changed files with 118 additions and 109 deletions

View File

@ -1774,7 +1774,7 @@ static const byte _terraform_down_flags[] = {
8, 4 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; PlayerID old_player;
uint32 r; uint32 r;
@ -1793,10 +1793,8 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
r >>= 2; r >>= 2;
if (r & 2) { if (r & 2) {
dir++; dir = ChangeDiagDir(dir, (r & 1) ? DIAGDIRDIFF_90LEFT : DIAGDIRDIFF_90RIGHT);
if (r & 1) dir -= 2;
} }
dir &= 3;
} while (--unk >= 0); } while (--unk >= 0);
slope = GetTileSlope(tile, &h); slope = GetTileSlope(tile, &h);
@ -1855,7 +1853,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
if (rule == -1) { if (rule == -1) {
// cannot build, terraform after a while // cannot build, terraform after a while
if (p->ai.state_counter >= 600) { 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 // also try the other terraform direction
if (++p->ai.state_counter >= 1000) { if (++p->ai.state_counter >= 1000) {
@ -1888,7 +1886,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
p->ai.state_mode = 255; 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; 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.tile2 = p->ai.cur_tile_a;
arpfd.flag = false; arpfd.flag = false;
arpfd.count = 0; 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); (TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
return arpfd.count > 8; return arpfd.count > 8;
} }
struct AiRailFinder { struct AiRailFinder {
TileIndex final_tile; TileIndex final_tile;
byte final_dir; DiagDirection final_dir;
byte depth; byte depth;
byte recursive_mode; byte recursive_mode;
byte cur_best_dir; DiagDirection cur_best_dir;
byte best_dir; DiagDirection best_dir;
byte cur_best_depth; byte cur_best_depth;
byte best_depth; byte best_depth;
uint cur_best_dist; 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) static bool AiCheckRailPathBetter(AiRailFinder *arf, const byte *p)
{ {
@ -2027,7 +2025,7 @@ static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile,
uint z; uint z;
bool flag; bool flag;
int dir2 = p[0] & 3; DiagDirection dir2 = (DiagDirection)(p[0] & 3);
tileh = GetTileSlope(tile, &z); tileh = GetTileSlope(tile, &z);
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { 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); 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)) { 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); 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; const byte *p;
@ -2086,7 +2084,7 @@ static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir)
// Reached destination? // Reached destination?
if (tile == arf->final_tile) { 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; if (arf->recursive_mode != 2) arf->recursive_mode = 1;
} else if (arf->recursive_mode != 2) { } else if (arf->recursive_mode != 2) {
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. // 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]) && 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))) { 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? // At the bottom depth?
@ -2228,7 +2226,7 @@ static void AiBuildRailConstruct(Player *p)
p->ai.state_counter = 0; p->ai.state_counter = 0;
} else { } else {
// rail // 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], 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); DC_EXEC | DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL);
p->ai.state_counter = 0; p->ai.state_counter = 0;
@ -2290,9 +2288,9 @@ static bool AiRemoveTileAndGoForward(Player *p)
return false; return false;
// Find the direction at the other edge of the rail. // 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; 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. // And then also switch tile.
p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - TileOffsByDiagDir(p->ai.cur_dir_a)); 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; AiBuildRec *aib;
byte cmd; byte cmd;
TileIndex tile; TileIndex tile;
int dir; DiagDirection dir;
// time out? // time out?
if (++p->ai.timeout_counter == 1388) { if (++p->ai.timeout_counter == 1388) {
@ -2751,7 +2749,7 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
if (rule == -1) { if (rule == -1) {
// cannot build, terraform after a while // cannot build, terraform after a while
if (p->ai.state_counter >= 600) { 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 // also try the other terraform direction
if (++p->ai.state_counter >= 1000) { if (++p->ai.state_counter >= 1000) {
@ -2788,11 +2786,11 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
struct AiRoadFinder { struct AiRoadFinder {
TileIndex final_tile; TileIndex final_tile;
byte final_dir; DiagDirection final_dir;
byte depth; byte depth;
byte recursive_mode; byte recursive_mode;
byte cur_best_dir; DiagDirection cur_best_dir;
byte best_dir; DiagDirection best_dir;
byte cur_best_depth; byte cur_best_depth;
byte best_depth; byte best_depth;
uint cur_best_dist; uint cur_best_dist;
@ -2810,13 +2808,13 @@ struct AiRoadEnum {
uint best_dist; uint best_dist;
}; };
static const byte _dir_by_track[] = { static const DiagDirection _dir_by_track[] = {
0, 1, 0, 1, 2, 1, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE,
0, 0, DIAGDIR_NE, DIAGDIR_NE,
2, 3, 3, 2, 3, 0, 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) static bool AiCheckRoadPathBetter(AiRoadFinder *arf, const byte *p)
{ {
@ -2880,7 +2878,7 @@ static bool AiCheckRoadFinished(Player *p)
{ {
AiRoadEnum are; AiRoadEnum are;
TileIndex tile; TileIndex tile;
int dir = p->ai.cur_dir_a; DiagDirection dir = p->ai.cur_dir_a;
uint32 bits; uint32 bits;
int i; int i;
@ -2926,7 +2924,7 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile,
uint z; uint z;
bool flag; bool flag;
int dir2 = p[0] & 3; DiagDirection dir2 = (DiagDirection)(p[0] & 3);
tileh = GetTileSlope(tile, &z); tileh = GetTileSlope(tile, &z);
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { 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); CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) { 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); 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; const byte *p;
@ -2987,7 +2985,7 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
// Reached destination? // Reached destination?
if (tile == arf->final_tile) { if (tile == arf->final_tile) {
if ((arf->final_dir ^ 2) == dir) { if (ReverseDiagDir(arf->final_dir) == dir) {
arf->recursive_mode = 2; arf->recursive_mode = 2;
arf->cur_best_depth = arf->depth; arf->cur_best_depth = arf->depth;
} }
@ -3020,7 +3018,7 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
do { do {
// Make sure that a road can be built here. // Make sure that a road can be built here.
if (AiBuildRoadHelper(tile, DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, p[0])) { 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? // At the bottom depth?
@ -3081,7 +3079,7 @@ do_some_terraform:
p->ai.state_mode = 1; 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_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; p->ai.state_counter = 0;
} }
return; 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])) if (!AiBuildRoadHelper(tile, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, arf.best_ptr[0]))
goto do_some_terraform; 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.cur_tile_a = tile;
p->ai.state_counter = 0; 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; const AiDefaultBlockData *p = _road_default_block_data[rule]->data;
while (p->mode != 1) p++; while (p->mode != 1) p++;
@ -3172,7 +3170,7 @@ static void AiStateBuildRoad(Player *p)
AiBuildRec *aib; AiBuildRec *aib;
byte cmd; byte cmd;
TileIndex tile; TileIndex tile;
int dir; DiagDirection dir;
// time out? // time out?
if (++p->ai.timeout_counter == 1388) { if (++p->ai.timeout_counter == 1388) {
@ -3477,7 +3475,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
if (rule == -1) { if (rule == -1) {
// cannot build, terraform after a while // cannot build, terraform after a while
if (p->ai.state_counter >= 600) { 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 // also try the other terraform direction
if (++p->ai.state_counter >= 1000) { if (++p->ai.state_counter >= 1000) {
@ -3682,7 +3680,7 @@ is_rail_crossing:;
if (rails & TRACK_BIT_3WAY_NE) { if (rails & TRACK_BIT_3WAY_NE) {
pos_0: pos_0:
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & TRACK_BIT_3WAY_SW) == 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.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE; p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return; return;
@ -3692,7 +3690,7 @@ pos_0:
if (rails & TRACK_BIT_3WAY_SE) { if (rails & TRACK_BIT_3WAY_SE) {
pos_1: pos_1:
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & TRACK_BIT_3WAY_NW) == 0) { 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.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE; p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return; return;
@ -3702,7 +3700,7 @@ pos_1:
if (rails & TRACK_BIT_3WAY_SW) { if (rails & TRACK_BIT_3WAY_SW) {
pos_2: pos_2:
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & TRACK_BIT_3WAY_NE) == 0) { 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.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE; p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return; return;
@ -3712,7 +3710,7 @@ pos_2:
if (rails & TRACK_BIT_3WAY_NW) { if (rails & TRACK_BIT_3WAY_NW) {
pos_3: pos_3:
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & TRACK_BIT_3WAY_SE) == 0) { 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.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE; p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
return; return;

View File

@ -573,7 +573,7 @@ static void AiNew_State_FindStation(Player *p)
int count = 0; int count = 0;
EngineID i; EngineID i;
TileIndex new_tile = 0; TileIndex new_tile = 0;
byte direction = 0; DiagDirection direction = DIAGDIR_NE;
Town *town = NULL; Town *town = NULL;
assert(p->ainew.state == AI_STATE_FIND_STATION); 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); r = AiNew_Build_Station(p, p->ainew.tbt, new_tile, 0, 0, 0, DC_QUERY_COST);
p->ainew.new_cost += r.GetCost(); 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) { } else if (new_tile == 0 && p->ainew.tbt == AI_TRUCK) {
// Truck station locater works differently.. a station can be on any place // 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 // as long as it is in range. So we give back code AI_STATION_RANGE
// so the pathfinder routine can work it out! // so the pathfinder routine can work it out!
new_tile = AI_STATION_RANGE; new_tile = AI_STATION_RANGE;
direction = AI_PATHFINDER_NO_DIRECTION; direction = (DiagDirection)AI_PATHFINDER_NO_DIRECTION;
} }
if (p->ainew.from_tile == 0) { 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 (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... // 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 // 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; TileIndex tile;
CommandCost ret; CommandCost ret;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
if (i == 0) { if (i == 0) {
tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction); tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction);
dir1 = p->ainew.from_direction - 1; dir1 = ChangeDiagDir(p->ainew.from_direction, DIAGDIRDIFF_90LEFT);
if (dir1 < 0) dir1 = 3; dir2 = ChangeDiagDir(p->ainew.from_direction, DIAGDIRDIFF_90RIGHT);
dir2 = p->ainew.from_direction + 1;
if (dir2 > 3) dir2 = 0;
dir3 = p->ainew.from_direction; dir3 = p->ainew.from_direction;
} else { } else {
tile = p->ainew.to_tile + TileOffsByDiagDir(p->ainew.to_direction); tile = p->ainew.to_tile + TileOffsByDiagDir(p->ainew.to_direction);
dir1 = p->ainew.to_direction - 1; dir1 = ChangeDiagDir(p->ainew.to_direction, DIAGDIRDIFF_90LEFT);
if (dir1 < 0) dir1 = 3; dir2 = ChangeDiagDir(p->ainew.to_direction, DIAGDIRDIFF_90RIGHT);
dir2 = p->ainew.to_direction + 1;
if (dir2 > 3) dir2 = 0;
dir3 = p->ainew.to_direction; 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)) { if (CmdSucceeded(ret)) {
dir1 = TileOffsByDiagDir(dir1); TileIndex offset = TileOffsByDiagDir(dir1);
if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); 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 (CmdSucceeded(ret)) {
if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES)) if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, 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); 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)) { if (CmdSucceeded(ret)) {
dir2 = TileOffsByDiagDir(dir2); TileIndex offset = TileOffsByDiagDir(dir2);
if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); 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 (CmdSucceeded(ret)) {
if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES)) if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, 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); 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)) { if (CmdSucceeded(ret)) {
dir3 = TileOffsByDiagDir(dir3); TileIndex offset = TileOffsByDiagDir(dir3);
if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) {
ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); 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 (CmdSucceeded(ret)) {
if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES)) if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, 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); 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);
} }
} }
} }

View File

@ -758,7 +758,7 @@ void GenerateClearTile()
SetClearGroundDensity(tile, CLEAR_ROCKS, 3); SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
do { do {
if (--j == 0) goto get_out; 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)); } while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
tile = tile_new; tile = tile_new;
} }

View File

@ -986,7 +986,7 @@ static void Disaster_CoalMine_Init()
{ {
TileIndex tile = i->xy; TileIndex tile = i->xy;
TileIndexDiff step = TileOffsByDiagDir(GB(Random(), 0, 2)); TileIndexDiff step = TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
uint n; uint n;
for (n = 0; n < 30; n++) { for (n = 0; n < 30; n++) {

View File

@ -6,6 +6,7 @@
#define MAP_H #define MAP_H
#include "stdafx.h" #include "stdafx.h"
#include "direction.h"
extern uint _map_tile_mask; extern uint _map_tile_mask;
@ -190,17 +191,19 @@ static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
uint TileAddWrap(TileIndex tile, int addx, int addy); uint TileAddWrap(TileIndex tile, int addx, int addy);
static inline TileIndexDiffC TileIndexDiffCByDiagDir(uint dir) { static inline TileIndexDiffC TileIndexDiffCByDiagDir(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 _tileoffs_by_diagdir[dir]; return _tileoffs_by_diagdir[dir];
} }
/* Returns tile + the diff given in diff. If the result tile would end up /* Returns tile + the diff given in diff. If the result tile would end up
* outside of the map, INVALID_TILE is returned instead. * 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 x = TileX(tile) + diff.x;
int y = TileY(tile) + diff.y; int y = TileY(tile) + diff.y;
if (x < 0 || y < 0 || x > (int)MapMaxX() || y > (int)MapMaxY()) 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); \ } 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]); 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]); return ToTileIndexDiff(_tileoffs_by_dir[dir]);
} }

View File

@ -53,13 +53,13 @@ struct PlayerAI {
TileIndex start_tile_a; TileIndex start_tile_a;
TileIndex cur_tile_a; TileIndex cur_tile_a;
byte cur_dir_a; DiagDirectionByte cur_dir_a;
byte start_dir_a; DiagDirectionByte start_dir_a;
TileIndex start_tile_b; TileIndex start_tile_b;
TileIndex cur_tile_b; TileIndex cur_tile_b;
byte cur_dir_b; DiagDirectionByte cur_dir_b;
byte start_dir_b; DiagDirectionByte start_dir_b;
Vehicle *cur_veh; ///< only used by some states Vehicle *cur_veh; ///< only used by some states
@ -77,8 +77,8 @@ struct Ai_PathFinderInfo {
TileIndex start_tile_br; ///< br = bottom-right TileIndex start_tile_br; ///< br = bottom-right
TileIndex end_tile_tl; ///< tl = top-left TileIndex end_tile_tl; ///< tl = top-left
TileIndex end_tile_br; ///< br = bottom-right TileIndex end_tile_br; ///< br = bottom-right
byte start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION DiagDirection start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
byte end_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION DiagDirection end_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
TileIndex route[500]; TileIndex route[500];
byte route_extra[500]; ///< Some extra information about the route like bridge/tunnel byte route_extra[500]; ///< Some extra information about the route like bridge/tunnel
@ -127,8 +127,8 @@ struct PlayerAiNew {
TileIndex from_tile; TileIndex from_tile;
TileIndex to_tile; TileIndex to_tile;
byte from_direction; DiagDirectionByte from_direction;
byte to_direction; DiagDirectionByte to_direction;
bool from_deliver; ///< True if this is the station that GIVES cargo bool from_deliver; ///< True if this is the station that GIVES cargo
bool to_deliver; bool to_deliver;

View File

@ -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]; (_opt.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking][v->u.road.frame + 1];
if (rd.x & RDE_NEXT_TILE) { 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; Trackdir dir;
uint32 r; uint32 r;
Direction newdir; Direction newdir;

View File

@ -2,7 +2,7 @@
struct AiDefaultBlockData { struct AiDefaultBlockData {
byte mode; byte mode;
byte attr; DiagDirection attr;
TileIndexDiffC tileoffs; TileIndexDiffC tileoffs;
}; };
@ -22,11 +22,11 @@ struct AiDefaultRoadBlock {
#define MKHDR(a, b, c, d, e) a, b, c, d, e, #define MKHDR(a, b, c, d, e) a, b, c, d, e,
#define MKDEPOT(a, b, c) {0, a, {b, c}} #define MKDEPOT(a, b, c) {0, (DiagDirection)a, {b, c}}
#define MKSTATION(a, b, c) {1, a, {b, c}} #define MKSTATION(a, b, c) {1, (DiagDirection)a, {b, c}}
#define MKRAIL(a, b, c) {2, a, {b, c}} #define MKRAIL(a, b, c) {2, (DiagDirection)a, {b, c}}
#define MKCLRRAIL(a, b, c) {3, a, {b, c}} #define MKCLRRAIL(a, b, c) {3, (DiagDirection)a, {b, c}}
#define MKEND {4, 0, {0, 0}} #define MKEND {4, (DiagDirection)0, {0, 0}}
static const AiDefaultBlockData _raildata_ai_0_data[] = { static const AiDefaultBlockData _raildata_ai_0_data[] = {
MKDEPOT(2, -1, 1), MKDEPOT(2, -1, 1),
@ -555,38 +555,50 @@ static const AiDefaultRoadBlock * const _road_default_block_data[] = {
NULL 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[] = { static const AiDefaultBlockData _airportdata_ai_0[] = {
MKAIR(1, 0, 0), MKAIR(1, 0, 0),
{1, 0, {0, 0}}, MKEND(),
}; };
static const AiDefaultBlockData _airportdata_ai_1[] = { static const AiDefaultBlockData _airportdata_ai_1[] = {
MKAIR(0, 0, 0), MKAIR(0, 0, 0),
{1, 0, {0, 0}} MKEND(),
}; };
static const AiDefaultBlockData _airportdata_ai_3[] = { static const AiDefaultBlockData _airportdata_ai_3[] = {
MKAIR(3, 0, 0), MKAIR(3, 0, 0),
{1, 0, {0, 0}}, MKEND(),
}; };
static const AiDefaultBlockData _airportdata_ai_4[] = { static const AiDefaultBlockData _airportdata_ai_4[] = {
MKAIR(4, 0, 0), MKAIR(4, 0, 0),
{1, 0, {0, 0}}, MKEND(),
}; };
static const AiDefaultBlockData _airportdata_ai_5[] = { static const AiDefaultBlockData _airportdata_ai_5[] = {
MKAIR(5, 0, 0), MKAIR(5, 0, 0),
{1, 0, {0, 0}}, MKEND(),
}; };
static const AiDefaultBlockData _airportdata_ai_7[] = { static const AiDefaultBlockData _airportdata_ai_7[] = {
MKAIR(7, 0, 0), MKAIR(7, 0, 0),
{1, 0, {0, 0}} MKEND(),
}; };
#undef MKAIR
#undef MDEND
static const AiDefaultBlockData * const _airport_default_block_data[] = { static const AiDefaultBlockData * const _airport_default_block_data[] = {
_airportdata_ai_7, // intercontinental airport _airportdata_ai_7, // intercontinental airport
_airportdata_ai_4, // international airport _airportdata_ai_4, // international airport

View File

@ -560,7 +560,7 @@ static void TileLoop_Trees(TileIndex tile)
case 2: { /* add a neighbouring tree */ case 2: { /* add a neighbouring tree */
TreeType treetype = GetTreeType(tile); TreeType treetype = GetTreeType(tile);
tile += TileOffsByDir(Random() & 7); tile += TileOffsByDir((Direction)(Random() & 7));
if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return; if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return;