Loading

Paste #pkhj1fu6a

  1. diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
  2. index aa445eb..37e9f9c 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_button_clicked = HasBit(p1, 8);
  18.  
  19.     Slope tileh = GetTileSlope(tile);
  20.  
  21. @@ -778,6 +780,7 @@ do_clear:;
  22.  
  23.             default:
  24.                 MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, company, company);
  25. +               SetCatenary(tile, _catenary_button_clicked);
  26.                 break;
  27.         }
  28.  
  29. @@ -827,6 +830,7 @@ static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
  30.   * - p2 = (bit 6) - defines two different behaviors for this command:
  31.   *      - 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
  32.   *      - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts
  33. + * - p2 = (bit 7) - catenary
  34.   * @param text unused
  35.   * @return the cost of this operation or an error
  36.   */
  37. @@ -886,8 +890,8 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
  38.             if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
  39.             if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
  40.         }
  41. -
  42. -       CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
  43. +       bool _has_catenary = HasBit(p2, 7);
  44. +       CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits | _has_catenary << 8 , 0, flags, CMD_BUILD_ROAD);
  45.         if (ret.Failed()) {
  46.             last_error = ret;
  47.             if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
  48. @@ -1298,7 +1302,7 @@ static void DrawRoadBits(TileInfo *ti)
  49.         return;
  50.     }
  51.  
  52. -   if (tram != ROAD_NONE) DrawTramCatenary(ti, tram);
  53. +   if (HasCatenary(ti->tile)) DrawTramCatenary(ti, tram);
  54.  
  55.     /* Return if full detail is disabled, or we are zoomed fully out. */
  56.     if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
  57. @@ -1388,7 +1392,7 @@ static void DrawTile_Road(TileInfo *ti)
  58.  
  59.             if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
  60.                 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
  61. -               DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
  62. +               if (HasCatenary(ti->tile)) DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
  63.             }
  64.             if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti);
  65.             break;
  66. diff --git a/src/road_gui.cpp b/src/road_gui.cpp
  67. index 92c660e..5392940 100644
  68. --- a/src/road_gui.cpp
  69. +++ b/src/road_gui.cpp
  70. @@ -41,6 +41,7 @@ static void ShowRoadDepotPicker(Window *parent);
  71.  
  72.  static bool _remove_button_clicked;
  73.  static bool _one_way_button_clicked;
  74. +static bool _catenary_button_clicked;
  75.  
  76.  /**
  77.   * Define the values of the RoadFlags
  78. @@ -359,13 +360,15 @@ struct BuildRoadToolbarWindow : Window {
  79.      */
  80.     void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
  81.     {
  82. -       /* The remove and the one way button state is driven
  83. +       /* The remove and the one way / catenary buttons state is driven
  84.          * by the other buttons so they don't act on themselves.
  85. -        * Both are only valid if they are able to apply as options. */
  86. +        * They are only valid if they are able to apply as options. */
  87.         switch (clicked_widget) {
  88.             case WID_ROT_REMOVE:
  89.                 this->RaiseWidget(WID_ROT_ONE_WAY);
  90.                 this->SetWidgetDirty(WID_ROT_ONE_WAY);
  91. +               this->RaiseWidget(WID_ROT_CATENARY);
  92. +               this->SetWidgetDirty(WID_ROT_CATENARY);
  93.                 break;
  94.  
  95.             case WID_ROT_ONE_WAY:
  96. @@ -373,6 +376,11 @@ struct BuildRoadToolbarWindow : Window {
  97.                 this->SetWidgetDirty(WID_ROT_REMOVE);
  98.                 break;
  99.  
  100. +           case WID_ROT_CATENARY:
  101. +               this->RaiseWidget(WID_ROT_REMOVE);
  102. +               this->SetWidgetDirty(WID_ROT_REMOVE);
  103. +               break;
  104. +
  105.             case WID_ROT_BUS_STATION:
  106.             case WID_ROT_TRUCK_STATION:
  107.                 this->DisableWidget(WID_ROT_ONE_WAY);
  108. @@ -385,6 +393,7 @@ struct BuildRoadToolbarWindow : Window {
  109.                 this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
  110.                         WID_ROT_REMOVE,
  111.                         WID_ROT_ONE_WAY,
  112. +                       WID_ROT_CATENARY,
  113.                         WIDGET_LIST_END);
  114.                 break;
  115.  
  116. @@ -394,10 +403,12 @@ struct BuildRoadToolbarWindow : Window {
  117.                 this->SetWidgetsDisabledState(true,
  118.                         WID_ROT_REMOVE,
  119.                         WID_ROT_ONE_WAY,
  120. +                       WID_ROT_CATENARY,
  121.                         WIDGET_LIST_END);
  122.                 this->SetWidgetsLoweredState(false,
  123.                         WID_ROT_REMOVE,
  124.                         WID_ROT_ONE_WAY,
  125. +                       WID_ROT_CATENARY,
  126.                         WIDGET_LIST_END);
  127.                 break;
  128.         }
  129. @@ -407,6 +418,7 @@ struct BuildRoadToolbarWindow : Window {
  130.     {
  131.         _remove_button_clicked = false;
  132.         _one_way_button_clicked = false;
  133. +       _catenary_button_clicked = false;
  134.         switch (widget) {
  135.             case WID_ROT_ROAD_X:
  136.                 HandlePlacePushButton(this, WID_ROT_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nwse, HT_RECT);
  137. @@ -459,6 +471,13 @@ struct BuildRoadToolbarWindow : Window {
  138.                 SetSelectionRed(false);
  139.                 break;
  140.  
  141. +           case WID_ROT_CATENARY:
  142. +               if (this->IsWidgetDisabled(WID_ROT_CATENARY)) return;
  143. +               this->SetDirty();
  144. +               this->ToggleWidgetLoweredState(WID_ROT_CATENARY);
  145. +               SetSelectionRed(false);
  146. +               break;
  147. +
  148.             case WID_ROT_BUILD_BRIDGE:
  149.                 HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
  150.                 this->last_started_action = widget;
  151. @@ -493,6 +512,7 @@ struct BuildRoadToolbarWindow : Window {
  152.     {
  153.         _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
  154.         _one_way_button_clicked = this->IsWidgetLowered(WID_ROT_ONE_WAY);
  155. +       _catenary_button_clicked = this->IsWidgetLowered(WID_ROT_CATENARY);
  156.         switch (this->last_started_action) {
  157.             case WID_ROT_ROAD_X:
  158.                 _place_road_flag = RF_DIR_X;
  159. @@ -549,9 +569,11 @@ struct BuildRoadToolbarWindow : Window {
  160.         this->SetWidgetsDisabledState(true,
  161.                 WID_ROT_REMOVE,
  162.                 WID_ROT_ONE_WAY,
  163. +               WID_ROT_CATENARY,
  164.                 WIDGET_LIST_END);
  165.         this->SetWidgetDirty(WID_ROT_REMOVE);
  166.         this->SetWidgetDirty(WID_ROT_ONE_WAY);
  167. +       this->SetWidgetDirty(WID_ROT_CATENARY);
  168.  
  169.         DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
  170.         DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
  171. @@ -626,7 +648,7 @@ struct BuildRoadToolbarWindow : Window {
  172.                      * not the 3rd bit set) */
  173.                     _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
  174.  
  175. -                   DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
  176. +                   DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5) | (_catenary_button_clicked << 7),
  177.                             _remove_button_clicked ?
  178.                             CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
  179.                             CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
  180. @@ -738,6 +760,8 @@ static const NWidgetPart _nested_build_road_widgets[] = {
  181.         NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
  182.         NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
  183.                         SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
  184. +       NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CATENARY),
  185. +                       SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
  186.         NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
  187.                         SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
  188.         NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
  189. @@ -778,6 +802,8 @@ static const NWidgetPart _nested_build_tramway_widgets[] = {
  190.                         SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
  191.         NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
  192.         NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY), SetMinimalSize(0, 0),
  193. +       NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CATENARY),
  194. +                       SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
  195.         NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
  196.                         SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
  197.         NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
  198. diff --git a/src/road_map.h b/src/road_map.h
  199. index 6937302..6baa446 100644
  200. --- a/src/road_map.h
  201. +++ b/src/road_map.h
  202. @@ -250,7 +250,10 @@ static inline bool HasTownOwnedRoad(TileIndex t)
  203.  {
  204.     return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
  205.  }
  206. -
  207. +static inline bool HasCatenary(TileIndex t)
  208. +{
  209. +   return GB(_m[t].m1, 7, 1);
  210. +}
  211.  /** Which directions are disallowed ? */
  212.  enum DisallowedRoadDirections {
  213.     DRD_NONE,       ///< None of the directions are disallowed
  214. @@ -286,6 +289,12 @@ static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirect
  215.     SB(_m[t].m5, 4, 2, drd);
  216.  }
  217.  
  218. +static inline void SetCatenary(TileIndex t, bool b)
  219. +{
  220. +   assert(IsNormalRoad(t));
  221. +   SB(_m[t].m1, 7, 1, b ? 1 : 0);
  222. +}
  223. +
  224.  /**
  225.   * Get the road axis of a level crossing.
  226.   * @param t The tile to query.
  227. diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
  228. index eb90c29..102fc15 100644
  229. --- a/src/station_cmd.cpp
  230. +++ b/src/station_cmd.cpp
  231. @@ -2902,7 +2902,7 @@ draw_default_foundation:
  232.     if (HasBit(roadtypes, ROADTYPE_TRAM)) {
  233.         Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
  234.         DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
  235. -       DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
  236. +       if (HasCatenary(ti->tile)) DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
  237.     }
  238.  
  239.     if (IsRailWaypoint(ti->tile)) {
  240. diff --git a/src/widgets/road_widget.h b/src/widgets/road_widget.h
  241. index f022489..09fc0ed 100644
  242. --- a/src/widgets/road_widget.h
  243. +++ b/src/widgets/road_widget.h
  244. @@ -23,6 +23,7 @@ enum RoadToolbarWidgets {
  245.     WID_ROT_BUS_STATION,    ///< Build bus station.
  246.     WID_ROT_TRUCK_STATION,  ///< Build truck station.
  247.     WID_ROT_ONE_WAY,        ///< Build one-way road.
  248. +   WID_ROT_CATENARY,       ///< Build catenary.
  249.     WID_ROT_BUILD_BRIDGE,   ///< Build bridge.
  250.     WID_ROT_BUILD_TUNNEL,   ///< Build tunnel.
  251.     WID_ROT_REMOVE,         ///< Remove road.

Comments