summaryrefslogtreecommitdiff
path: root/src/road_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-10-01 16:45:25 +0000
committerfrosch <frosch@openttd.org>2011-10-01 16:45:25 +0000
commit804090b317aad7c53a59ef68a40dd913f4618c95 (patch)
treec10c780495ededa468af0f8c3dc2476ff20a7c5b /src/road_cmd.cpp
parentbf12ba49877525ba4fe6f3eac6ad8d40c07ca2a3 (diff)
downloadopenttd-804090b317aad7c53a59ef68a40dd913f4618c95.tar.xz
(svn r22968) -Feature: Allow road corners on steep slopes.
Diffstat (limited to 'src/road_cmd.cpp')
-rw-r--r--src/road_cmd.cpp45
1 files changed, 21 insertions, 24 deletions
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);
}