|
@@ -228,60 +228,62 @@ int32 CmdBuildCanal(int x, int y, uint32
|
|
|
if (y < sy) intswap(y, sy);
|
|
|
size_x = (x - sx) + 1;
|
|
|
size_y = (y - sy) + 1;
|
|
|
|
|
|
/* Outside the editor you can only drag canals, and not areas */
|
|
|
if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
|
|
|
|
|
|
cost = 0;
|
|
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
|
|
if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
|
|
|
|
|
// can't make water of water!
|
|
|
if (IsTileType(tile, MP_WATER)) {
|
|
|
_error_message = STR_1007_ALREADY_BUILT;
|
|
|
} else {
|
|
|
if (IsTileType(tile, MP_WATER)) continue;
|
|
|
|
|
|
/* is middle piece of a bridge? */
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE) && _m[tile].m5 & 0x40) { /* build under bridge */
|
|
|
if (_m[tile].m5 & 0x20) // transport route under bridge
|
|
|
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
|
|
|
|
|
|
if (_m[tile].m5 & 0x18) { // already water under bridge
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
// change owner to OWNER_WATER and set land under bridge bit to water
|
|
|
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
|
|
|
}
|
|
|
} else {
|
|
|
/* no bridge, try to clear it. */
|
|
|
int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
|
|
if (CmdFailed(ret)) return ret;
|
|
|
cost += ret;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
MakeWater(tile);
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) MarkTilesAroundDirty(tile);
|
|
|
|
|
|
cost += _price.clear_water;
|
|
|
}
|
|
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
|
|
|
|
|
return (cost == 0) ? CMD_ERROR : cost;
|
|
|
if (cost == 0) {
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
} else {
|
|
|
return cost;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static int32 ClearTile_Water(TileIndex tile, byte flags)
|
|
|
{
|
|
|
byte m5 = _m[tile].m5;
|
|
|
|
|
|
if (m5 <= 1) { // water and shore
|
|
|
// Allow building on water? It's ok to build on shores.
|
|
|
if (flags & DC_NO_WATER && m5 != 1)
|
|
|
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
|
|
|
|
|
// Make sure no vehicle is on the tile
|