Loading

Paste #p2fjj0a2y

  1. commit cb6ba38d1367b0edbdb1662a57d3e9425e7316ed
  2. Author: frosch <frosch@openttd.org>
  3. Date:   Sun Oct 30 13:52:45 2016 +0100
  4.  
  5.     -Add: Drawing of road/tram with overlays.
  6.  
  7. diff --git a/src/road.h b/src/road.h
  8. index 00fd231..f94523d 100644
  9. --- a/src/road.h
  10. +++ b/src/road.h
  11. @@ -198,6 +198,11 @@ struct RoadtypeInfo {
  12.      * Sprite groups for resolving sprites
  13.      */
  14.     const SpriteGroup *group[ROTSG_END];
  15. +
  16. +   inline bool UsesOverlay() const
  17. +   {
  18. +       return this->group[ROTSG_GROUND] != NULL;
  19. +   }
  20.  };
  21.  
  22.  struct RoadTypeIdentifier {
  23. diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
  24. index c7da9e6..bc45cb9 100644
  25. --- a/src/road_cmd.cpp
  26. +++ b/src/road_cmd.cpp
  27. @@ -1373,6 +1373,27 @@ static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int
  28.     AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z);
  29.  }
  30.  
  31. +static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
  32. +{
  33. +   if (slope != SLOPE_FLAT) {
  34. +       switch (slope) {
  35. +           case SLOPE_NE: return 11;
  36. +           case SLOPE_SE: return 12;
  37. +           case SLOPE_SW: return 13;
  38. +           case SLOPE_NW: return 14;
  39. +           default: NOT_REACHED();
  40. +       }
  41. +   } else {
  42. +       static const uint offsets[] = {
  43. +           0, 18, 17, 7,
  44. +           16, 0, 10, 5,
  45. +           15, 8, 1, 4,
  46. +           9, 3, 6, 2
  47. +       };
  48. +       return offsets[bits];
  49. +   }
  50. +}
  51. +
  52.  /**
  53.   * Draw ground sprite and road pieces
  54.   * @param ti TileInfo
  55. @@ -1385,29 +1406,20 @@ static void DrawRoadBits(TileInfo *ti)
  56.     const RoadtypeInfo* road_rti = GetRoadTypeInfo(GetRoadTypeRoad(ti->tile));
  57.     const RoadtypeInfo* tram_rti = GetRoadTypeInfo(GetRoadTypeTram(ti->tile));
  58.  
  59. -   SpriteID image = 0;
  60. -   PaletteID pal = PAL_NONE;
  61. -
  62.     if (ti->tileh != SLOPE_FLAT) {
  63.         DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
  64. -
  65. -       /* DrawFoundation() modifies ti.
  66. -        * Default sloped sprites.. */
  67. -       if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + SPR_ROAD_SLOPE_START;
  68. +       /* DrawFoundation() modifies ti. */
  69.     }
  70.  
  71. -   if (image == 0) {
  72. -       if (road != ROAD_NONE) {
  73. -           image = road_rti->base_sprites.roadbits[road];
  74. -       } else {
  75. -           image = tram_rti->base_sprites.roadbits[tram];
  76. -       }
  77. -   }
  78. +   /* Determine sprite offsets */
  79. +   uint road_offset = GetRoadSpriteOffset(ti->tileh, road);
  80. +   uint tram_offset = GetRoadSpriteOffset(ti->tileh, tram);
  81.  
  82. -   //if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
  83. +   /* Draw baseset underlay */
  84. +   SpriteID image = SPR_ROAD_Y + (road != ROAD_NONE ? road_offset : tram_offset);
  85. +   PaletteID pal = PAL_NONE;
  86.  
  87.     Roadside roadside = GetRoadside(ti->tile);
  88. -
  89.     if (DrawRoadAsSnowDesert(ti->tile, roadside)) {
  90.         image += 19;
  91.     } else {
  92. @@ -1421,45 +1433,58 @@ static void DrawRoadBits(TileInfo *ti)
  93.  
  94.     DrawGroundSprite(image, pal);
  95.  
  96. -   /* For tram we overlay the road graphics with either tram tracks only
  97. -    * (when there is actual road beneath the trams) or with tram tracks
  98. -    * and some dirts which hides the road graphics */
  99. -   //if (tram != ROAD_NONE) {
  100. -   //  if (ti->tileh != SLOPE_FLAT) {
  101. -   //      image = _road_sloped_sprites[ti->tileh - 1] + SPR_TRAMWAY_SLOPED_OFFSET;
  102. -   //  } else {
  103. -   //      image = _road_tile_sprites_1[tram] - SPR_ROAD_Y;
  104. -   //  }
  105. -   //  image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
  106. -   //  DrawGroundSprite(image, pal);
  107. -   //}
  108. -
  109. -   if (tram != ROAD_NONE) {
  110. -       if (ti->tileh != SLOPE_FLAT) {
  111. -           image = _road_sloped_sprites[ti->tileh - 1] + tram_rti->base_sprites.slopes_offset;
  112. +   /* Draw roadtype underlay */
  113. +   if (road != ROAD_NONE) {
  114. +       /* If road exists, then the underlay is provided by the road */
  115. +       if (road_rti->UsesOverlay()) {
  116. +           SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_GROUND);
  117. +           DrawGroundSprite(ground + road_offset, PAL_NONE);
  118. +       }
  119. +   } else {
  120. +       /* Tram only draws underlay if there is no road */
  121. +       if (tram_rti->UsesOverlay()) {
  122. +           SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_GROUND);
  123. +           DrawGroundSprite(ground + tram_offset, PAL_NONE);
  124.         } else {
  125. -           image = tram_rti->base_sprites.roadbits[tram] - SPR_ROAD_Y;
  126. +           DrawGroundSprite(SPR_TRAMWAY_TRAM + tram_offset, PAL_NONE);
  127.         }
  128. -       image += (road == ROAD_NONE) ? SPR_TRAMWAY_TRAM : SPR_TRAMWAY_OVERLAY;
  129. -       DrawGroundSprite(image, pal);
  130.     }
  131.  
  132. +   /* Draw road overlay */
  133.     if (road != ROAD_NONE) {
  134. +       if (road_rti->UsesOverlay()) {
  135. +           SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_OVERLAY);
  136. +           DrawGroundSprite(ground + road_offset, PAL_NONE);
  137. +       }
  138. +   }
  139. +
  140. +   /* Draw tram overlay */
  141. +   if (tram != ROAD_NONE) {
  142. +       if (tram_rti->UsesOverlay()) {
  143. +           SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_OVERLAY);
  144. +           DrawGroundSprite(ground + tram_offset, PAL_NONE);
  145. +       } else if (road != ROAD_NONE) {
  146. +           DrawGroundSprite(SPR_TRAMWAY_OVERLAY + tram_offset, PAL_NONE);
  147. +       }
  148. +   }
  149. +
  150. +   /* Draw one way */
  151. +   if (road != ROAD_NONE) { // TODO custom oneway?
  152.         DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
  153.         if (drd != DRD_NONE) {
  154.             DrawGroundSpriteAt(road_rti->base_sprites.road_oneway_base + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
  155. -           //DrawGroundSpriteAt(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
  156. +           //DrawGroundSpriteAt(SPR_ONEWAY_BASE + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh)); // TODO revert
  157.         }
  158.     }
  159.  
  160.     if (HasRoadWorks(ti->tile)) {
  161.         /* Road works */
  162.         DrawGroundSprite((road | tram) & ROAD_X ? road_rti->base_sprites.road_excavation_x : road_rti->base_sprites.road_excavation_y, PAL_NONE);
  163. -       //DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
  164. +       //DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE); // TODO revert
  165.         return;
  166.     }
  167.  
  168. -   if (HasCatenary(ti->tile)) DrawTramCatenary(ti, tram);
  169. +   if (HasCatenary(ti->tile)) DrawTramCatenary(ti, tram); // TODO catenary flag for roadtype TODO draw only one catenary, road takes precendence
  170.  
  171.     /* Return if full detail is disabled, or we are zoomed fully out. */
  172.     if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
  173.  

Comments