Loading

Paste #p1rsgdcxb

  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. }
  75.  
  76.  
  77. static void DrawRiverWater(const TileInfo *ti)
  78. {
  79.     SpriteID image = SPR_FLAT_WATER_TILE;
  80.     uint     offset = 0;
  81.     uint     edges_offset = 0;
  82.  
  83.     if (ti->tileh != SLOPE_FLAT || HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
  84.         image = GetCanalSprite(CF_RIVER_SLOPE, ti->tile);
  85.         if (image == 0) {
  86.             switch (ti->tileh) {
  87.                 case SLOPE_NW: image = SPR_WATER_SLOPE_Y_DOWN; break;
  88.                 case SLOPE_SW: image = SPR_WATER_SLOPE_X_UP;   break;
  89.                 case SLOPE_SE: image = SPR_WATER_SLOPE_Y_UP;   break;
  90.                 case SLOPE_NE: image = SPR_WATER_SLOPE_X_DOWN; break;
  91.                 default:       image = SPR_FLAT_WATER_TILE;    break;
  92.             }
  93.         } else {
  94.             /* Flag bit 0 indicates that the first sprite is flat water. */
  95.             offset = HasBit(_water_feature[CF_RIVER_SLOPE].flags, CFF_HAS_FLAT_SPRITE) ? 1 : 0;
  96.  
  97.             switch (ti->tileh) {
  98.                 case SLOPE_SE:              edges_offset += 12; break;
  99.                 case SLOPE_NE: offset += 1; edges_offset += 24; break;
  100.                 case SLOPE_SW: offset += 2; edges_offset += 36; break;
  101.                 case SLOPE_NW: offset += 3; edges_offset += 48; break;
  102.                 case SLOPE_E:  offset  = 0; edges_offset = 0; break;
  103.                 case SLOPE_S:  offset  = 0; edges_offset = 0; break;
  104.                 case SLOPE_W:  offset  = 0; edges_offset = 0; break;
  105.                 case SLOPE_N:  offset  = 0; edges_offset = 0; break;
  106.                 default:       offset  = 0; break;
  107.             }
  108.  
  109.             offset = GetCanalSpriteOffset(CF_RIVER_SLOPE, ti->tile, offset);
  110.         }
  111.     }
  112.  
  113.     DrawGroundSprite(image + offset, PAL_NONE);
  114.  
  115.     /* Draw river edges if available. */
  116.     DrawWaterEdges(false, edges_offset, ti->tile);
  117. }

Version history

Revision # Author Created at
pdxvxbyaw Anonymous 03 Apr 2016, 17:55:51 UTC Diff

Comments