Mercurial > hg > openttd
changeset 3644:1aeabc9a0335 draft
(svn r4553) int and magic numbers -> Slope and DiagDirection
author | tron <tron@openttd.org> |
---|---|
date | Sun, 23 Apr 2006 19:08:33 +0000 |
parents | 25fe7b69e90e |
children | 42fd7728359e |
files | ai/default/default.c ai/trolly/pathfinder.c ai/trolly/shared.c ai/trolly/trolly.c ai/trolly/trolly.h |
diffstat | 5 files changed, 38 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/ai/default/default.c +++ b/ai/default/default.c @@ -1603,7 +1603,7 @@ } } else if (p->mode == 3) { //Clear stuff and then build single rail. - if (GetTileSlope(c,NULL) != 0) + if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR; ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR); if (CmdFailed(ret)) return CMD_ERROR; @@ -1675,7 +1675,7 @@ { PlayerID old_player; uint32 r; - uint slope; + Slope slope; uint h; old_player = _current_player; @@ -1698,7 +1698,7 @@ slope = GetTileSlope(tile, &h); - if (slope != 0) { + if (slope != SLOPE_FLAT) { if (mode > 0 || (mode == 0 && !(r & 0xC))) { // Terraform up DoCommand(tile, _terraform_up_flags[slope - 1], 1, @@ -1920,14 +1920,14 @@ static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p) { TileIndex tile_new; - uint tileh; + Slope tileh; uint z; bool flag; int dir2 = p[0] & 3; tileh = GetTileSlope(tile, &z); - if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) { + if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { tile_new = tile; // Allow bridges directly over bottom tiles flag = z == 0; @@ -1938,7 +1938,7 @@ tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2)); type = GetTileType(tile_new); - if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != 0) { + if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) { if (!flag) return; break; } @@ -2586,7 +2586,7 @@ } else if (p->mode == 3) { if (flag & DC_EXEC) continue; - if (GetTileSlope(c, NULL) != 0) return CMD_ERROR; + if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR; if (!IsTileType(c, MP_STREET) || GetRoadType(c) != ROAD_NORMAL) { ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR); @@ -2828,14 +2828,14 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p) { TileIndex tile_new; - uint tileh; + Slope tileh; uint z; bool flag; int dir2 = p[0] & 3; tileh = GetTileSlope(tile, &z); - if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) { + if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { tile_new = tile; // Allow bridges directly over bottom tiles flag = z == 0; @@ -2846,7 +2846,7 @@ tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2)); type = GetTileType(tile_new); - if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != 0) { + if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != SLOPE_FLAT) { // Allow a bridge if either we have a tile that's water, rail or street, // or if we found an up tile. if (!flag) return;
--- a/ai/trolly/pathfinder.c +++ b/ai/trolly/pathfinder.c @@ -314,17 +314,15 @@ // Next step, check for bridges and tunnels if (current->path.parent != NULL && current->path.node.user_data[0] == 0) { // First we get the dir from this tile and his parent - int dir = AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile); + DiagDirection dir = AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile); // It means we can only walk with the track, so the bridge has to be in the same direction TileIndex tile = current->path.node.tile; TileIndex new_tile = tile; - uint tileh; - - tileh = GetTileSlope(tile, NULL); + Slope tileh = GetTileSlope(tile, NULL); // Bridges can only be build on land that is not flat // And if there is a road or rail blocking - if (tileh != 0 || + if (tileh != SLOPE_FLAT || (PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_STREET)) || (!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_RAILWAY))) { for (;;) { @@ -349,16 +347,16 @@ } // Next, check for tunnels! - // Tunnels can only be build with tileh of 3, 6, 9 or 12, depending on the direction + // Tunnels can only be built on slopes corresponding to the direction // For now, we check both sides for this tile.. terraforming gives fuzzy result - if ((dir == 0 && tileh == 12) || - (dir == 1 && tileh == 6) || - (dir == 2 && tileh == 3) || - (dir == 3 && tileh == 9)) { + if ((dir == DIAGDIR_NE && tileh == SLOPE_NE) || + (dir == DIAGDIR_SE && tileh == SLOPE_SE) || + (dir == DIAGDIR_SW && tileh == SLOPE_SW) || + (dir == DIAGDIR_NW && tileh == SLOPE_NW)) { // Now simply check if a tunnel can be build ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL); tileh = GetTileSlope(_build_tunnel_endtile, NULL); - if (!CmdFailed(ret) && (tileh == 3 || tileh == 6 || tileh == 9 || tileh == 12)) { + if (!CmdFailed(ret) && (tileh == SLOPE_SW || tileh == SLOPE_SE || tileh == SLOPE_NW || tileh == SLOPE_NE)) { aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile; aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8); aystar->neighbours[aystar->num_neighbours++].direction = 0; @@ -368,9 +366,9 @@ } -extern uint GetRailFoundation(uint tileh, TrackBits bits); -extern uint GetRoadFoundation(uint tileh, uint bits); -extern uint GetBridgeFoundation(uint tileh, Axis); // XXX function declaration in .c +extern uint GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c +extern uint GetRoadFoundation(Slope tileh, uint bits); // XXX function declaration in .c +extern uint GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c enum { BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, }; @@ -380,8 +378,8 @@ { Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target; int r, res = 0; - uint tileh = GetTileSlope(current->tile, NULL); - uint parent_tileh = GetTileSlope(parent->path.node.tile, NULL); + Slope tileh = GetTileSlope(current->tile, NULL); + Slope parent_tileh = GetTileSlope(parent->path.node.tile, NULL); // Check if we hit the end-tile if (TILES_BETWEEN(current->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) { @@ -411,13 +409,13 @@ // when there is a flat land all around, they are more expensive to build, and // especially they essentially block the ability to connect or cross the road // from one side. - if (parent_tileh != 0 && parent->path.parent != NULL) { + if (parent_tileh != SLOPE_FLAT && parent->path.parent != NULL) { // Skip if the tile was from a bridge or tunnel if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) { if (PathFinderInfo->rail_or_road) { r = GetRailFoundation(parent_tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); // Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information.. - if (r >= 15 || (r == 0 && (BRIDGE_NO_FOUNDATION & (1 << tileh)))) { + if (r >= 15 || (r == 0 && HASBIT(BRIDGE_NO_FOUNDATION, tileh))) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; } else { res += AI_PATHFINDER_FOUNDATION_PENALTY; @@ -448,17 +446,17 @@ res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile); // Check if we are going up or down, first for the starting point // In user_data[0] is at the 8th bit the direction - if (!(BRIDGE_NO_FOUNDATION & (1 << parent_tileh))) { + if (!HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh)) { if (GetBridgeFoundation(parent_tileh, (current->user_data[0] >> 8) & 1) < 15) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } // Second for the end point - if (!(BRIDGE_NO_FOUNDATION & (1 << tileh))) { + if (!HASBIT(BRIDGE_NO_FOUNDATION, tileh)) { if (GetBridgeFoundation(tileh, (current->user_data[0] >> 8) & 1) < 15) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } - if (parent_tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; - if (tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; + if (parent_tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; + if (tileh == SLOPE_FLAT) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } // To prevent the AI from taking the fastest way in tiles, but not the fastest way
--- a/ai/trolly/shared.c +++ b/ai/trolly/shared.c @@ -79,12 +79,12 @@ } // Get's the direction between 2 tiles seen from tile_a -int AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b) +DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b) { - if (TileY(tile_a) < TileY(tile_b)) return 1; - if (TileY(tile_a) > TileY(tile_b)) return 3; - if (TileX(tile_a) < TileX(tile_b)) return 2; - return 0; + if (TileY(tile_a) < TileY(tile_b)) return DIAGDIR_SE; + if (TileY(tile_a) > TileY(tile_b)) return DIAGDIR_NW; + if (TileX(tile_a) < TileX(tile_b)) return DIAGDIR_SW; + return DIAGDIR_NE; } // This functions looks up if this vehicle is special for this AI
--- a/ai/trolly/trolly.c +++ b/ai/trolly/trolly.c @@ -838,8 +838,8 @@ if (IsTileType(tile, MP_TUNNELBRIDGE)) continue; // Is the terrain clear? if (IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)) { - // If the current tile is on a slope (tileh != 0) then we do not allow this - if (GetTileSlope(tile, NULL) != 0) continue; + // If the current tile is on a slope then we do not allow this + if (GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; // Check if everything went okay.. r = AiNew_Build_Depot(p, t, ReverseDiagDir(j), 0); if (CmdFailed(r)) continue;
--- a/ai/trolly/trolly.h +++ b/ai/trolly/trolly.h @@ -245,7 +245,7 @@ // ai_shared.c int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c); int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c); -int AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b); +DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b); bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag); uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);