Loading

Paste #prvlugqkf

  1. diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
  2. index aa445eb..819bc1d 100644
  3. --- a/src/road_cmd.cpp
  4. +++ b/src/road_cmd.cpp
  5. @@ -477,6 +477,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi
  6.   * @param p1 bit 0..3 road pieces to build (RoadBits)
  7.   *           bit 4..5 road type
  8.   *           bit 6..7 disallowed directions to toggle
  9. + *           bit 8 catenary
  10.   * @param p2 the town that is building the road (0 if not applicable)
  11.   * @param text unused
  12.   * @return the cost of this operation or an error
  13. @@ -515,6 +516,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
  14.     if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
  15.  
  16.     DisallowedRoadDirections toggle_drd = Extract<DisallowedRoadDirections, 6, 2>(p1);
  17. +    bool _catenary_flag = HasBit(p1, 8);
  18.  
  19.     Slope tileh = GetTileSlope(tile);
  20.  
  21. @@ -759,6 +761,8 @@ do_clear:;
  22.                 SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
  23.                 SetRoadOwner(other_end, rt, company);
  24.                 SetRoadOwner(tile, rt, company);
  25. +                SetCatenary(other_end, _catenary_flag);
  26. +                SetCatenary(tile, _catenary_flag);
  27.  
  28.                 /* Mark tiles dirty that have been repaved */
  29.                 if (IsBridge(tile)) {
  30. @@ -794,7 +798,7 @@ do_clear:;
  31.             SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ?
  32.                     GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
  33.         }
  34. -
  35. +        SetCatenary(tile, _catenary_flag);
  36.         MarkTileDirtyByTile(tile);
  37.     }
  38.     return cost;
  39. @@ -827,6 +831,7 @@ static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
  40.   * - p2 = (bit 6) - defines two different behaviors for this command:
  41.   *      - 0 = Build up to an obstacle. Do not build the first and last roadbits unless they can be connected to something, or if we are building a single tile
  42.   *      - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts
  43. + * - p2 = (bit 7) - catenary
  44.   * @param text unused
  45.   * @return the cost of this operation or an error
  46.   */
  47. @@ -886,8 +891,8 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
  48.             if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
  49.             if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
  50.         }
  51. -
  52. -       CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
  53. +       bool _has_catenary = HasBit(p2, 7);
  54. +       CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits | _has_catenary << 8 , 0, flags, CMD_BUILD_ROAD);
  55.         if (ret.Failed()) {
  56.             last_error = ret;
  57.             if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
  58. @@ -1298,7 +1303,7 @@ static void DrawRoadBits(TileInfo *ti)
  59.         return;
  60.     }
  61.  
  62. -   if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
  63. +   if (HasCatenary(ti->tile)) DrawTramCatenary(ti, tram);
  64.  
  65.     /* Return if full detail is disabled, or we are zoomed fully out. */
  66.     if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
  67. @@ -1388,7 +1393,7 @@ static void DrawTile_Road(TileInfo *ti)
  68.  
  69.             if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
  70.                 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
  71. -               DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
  72. +               if (HasCatenary(ti->tile)) DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
  73.             }
  74.             if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
  75.             break;
  76. diff --git a/src/road_gui.cpp b/src/road_gui.cpp
  77. index 92c660e..982e85c 100644
  78. --- a/src/road_gui.cpp
  79. +++ b/src/road_gui.cpp
  80. @@ -60,6 +60,7 @@ DECLARE_ENUM_AS_BIT_SET(RoadFlags)
  81.  static RoadFlags _place_road_flag;
  82.  
  83.  static RoadType _cur_roadtype;
  84. +bool _catenary_flag;
  85.  
  86.  static DiagDirection _road_depot_orientation;
  87.  static DiagDirection _road_station_picker_orientation;
  88. @@ -626,7 +627,7 @@ struct BuildRoadToolbarWindow : Window {
  89.                      * not the 3rd bit set) */
  90.                     _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
  91.  
  92. -                   DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
  93. +                   DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5) | (_catenary_flag << 7),
  94.                             _remove_button_clicked ?
  95.                             CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
  96.                             CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
  97. @@ -802,10 +803,11 @@ static WindowDesc _build_tramway_desc(
  98.   *
  99.   * @return newly opened road toolbar, or NULL if the toolbar could not be opened.
  100.   */
  101. -Window *ShowBuildRoadToolbar(RoadType roadtype)
  102. +Window *ShowBuildRoadToolbar(RoadType roadtype, bool catenary_flag)
  103.  {
  104.     if (!Company::IsValidID(_local_company)) return NULL;
  105.     _cur_roadtype = roadtype;
  106. +    _catenary_flag = catenary_flag;
  107.  
  108.     DeleteWindowByClass(WC_BUILD_TOOLBAR);
  109.     return AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
  110. diff --git a/src/road_gui.h b/src/road_gui.h
  111. index c56443c..dd61ce9 100644
  112. --- a/src/road_gui.h
  113. +++ b/src/road_gui.h
  114. @@ -16,7 +16,7 @@
  115.  #include "tile_type.h"
  116.  #include "direction_type.h"
  117.  
  118. -struct Window *ShowBuildRoadToolbar(RoadType roadtype);
  119. +struct Window *ShowBuildRoadToolbar(RoadType roadtype, bool catenary_flag = false);
  120.  struct Window *ShowBuildRoadScenToolbar();
  121.  void ConnectRoadToStructure(TileIndex tile, DiagDirection direction);
  122.  
  123. diff --git a/src/road_map.h b/src/road_map.h
  124. index 6937302..6baa446 100644
  125. --- a/src/road_map.h
  126. +++ b/src/road_map.h
  127. @@ -250,7 +250,10 @@ static inline bool HasTownOwnedRoad(TileIndex t)
  128.  {
  129.     return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
  130.  }
  131. -
  132. +static inline bool HasCatenary(TileIndex t)
  133. +{
  134. +   return GB(_m[t].m1, 7, 1);
  135. +}
  136.  /** Which directions are disallowed ? */
  137.  enum DisallowedRoadDirections {
  138.     DRD_NONE,       ///< None of the directions are disallowed
  139. @@ -286,6 +289,12 @@ static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirect
  140.     SB(_m[t].m5, 4, 2, drd);
  141.  }
  142.  
  143. +static inline void SetCatenary(TileIndex t, bool b)
  144. +{
  145. +   assert(IsNormalRoad(t));
  146. +   SB(_m[t].m1, 7, 1, b ? 1 : 0);
  147. +}
  148. +
  149.  /**
  150.   * Get the road axis of a level crossing.
  151.   * @param t The tile to query.
  152. diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
  153. index eb90c29..102fc15 100644
  154. --- a/src/station_cmd.cpp
  155. +++ b/src/station_cmd.cpp
  156. @@ -2902,7 +2902,7 @@ draw_default_foundation:
  157.     if (HasBit(roadtypes, ROADTYPE_TRAM)) {
  158.         Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
  159.         DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
  160. -       DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
  161. +       if (HasCatenary(ti->tile)) DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
  162.     }
  163.  
  164.     if (IsRailWaypoint(ti->tile)) {
  165. diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
  166. index 45d751d..0f28fbd 100644
  167. --- a/src/toolbar_gui.cpp
  168. +++ b/src/toolbar_gui.cpp
  169. @@ -891,7 +891,8 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w)
  170.     DropDownList *list = new DropDownList();
  171.  
  172.     /* Road is always visible and available. */
  173. -   *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false);
  174. +   *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, 0, false);
  175. +   *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, 1, false);
  176.  
  177.     /* Tram is only visible when there will be a tram, and available when that has been introduced. */
  178.     Engine *e;
  179. @@ -899,7 +900,8 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w)
  180.         if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
  181.         if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
  182.  
  183. -       *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
  184. +       *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, 2, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
  185. +       *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, 3, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
  186.         break;
  187.     }
  188.     ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true);
  189. @@ -915,8 +917,19 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w)
  190.   */
  191.  static CallBackFunction MenuClickBuildRoad(int index)
  192.  {
  193. -   _last_built_roadtype = (RoadType)index;
  194. -   ShowBuildRoadToolbar(_last_built_roadtype);
  195. +    bool _catenary_flag = false;
  196. +    if (index == 0) {
  197. +       _last_built_roadtype = (RoadType)ROADTYPE_ROAD;
  198. +    } else if (index == 1) {
  199. +       _last_built_roadtype = (RoadType)ROADTYPE_ROAD;
  200. +       _catenary_flag = true;
  201. +    } else if (index == 2) {
  202. +       _last_built_roadtype = (RoadType)ROADTYPE_TRAM;
  203. +    } else if (index == 3) {
  204. +       _last_built_roadtype = (RoadType)ROADTYPE_TRAM;
  205. +       _catenary_flag = true;
  206. +   }
  207. +   ShowBuildRoadToolbar(_last_built_roadtype, _catenary_flag);
  208.     return CBF_NONE;
  209.  }
  210.  
  211. diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
  212. index 5f2534b..cdd576b 100644
  213. --- a/src/tunnelbridge_cmd.cpp
  214. +++ b/src/tunnelbridge_cmd.cpp
  215. @@ -1087,7 +1087,7 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis
  216.   * @param overlay do we want to still see the road?
  217.   * @param head    are we drawing bridge head?
  218.   */
  219. -static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bool head)
  220. +static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bool head, bool has_catenary)
  221.  {
  222.     static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
  223.     static const SpriteID back_offsets[6]    =   {  95,  96,  99, 102, 100, 101 };
  224. @@ -1107,7 +1107,7 @@ static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bo
  225.     }
  226.  
  227.     /* Do not draw catenary if it is set invisible */
  228. -   if (!IsInvisibilitySet(TO_CATENARY)) {
  229. +   if (has_catenary && !IsInvisibilitySet(TO_CATENARY)) {
  230.         AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE,
  231.             x, y, size_x[offset], size_y[offset], 0x28, z,
  232.             IsTransparencySet(TO_CATENARY));
  233. @@ -1118,7 +1118,7 @@ static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bo
  234.     StartSpriteCombine();
  235.  
  236.     /* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
  237. -   if (!IsInvisibilitySet(TO_CATENARY)) {
  238. +   if (has_catenary && !IsInvisibilitySet(TO_CATENARY)) {
  239.         AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE,
  240.             x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
  241.             IsTransparencySet(TO_CATENARY), front_bb_offset_x[offset], front_bb_offset_y[offset]);
  242. @@ -1193,7 +1193,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
  243.                 DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE);
  244.  
  245.                 /* Do not draw wires if they are invisible */
  246. -               if (!IsInvisibilitySet(TO_CATENARY)) {
  247. +               if (HasCatenary(ti->tile) && !IsInvisibilitySet(TO_CATENARY)) {
  248.                     catenary = true;
  249.                     StartSpriteCombine();
  250.                     AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
  251. @@ -1303,7 +1303,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
  252.                     offset += 2;
  253.                 }
  254.                 /* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
  255. -               DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true);
  256. +               DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true, HasCatenary(ti->tile));
  257.             }
  258.             EndSpriteCombine();
  259.         } else if (transport_type == TRANSPORT_RAIL) {
  260. @@ -1466,7 +1466,7 @@ void DrawBridgeMiddle(const TileInfo *ti)
  261.  
  262.         if (HasBit(rts, ROADTYPE_TRAM)) {
  263.             /* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
  264. -           DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false);
  265. +           DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false, HasCatenary(ti->tile));
  266.         } else {
  267.             EndSpriteCombine();
  268.             StartSpriteCombine();

Comments