Loading

Paste #pdxvxbyaw

  1. /**
  2.  * Draw canal or river edges.
  3.  * @param canal  True if canal edges should be drawn, false for river edges.
  4.  * @param offset Sprite offset.
  5.  * @param tile   Tile to draw.
  6.  */
  7. static void DrawWaterEdges(bool canal, uint offset, TileIndex tile)
  8. {
  9.     CanalFeature feature;
  10.     SpriteID base = 0;
  11.     if (canal) {
  12.         feature = CF_DIKES;
  13.         base = GetCanalSprite(CF_DIKES, tile);
  14.         if (base == 0) base = SPR_CANAL_DIKES_BASE;
  15.     } else {
  16.         feature = CF_RIVER_EDGE;
  17.         base = GetCanalSprite(CF_RIVER_EDGE, tile);
  18.         if (base == 0) return; // Don't draw if no sprites provided.
  19.     }
  20.  
  21.     uint wa;
  22.  
  23.     /* determine the edges around with water. */
  24.     wa  = IsWateredTile(TILE_ADDXY(tile, -1,  0), DIR_SW) << 0;  // NE
  25.     wa += IsWateredTile(TILE_ADDXY(tile,  0,  1), DIR_NW) << 1;  // SE
  26.     wa += IsWateredTile(TILE_ADDXY(tile,  1,  0), DIR_NE) << 2;  // SW
  27.     wa += IsWateredTile(TILE_ADDXY(tile,  0, -1), DIR_SE) << 3;  // NW
  28.  
  29.     Slope tileh = GetTileSlope(tile);
  30.     if (!(wa & 1)) {
  31.         DrawWaterSprite(base, offset, feature, tile);
  32.         if (tileh == SLOPE_N) DrawWaterSprite(base, offset + 48, feature, tile);
  33.         if (tileh == SLOPE_E) DrawWaterSprite(base, offset + 12, feature, tile);
  34.     }
  35.     if (!(wa & 2)) {
  36.         DrawWaterSprite(base, offset + 1, feature, tile);
  37.         if (tileh == SLOPE_E) DrawWaterSprite(base, offset + 25, feature, tile);
  38.         if (tileh == SLOPE_S) DrawWaterSprite(base, offset + 37, feature, tile);
  39.     }
  40.     if (!(wa & 4)) {
  41.         DrawWaterSprite(base, offset + 2, feature, tile);
  42.         if (tileh == SLOPE_S) DrawWaterSprite(base, offset + 14, feature, tile);
  43.         if (tileh == SLOPE_W) DrawWaterSprite(base, offset + 50, feature, tile);
  44.     }
  45.     if (!(wa & 8)) {
  46.         DrawWaterSprite(base, offset + 3, feature, tile);
  47.         if (tileh == SLOPE_W) DrawWaterSprite(base, offset + 39, feature, tile);
  48.         if (tileh == SLOPE_N) DrawWaterSprite(base, offset + 27, feature, tile);
  49.     }
  50.  
  51.     /* right corner */
  52.     switch (wa & 0x03) {
  53.         case 0: DrawWaterSprite(base, offset + 4, feature, tile); break;
  54.         case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1), DIR_W)) DrawWaterSprite(base, offset + 8, feature, tile); break;
  55.     }
  56.  
  57.     /* bottom corner */
  58.     switch (wa & 0x06) {
  59.         case 0: DrawWaterSprite(base, offset + 5, feature, tile); break;
  60.         case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1), DIR_N)) DrawWaterSprite(base, offset + 9, feature, tile); break;
  61.     }
  62.  
  63.     /* left corner */
  64.     switch (wa & 0x0C) {
  65.         case  0: DrawWaterSprite(base, offset + 6, feature, tile); break;
  66.         case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1), DIR_E)) DrawWaterSprite(base, offset + 10, feature, tile); break;
  67.     }
  68.  
  69.     /* upper corner */
  70.     switch (wa & 0x09) {
  71.         case 0: DrawWaterSprite(base, offset + 7, feature, tile); break;
  72.         case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1), DIR_S)) DrawWaterSprite(base, offset + 11, feature, tile); break;
  73.     }
  74. }

Comments