(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
tron 18 years ago
parent 4ccdb04cd3
commit 5f943a4ba7

@ -214,6 +214,17 @@ void DrawFoundation(TileInfo *ti, uint f)
OffsetGroundSprite(31, 1);
} else {
// inclined foundation
if (IsSteepSlope(ti->tileh)) {
uint32 lower_base;
// Lower part of foundation
lower_base = sprite_base;
if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
AddSortableSpriteToDraw(
lower_base + (ti->tileh & ~SLOPE_STEEP), ti->x, ti->y, 16, 16, 7, ti->z
);
ti->z += TILE_HEIGHT;
}
AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
ti->tileh = _inclined_tileh[f - 15];
OffsetGroundSprite(31, 9);

@ -154,8 +154,10 @@ uint GetRailFoundation(Slope tileh, TrackBits bits)
{
uint i;
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0;
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh;
if (!IsSteepSlope(tileh)) {
if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0;
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh;
}
switch (bits) {
case TRACK_BIT_X: i = 0; break;
@ -163,11 +165,15 @@ uint GetRailFoundation(Slope tileh, TrackBits bits)
default: return 0;
}
switch (tileh) {
case SLOPE_W: i += 0; break;
case SLOPE_S: i += 2; break;
case SLOPE_E: i += 4; break;
case SLOPE_N: i += 6; break;
default: return 0;
case SLOPE_W:
case SLOPE_STEEP_W: i += 0; break;
case SLOPE_S:
case SLOPE_STEEP_S: i += 2; break;
case SLOPE_E:
case SLOPE_STEEP_E: i += 4; break;
case SLOPE_N:
case SLOPE_STEEP_N: i += 6; break;
default: return 0;
}
return i + 15;
}
@ -175,8 +181,12 @@ uint GetRailFoundation(Slope tileh, TrackBits bits)
static uint32 CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
{
// never allow building on top of steep tiles
if (!IsSteepSlope(tileh)) {
if (IsSteepSlope(tileh)) {
if (existing == 0 &&
(rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y)) {
return _price.terraform;
}
} else {
rail_bits |= existing;
// don't allow building on the lower side of a coast
@ -1702,7 +1712,11 @@ static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y)
uint f = GetRailFoundation(tileh, GetTrackBits(tile));
if (f != 0) {
if (f < 15) return z + TILE_HEIGHT; // leveled foundation
if (IsSteepSlope(tileh)) {
z += TILE_HEIGHT;
} else if (f < 15) {
return z + TILE_HEIGHT; // leveled foundation
}
tileh = _inclined_tileh[f - 15]; // inclined foundation
}
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);

@ -243,7 +243,15 @@ static uint32 CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
{
RoadBits road_bits;
if (IsSteepSlope(tileh)) return CMD_ERROR;
if (IsSteepSlope(tileh)) {
if (existing == 0) {
// force full pieces.
*pieces |= (*pieces & 0xC) >> 2;
*pieces |= (*pieces & 0x3) << 2;
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
}
return CMD_ERROR;
}
road_bits = *pieces | existing;
// no special foundation
@ -354,11 +362,6 @@ int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
case MP_TUNNELBRIDGE:
/* check for flat land */
if (IsSteepSlope(tileh)) {
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
}
if (!IsBridge(tile) || !IsBridgeMiddle(tile)) goto do_clear;
/* only allow roads pertendicular to bridge */
@ -659,7 +662,10 @@ uint GetRoadFoundation(Slope tileh, RoadBits bits)
uint i;
// normal level sloped building
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return tileh;
if (!IsSteepSlope(tileh) &&
(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) {
return tileh;
}
// inclined sloped building
switch (bits) {
@ -668,11 +674,15 @@ uint GetRoadFoundation(Slope tileh, RoadBits bits)
default: return 0;
}
switch (tileh) {
case SLOPE_W: i += 0; break;
case SLOPE_S: i += 2; break;
case SLOPE_E: i += 4; break;
case SLOPE_N: i += 6; break;
default: return 0;
case SLOPE_W:
case SLOPE_STEEP_W: i += 0; break;
case SLOPE_S:
case SLOPE_STEEP_S: i += 2; break;
case SLOPE_E:
case SLOPE_STEEP_E: i += 4; break;
case SLOPE_N:
case SLOPE_STEEP_N: i += 6; break;
default: return 0;
}
return i + 15;
}
@ -839,7 +849,11 @@ static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y)
uint f = GetRoadFoundation(tileh, GetRoadBits(tile));
if (f != 0) {
if (f < 15) return z + TILE_HEIGHT; // leveled foundation
if (IsSteepSlope(tileh)) {
z += TILE_HEIGHT;
} else if (f < 15) {
return z + TILE_HEIGHT; // leveled foundation
}
tileh = _inclined_tileh[f - 15]; // inclined foundation
}
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);

@ -38,14 +38,14 @@ static const int _AutorailTilehSprite[][6] = {
{ 0, 1, 2, 3, 4, 5 }, // invalid (20)
{ 0, 1, 2, 3, 4, 5 }, // invalid (21)
{ 0, 1, 2, 3, 4, 5 }, // invalid (22)
{ RED(6), RED(11), RED(17), RED(27), RED(39), RED(47) }, // tileh = 23
{ 6, 11, RED(17), RED(27), RED(39), RED(47) }, // tileh = 23
{ 0, 1, 2, 3, 4, 5 }, // invalid (24)
{ 0, 1, 2, 3, 4, 5 }, // invalid (25)
{ 0, 1, 2, 3, 4, 5 }, // invalid (26)
{ RED(7), RED(15), RED(24), RED(33), RED(36), RED(44) }, // tileh = 27
{ 7, 15, RED(24), RED(33), RED(36), RED(44) }, // tileh = 27
{ 0, 1, 2, 3, 4, 5 }, // invalid (28)
{ RED(3), RED(14), RED(18), RED(26), RED(41), RED(49) }, // tileh = 29
{ RED(4), RED(12), RED(21), RED(30), RED(37), RED(45) }, // tileh = 30
{ 3, 14, RED(18), RED(26), RED(41), RED(49) }, // tileh = 29
{ 4, 12, RED(21), RED(30), RED(37), RED(45) } // tileh = 30
};
#undef RED

@ -118,8 +118,8 @@ static int32 CheckBridgeSlopeNorth(Axis axis, Slope tileh)
if (HASBIT(valid, tileh)) return 0;
valid =
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) |
(axis == AXIS_X ? M(SLOPE_E) : M(SLOPE_W));
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
if (HASBIT(valid, tileh)) return _price.terraform;
return CMD_ERROR;
@ -133,8 +133,8 @@ static int32 CheckBridgeSlopeSouth(Axis axis, Slope tileh)
if (HASBIT(valid, tileh)) return 0;
valid =
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) |
(axis == AXIS_X ? M(SLOPE_W) : M(SLOPE_E));
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
if (HASBIT(valid, tileh)) return _price.terraform;
return CMD_ERROR;
@ -245,11 +245,13 @@ int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
tileh_start = GetTileSlope(tile_start, &z_start);
tileh_end = GetTileSlope(tile_end, &z_end);
if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT;
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
z_start += TILE_HEIGHT;
tileh_start = SLOPE_FLAT;
}
if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT;
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
z_end += TILE_HEIGHT;
tileh_end = SLOPE_FLAT;
@ -596,7 +598,10 @@ static uint GetBridgeHeightRamp(TileIndex t)
uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
// one height level extra if the ramp is on a flat foundation
return h + TILE_HEIGHT + (IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0);
return
h + TILE_HEIGHT +
(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
}
@ -832,10 +837,10 @@ uint GetBridgeHeight(TileIndex t)
return GetBridgeHeightRamp(GetSouthernBridgeEnd(t));
}
static const byte _bridge_foundations[2][16] = {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{0,16,18,3,20,5,0,7,22,0,10,11,12,13,14},
{0,15,17,0,19,5,6,7,21,9,10,11, 0,13,14},
static const byte _bridge_foundations[][31] = {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 _S _W _N _E
{ 0,16,18, 3,20, 5, 0, 7,22, 0,10,11,12,13,14, 0, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 0,16, 0,22,20 },
{ 0,15,17, 0,19, 5, 6, 7,21, 9,10,11, 0,13,14, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0,15, 0,21,19 }
};
extern const byte _road_sloped_sprites[14];
@ -890,11 +895,15 @@ uint GetBridgeFoundation(Slope tileh, Axis axis)
// inclined sloped building
switch (tileh) {
case SLOPE_W: i = 0; break;
case SLOPE_S: i = 2; break;
case SLOPE_E: i = 4; break;
case SLOPE_N: i = 6; break;
default: return 0;
case SLOPE_W:
case SLOPE_STEEP_W: i = 0; break;
case SLOPE_S:
case SLOPE_STEEP_S: i = 2; break;
case SLOPE_E:
case SLOPE_STEEP_E: i = 4; break;
case SLOPE_N:
case SLOPE_STEEP_N: i = 6; break;
default: return 0;
}
if (axis != AXIS_X) ++i;
return i + 15;
@ -1103,6 +1112,7 @@ static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
if (5 <= pos && pos <= 10) {
uint delta;
if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
@ -1118,19 +1128,32 @@ static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
if (f != 0) {
if (f < 15) return z + TILE_HEIGHT;
if (IsSteepSlope(tileh)) {
z += TILE_HEIGHT;
} else if (f < 15) {
return z + TILE_HEIGHT;
}
tileh = _inclined_tileh[f - 15];
}
}
} else {
uint ground_z;
// HACK on the bridge?
if (_get_z_hint >= z + TILE_HEIGHT + (tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)) return _get_z_hint;
ground_z = z + TILE_HEIGHT;
if (tileh != SLOPE_FLAT) ground_z += TILE_HEIGHT;
if (IsSteepSlope(tileh)) ground_z += TILE_HEIGHT;
if (_get_z_hint >= ground_z) return _get_z_hint;
if (IsTransportUnderBridge(tile)) {
uint f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
if (f != 0) {
if (f < 15) return z + TILE_HEIGHT;
if (IsSteepSlope(tileh)) {
z += TILE_HEIGHT;
} else if (f < 15) {
return z + TILE_HEIGHT;
}
tileh = _inclined_tileh[f - 15];
}
}

Loading…
Cancel
Save