diff options
author | frosch <frosch@openttd.org> | 2008-01-22 16:08:17 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2008-01-22 16:08:17 +0000 |
commit | b99c83246b4029f91579712ae9044fa9e1f6b2c9 (patch) | |
tree | 78534c41444e96dbc9179ae15b7f8cbdddcaa1c4 /src/ai | |
parent | 7d1e3086b8dfb7ffdf75478e159ce90543a1ee6e (diff) | |
download | openttd-b99c83246b4029f91579712ae9044fa9e1f6b2c9.tar.xz |
(svn r11946) -Fix: slope detection of bridge ramps.
YAPF failed for steep slopes.
Trolly failed for a lot.
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/trolly/pathfinder.cpp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp index d3dcc96c2..caef80147 100644 --- a/src/ai/trolly/pathfinder.cpp +++ b/src/ai/trolly/pathfinder.cpp @@ -359,10 +359,6 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr extern Foundation GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c extern Foundation GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c -extern Foundation GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c -enum BridgeFoundation { - BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, -}; // The most important function: it calculates the g-value static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent) @@ -403,10 +399,10 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, 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) { + static const uint32 SLOPED_TILEHS = (1 << SLOPE_NW) | (1 << SLOPE_SW) | (1 << SLOPE_SE) | (1 << SLOPE_NE); if (PathFinderInfo->rail_or_road) { Foundation f = GetRailFoundation(parent_tileh, (TrackBits)(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 (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) { + if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(SLOPED_TILEHS, parent_tileh))) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; } else { res += AI_PATHFINDER_FOUNDATION_PENALTY; @@ -414,7 +410,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, } else { if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) { Foundation f = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); - if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(BRIDGE_NO_FOUNDATION, parent_tileh))) { + if (IsInclinedFoundation(f) || (!IsFoundation(f) && HasBit(SLOPED_TILEHS, parent_tileh))) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; } else { res += AI_PATHFINDER_FOUNDATION_PENALTY; @@ -439,19 +435,9 @@ 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 (!HasBit(BRIDGE_NO_FOUNDATION, parent_tileh)) { - if (IsLeveledFoundation(GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { - res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; - } - } + if (!HasBridgeFlatRamp(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; // Second for the end point - if (!HasBit(BRIDGE_NO_FOUNDATION, tileh)) { - if (IsLeveledFoundation(GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)))) { - 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; + if (!HasBridgeFlatRamp(tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } // To prevent the AI from taking the fastest way in tiles, but not the fastest way |