From 8ef2c13c65498dfc39cb80bd1c07589b747fe1e6 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 23 Apr 2006 19:08:33 +0000 Subject: (svn r4553) int and magic numbers -> Slope and DiagDirection --- ai/trolly/pathfinder.c | 42 ++++++++++++++++++++---------------------- ai/trolly/shared.c | 10 +++++----- ai/trolly/trolly.c | 4 ++-- ai/trolly/trolly.h | 2 +- 4 files changed, 28 insertions(+), 30 deletions(-) (limited to 'ai/trolly') diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c index 79ea878c3..09027454c 100644 --- a/ai/trolly/pathfinder.c +++ b/ai/trolly/pathfinder.c @@ -314,17 +314,15 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr // 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 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr } // 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 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr } -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 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, { 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 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, // 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 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, 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 diff --git a/ai/trolly/shared.c b/ai/trolly/shared.c index 4b33a13a5..c745f31f6 100644 --- a/ai/trolly/shared.c +++ b/ai/trolly/shared.c @@ -79,12 +79,12 @@ int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c) } // 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 diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c index 29ae7b9f2..257990164 100644 --- a/ai/trolly/trolly.c +++ b/ai/trolly/trolly.c @@ -838,8 +838,8 @@ static void AiNew_State_FindDepot(Player *p) 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; diff --git a/ai/trolly/trolly.h b/ai/trolly/trolly.h index acf371896..8100aacff 100644 --- a/ai/trolly/trolly.h +++ b/ai/trolly/trolly.h @@ -245,7 +245,7 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo // 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); -- cgit v1.2.3-54-g00ecf