From fc32e2019561f398c193f6e510e8482797303021 Mon Sep 17 00:00:00 2001 From: celestar Date: Mon, 20 Mar 2006 16:43:48 +0000 Subject: (svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed. Fixes a bug where you could terraform a tunnel (fixed by r3228, but reverted that one) Fixes a bug introduced by r3228 which allowed steep rail tiles resulting in ... unwanted effects such as display artifacts. That means the terraform feature should not work as intended; it also uses _valid_tileh_slopes to determine valid configurations instead of hand-brewn stuff. TODO: _terraform_err_tile and similar TileIndices should have INVALID_TILE as "unused", not 0. (0 is a valid tile). --- clear_cmd.c | 60 ++++++++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 38 deletions(-) (limited to 'clear_cmd.c') diff --git a/clear_cmd.c b/clear_cmd.c index c7142bb56..364e7733b 100644 --- a/clear_cmd.c +++ b/clear_cmd.c @@ -88,38 +88,13 @@ static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) { int r; - bool skip_clear = false; assert(tile < MapSize()); if ((r=TerraformAllowTileProcess(ts, tile)) <= 0) return r; - if (IsTileType(tile, MP_RAILWAY)) { - static const TrackBits _railway_modes[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT }; - static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb}; - static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4}; - - // Nothing could be built at the steep slope - this avoids a bug - // when you have a single diagonal track in one corner on a - // basement and then you raise/lower the other corner. - int tileh = GetTileSlope(tile, NULL) & 0xF; - if (tileh == _railway_dangslopes[mode] || - tileh == _railway_dangslopes2[mode]) { - _terraform_err_tile = tile; - _error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK; - return -1; - } - - // If we have a single diagonal track there, the other side of - // tile can be terraformed. - if (IsPlainRailTile(tile) && GetTrackBits(tile) == _railway_modes[mode]) { - if (ts->direction == 1) return 0; - skip_clear = true; - } - } - - if (!skip_clear) { + if (!IsTileType(tile, MP_RAILWAY)) { int32 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); if (CmdFailed(ret)) { @@ -261,26 +236,35 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) return CMD_ERROR; } - if (direction == -1) { - /* Check if tunnel would take damage */ + { /* Check if tunnel or track would take damage */ int count; TileIndex *ti = ts.tile_table; for (count = ts.tile_table_count; count != 0; count--, ti++) { - uint z, t; + uint a, b, c, d, r, min; TileIndex tile = *ti; - z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); - t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); - if (t <= z) z = t; - t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); - if (t <= z) z = t; - t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); - if (t <= z) z = t; + _terraform_err_tile = tile; + + a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); + b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); + c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); + d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); + + r = GetTileh(a, b, c, d, &min); - if (IsTunnelInWay(tile, z * 8)) { - return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); + if (IsTileType(tile, MP_RAILWAY)) { + if (IsSteepTileh(r)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); + + if (IsPlainRailTile(tile)) { + extern const TrackBits _valid_tileh_slopes[2][15]; + if (GetTrackBits(tile) & ~_valid_tileh_slopes[0][r]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); + } else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); } + + if (direction == -1 && IsTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); + + _terraform_err_tile = 0; } } -- cgit v1.2.3-54-g00ecf