239 { /* Check if tunnel or track would take damage */ |
239 { /* Check if tunnel or track would take damage */ |
240 int count; |
240 int count; |
241 TileIndex *ti = ts.tile_table; |
241 TileIndex *ti = ts.tile_table; |
242 |
242 |
243 for (count = ts.tile_table_count; count != 0; count--, ti++) { |
243 for (count = ts.tile_table_count; count != 0; count--, ti++) { |
244 uint a, b, c, d, r, min; |
244 uint a, b, c, d, min; |
|
245 Slope s; |
245 TileIndex tile = *ti; |
246 TileIndex tile = *ti; |
246 |
247 |
247 _terraform_err_tile = tile; |
248 _terraform_err_tile = tile; |
248 |
249 |
249 a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
250 a = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
250 b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
251 b = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
251 c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
252 c = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
252 d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
253 d = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
253 |
254 |
254 r = GetTileh(a, b, c, d, &min); |
255 s = GetTileh(a, b, c, d, &min); |
255 |
256 |
256 if (IsTileType(tile, MP_RAILWAY)) { |
257 if (IsTileType(tile, MP_RAILWAY)) { |
257 if (IsSteepSlope(r)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
258 if (IsSteepSlope(s)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
258 |
259 |
259 if (IsPlainRailTile(tile)) { |
260 if (IsPlainRailTile(tile)) { |
|
261 /* We need to check if a rail is on a leveled foundation and |
|
262 * then treat it as such. Important for correct tunneling */ |
260 extern const TrackBits _valid_tileh_slopes[2][15]; |
263 extern const TrackBits _valid_tileh_slopes[2][15]; |
261 if (GetTrackBits(tile) & ~_valid_tileh_slopes[0][r]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
264 TrackBits tb = GetTrackBits(tile); |
|
265 uint foundation = (GetRailFoundation(s, tb) == 0) ? 1 : 0; |
|
266 |
|
267 if (tb & ~_valid_tileh_slopes[foundation][s]) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
262 } else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
268 } else return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
263 } |
269 } |
264 |
270 |
265 if (direction == -1 && IsTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
271 if (direction == -1 && IsTunnelInWay(tile, min)) return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
266 |
272 |