summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/api/ai_road.cpp18
-rw-r--r--src/road_cmd.cpp45
2 files changed, 24 insertions, 39 deletions
diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp
index 7c6663157..784ca69b7 100644
--- a/src/ai/api/ai_road.cpp
+++ b/src/ai/api/ai_road.cpp
@@ -193,21 +193,9 @@ static RoadBits NeighbourToRoadBits(int32 neighbour)
*/
static int32 LookupWithBuildOnSlopes(::Slope slope, Array *existing, int32 start, int32 end)
{
- if (::IsSteepSlope(slope)) {
- switch (slope) {
- /* On steep slopes one can only build straight roads that will be
- * automatically expanded to a straight road. Just check that the existing
- * road parts are in the same direction. */
- case SLOPE_STEEP_S:
- case SLOPE_STEEP_W:
- case SLOPE_STEEP_N:
- case SLOPE_STEEP_E:
- return CheckAutoExpandedRoadBits(existing, start, end) ? (existing->size == 0 ? 2 : 1) : 0;
-
- /* All other slopes are invalid slopes!. */
- default:
- return -1;
- }
+ /* Steep slopes behave the same as slopes with one corner raised. */
+ if (IsSteepSlope(slope)) {
+ slope = SlopeWithOneCornerRaised(GetHighestSlopeCorner(slope));
}
/* The slope is not steep. Furthermore lots of slopes are generally the
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index e9276e809..e2df5d950 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -254,7 +254,13 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
switch (GetRoadTileType(tile)) {
case ROAD_TILE_NORMAL: {
- const Slope tileh = GetTileSlope(tile, NULL);
+ Slope tileh = GetTileSlope(tile, NULL);
+
+ /* Steep slopes behave the same as slopes with one corner raised. */
+ if (IsSteepSlope(tileh)) {
+ tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
+ }
+
RoadBits present = GetRoadBits(tile, rt);
const RoadBits other = GetOtherRoadBits(tile, rt);
const Foundation f = GetRoadFoundation(tileh, present);
@@ -262,11 +268,9 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
/* Autocomplete to a straight road
- * @li on steep slopes
* @li if the bits of the other roadtypes result in another foundation
* @li if build on slopes is disabled */
- if (IsSteepSlope(tileh) || (IsStraightRoad(other) &&
- (other & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) != ROAD_NONE) ||
+ if ((IsStraightRoad(other) && (other & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) != ROAD_NONE) ||
(tileh != SLOPE_FLAT && !_settings_game.construction.build_on_slopes)) {
pieces |= MirrorRoadBits(pieces);
}
@@ -383,19 +387,9 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi
/* All RoadBit combos are valid on flat land */
if (tileh == SLOPE_FLAT) return CommandCost();
- /* Proceed steep Slopes first to reduce lookup table size */
+ /* Steep slopes behave the same as slopes with one corner raised. */
if (IsSteepSlope(tileh)) {
- /* Force straight roads. */
- *pieces |= MirrorRoadBits(*pieces);
-
- /* Use existing as all existing since only straight
- * roads are allowed here. */
- existing |= other;
-
- if ((existing == ROAD_NONE || existing == *pieces) && IsStraightRoad(*pieces)) {
- return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
- }
- return CMD_ERROR;
+ tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
}
/* Save the merge of all bits of the current type */
@@ -1033,16 +1027,19 @@ static Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
/* Flat land and land without a road doesn't require a foundation */
if (tileh == SLOPE_FLAT || bits == ROAD_NONE) return FOUNDATION_NONE;
- if (!IsSteepSlope(tileh)) {
- /* Leveled RoadBits on a slope */
- if ((_invalid_tileh_slopes_road[0][tileh] & bits) == ROAD_NONE) return FOUNDATION_LEVELED;
-
- /* Straight roads without foundation on a slope */
- if (!IsSlopeWithOneCornerRaised(tileh) &&
- (_invalid_tileh_slopes_road[1][tileh] & bits) == ROAD_NONE)
- return FOUNDATION_NONE;
+ /* Steep slopes behave the same as slopes with one corner raised. */
+ if (IsSteepSlope(tileh)) {
+ tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
}
+ /* Leveled RoadBits on a slope */
+ if ((_invalid_tileh_slopes_road[0][tileh] & bits) == ROAD_NONE) return FOUNDATION_LEVELED;
+
+ /* Straight roads without foundation on a slope */
+ if (!IsSlopeWithOneCornerRaised(tileh) &&
+ (_invalid_tileh_slopes_road[1][tileh] & bits) == ROAD_NONE)
+ return FOUNDATION_NONE;
+
/* Roads on steep Slopes or on Slopes with one corner raised */
return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
}