74 ts->tile_table[ts->tile_table_count++] = tile; |
74 ts->tile_table[ts->tile_table_count++] = tile; |
75 } |
75 } |
76 |
76 |
77 static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
77 static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) |
78 { |
78 { |
79 TerraformAddDirtyTile(ts, tile+TILE_XY(0,-1)); |
79 TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); |
80 TerraformAddDirtyTile(ts, tile+TILE_XY(-1,-1)); |
80 TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); |
81 TerraformAddDirtyTile(ts, tile+TILE_XY(-1,0)); |
81 TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); |
82 TerraformAddDirtyTile(ts, tile); |
82 TerraformAddDirtyTile(ts, tile); |
83 } |
83 } |
84 |
84 |
85 static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
85 static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) |
86 { |
86 { |
150 |
150 |
151 nh = TerraformGetHeightOfTile(ts, tile); |
151 nh = TerraformGetHeightOfTile(ts, tile); |
152 if (nh < 0 || height == nh) |
152 if (nh < 0 || height == nh) |
153 return false; |
153 return false; |
154 |
154 |
155 if (TerraformProc(ts, tile, 0)<0) |
155 if (TerraformProc(ts, tile, 0) < 0) return false; |
156 return false; |
156 if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; |
157 |
157 if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false; |
158 if (TerraformProc(ts, tile + TILE_XY(0,-1), 1)<0) |
158 if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false; |
159 return false; |
|
160 |
|
161 if (TerraformProc(ts, tile + TILE_XY(-1,-1), 2)<0) |
|
162 return false; |
|
163 |
|
164 if (TerraformProc(ts, tile + TILE_XY(-1,0), 3)<0) |
|
165 return false; |
|
166 |
159 |
167 mod = ts->modheight; |
160 mod = ts->modheight; |
168 count = ts->modheight_count; |
161 count = ts->modheight_count; |
169 |
162 |
170 for(;;) { |
163 for(;;) { |
237 ts.tile_table = tile_table_data; |
230 ts.tile_table = tile_table_data; |
238 |
231 |
239 tile = TileVirtXY(x, y); |
232 tile = TileVirtXY(x, y); |
240 |
233 |
241 /* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
234 /* Make an extra check for map-bounds cause we add tiles to the originating tile */ |
242 if (tile + TILE_XY(1,1) > MapSize()) return CMD_ERROR; |
235 if (tile + TileDiffXY(1, 1) > MapSize()) return CMD_ERROR; |
243 |
236 |
244 if (p1 & 1) { |
237 if (p1 & 1) { |
245 if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0), |
238 if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0), |
246 TileHeight(tile + TILE_XY(1, 0)) + direction)) |
239 TileHeight(tile + TileDiffXY(1, 0)) + direction)) |
247 return CMD_ERROR; |
240 return CMD_ERROR; |
248 } |
241 } |
249 |
242 |
250 if (p1 & 2) { |
243 if (p1 & 2) { |
251 if (!TerraformTileHeight(&ts, tile+TILE_XY(1,1), |
244 if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1), |
252 TileHeight(tile + TILE_XY(1, 1)) + direction)) |
245 TileHeight(tile + TileDiffXY(1, 1)) + direction)) |
253 return CMD_ERROR; |
246 return CMD_ERROR; |
254 } |
247 } |
255 |
248 |
256 if (p1 & 4) { |
249 if (p1 & 4) { |
257 if (!TerraformTileHeight(&ts, tile+TILE_XY(0,1), |
250 if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1), |
258 TileHeight(tile + TILE_XY(0, 1)) + direction)) |
251 TileHeight(tile + TileDiffXY(0, 1)) + direction)) |
259 return CMD_ERROR; |
252 return CMD_ERROR; |
260 } |
253 } |
261 |
254 |
262 if (p1 & 8) { |
255 if (p1 & 8) { |
263 if (!TerraformTileHeight(&ts, tile+TILE_XY(0,0), |
256 if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0), |
264 TileHeight(tile + TILE_XY(0, 0)) + direction)) |
257 TileHeight(tile + TileDiffXY(0, 0)) + direction)) |
265 return CMD_ERROR; |
258 return CMD_ERROR; |
266 } |
259 } |
267 |
260 |
268 if (direction == -1) { |
261 if (direction == -1) { |
269 /* Check if tunnel would take damage */ |
262 /* Check if tunnel would take damage */ |
272 |
265 |
273 for (count = ts.tile_table_count; count != 0; count--, ti++) { |
266 for (count = ts.tile_table_count; count != 0; count--, ti++) { |
274 uint z, t; |
267 uint z, t; |
275 TileIndex tile = *ti; |
268 TileIndex tile = *ti; |
276 |
269 |
277 z = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,0)); |
270 z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); |
278 t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,0)); |
271 t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |
279 if (t <= z) z = t; |
272 if (t <= z) z = t; |
280 t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,1)); |
273 t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1)); |
281 if (t <= z) z = t; |
274 if (t <= z) z = t; |
282 t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,1)); |
275 t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); |
283 if (t <= z) z = t; |
276 if (t <= z) z = t; |
284 |
277 |
285 if (!CheckTunnelInWay(tile, z*8)) |
278 if (!CheckTunnelInWay(tile, z*8)) |
286 return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
279 return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); |
287 } |
280 } |
349 // make sure sx,sy are smaller than ex,ey |
342 // make sure sx,sy are smaller than ex,ey |
350 sx = TileX(p1); |
343 sx = TileX(p1); |
351 sy = TileY(p1); |
344 sy = TileY(p1); |
352 if (ex < sx) intswap(ex, sx); |
345 if (ex < sx) intswap(ex, sx); |
353 if (ey < sy) intswap(ey, sy); |
346 if (ey < sy) intswap(ey, sy); |
354 tile = TILE_XY(sx,sy); |
347 tile = TileXY(sx, sy); |
355 |
348 |
356 size_x = ex-sx+1; |
349 size_x = ex-sx+1; |
357 size_y = ey-sy+1; |
350 size_y = ey-sy+1; |
358 |
351 |
359 money = GetAvailableMoneyForCommand(); |
352 money = GetAvailableMoneyForCommand(); |
708 return; |
701 return; |
709 |
702 |
710 if (GetMapExtraBits(tile) == 1) { |
703 if (GetMapExtraBits(tile) == 1) { |
711 _map5[tile] = 0x17; |
704 _map5[tile] = 0x17; |
712 } else { |
705 } else { |
713 if (GetMapExtraBits(tile+TILE_XY(1,0)) != 1 && |
706 if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
714 GetMapExtraBits(tile+TILE_XY(-1,0)) != 1 && |
707 GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
715 GetMapExtraBits(tile+TILE_XY(0,1)) != 1 && |
708 GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
716 GetMapExtraBits(tile+TILE_XY(0,-1)) != 1) |
709 GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
717 return; |
710 return; |
718 _map5[tile] = 0x15; |
711 _map5[tile] = 0x15; |
719 } |
712 } |
720 |
713 |
721 MarkTileDirtyByTile(tile); |
714 MarkTileDirtyByTile(tile); |
722 } |
715 } |